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: import java.util.*;
025:
026: import org.omg.CORBA.INTF_REPOS;
027: import org.omg.PortableServer.POA;
028:
029: import org.apache.avalon.framework.logger.Logger;
030:
031: /**
032: * @version $Id: ExceptionDef.java,v 1.11 2004/10/18 13:12:41 simon.mcqueen Exp $
033: */
034:
035: public class ExceptionDef extends Contained implements
036: org.omg.CORBA.ExceptionDefOperations {
037: private org.omg.CORBA.TypeCode type;
038: private Class myClass;
039: private Class helperClass;
040: private org.omg.CORBA.StructMember[] members;
041: private Hashtable contained = new Hashtable();
042: private Logger logger;
043: private ClassLoader loader;
044: private POA poa;
045:
046: public ExceptionDef(Class c, org.omg.CORBA.Container _defined_in,
047: org.omg.CORBA.Repository ir, ClassLoader loader, POA poa,
048: Logger logger) {
049: this .logger = logger;
050: this .loader = loader;
051: this .poa = poa;
052: def_kind = org.omg.CORBA.DefinitionKind.dk_Exception;
053: containing_repository = ir;
054: defined_in = _defined_in;
055: if (defined_in == null) {
056: throw new INTF_REPOS("defined_in = null");
057: }
058: if (containing_repository == null) {
059: throw new INTF_REPOS("containing_repository = null");
060: }
061:
062: try {
063: String classId = c.getName();
064: myClass = c;
065: version("1.0");
066: if (classId.indexOf('.') > 0) {
067: name(classId.substring(classId.lastIndexOf('.') + 1));
068: absolute_name = org.omg.CORBA.ContainedHelper.narrow(
069: defined_in).absolute_name()
070: + "::" + name;
071: } else {
072: name(classId);
073: absolute_name = "::" + name;
074: }
075:
076: helperClass = this .loader.loadClass(classId + "Helper");
077: id((String) helperClass.getDeclaredMethod("id",
078: (Class[]) null).invoke(null, (Object[]) null));
079: type = TypeCodeUtil.getTypeCode(myClass, this .loader, null,
080: classId, this .logger);
081: try {
082: members = new org.omg.CORBA.StructMember[type
083: .member_count()];
084: for (int i = 0; i < members.length; i++) {
085: members[i] = new org.omg.CORBA.StructMember(type
086: .member_name(i), type.member_type(i), null);
087: }
088: } catch (Exception e) {
089: this .logger.error("Caught Exception", e);
090: }
091:
092: if (this .logger.isDebugEnabled()) {
093: this .logger.debug("ExceptionDef: " + absolute_name);
094: }
095: } catch (Exception e) {
096: this .logger.error("Caught Exception", e);
097: throw new INTF_REPOS(ErrorMsg.IR_Not_Implemented,
098: org.omg.CORBA.CompletionStatus.COMPLETED_NO);
099: }
100: }
101:
102: /**
103: */
104:
105: void define() {
106: for (int i = 0; i < members.length; i++) {
107: members[i].type_def = IDLType.create(members[i].type,
108: containing_repository, this .logger, this .poa);
109: }
110: }
111:
112: /**
113: */
114:
115: public org.omg.CORBA.ExceptionDescription describe_exception() {
116: return new org.omg.CORBA.ExceptionDescription(name(), id(),
117: org.omg.CORBA.ContainedHelper.narrow(defined_in).id(),
118: version(), type());
119: }
120:
121: public org.omg.CORBA.TypeCode type() {
122: if (type == null) {
123: throw new INTF_REPOS("Exception TypeCode is null");
124: }
125: return type;
126: }
127:
128: public org.omg.CORBA.Contained lookup(java.lang.String search_name) {
129: return null;
130: }
131:
132: public org.omg.CORBA.StructMember[] members() {
133: return members;
134: }
135:
136: // write interface not supported!
137:
138: public void members(org.omg.CORBA.StructMember[] a) {
139: }
140:
141: public org.omg.CORBA.ModuleDef create_module(String id,
142: String name, String version) {
143: return null;
144: }
145:
146: public org.omg.CORBA.ConstantDef create_constant(
147: java.lang.String id, java.lang.String name,
148: java.lang.String version, org.omg.CORBA.IDLType type,
149: org.omg.CORBA.Any value) {
150: return null;
151: }
152:
153: public org.omg.CORBA.StructDef create_struct(String id,
154: String name, String version, /*StructMemberSeq*/
155: org.omg.CORBA.StructMember[] members) {
156: return null;
157: }
158:
159: public org.omg.CORBA.UnionDef create_union(String id, String name,
160: String version, org.omg.CORBA.IDLType discriminator_type, /*UnionMemberSeq*/
161: org.omg.CORBA.UnionMember[] members) {
162: return null;
163: }
164:
165: public org.omg.CORBA.EnumDef create_enum(String id, String name,
166: String version, String[] members) {
167: return null;
168: }
169:
170: public org.omg.CORBA.AliasDef create_alias(String id, String name,
171: String version, org.omg.CORBA.IDLType original_type) {
172: return null;
173: }
174:
175: /**
176: * not supported
177: */
178:
179: public org.omg.CORBA.ExceptionDef create_exception(
180: java.lang.String id, java.lang.String name,
181: java.lang.String version,
182: org.omg.CORBA.StructMember[] member) {
183: return null;
184: }
185:
186: /**
187: * not supported
188: */
189:
190: public org.omg.CORBA.InterfaceDef create_interface(
191: String id,
192: String name,
193: String version,
194: /*InterfaceDefSeq*/org.omg.CORBA.InterfaceDef[] base_interfaces,
195: boolean is_abstract) {
196: return null;
197: }
198:
199: /**
200: * not supported
201: */
202:
203: public org.omg.CORBA.ValueBoxDef create_value_box(
204: java.lang.String id, java.lang.String name,
205: java.lang.String version, org.omg.CORBA.IDLType type) {
206: return null;
207: }
208:
209: /**
210: * not supported
211: */
212:
213: public org.omg.CORBA.ValueDef create_value(java.lang.String id,
214: java.lang.String name, java.lang.String version,
215: boolean is_custom, boolean is_abstract,
216: org.omg.CORBA.ValueDef base_value, boolean is_truncatable,
217: org.omg.CORBA.ValueDef[] abstract_base_values,
218: org.omg.CORBA.InterfaceDef[] supported_interfaces,
219: org.omg.CORBA.Initializer[] initializers) {
220: return null;
221: }
222:
223: /**
224: * not supported
225: */
226:
227: public org.omg.CORBA.NativeDef create_native(java.lang.String id,
228: java.lang.String name, java.lang.String version) {
229: return null;
230: }
231:
232: // from IRObject
233:
234: public org.omg.CORBA.DefinitionKind def_kind() {
235: return org.omg.CORBA.DefinitionKind.dk_Exception;
236: }
237:
238: public void destroy() {
239: throw new INTF_REPOS(ErrorMsg.IR_Not_Implemented,
240: org.omg.CORBA.CompletionStatus.COMPLETED_NO);
241: }
242:
243: public/*ContainedSeq*/org.omg.CORBA.Contained[] lookup_name(
244: /*Identifier*/String search_name, int levels_to_search,
245: org.omg.CORBA.DefinitionKind limit_type,
246: boolean exclude_inherited) {
247: return null;
248: }
249:
250: public/*DescriptionSeq*/org.omg.CORBA.ContainerPackage.Description[] describe_contents(
251: org.omg.CORBA.DefinitionKind limit_type,
252: boolean exclude_inherited, int max_returned_objs) {
253: return null;
254: }
255:
256: public org.omg.CORBA.Contained[] contents(
257: org.omg.CORBA.DefinitionKind limit_type,
258: boolean exclude_inherited) {
259: Hashtable limited = new Hashtable();
260:
261: // analog constants, exceptions etc.
262:
263: for (Enumeration e = contained.elements(); e.hasMoreElements();) {
264: Contained c = (Contained) e.nextElement();
265: if (limit_type.value() == org.omg.CORBA.DefinitionKind._dk_all
266: || limit_type.value() == c.def_kind.value()) {
267: limited.put(c, "");
268: }
269: }
270:
271: org.omg.CORBA.Contained[] c = new org.omg.CORBA.Contained[limited
272: .size()];
273: int i;
274: Enumeration e;
275: for (e = limited.keys(), i = 0; e.hasMoreElements(); i++)
276: c[i] = (org.omg.CORBA.Contained) e.nextElement();
277: return c;
278:
279: }
280:
281: // from Contained
282:
283: public org.omg.CORBA.ContainedPackage.Description describe() {
284: org.omg.CORBA.Any a = orb.create_any();
285: org.omg.CORBA.ExceptionDescription ed = describe_exception();
286: org.omg.CORBA.ExceptionDescriptionHelper.insert(a, ed);
287: return new org.omg.CORBA.ContainedPackage.Description(
288: org.omg.CORBA.DefinitionKind.dk_Exception, a);
289: }
290:
291: }
|