1 2 package SOFA.Connector; 3 4 import java.util.StringTokenizer ; 5 import java.util.Vector ; 6 7 import SOFA.Connector.ECG.Profiles.CORBAProfile; 8 import SOFA.Connector.ECG.Profiles.LocalProfile; 9 import SOFA.Connector.ECG.Profiles.RMIProfile; 10 11 13 public final class Reference implements java.io.Serializable , cz.cuni.sofa.lib.Streamable { 14 15 16 public String conn_type; 17 18 public TaggedProfile[] profiles; 19 20 public Reference () { 21 } 22 23 public Reference (final String conn_type, final TaggedProfile[] profiles) { 24 this.conn_type = conn_type; 25 this.profiles = profiles; 26 } 27 28 public void _write(cz.cuni.sofa.lib.OutputStream os) throws java.io.IOException { 29 os.write_string(conn_type); 30 int len = 0; 31 for (int i=0; i<profiles.length; i++) { 32 if (profiles[i] instanceof RMIProfile || profiles[i] instanceof CORBAProfile) { 33 len++; 34 } 35 } 36 os.write_long(len); 37 for (int i=0; i<profiles.length; i++) { 38 if (profiles[i] instanceof RMIProfile) { 39 os.write_string(profiles[i].tag); 40 os.write_string( ((RMIProfile) profiles[i]).URL); 41 } 42 if (profiles[i] instanceof CORBAProfile) { 43 os.write_string(profiles[i].tag); 44 os.write_string( ((CORBAProfile) profiles[i]).IOR); 45 } 46 } 47 } 48 49 public void _read(cz.cuni.sofa.lib.InputStream is) throws java.io.IOException { 50 conn_type = is.read_string(); 51 int len = is.read_long(); 52 profiles = new TaggedProfile [len]; 53 for (int i=0; i<len; i++) { 54 String tag = is.read_string(); 55 if (tag.compareTo("RMI")==0) { 56 profiles[i] = new RMIProfile(is.read_string()); 57 } 58 if (tag.compareTo("CORBA")==0) { 59 profiles[i] = new CORBAProfile(is.read_string()); 60 } 61 } 62 } 63 64 public String toString() { 65 StringBuffer sb = new StringBuffer (conn_type); 66 sb.append("-"); 67 for (int i=0; i<profiles.length; i++) { 68 if (profiles[i] instanceof RMIProfile) { 69 sb.append(profiles[i].tag); 70 sb.append(";"); 71 sb.append( ((RMIProfile) profiles[i]).URL); 72 sb.append("-"); 73 } 74 if (profiles[i] instanceof CORBAProfile) { 75 sb.append(profiles[i].tag); 76 sb.append("x"); 77 sb.append( ((CORBAProfile) profiles[i]).IOR); 78 sb.append("-"); 79 } 80 if (profiles[i] instanceof LocalProfile) { 81 sb.append(profiles[i].tag); 82 sb.append("-"); 83 } 84 85 } 86 return sb.toString(); 87 } 88 89 95 public static Reference fromString (String s) { 96 StringTokenizer st = new StringTokenizer (s, "-"); 97 String type = st.nextToken(); 98 Vector profiles = new Vector (); 99 100 while (st.hasMoreTokens()) { 101 String token = st.nextToken(); 102 if (token.equals("LOCAL")) { 103 profiles.add(new LocalProfile()); 104 continue; 105 } 106 if (token.startsWith("RMI")) { 107 String url = token.substring(4); profiles.add(new RMIProfile(url)); 109 continue; 110 } 111 if (token.startsWith("CORBA")) { 112 String ior = token.substring(6); profiles.add(new CORBAProfile(ior)); 114 continue; 115 } 116 } 117 return new Reference(type, (TaggedProfile [])profiles.toArray(new TaggedProfile[profiles.size()])); 118 } 119 120 } 121 | Popular Tags |