1 21 package org.jacorb.orb.etf; 22 23 import org.apache.avalon.framework.configuration.*; 24 25 import org.jacorb.orb.CDROutputStream; 26 import org.jacorb.orb.CDRInputStream; 27 import org.jacorb.orb.TaggedComponentList; 28 29 import org.omg.ETF.*; 30 import org.omg.IOP.*; 31 32 36 public abstract class ProfileBase 37 extends _ProfileLocalBase 38 implements Cloneable , Configurable 39 { 40 protected org.omg.GIOP.Version version = null; 41 protected byte[] objectKey = null; 42 protected TaggedComponentList components = null; 43 44 protected org.jacorb.config.Configuration configuration; 45 protected String corbalocStr = null; 46 47 public ProfileBase() 48 { 49 } 50 51 54 public void set_object_key(byte[] key) 55 { 56 this.objectKey = key; 57 } 58 59 62 public byte[] get_object_key() 63 { 64 return objectKey; 65 } 66 67 70 public org.omg.GIOP.Version version() 71 { 72 return version; 73 } 74 75 78 public abstract int tag(); 79 80 94 public void marshal (TaggedProfileHolder tagged_profile, 95 TaggedComponentSeqHolder components) 96 { 97 if (encapsulation() != 0) 98 { 99 throw new Error ("We can only marshal big endian stylee profiles !!"); 103 } 104 105 CDROutputStream profileDataStream = new CDROutputStream(); 107 profileDataStream.beginEncapsulatedArray(); 108 109 writeAddressProfile(profileDataStream); 111 112 profileDataStream.write_long(objectKey.length); 114 profileDataStream.write_octet_array(objectKey,0,objectKey.length); 115 116 switch( version.minor ) 117 { 118 case 0 : 119 break; 121 default : 122 if (components == null) 124 { 125 components = new TaggedComponentSeqHolder (new TaggedComponent[0]); 126 } 127 profileDataStream.write_long(this.components.size() + components.value.length); 129 130 for (int i = 0; i < this.components.asArray().length; i++) 132 { 133 TaggedComponentHelper.write(profileDataStream, this.components.asArray()[i]); 134 } 135 for (int i = 0; i < components.value.length; i++) 136 { 137 TaggedComponentHelper.write(profileDataStream, components.value[i]); 138 } 139 } 140 141 tagged_profile.value = new TaggedProfile 143 ( 144 this.tag(), 145 profileDataStream.getBufferCopy() 146 ); 147 } 148 149 152 public void demarshal(TaggedProfileHolder tagged_profile, 153 TaggedComponentSeqHolder components) 154 { 155 if (tagged_profile.value.tag != this.tag()) 156 { 157 throw new org.omg.CORBA.BAD_PARAM 158 ("Wrong tag for Transport, tag: " 159 + tagged_profile.value.tag); 160 } 161 initFromProfileData(tagged_profile.value.profile_data); 162 components.value = getComponents().asArray(); 163 } 164 165 172 public short encapsulation() 173 { 174 return 0; } 176 177 181 public abstract void writeAddressProfile(CDROutputStream stream); 182 183 186 public abstract void readAddressProfile(CDRInputStream stream); 187 188 191 public TaggedComponentList getComponents() 192 { 193 return components; 194 } 195 196 public Object getComponent(int tag, Class helper) 197 { 198 return components.getComponent(tag, helper); 199 } 200 201 public void addComponent(int tag, Object data, Class helper) 202 { 203 components.addComponent(tag, data, helper); 204 } 205 206 public void addComponent(int tag, byte[] data) 207 { 208 components.addComponent(tag, data); 209 } 210 211 public TaggedProfile asTaggedProfile() 212 { 213 TaggedProfileHolder result = new TaggedProfileHolder(); 214 this.marshal(result, null); 215 return result.value; 216 } 217 218 222 public Profile copy() 223 { 224 try 225 { 226 return (Profile)this.clone(); 227 } 228 catch (CloneNotSupportedException e) 229 { 230 throw new RuntimeException ("error cloning profile: " + e); 231 } 232 } 233 234 239 protected void initFromProfileData(byte[] data) 240 { 241 CDRInputStream in = new CDRInputStream(null, data); 242 in.openEncapsulatedArray(); 243 244 readAddressProfile(in); 245 246 int length = in.read_ulong(); 247 248 objectKey = new byte[length]; 249 in.read_octet_array(objectKey, 0, length); 250 251 components = (version != null && version.minor > 0) ? new TaggedComponentList(in) 252 : new TaggedComponentList(); 253 } 254 } 255 | Popular Tags |