📄 generationplan.java
字号:
/*
* The contents of this file are subject to the BT "ZEUS" Open Source
* Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
* except in compliance with the Licence. You may obtain a copy of the Licence
* from $ZEUS_INSTALL/licence.html or alternatively from
* http://www.labs.bt.com/projects/agents/zeus/licence.htm
*
* Except as stated in Clause 7 of the Licence, software distributed under the
* Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the Licence for the specific language governing rights and
* limitations under the Licence.
*
* The Original Code is within the package zeus.*.
* The Initial Developer of the Original Code is British Telecommunications
* public limited company, whose registered office is at 81 Newgate Street,
* London, EC1A 7AJ, England. Portions created by British Telecommunications
* public limited company are Copyright 1996-9. All Rights Reserved.
*
* THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
*/
package zeus.generator.code;
import java.util.*;
import javax.swing.event.*;
import zeus.util.*;
import zeus.concepts.*;
import zeus.generator.event.*;
import zeus.generator.*;
/*****************************************************************************
* GenerationPlan.java
*
* Underlying Model of the Zeus Agent Generator
* Change Log
*-----------
* Simon made some variables public
*****************************************************************************/
public class GenerationPlan
implements AgentListener, TaskListener, ChangeListener {
public static final String WINDOWS = "Windows";
public static final String UNIX = "Unix";
public static final String ZSH = "zsh";
public static final String NONE = "no shell";
public static final String SAVE_NEEDED = "Modified";
public static final String NO_SAVE_NEEDED = "Saved";
protected EventListenerList changeListeners = new EventListenerList();
protected Hashtable agentTable = new Hashtable();
protected Hashtable taskTable = new Hashtable();
protected Hashtable nameserverTable = new Hashtable();
protected Hashtable visualiserTable = new Hashtable();
protected Hashtable facilitatorTable = new Hashtable();
protected Hashtable dbProxyTable = new Hashtable();
protected String directory = System.getProperty("user.dir");
protected String platform = UNIX;
protected String shell = NONE;
protected GeneratorModel genmodel;
protected OntologyDb ontology;
public GenerationPlan(GeneratorModel genmodel, OntologyDb ontology) {
this.genmodel = genmodel;
this.ontology = ontology;
genmodel.addAgentListener(this);
genmodel.addTaskListener(this);
ontology.addChangeListener(this);
reset();
}
// why are these synchronized?
public synchronized void setPlatform(String input) {
if ( !input.equals(UNIX) && !input.equals(WINDOWS) ) {
System.err.println("Unknown platform");
return;
}
if ( platform != null && platform.equals(input) ) return;
platform = input;
recomputeOntologyFilePath();
recomputeSavedState();
fireChanged();
}
/**
set the shell selected by the user
*/
public void setShell (String input) {
if (input.equals (ZSH))
shell = input;
else
shell = NONE;
}
/**
should we generate scripts for a shell, or not? Which one?
*/
public String getShell() {
return shell;
}
public synchronized String getPlatform() {
return platform;
}
public synchronized void setDirectory(String input) {
if ( directory != null && directory.equals(input) ) return;
directory = input;
recomputeOntologyFilePath();
recomputeSavedState();
fireChanged();
}
public synchronized String getDirectory() {
return directory;
}
protected void recomputeSavedState() {
Enumeration enum;
AgentInfo agentInfo;
TaskInfo taskInfo;
enum = agentTable.elements();
while( enum.hasMoreElements() ) {
agentInfo = (AgentInfo)enum.nextElement();
agentInfo.generate = true;
agentInfo.status = SAVE_NEEDED;
}
enum = taskTable.elements();
while( enum.hasMoreElements() ) {
taskInfo = (TaskInfo)enum.nextElement();
taskInfo.generate = true;
taskInfo.status = SAVE_NEEDED;
}
}
protected void recomputeOntologyFilePath() {
Enumeration enum;
AgentInfo agentInfo;
FacilitatorInfo facilitatorInfo;
VisualiserInfo visualiserInfo;
String ontology_file = getOntologyFilename();
enum = agentTable.elements();
while( enum.hasMoreElements() ) {
agentInfo = (AgentInfo)enum.nextElement();
agentInfo.ontology_file = ontology_file;
}
enum = facilitatorTable.elements();
while( enum.hasMoreElements() ) {
facilitatorInfo = (FacilitatorInfo)enum.nextElement();
facilitatorInfo.ontology_file = ontology_file;
}
enum = visualiserTable.elements();
while( enum.hasMoreElements() ) {
visualiserInfo = (VisualiserInfo)enum.nextElement();
visualiserInfo.ontology_file = ontology_file;
}
}
public synchronized AgentInfo[] getAgents() {
AgentInfo[] out = new AgentInfo[agentTable.size()];
Enumeration enum = agentTable.elements();
for(int i = 0; i < out.length; i++ )
out[i] = (AgentInfo)enum.nextElement();
return out;
}
public synchronized void setAgent(AgentInfo info) {
info.icon_file = genmodel.getAgentIcon(info.id);
agentTable.put(info.id,info);
fireChanged();
}
public synchronized void setAgentIcon(AgentInfo info) {
genmodel.setAgentIcon(info.id,info.icon_file);
}
public synchronized TaskInfo[] getTasks() {
TaskInfo[] out = new TaskInfo[taskTable.size()];
Enumeration enum = taskTable.elements();
for(int i = 0; i < out.length; i++ )
out[i] = (TaskInfo)enum.nextElement();
return out;
}
public synchronized void setTask(TaskInfo info) {
taskTable.put(info.id,info);
fireChanged();
}
public synchronized TaskInfo[] getSelectedTasks() {
// return only tasks the are marked for generation;
Enumeration enum = taskTable.elements();
Vector results = new Vector();
TaskInfo info;
while( enum.hasMoreElements() ) {
info = (TaskInfo)enum.nextElement();
if ( info.generate ) results.addElement(info);
}
TaskInfo[] out = new TaskInfo[results.size()];
for(int i = 0; i < out.length; i++ )
out[i] = (TaskInfo)results.elementAt(i);
return out;
}
public synchronized AgentInfo[] getSelectedAgents() {
// return only tasks the are marked for generation;
Enumeration enum = agentTable.elements();
Vector results = new Vector();
AgentInfo info;
while( enum.hasMoreElements() ) {
info = (AgentInfo)enum.nextElement();
if ( info.generate ) results.addElement(info);
}
AgentInfo[] out = new AgentInfo[results.size()];
for(int i = 0; i < out.length; i++ )
out[i] = (AgentInfo)results.elementAt(i);
return out;
}
public synchronized NameserverInfo[] getNameservers() {
NameserverInfo[] out = new NameserverInfo[nameserverTable.size()];
Enumeration enum = nameserverTable.elements();
for(int i = 0; i < out.length; i++ )
out[i] = (NameserverInfo)enum.nextElement();
return out;
}
public synchronized void setNameserver(NameserverInfo info) {
nameserverTable.put(info.id,info);
fireChanged();
}
public synchronized void removeNameserver(String id) {
nameserverTable.remove(id);
fireChanged();
}
public synchronized void createNameserver() {
NameserverInfo info = new NameserverInfo();
nameserverTable.put(info.id,info);
fireChanged();
}
public synchronized FacilitatorInfo[] getFacilitators() {
FacilitatorInfo[] out = new FacilitatorInfo[facilitatorTable.size()];
Enumeration enum = facilitatorTable.elements();
for(int i = 0; i < out.length; i++ )
out[i] = (FacilitatorInfo)enum.nextElement();
return out;
}
public synchronized void setFacilitator(FacilitatorInfo info) {
facilitatorTable.put(info.id,info);
fireChanged();
}
public synchronized void removeFacilitator(String id) {
facilitatorTable.remove(id);
fireChanged();
}
public synchronized void createFacilitator() {
FacilitatorInfo info = new FacilitatorInfo(getOntologyFilename());
facilitatorTable.put(info.id,info);
fireChanged();
}
public synchronized VisualiserInfo[] getVisualisers() {
VisualiserInfo[] out = new VisualiserInfo[visualiserTable.size()];
Enumeration enum = visualiserTable.elements();
for(int i = 0; i < out.length; i++ )
out[i] = (VisualiserInfo)enum.nextElement();
return out;
}
public synchronized void setVisualiser(VisualiserInfo info) {
visualiserTable.put(info.id,info);
fireChanged();
}
public synchronized void removeVisualiser(String id) {
visualiserTable.remove(id);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -