1 package org.jacorb.orb.dynany; 2 3 22 23 import org.omg.DynamicAny.DynAnyPackage.*; 24 import org.omg.DynamicAny.*; 25 26 import org.jacorb.orb.*; 27 28 import java.util.*; 29 30 36 37 public final class DynArray 38 extends DynAny 39 implements org.omg.DynamicAny.DynArray 40 { 41 private org.omg.CORBA.TypeCode elementType; 42 private org.omg.CORBA.Any [] members; 43 44 DynArray( org.omg.DynamicAny.DynAnyFactory dynFactory, 45 org.omg.CORBA.TypeCode tc) 46 throws InvalidValue, TypeMismatch 47 { 48 org.omg.CORBA.TypeCode _type = 49 TypeCode.originalType( tc ); 50 51 if( _type.kind() != org.omg.CORBA.TCKind.tk_array ) 52 throw new TypeMismatch(); 53 54 try 55 { 56 type = _type; 57 this.orb = org.omg.CORBA.ORB.init(); 58 this.dynFactory = dynFactory; 59 elementType = TypeCode.originalType( type.content_type() ); 60 61 limit = type.length(); 62 members = new Any[limit]; 63 try 64 { 65 for( int i = limit; i-- > 0;) 66 { 67 members[i] = dynFactory.create_dyn_any_from_type_code( elementType ).to_any(); 68 } 69 } 70 catch( org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode itc ) 71 { 72 itc.printStackTrace(); 74 } 75 } 76 catch( org.omg.CORBA.TypeCodePackage.BadKind bk ) 77 { 78 bk.printStackTrace(); 79 } 80 } 81 82 DynArray( org.omg.DynamicAny.DynAnyFactory dynFactory, 83 org.omg.CORBA.TypeCode tc, org.omg.CORBA.ORB orb) 84 throws InvalidValue, TypeMismatch 85 { 86 org.omg.CORBA.TypeCode _type = 87 TypeCode.originalType( tc ); 88 89 if( _type.kind() != org.omg.CORBA.TCKind.tk_array ) 90 throw new TypeMismatch(); 91 92 try 93 { 94 type = _type; 95 this.orb = orb; 96 this.dynFactory = dynFactory; 97 elementType = TypeCode.originalType( type.content_type() ); 98 99 limit = type.length(); 100 members = new Any[limit]; 101 try 102 { 103 for( int i = limit; i-- > 0;) 104 { 105 members[i] = dynFactory.create_dyn_any_from_type_code( elementType ).to_any(); 106 } 107 } 108 catch( org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode itc ) 109 { 110 itc.printStackTrace(); 112 } 113 } 114 catch( org.omg.CORBA.TypeCodePackage.BadKind bk ) 115 { 116 bk.printStackTrace(); 117 } 118 } 119 120 public void from_any(org.omg.CORBA.Any value) 121 throws InvalidValue, TypeMismatch 122 { 123 checkDestroyed (); 124 if( ! type.equivalent( value.type() )) 125 throw new org.omg.DynamicAny.DynAnyPackage.TypeMismatch (); 126 127 type = TypeCode.originalType( value.type() ); 128 129 try 130 { 131 limit = type().length(); 132 elementType = TypeCode.originalType( type.content_type() ); 133 134 if( limit > 0 ) 135 pos = 0; 136 137 org.omg.CORBA.portable.InputStream is = value.create_input_stream(); 138 members = new org.omg.CORBA.Any [limit]; 139 140 for( int i = 0 ; i < limit; i++ ) 141 { 142 members[i] = org.omg.CORBA.ORB.init().create_any(); 143 members[i].read_value(is, elementType); 144 } 145 } 146 catch( org.omg.CORBA.TypeCodePackage.BadKind bk ) 147 { 148 bk.printStackTrace(); 150 } 151 } 152 153 public org.omg.CORBA.Any to_any() 154 { 155 checkDestroyed (); 156 org.jacorb.orb.Any out_any = 157 (org.jacorb.orb.Any)org.omg.CORBA.ORB.init().create_any(); 158 out_any.type( type()); 159 160 CDROutputStream os = new CDROutputStream(); 161 162 for( int i = 0; i < limit; i++) 163 { 164 os.write_value( elementType, 165 (CDRInputStream)members[i].create_input_stream()); 166 } 167 168 CDRInputStream is = new CDRInputStream(orb, os.getBufferCopy()); 169 out_any.read_value( is, type()); 170 return out_any; 171 } 172 173 176 177 public boolean equal( org.omg.DynamicAny.DynAny dyn_any ) 178 { 179 checkDestroyed (); 180 if( !type().equal( dyn_any.type()) ) 181 return false; 182 183 org.omg.DynamicAny.DynArray other = DynArrayHelper.narrow( dyn_any ); 184 185 org.omg.CORBA.Any [] elements = get_elements(); 186 org.omg.CORBA.Any [] other_elements = other.get_elements(); 187 188 for( int i = 0; i < elements.length; i++ ) 189 { 190 if( ! (elements[i].equal( other_elements[i] ))) 191 return false; 192 } 193 194 return true; 195 } 196 197 198 public org.omg.CORBA.Any [] get_elements() 199 { 200 checkDestroyed (); 201 return members; 202 } 203 204 205 public void set_elements(org.omg.CORBA.Any [] value) 206 throws TypeMismatch, InvalidValue 207 { 208 checkDestroyed (); 209 if( value.length != limit ) 210 throw new InvalidValue(); 211 212 for( int i = value.length; i-- > 0 ;) 213 { 214 org.omg.CORBA.TypeCode tc = 215 TypeCode.originalType( value[i].type() ); 216 217 if( tc.kind() != elementType.kind() ) 218 throw new TypeMismatch(); 219 } 220 221 222 members = value; 223 } 224 225 public org.omg.DynamicAny.DynAny [] get_elements_as_dyn_any() 226 { 227 checkDestroyed (); 228 org.omg.DynamicAny.DynAny [] result = 229 new org.omg.DynamicAny.DynAny [ members.length ]; 230 try 231 { 232 for( int i = members.length; i-- > 0; ) 233 result[i] = dynFactory.create_dyn_any( members[i]); 234 return result; 235 } 236 catch( org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode itc ) 237 { 238 itc.printStackTrace(); 240 } 241 return null; 242 } 243 244 245 public void set_elements_as_dyn_any(org.omg.DynamicAny.DynAny [] value) 246 throws TypeMismatch, InvalidValue 247 { 248 checkDestroyed (); 249 org.omg.CORBA.Any [] any_seq = 250 new org.omg.CORBA.Any [value.length]; 251 for( int i = value.length; i-- > 0; ) 252 any_seq[i] = value[i].to_any(); 253 254 set_elements( any_seq ); 255 } 256 257 public void destroy() 258 { 259 super.destroy(); 260 members = null; 261 elementType = null; 262 } 263 264 269 270 protected org.omg.CORBA.Any getRepresentation() 271 { 272 return members[pos]; 273 } 274 275 276 277 public org.omg.DynamicAny.DynAny current_component() 278 { 279 checkDestroyed (); 280 if( pos == -1 ) 281 return null; 282 try 283 { 284 return dynFactory.create_dyn_any( members[pos] ); 285 } 286 catch( org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode itc ) 287 { 288 itc.printStackTrace(); 290 } 291 return null; 292 } 293 294 295 } 296 | Popular Tags |