1 package org.jacorb.orb.dynany; 2 3 22 23 import org.omg.DynamicAny.DynAnyPackage.*; 24 import org.omg.DynamicAny.*; 25 import org.jacorb.orb.*; 26 27 33 34 public final class DynEnum 35 extends DynAny 36 implements org.omg.DynamicAny.DynEnum 37 { 38 private int enum_value; 39 private int max; 40 private String [] member_names; 41 42 DynEnum( org.omg.DynamicAny.DynAnyFactory dynFactory, 43 org.omg.CORBA.TypeCode tc,org.omg.CORBA.ORB orb) 44 throws InvalidValue, TypeMismatch 45 { 46 org.omg.CORBA.TypeCode _type = TypeCode.originalType( tc ); 47 48 if( _type.kind().value() != org.omg.CORBA.TCKind._tk_enum ) 49 throw new TypeMismatch(); 50 51 type = _type; 52 53 this.orb = orb; 54 this.dynFactory = dynFactory; 55 pos = -1; 56 enum_value = 0; 57 58 try 59 { 60 member_names = new String [ type().member_count()]; 61 max = member_names.length; 62 for( int i = 0; i < member_names.length; i++ ) 63 member_names[i] = type().member_name(i); 64 } 65 catch( org.omg.CORBA.TypeCodePackage.BadKind bk ) 66 { 67 bk.printStackTrace(); 69 } 70 catch( org.omg.CORBA.TypeCodePackage.Bounds b ) 71 { 72 b.printStackTrace(); 74 } 75 } 76 77 DynEnum( org.omg.DynamicAny.DynAnyFactory dynFactory, 78 org.omg.CORBA.TypeCode tc) 79 throws InvalidValue, TypeMismatch 80 { 81 org.omg.CORBA.TypeCode _type = TypeCode.originalType( tc ); 82 83 if( _type.kind().value() != org.omg.CORBA.TCKind._tk_enum ) 84 throw new TypeMismatch(); 85 86 type = _type; 87 88 this.orb = org.omg.CORBA.ORB.init(); 89 this.dynFactory = dynFactory; 90 pos = -1; 91 enum_value = 0; 92 93 try 94 { 95 member_names = new String [ type().member_count()]; 96 max = member_names.length; 97 for( int i = 0; i < member_names.length; i++ ) 98 member_names[i] = type().member_name(i); 99 } 100 catch( org.omg.CORBA.TypeCodePackage.BadKind bk ) 101 { 102 bk.printStackTrace(); 104 } 105 catch( org.omg.CORBA.TypeCodePackage.Bounds b ) 106 { 107 b.printStackTrace(); 109 } 110 } 111 112 113 116 117 public void from_any( org.omg.CORBA.Any value ) 118 throws InvalidValue, TypeMismatch 119 { 120 checkDestroyed (); 121 if( ! value.type().equivalent( type()) ) 122 throw new TypeMismatch(); 123 124 type = TypeCode.originalType( value.type() ); 125 126 try 127 { 128 enum_value = value.create_input_stream().read_long(); 129 member_names = new String [ type().member_count()]; 130 max = member_names.length; 131 for( int i = 0; i < member_names.length; i++ ) 132 { 133 member_names[i] = type().member_name(i); 134 } 135 } 136 catch( org.omg.CORBA.TypeCodePackage.Bounds b ) 137 { 138 b.printStackTrace(); 140 } 141 catch( org.omg.CORBA.TypeCodePackage.BadKind bk ) 142 { 143 bk.printStackTrace(); 145 } 146 } 147 148 151 152 public boolean equal( org.omg.DynamicAny.DynAny dyn_any ) 153 { 154 checkDestroyed (); 155 if( !type().equal( dyn_any.type())) 156 return false; 157 158 return DynEnumHelper.narrow( dyn_any).get_as_ulong() == get_as_ulong(); 159 } 160 161 162 public org.omg.CORBA.Any to_any() 163 { 164 checkDestroyed (); 165 CDROutputStream os = new CDROutputStream(); 166 os.write_long( enum_value ); 167 168 org.jacorb.orb.Any out_any = 169 (org.jacorb.orb.Any)org.omg.CORBA.ORB.init().create_any(); 170 out_any.type(type()); 171 out_any.read_value( new CDRInputStream(orb, os.getBufferCopy()), type()); 172 return out_any; 173 } 174 175 public java.lang.String get_as_string() 176 { 177 checkDestroyed (); 178 return member_names[ enum_value ]; 179 } 180 181 public void set_as_string( java.lang.String arg ) 182 throws InvalidValue 183 { 184 checkDestroyed (); 185 int i = 0; 186 while( i < member_names.length && !(arg.equals(member_names[i])) ) 187 i++; 188 189 if( i < member_names.length ) 190 set_as_ulong(i); 191 else 192 throw new InvalidValue(); 193 } 194 195 public int get_as_ulong() 196 { 197 checkDestroyed (); 198 return enum_value; 199 } 200 201 public void set_as_ulong(int arg) 202 throws InvalidValue 203 { 204 checkDestroyed (); 205 if( arg < 0 || arg > max ) 206 throw new InvalidValue(); 207 208 enum_value = arg; 209 } 210 211 212 } 213 | Popular Tags |