1 26 27 28 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer; 29 30 import java.util.Iterator ; 32 import java.util.StringTokenizer ; 33 import org.objectweb.openccm.corba.TheORB; 34 import org.objectweb.openccm.corba.TheORBSingleton; 35 import org.objectweb.openccm.descriptor.properties.beans.*; 36 import org.omg.CORBA.*; 37 import org.omg.Components.CCMObject; 38 import org.omg.DynamicAny.DynAny ; 39 import org.omg.DynamicAny.DynAnyFactory ; 40 import org.omg.DynamicAny.DynAnyFactoryHelper ; 41 import org.omg.DynamicAny.DynSequence ; 42 import org.omg.DynamicAny.DynSequenceHelper ; 43 44 51 public class ComponentpropertiesDeployer 52 extends ComponentpropertiesDeployerContext { 53 54 71 private void 72 setupSimpleProperty( 73 PropertiesBean propertiesObject, 74 org.omg.Components.CCMObject new_component) 75 throws Exception 76 { 77 for (java.util.Iterator i = propertiesObject.getSimpleList().iterator(); 79 i.hasNext(); 80 ) { 81 SimpleBean property = (SimpleBean) i.next(); 82 org.omg.CORBA.Request request = 84 new_component._request("_set_" + property.getName()); 85 processSimple(property, request.add_in_arg()); 87 request.invoke(); 89 } 90 } 91 92 99 private void 100 setupSequenceListProperty( 101 CCMObject new_component, 102 PropertiesBean propertiesObject) 103 throws Exception 104 { 105 for (java.util.Iterator i = 106 propertiesObject.getSequenceList().iterator(); 107 i.hasNext();) 108 { 109 SequenceBean property = (SequenceBean) i.next(); 110 111 org.omg.CORBA.Request request = 112 new_component._request("_set_" + property.getName()); 113 114 NVList nvlist = request.arguments(); 115 nvlist.add_value( 116 property.getName(), 117 processSequence(property).to_any(), 118 ARG_IN.value); 119 request.invoke(); 120 } 121 } 122 123 129 private TCKind 130 getTCKing(String typeCodeId) 131 { 132 133 if (typeCodeId.equals("boolean")) 135 return org.omg.CORBA.TCKind.tk_boolean; 136 else if (typeCodeId.equals("char")) 137 return org.omg.CORBA.TCKind.tk_char; 138 else if (typeCodeId.equals("double")) 139 return org.omg.CORBA.TCKind.tk_double; 140 else if (typeCodeId.equals("float")) 141 return org.omg.CORBA.TCKind.tk_float; 142 else if (typeCodeId.equals("short")) 143 return org.omg.CORBA.TCKind.tk_short; 144 else if (typeCodeId.equals("long")) 145 return org.omg.CORBA.TCKind.tk_long; 146 else if (typeCodeId.equals("objref")) 147 return org.omg.CORBA.TCKind.tk_objref; 148 else if (typeCodeId.equals("octet")) 149 return org.omg.CORBA.TCKind.tk_octet; 150 else if (typeCodeId.equals("string")) 151 return org.omg.CORBA.TCKind.tk_string; 152 else if (typeCodeId.equals("ulong")) 153 return org.omg.CORBA.TCKind.tk_ulong; 154 else if (typeCodeId.equals("ushort")) 155 return org.omg.CORBA.TCKind.tk_ushort; 156 else if (typeCodeId.equals("sequence")) 157 return org.omg.CORBA.TCKind.tk_sequence; 158 else if (typeCodeId.equals("struct")) 159 return org.omg.CORBA.TCKind.tk_struct; 160 return null; 162 } 163 164 171 private TypeCode 172 getTypeCode(String type_identifier) 173 { 174 return TheORB.getORB().get_primitive_tc(getTCKing(type_identifier)); 175 } 176 177 186 private TypeCode 187 getSequenceTypeCode(String type) 188 { 189 return getSequenceType(new StringTokenizer (type, ":")); 190 } 191 192 198 private TypeCode 199 getSequenceType(StringTokenizer tok) 200 { 201 String ch = tok.nextToken(); 202 if (ch.equals("sequence")) 203 return TheORB.getORB().create_sequence_tc(0, getSequenceType(tok)); 204 else 205 return getTypeCode(ch); 206 } 207 208 217 private void 218 processSequence(SequenceBean si, DynSequence ds) 219 throws Exception 220 { 221 if (si.getSimpleList() != null && si.getSimpleList().size() != 0) { 222 223 ds.set_length(si.getSimpleList().size()); 224 225 for (java.util.Iterator i = si.getSimpleList().iterator(); 226 i.hasNext(); 227 ds.next()) { 228 SimpleBean property = (SimpleBean) i.next(); 229 DynAny any = ds.current_component(); processSimple(property, any); 231 } 232 return; 233 } 234 ds.set_length(si.getSequenceList().size()); 235 236 for (java.util.Iterator i = si.getSequenceList().iterator(); 237 i.hasNext(); 238 ds.next()) { 239 SequenceBean seqBean = (SequenceBean) i.next(); 240 processSequence( 241 seqBean, 242 DynSequenceHelper.narrow(ds.current_component())); 243 } 244 ds.rewind(); 245 } 246 247 255 private DynSequence 256 processSequence(SequenceBean si) 257 throws Exception 258 { 259 isValid(si,si.getType()); 260 261 DynAnyFactory daf = 262 DynAnyFactoryHelper.narrow( 263 TheORBSingleton.resolve_initial_reference("DynAnyFactory")); 264 265 DynAny da = 266 daf.create_dyn_any_from_type_code( 267 getSequenceTypeCode(si.getType().trim())); 268 DynSequence ds = DynSequenceHelper.narrow(da); 269 270 processSequence(si, ds); 271 return ds; 272 } 273 274 276 277 284 private Any 285 processSimple(SimpleBean property, Any any) 286 throws Exception 287 { 288 289 if (property.getType().equals("double")) 290 any.insert_longlong(Long.parseLong(property.getValue().getValue())); 291 else if (property.getType().equals("boolean")) 294 any.insert_boolean( 295 305 Boolean.valueOf(property.getValue().getValue()).booleanValue()); 306 307 else if (property.getType().equals("char")) 309 any.insert_char(property.getValue().getValue().charAt(0)); 310 else if (property.getType().equals("float")) 311 any.insert_float(Integer.parseInt(property.getValue().getValue())); 312 else if (property.getType().equals("short")) 313 any.insert_short(Short.parseShort(property.getValue().getValue())); 314 else if (property.getType().equals("long")) 315 any.insert_long(Integer.parseInt(property.getValue().getValue())); 316 else if (property.getType().equals("octet")) 317 any.insert_octet(Byte.parseByte(property.getValue().getValue())); 318 else if (property.getType().equals("string")) 319 any.insert_string(property.getValue().getValue()); 320 else if (property.getType().equals("ulong")) 321 any.insert_ulong(Integer.parseInt(property.getValue().getValue())); 322 else if (property.getType().equals("ushort")) 323 any.insert_ushort(Short.parseShort(property.getValue().getValue())); 324 325 return any; 326 } 327 328 335 private void 336 processSimple(SimpleBean property, DynAny any) 337 throws Exception 338 { 339 if (property.getType().equals("double")) 341 any.insert_longlong(Long.parseLong(property.getValue().getValue())); 342 else if (property.getType().equals("boolean")) 345 any.insert_boolean( 346 356 Boolean.valueOf(property.getValue().getValue()).booleanValue()); 357 358 else if (property.getType().equals("char")) 360 any.insert_char(property.getValue().getValue().charAt(0)); 361 else if (property.getType().equals("float")) 362 any.insert_float(Integer.parseInt(property.getValue().getValue())); 363 else if (property.getType().equals("short")) 364 any.insert_short(Short.parseShort(property.getValue().getValue())); 365 else if (property.getType().equals("long")) 366 any.insert_long(Integer.parseInt(property.getValue().getValue())); 367 else if (property.getType().equals("octet")) 368 any.insert_octet(Byte.parseByte(property.getValue().getValue())); 369 else if (property.getType().equals("string")) 370 any.insert_string(property.getValue().getValue()); 371 else if (property.getType().equals("ulong")) 372 any.insert_ulong(Integer.parseInt(property.getValue().getValue())); 373 else if (property.getType().equals("ushort")) 374 any.insert_ushort(Short.parseShort(property.getValue().getValue())); 375 376 } 378 379 private void 380 isValid(SequenceBean sb,String typeToRespect) 381 throws ComponentpropertiesMalFormedException 382 { 383 384 if(!sb.getType().equals(typeToRespect)) 385 throw new ComponentpropertiesMalFormedException(typeToRespect,sb.getType()); 386 387 String following=typeToRespect.substring(typeToRespect.indexOf(":")+1); 388 389 391 if(sb.getSequenceList()!=null) 392 for(Iterator i=sb.getSequenceList().iterator();i.hasNext();) 393 isValid((SequenceBean)i.next(),following); 394 395 else if(sb.getSimpleList()!=null) 396 for(Iterator it=sb.getSimpleList().iterator();it.hasNext();) 397 isValid((SimpleBean)it.next(),following); 398 399 } 400 401 private void 402 isValid(SimpleBean sb,String typeToRespect) 403 throws ComponentpropertiesMalFormedException 404 { 405 if(!sb.getType().equals(typeToRespect)) 406 throw new ComponentpropertiesMalFormedException(typeToRespect,sb.getType()); 407 } 408 409 415 public class ComponentpropertiesMalFormedException extends Exception { 416 417 public 418 ComponentpropertiesMalFormedException(String excepted, String found){ 419 super("The componentproperties seem to be corrupted, imbricated"+ 420 " properties were expected to be ["+excepted+"] and it was found"+ 421 " a ["+found+"]"); 422 } 423 } 424 432 public void 433 setupComponentProperties( 434 org.omg.Components.CCMObject new_component) 435 throws ComponentPropertiesSetupFailureException 436 { 437 try { 438 java.io.InputStreamReader reader = 439 getFileinarchiveDeployer().getInputStreamReader(); 440 441 PropertiesBean propertiesObject = 443 PropertiesBeanImpl.unmarshalBean(reader, true); 444 setupSimpleProperty(propertiesObject, new_component); 446 setupSequenceListProperty(new_component, propertiesObject); 448 } catch (Exception e) { 449 e.printStackTrace(); 450 throw new ComponentPropertiesSetupFailureException(this, e); 451 } 452 } 453 454 } | Popular Tags |