/* * Originally written by flying@cs.pitt.edu for VC server * Simplified and modified to serve as SIS Server by yaosun@cs.pitt.edu * */ import java.io.*; import java.net.*; import java.util.*; /* Class KeyValueList: List of (Key, Value) pair--the basic format of message keys: MsgID and Description are required for any messages */ class KeyValueList { private Vector keys; private Vector values; /* Constructor */ public KeyValueList() { keys = new Vector(); values = new Vector(); } /* Look up the value given key, used in getValue() */ public int lookupKey(String strKey) { for(int i=0; i < keys.size(); i++) { String k = (String) keys.elementAt(i); if (strKey.equals(k)) return i; } return -1; } /* add new (key,value) pair to list */ public boolean addPair(String strKey,String strValue) { return (keys.add(strKey) && values.add(strValue)); } /* get the value given key */ public String getValue(String strKey) { int index=lookupKey(strKey); if (index==-1) return null; return (String) values.elementAt(index); } public void setValue(int index, String val) { if(index >= 0 && index < size()) values.set(index, val); } /* Show whole list */ public String toString() { String result = new String(); for(int i=0; i getValueLike(String key) { String temp; ArrayList results = new ArrayList(); for(int i=0; i < keys.size(); i++) { temp = (String) keys.elementAt(i); if (temp.contains(key)) results.add((String) values.elementAt(i)); } if(results.size() == 0) return null; return results; } } /* Class MsgEncoder: Serialize the KeyValue List and Send it out to a Stream. */ class MsgEncoder { private PrintStream printOut; /*If you would like to write msg interpreter your self, read below*/ /* Default of delimiter in system is $$$ */ private final String delimiter = "$$$"; public MsgEncoder(){} /* Encode the Key Value List into a string and Send it out */ public void sendMsg(KeyValueList kvList, OutputStream out) throws IOException { PrintStream printOut= new PrintStream(out); if (kvList == null) return; String outMsg= new String(); for(int i=0; i InMsgs= new ArrayList(); ArrayList OutMsgs= new ArrayList(); } public class SISServer { private static final int port = 7999; private static Socket client; private static Socket component; static Vector csm = new Vector() ; static Vector cmc = new Vector(); private static SISComponentBase siscompbase; static Vector createhistory = new Vector(); /*Find socket by comp name*/ public static ArrayList FindSocketCSM(String in) { ArrayList results = new ArrayList(); for(int i=0; i