001: package org.jacorb.ir;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import java.lang.reflect.*;
024:
025: import org.omg.CORBA.TypeCode;
026: import org.omg.CORBA.Any;
027:
028: public class EnumDef extends TypedefDef implements
029: org.omg.CORBA.EnumDefOperations {
030: /** enum member sequence */
031: private String[] members;
032: /* reference to my container as a contained object */
033: private org.omg.CORBA.Contained myContainer;
034:
035: public EnumDef(Class c, org.omg.CORBA.Container _defined_in,
036: org.omg.CORBA.Repository ir, ClassLoader loader) {
037: def_kind = org.omg.CORBA.DefinitionKind.dk_Enum;
038: defined_in = _defined_in;
039: containing_repository = ir;
040: version = "1.0";
041: String classId = c.getName();
042: myContainer = org.omg.CORBA.ContainedHelper.narrow(defined_in);
043:
044: if (classId.indexOf('.') > 0) {
045: name(classId.substring(classId.lastIndexOf('.') + 1));
046: String path = classId
047: .substring(0, classId.lastIndexOf('.'));
048:
049: if (path.endsWith("Package")) {
050: id(RepositoryID.toRepositoryID(path.substring(0, path
051: .lastIndexOf("Package"))
052: + "." + name, loader));
053: } else {
054: id(RepositoryID.toRepositoryID(path + "." + name,
055: loader));
056: }
057:
058: absolute_name = myContainer.absolute_name() + "::" + name;
059: } else {
060: name(classId);
061: defined_in = containing_repository;
062: id(RepositoryID.toRepositoryID(name, loader));
063: absolute_name = "::" + name;
064: }
065:
066: Field memberFields[] = c.getDeclaredFields();
067: int member_size = (memberFields.length - 1) / 2;
068: members = new String[member_size];
069: // only every second field denotes an original enum member
070: for (int i = 0; i < member_size; i++) {
071: members[i] = memberFields[2 + (2 * i)].getName();
072: }
073: type = org.omg.CORBA.ORB.init().create_enum_tc(id, name,
074: members);
075: }
076:
077: public String[] members() {
078: return members;
079: }
080:
081: public void members(String[] m) {
082: members = m;
083: }
084:
085: public void define() {
086: }
087:
088: // from Contained
089:
090: public org.omg.CORBA.ContainedPackage.Description describe() {
091: org.omg.CORBA.Any a = orb.create_any();
092:
093: String def_in_name;
094: if (myContainer != null)
095: def_in_name = myContainer.id();
096: else
097: def_in_name = "IDL:/:1.0";
098:
099: org.omg.CORBA.TypeDescriptionHelper.insert(a,
100: new org.omg.CORBA.TypeDescription(name(), id(),
101: def_in_name, version(), type()));
102: return new org.omg.CORBA.ContainedPackage.Description(
103: org.omg.CORBA.DefinitionKind.dk_Enum, a);
104: }
105:
106: // from IRObject
107:
108: public void destroy() {
109: }
110:
111: }
|