1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.coach.util; 26 27 public final class InternetProfile { 28 private static final int DEFAULT_IIOP_PORT = 2089; 29 public byte major, minor; 30 public String host; 31 public int port; 32 public byte object_key[]; 33 public org.omg.IOP.TaggedComponent components[]; 34 35 private boolean Check() { 36 if (host == null || object_key == null) { 37 return false; 38 } 39 40 if (components != null) { 41 for (int i = 0; i < components.length; i++) { 42 if (components[i].component_data == null) { 43 return false; 44 } 45 } 46 } 47 48 return true; 49 } 50 51 void Read_ior(byte profile_data[]) { 52 ModestInputStream in = new ModestInputStream(profile_data); 53 major = in.ReadOctet(); 54 minor = in.ReadOctet(); 55 host = in.ReadString(); 56 port = in.ReadUShort(); 57 object_key = in.ReadOctetArray(); 58 59 if (major >= 1 && minor >= 1) { 60 int ncomponents = in.ReadULong(); 61 components = new org.omg.IOP.TaggedComponent [ncomponents]; 62 63 for (int i = 0; i < ncomponents; i++) { 64 org.omg.IOP.TaggedComponent component = new org.omg.IOP.TaggedComponent (); 65 component.tag = in.ReadULong(); 66 component.component_data = in.ReadOctetArray(); 67 components[i] = component; 68 } 69 } 70 } 71 72 void Read_corbaloc(String address) { 73 int index; 75 76 if (address.startsWith(":")) { 77 index = 1; 78 } else if (address.length() >= 5 && address.substring(0, 5).compareToIgnoreCase("iiop:") == 0) { 79 index = 5; 80 } else { 81 throw new org.omg.CORBA.INV_OBJREF ("Bad address: " + address + " (<iiop_id> not found)"); 82 } 84 int ver = address.indexOf('@', index); 85 86 if (ver == - 1) { 87 major = 1; 88 minor = 0; 89 } else { 90 int dot = address.indexOf('.'); 91 92 if (dot == - 1 || dot > ver) { 93 throw new org.omg.CORBA.INV_OBJREF ("Bad version number: \"" + address.substring(index, ver) + '"'); 94 } 95 96 try { 97 major = (byte)Integer.parseInt(address.substring(index, dot)); 98 minor = (byte)Integer.parseInt(address.substring(dot + 1, ver)); 99 } catch (NumberFormatException exc) { 100 throw new org.omg.CORBA.INV_OBJREF ("Bad version number: \"" + address.substring(index, ver) + '"'); 101 } 102 103 index = ver + 1; 104 } 105 int colon = address.indexOf(':', index); 107 108 if (colon == - 1) { 109 host = address.substring(index); 110 port = DEFAULT_IIOP_PORT; 111 } else { 112 host = address.substring(index, colon); 113 114 try { 115 port = Integer.parseInt(address.substring(colon + 1)); 116 } catch (NumberFormatException exc) { 117 throw new org.omg.CORBA.INV_OBJREF ("Bad port number: \"" + address.substring(colon + 1) + '"'); 118 } 119 } 120 121 if (host.length() == 0) { 122 throw new org.omg.CORBA.INV_OBJREF ("No host/IP address found"); 123 } 124 125 components = null; 126 } 127 128 byte[] Write_ior(boolean little_endian) { 129 if (!Check()) { 130 throw new org.omg.CORBA.INV_OBJREF (); 131 } 132 ModestOutputStream out = new ModestOutputStream(little_endian); 133 134 out.WriteOctet(major); 135 out.WriteOctet(minor); 136 out.WriteString(host); 137 out.WriteUShort((short)port); 138 out.WriteOctetArray(object_key); 139 140 if (major >= 1 && minor >= 1) { 141 if (components == null) { 142 out.WriteULong(0); 143 } else { 144 out.WriteULong(components.length); 145 146 for (int i = 0; i < components.length; i++) { 147 out.WriteULong(components[i].tag); 148 out.WriteOctetArray(components[i].component_data); 149 } 150 } 151 } 152 153 return out.GetBytes(); 154 } 155 156 void Write_corbaloc(StringBuffer sb) { 157 if (!Check()) { 158 throw new org.omg.CORBA.INV_OBJREF (); 159 } 160 161 sb.append(':'); 162 163 if (major != 1 || minor != 0) { 164 sb.append(Integer.toString(major) + '.' + minor + '@'); 165 } 166 167 sb.append(host); 168 169 if (port != DEFAULT_IIOP_PORT) { 170 sb.append(":" + port); 171 } 172 } 173 174 public InternetProfile() { 175 } 176 177 public InternetProfile(InternetProfile profile) { 178 179 Set(profile); 180 } 181 182 public void Set(InternetProfile profile) { 183 major = profile.major; 184 minor = profile.minor; 185 host = profile.host; 186 port = profile.port; 187 188 if (profile.object_key != null) { 189 object_key = new byte[profile.object_key.length]; 190 System.arraycopy(profile.object_key, 0, object_key, 0, object_key.length); 191 } else { 192 object_key = null; 193 } 194 195 if (profile.components != null) { 196 components = new org.omg.IOP.TaggedComponent [profile.components.length]; 197 System.arraycopy(profile.components, 0, components, 0, components.length); 198 } else { 199 components = null; 200 } 201 } 202 } 203 | Popular Tags |