1 package org.jacorb.ir; 2 3 22 23 import java.lang.reflect.*; 24 25 import org.omg.CORBA.TypeCode ; 26 import org.omg.CORBA.Any ; 27 28 public class EnumDef 29 extends TypedefDef 30 implements org.omg.CORBA.EnumDefOperations 31 { 32 33 private String [] members; 34 35 private org.omg.CORBA.Contained myContainer; 36 37 public EnumDef( Class c, 38 org.omg.CORBA.Container _defined_in, 39 org.omg.CORBA.Repository ir, 40 ClassLoader loader) 41 { 42 def_kind = org.omg.CORBA.DefinitionKind.dk_Enum; 43 defined_in = _defined_in; 44 containing_repository = ir; 45 version = "1.0"; 46 String classId = c.getName(); 47 myContainer = org.omg.CORBA.ContainedHelper.narrow( defined_in ); 48 49 if( classId.indexOf('.') > 0 ) 50 { 51 name( classId.substring( classId.lastIndexOf('.')+1)); 52 String path = classId.substring( 0, classId.lastIndexOf('.')); 53 54 if( path.endsWith("Package")) 55 { 56 id( RepositoryID.toRepositoryID( path.substring( 0, path.lastIndexOf("Package")) + "." + name, loader)); 57 } 58 else 59 { 60 id( RepositoryID.toRepositoryID( path + "." + name, loader)); 61 } 62 63 absolute_name = myContainer.absolute_name() + "::" + name; 64 } 65 else 66 { 67 name( classId ); 68 defined_in = containing_repository; 69 id( RepositoryID.toRepositoryID(name, loader)); 70 absolute_name = "::" + name; 71 } 72 73 Field memberFields[] = c.getDeclaredFields(); 74 int member_size = (memberFields.length - 1 ) / 2; 75 members = new String [member_size]; 76 for( int i = 0; i < member_size; i++ ) 78 { 79 members[ i ] = memberFields[2+(2*i)].getName(); 80 } 81 type = org.omg.CORBA.ORB.init().create_enum_tc( id, name, members ); 82 } 83 84 public String [] members() 85 { 86 return members; 87 } 88 89 public void members(String [] m) 90 { 91 members = m; 92 } 93 94 public void define() 95 { 96 } 97 98 100 public org.omg.CORBA.ContainedPackage.Description describe() 101 { 102 org.omg.CORBA.Any a = orb.create_any(); 103 104 105 String def_in_name; 106 if( myContainer != null ) 107 def_in_name = myContainer.id(); 108 else 109 def_in_name = "IDL:/:1.0"; 110 111 org.omg.CORBA.TypeDescriptionHelper.insert( a, 112 new org.omg.CORBA.TypeDescription (name(), 113 id(), 114 def_in_name, 115 version(), 116 type() 117 ) ); 118 return new org.omg.CORBA.ContainedPackage.Description( org.omg.CORBA.DefinitionKind.dk_Enum, a); 119 } 120 121 123 public void destroy(){} 124 125 126 } 127 128 129 130 131 132 | Popular Tags |