1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 public class AnyValue 39 { 40 46 49 private int type_; 50 51 54 private long integer_; 55 private String string_; 56 private char char_; 57 private String fixed_; 58 private double floating_; 59 private boolean boolean_; 60 private org.omg.CORBA.TypeCode tc_; 61 private int enumerator_; 62 63 69 72 final public int NONE = 0; 73 74 77 final public int INTEGER = 1; 78 79 82 final public int STRING = 2; 83 84 87 final public int WSTRING = 3; 88 89 92 final public int CHAR = 4; 93 94 97 final public int WCHAR = 5; 98 99 102 final public int FIXED = 6; 103 104 107 final public int FLOATING = 7; 108 109 112 final public int BOOLEAN = 8; 113 114 117 final public int ENUM = 9; 118 119 125 128 public 129 AnyValue() 130 { 131 type_ = NONE; 132 } 133 134 140 151 protected org.omg.CORBA.Any 152 computeAny(org.omg.CORBA.TypeCode tc) 153 { 154 if(type_ == NONE) 155 { 156 org.omg.CORBA.Any any = 157 org.objectweb.openccm.corba.TheORB.create_any(); 158 any.insert_octet((byte)0); 159 return any; 160 } 161 162 org.omg.CORBA.TypeCode origTC = 163 org.objectweb.openccm.corba.TypeCodeUtils.getOrigType(tc); 164 org.omg.DynamicAny.DynAny dynAny = 165 org.objectweb.openccm.corba.TheDynamicAnyFactory. 166 create_dyn_any_from_type_code(origTC); 167 168 try 169 { 170 switch(origTC.kind().value()) 171 { 172 case org.omg.CORBA.TCKind._tk_short: 173 if(type_ != INTEGER) 174 throw new Error ("Invalid constant value!"); 175 dynAny.insert_short((short)integer_); 176 break; 177 178 case org.omg.CORBA.TCKind._tk_long: 179 if(type_ != INTEGER) 180 throw new Error ("Invalid constant value!"); 181 dynAny.insert_long((int)integer_); 182 break; 183 184 case org.omg.CORBA.TCKind._tk_ushort: 185 if(type_ != INTEGER) 186 throw new Error ("Invalid constant value!"); 187 dynAny.insert_ushort((short)integer_); 188 break; 189 190 case org.omg.CORBA.TCKind._tk_ulong: 191 if(type_ != INTEGER) 192 throw new Error ("Invalid constant value!"); 193 dynAny.insert_ulong((int)integer_); 194 break; 195 196 case org.omg.CORBA.TCKind._tk_float: 197 if(type_ != FLOATING) 198 throw new Error ("Invalid constant value!"); 199 dynAny.insert_float((float)floating_); 200 break; 201 202 case org.omg.CORBA.TCKind._tk_double: 203 if(type_ != FLOATING) 204 throw new Error ("Invalid constant value!"); 205 dynAny.insert_double(floating_); 206 break; 207 208 case org.omg.CORBA.TCKind._tk_boolean: 209 if(type_ != BOOLEAN) 210 throw new Error ("Invalid constant value!"); 211 dynAny.insert_boolean(boolean_); 212 break; 213 214 case org.omg.CORBA.TCKind._tk_char: 215 if(type_ != CHAR) 216 throw new Error ("Invalid constant value!"); 217 dynAny.insert_char(char_); 218 break; 219 220 case org.omg.CORBA.TCKind._tk_string: 221 if(type_ != STRING) 222 throw new Error ("Invalid constant value!"); 223 dynAny.insert_string(string_); 224 break; 225 226 case org.omg.CORBA.TCKind._tk_longlong: 227 if(type_ != INTEGER) 228 throw new Error ("Invalid constant value!"); 229 dynAny.insert_longlong(integer_); 230 break; 231 232 case org.omg.CORBA.TCKind._tk_ulonglong: 233 if(type_ != INTEGER) 234 throw new Error ("Invalid constant value!"); 235 dynAny.insert_ulonglong(integer_); 236 break; 237 238 case org.omg.CORBA.TCKind._tk_wchar: 239 if(type_ != WCHAR) 240 throw new Error ("Invalid constant value!"); 241 dynAny.insert_wchar(char_); 242 break; 243 244 case org.omg.CORBA.TCKind._tk_wstring: 245 if(type_ != WSTRING) 246 throw new Error ("Invalid constant value!"); 247 dynAny.insert_wstring(string_); 248 break; 249 250 case org.omg.CORBA.TCKind._tk_fixed: 251 if(type_ != FIXED) 252 throw new Error ("Invalid constant value!"); 253 org.omg.DynamicAny.DynFixedHelper.narrow(dynAny).set_value(fixed_); 255 break; 256 257 case org.omg.CORBA.TCKind._tk_enum: 258 if(type_ != ENUM) 259 throw new Error ("Invalid constant value!"); 260 if(!tc_.equal(origTC)) 261 throw new Error ("Invalid constant type!"); 262 org.omg.DynamicAny.DynEnumHelper.narrow(dynAny).set_as_ulong(enumerator_); 263 break; 264 265 default: 266 throw new Error ("Invalid constant type!"); 267 } 268 return dynAny.to_any(); 269 } 270 catch(org.omg.DynamicAny.DynAnyPackage.InvalidValue exc) 271 { 272 throw new org.objectweb.openccm.corba.UserExceptionWrapper(exc); 274 } 275 catch(org.omg.DynamicAny.DynAnyPackage.TypeMismatch exc) 276 { 277 throw new org.objectweb.openccm.corba.UserExceptionWrapper(exc); 279 } 280 } 281 282 285 protected void 286 loadAny(org.omg.CORBA.Any any) 287 { 288 org.omg.CORBA.TypeCode tc = any.type(); 289 try 290 { 291 switch(tc.kind().value()) 292 { 293 case org.omg.CORBA.TCKind._tk_short: 294 setAsInteger(any.extract_short()); 295 break; 296 case org.omg.CORBA.TCKind._tk_long: 297 setAsInteger(any.extract_long()); 298 break; 299 case org.omg.CORBA.TCKind._tk_ushort: 300 setAsInteger(any.extract_ushort()); 301 break; 302 case org.omg.CORBA.TCKind._tk_ulong: 303 setAsInteger(any.extract_ulong()); 304 break; 305 case org.omg.CORBA.TCKind._tk_float: 306 setAsFloating(any.extract_float()); 307 break; 308 case org.omg.CORBA.TCKind._tk_double: 309 setAsFloating(any.extract_double()); 310 break; 311 case org.omg.CORBA.TCKind._tk_boolean: 312 setAsBoolean(any.extract_boolean()); 313 break; 314 case org.omg.CORBA.TCKind._tk_char: 315 setAsChar(any.extract_char()); 316 break; 317 case org.omg.CORBA.TCKind._tk_wchar: 318 setAsWChar(any.extract_wchar()); 319 break; 320 case org.omg.CORBA.TCKind._tk_string: 321 setAsString(any.extract_string()); 322 break; 323 case org.omg.CORBA.TCKind._tk_wstring: 324 setAsWString(any.extract_wstring()); 325 break; 326 case org.omg.CORBA.TCKind._tk_longlong: 327 setAsInteger(any.extract_longlong()); 328 break; 329 case org.omg.CORBA.TCKind._tk_ulonglong: 330 setAsInteger(any.extract_ulonglong()); 331 break; 332 case org.omg.CORBA.TCKind._tk_fixed: 333 org.omg.DynamicAny.DynFixed fixed = 334 org.objectweb.openccm.corba.TheDynamicAnyFactory.create_dyn_fixed(any); 335 setAsFixed(fixed.get_value()); 336 break; 337 case org.omg.CORBA.TCKind._tk_enum: 338 org.omg.DynamicAny.DynEnum dynEnum = 339 org.objectweb.openccm.corba.TheDynamicAnyFactory.create_dyn_enum(any); 340 setAsEnum(tc, dynEnum.get_as_ulong(), dynEnum.get_as_string()); 341 break; 342 default: 343 break; 344 } 345 } 346 catch(org.omg.CORBA.BAD_OPERATION ex) 347 {} 348 } 349 350 356 361 public boolean 362 isInteger() 363 { 364 return type_ == INTEGER; 365 } 366 367 372 public void 373 setAsInteger(long value) 374 { 375 type_ = INTEGER; 376 integer_ = value; 377 } 378 379 384 public long 385 getAsInteger() 386 { 387 return integer_; 388 } 389 390 395 public boolean 396 isString() 397 { 398 return type_ == STRING; 399 } 400 401 406 public void 407 setAsString(String value) 408 { 409 type_ = STRING; 410 string_ = value; 411 } 412 413 418 public String 419 getAsString() 420 { 421 return string_; 422 } 423 424 429 public boolean 430 isWString() 431 { 432 return type_ == WSTRING; 433 } 434 435 440 public void 441 setAsWString(String value) 442 { 443 type_ = WSTRING; 444 string_ = value; 445 } 446 447 452 public String 453 getAsWString() 454 { 455 return string_; 456 } 457 458 463 public boolean 464 isChar() 465 { 466 return type_ == CHAR; 467 } 468 469 474 public void 475 setAsChar(char value) 476 { 477 type_ = CHAR; 478 char_ = value; 479 } 480 481 486 public char 487 getAsChar() 488 { 489 return char_; 490 } 491 492 497 public boolean 498 isWChar() 499 { 500 return type_ == WCHAR; 501 } 502 503 508 public void 509 setAsWChar(char value) 510 { 511 type_ = WCHAR; 512 char_ = value; 513 } 514 515 520 public char 521 getAsWChar() 522 { 523 return char_; 524 } 525 526 531 public boolean 532 isFixed() 533 { 534 return type_ == FIXED; 535 } 536 537 542 public void 543 setAsFixed(String value) 544 { 545 type_ = FIXED; 546 fixed_ = value; 547 } 548 549 554 public String 555 getAsFixed() 556 { 557 return fixed_; 558 } 559 560 565 public boolean 566 isFloating() 567 { 568 return type_ == FLOATING; 569 } 570 571 576 public void 577 setAsFloating(double value) 578 { 579 type_ = FLOATING; 580 floating_ = value; 581 } 582 583 588 public double 589 getAsFloating() 590 { 591 return floating_; 592 } 593 594 599 public boolean 600 isBoolean() 601 { 602 return type_ == BOOLEAN; 603 } 604 605 610 public void 611 setAsBoolean(boolean value) 612 { 613 type_ = BOOLEAN; 614 boolean_ = value; 615 } 616 617 622 public boolean 623 getAsBoolean() 624 { 625 return boolean_; 626 } 627 628 633 public boolean 634 isEnum() 635 { 636 return type_ == ENUM; 637 } 638 639 644 public void 645 setAsEnum(org.omg.CORBA.TypeCode tc, 646 int value, 647 String name) 648 { 649 type_ = ENUM; 650 tc_ = tc; 651 enumerator_ = value; 652 string_ = name; 653 } 654 655 660 public String 661 getAsEnum() 662 { 663 return string_; 664 } 665 666 } 667 | Popular Tags |