1 7 8 package com.sun.corba.se.impl.dynamicany; 9 10 import org.omg.CORBA.TypeCode ; 11 import org.omg.CORBA.Any ; 12 import org.omg.CORBA.BAD_OPERATION ; 13 import org.omg.CORBA.INTERNAL ; 14 import org.omg.CORBA.TypeCodePackage.BadKind ; 15 import org.omg.CORBA.TypeCodePackage.Bounds ; 16 import org.omg.DynamicAny.*; 17 import org.omg.DynamicAny.DynAnyPackage.*; 18 19 import com.sun.corba.se.spi.orb.ORB ; 20 import com.sun.corba.se.spi.logging.CORBALogDomains ; 21 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 22 23 public class DynEnumImpl extends DynAnyBasicImpl implements DynEnum 24 { 25 29 int currentEnumeratorIndex = NO_INDEX; 31 32 36 private DynEnumImpl() { 37 this(null, (Any )null, false); 38 } 39 40 protected DynEnumImpl(ORB orb, Any anAny, boolean copyValue) { 42 super(orb, anAny, copyValue); 43 index = NO_INDEX; 44 try { 46 currentEnumeratorIndex = any.extract_long(); 47 } catch (BAD_OPERATION e) { 48 currentEnumeratorIndex = 0; 50 any.type(any.type()); 51 any.insert_long(0); 52 } 53 } 54 55 protected DynEnumImpl(ORB orb, TypeCode typeCode) { 58 super(orb, typeCode); 59 index = NO_INDEX; 60 currentEnumeratorIndex = 0; 61 any.insert_long(0); 62 } 63 64 68 private int memberCount() { 69 int memberCount = 0; 70 try { 71 memberCount = any.type().member_count(); 72 } catch (BadKind bad) { 73 } 74 return memberCount; 75 } 76 77 private String memberName(int i) { 78 String memberName = null; 79 try { 80 memberName = any.type().member_name(i); 81 } catch (BadKind bad) { 82 } catch (Bounds bounds) { 83 } 84 return memberName; 85 } 86 87 private int computeCurrentEnumeratorIndex(String value) { 88 int memberCount = memberCount(); 89 for (int i=0; i<memberCount; i++) { 90 if (memberName(i).equals(value)) { 91 return i; 92 } 93 } 94 return NO_INDEX; 95 } 96 97 101 public int component_count() { 103 return 0; 104 } 105 106 public org.omg.DynamicAny.DynAny current_component() 109 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch 110 { 111 if (status == STATUS_DESTROYED) { 112 throw wrapper.dynAnyDestroyed() ; 113 } 114 throw new TypeMismatch(); 115 } 116 117 121 public String get_as_string () { 123 if (status == STATUS_DESTROYED) { 124 throw wrapper.dynAnyDestroyed() ; 125 } 126 return memberName(currentEnumeratorIndex); 127 } 128 129 public void set_as_string (String value) 134 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 135 { 136 if (status == STATUS_DESTROYED) { 137 throw wrapper.dynAnyDestroyed() ; 138 } 139 int newIndex = computeCurrentEnumeratorIndex(value); 140 if (newIndex == NO_INDEX) { 141 throw new InvalidValue(); 142 } 143 currentEnumeratorIndex = newIndex; 144 any.insert_long(newIndex); 145 } 146 147 public int get_as_ulong () { 151 if (status == STATUS_DESTROYED) { 152 throw wrapper.dynAnyDestroyed() ; 153 } 154 return currentEnumeratorIndex; 155 } 156 157 public void set_as_ulong (int value) 161 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 162 { 163 if (status == STATUS_DESTROYED) { 164 throw wrapper.dynAnyDestroyed() ; 165 } 166 if (value < 0 || value >= memberCount()) { 167 throw new InvalidValue(); 168 } 169 currentEnumeratorIndex = value; 170 any.insert_long(value); 171 } 172 } 173 | Popular Tags |