KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > ir > EnumDef


1 package org.jacorb.ir;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.lang.reflect.*;
24
25 import org.omg.CORBA.TypeCode JavaDoc;
26 import org.omg.CORBA.Any JavaDoc;
27
28 public class EnumDef
29     extends TypedefDef
30     implements org.omg.CORBA.EnumDefOperations JavaDoc
31 {
32     /** enum member sequence */
33     private String JavaDoc [] members;
34     /* reference to my container as a contained object */
35     private org.omg.CORBA.Contained JavaDoc myContainer;
36
37     public EnumDef( Class JavaDoc c,
38                     org.omg.CORBA.Container JavaDoc _defined_in,
39                     org.omg.CORBA.Repository JavaDoc ir,
40                     ClassLoader JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc [member_size];
76         // only every second field denotes an original enum member
77
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 JavaDoc[] members()
85     {
86         return members;
87     }
88
89     public void members(String JavaDoc[] m)
90     {
91         members = m;
92     }
93
94     public void define()
95     {
96     }
97
98     // from Contained
99

100     public org.omg.CORBA.ContainedPackage.Description describe()
101     {
102         org.omg.CORBA.Any JavaDoc a = orb.create_any();
103
104
105         String JavaDoc 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 JavaDoc(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     // from IRObject
122

123     public void destroy(){}
124
125
126 }
127
128
129
130
131
132
Popular Tags