⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servicedescriptionreceiver.java

📁 人工智能中Agent开发包。多 Agent 系统是处理自治 Agent 之间知识层的协作问题
💻 JAVA
字号:
package zeus.ontology.service;

import zeus.actors.AgentContext;
import zeus.util.SystemProps;
import zeus.concepts.Performative;

import java.io.*;

/**
 * Class to receive and write out the various elements of a service
 * description.
 */
public class ServiceDescriptionReceiver {

  private AgentContext context;

  public ServiceDescriptionReceiver(AgentContext context) {
    
    this.context = context;
  }

  public void serviceProfileReceived(Performative msg) {
    
    String serviceDir = SystemProps.getProperty("http_root");
    
    String profile = msg.getContent();
    profile = profile.substring(profile.indexOf(":serviceProfile")
				+ ":serviceProfile".length()).trim();
    
    profile = profile.substring(profile.indexOf("<"),
				profile.lastIndexOf(">") + 1);
    
    int nameBegin =
      profile.toLowerCase().indexOf("service:serviceprofile ");
    
    nameBegin = profile.toLowerCase().indexOf("rdf:id", nameBegin);
    nameBegin = profile.indexOf("\"", nameBegin) + 1;

    int nameEnd = profile.indexOf("\"", nameBegin);

    String name = profile.substring(nameBegin, nameEnd);

    File profileDir = new File(serviceDir + "\\services\\classes\\" +name);
    File profileFile = new File(profileDir.getPath() +
				"\\" + name + "Profile.daml");

    profileDir.mkdirs();
    write(profileFile, profile);
    
    //Send service profile to DF
    msg.setReceiver("df");
    msg.setContent(msg.getContent());
    msg.setInReplyTo(zeus.agents.Facilitator.SERVICE_KEY);
    context.MailBox().sendMsg(msg);
  }

  public void serviceInstanceReceived(Performative msg) {

    String serviceDir = SystemProps.getProperty("http_root");

    String description = msg.getContent();
    description = description.substring(description.indexOf(":serviceInstance")
					+ ":serviceInstance".length()).trim();

    description = description.substring(description.indexOf("<"),
					description.lastIndexOf(">") + 1);

    int nameBegin = description.toLowerCase().indexOf("service:service ");
    nameBegin = description.toLowerCase().indexOf("rdf:id", nameBegin);
    nameBegin = description.indexOf("\"", nameBegin) + 1;
    
    int nameEnd = description.indexOf("\"", nameBegin);

    String name = description.substring(nameBegin, nameEnd);

    File instanceDir = new File(serviceDir + "\\services\\instances\\" +
				name);
    File instanceFile = new File(instanceDir.getPath() + "\\" +
				 name + "Instance.daml");

    instanceDir.mkdirs();

    write(instanceFile, description);
  }


  public void serviceRangeReceived(Performative msg) {

    String serviceDir = SystemProps.getProperty("http_root");

    String description = msg.getContent();
    description = description.substring(description.indexOf(":serviceRange")
					+ ":serviceRange".length()).trim();

    String task = description.substring(description.indexOf(":task") +
					":task".length(),
					description.indexOf(":content")
					).trim();

    description = description.substring(description.indexOf("<"),
					description.lastIndexOf(">") + 1);

    String name = msg.getSender() + "__" + task;

    File instanceDir = new File(serviceDir + "\\services\\instances\\" +
				name);
    File instanceFile = new File(instanceDir.getPath() + "\\" +
				 name + "Range.xsd");

    instanceDir.mkdirs();
    write(instanceFile, description);
  }

  private boolean write(File file, String content) {

    try {
      FileWriter writer = new FileWriter(file);
      writer.write(content);
      writer.flush();
      writer.close();
      return true;
    }
    catch(IOException i) {
      i.printStackTrace();
      return false;
    }
  }

  public void processModelReceived(Performative msg) {
    
    String serviceDir = SystemProps.getProperty("http_root");
    
    String process = msg.getContent();
    process = process.substring(process.indexOf(":processModel")
				+ ":processModel".length()).trim();
    
    process = process.substring(process.indexOf("<"),
				process.lastIndexOf(">") + 1);
    
    int nameBegin =
      process.toLowerCase().indexOf("process:processmodel ");
    
    nameBegin = process.toLowerCase().indexOf("rdf:id", nameBegin);
    nameBegin = process.indexOf("\"", nameBegin) + 1;

    int nameEnd = process.indexOf("_", nameBegin);

    String name = process.substring(nameBegin, nameEnd);

    File processDir = new File(serviceDir + "\\services\\classes\\" +name);
    File processFile = new File(processDir.getPath() +
				"\\" + name + "Process.daml");

    processDir.mkdirs();
    write(processFile, process);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -