KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
25
26 import org.omg.CORBA.INTF_REPOS JavaDoc;
27 import org.omg.PortableServer.POA JavaDoc;
28
29 import org.apache.avalon.framework.logger.Logger;
30
31 /**
32  * @version $Id: ExceptionDef.java,v 1.11 2004/10/18 13:12:41 simon.mcqueen Exp $
33  */

34
35 public class ExceptionDef
36     extends Contained
37     implements org.omg.CORBA.ExceptionDefOperations JavaDoc
38 {
39     private org.omg.CORBA.TypeCode JavaDoc type;
40     private Class JavaDoc myClass;
41     private Class JavaDoc helperClass;
42     private org.omg.CORBA.StructMember JavaDoc[] members;
43     private Hashtable contained = new Hashtable();
44     private Logger logger;
45     private ClassLoader JavaDoc loader;
46     private POA JavaDoc poa;
47   
48     public ExceptionDef(Class JavaDoc c,
49                         org.omg.CORBA.Container JavaDoc _defined_in,
50                         org.omg.CORBA.Repository JavaDoc ir,
51                         ClassLoader JavaDoc loader,
52                         POA JavaDoc poa,
53                         Logger logger)
54     {
55         this.logger = logger;
56         this.loader = loader;
57         this.poa = poa;
58         def_kind = org.omg.CORBA.DefinitionKind.dk_Exception;
59         containing_repository = ir;
60         defined_in = _defined_in;
61         if (defined_in == null)
62         {
63             throw new INTF_REPOS JavaDoc ("defined_in = null");
64         }
65         if (containing_repository == null)
66         {
67             throw new INTF_REPOS JavaDoc ("containing_repository = null");
68         }
69
70         try
71         {
72             String JavaDoc classId = c.getName();
73             myClass = c;
74             version( "1.0" );
75             if( classId.indexOf('.') > 0 )
76             {
77                 name( classId.substring( classId.lastIndexOf('.')+1));
78                 absolute_name =
79                     org.omg.CORBA.ContainedHelper.narrow( defined_in ).absolute_name() + "::" + name;
80             }
81             else
82             {
83                 name( classId );
84                 absolute_name = "::" + name;
85             }
86
87             helperClass = this.loader.loadClass(classId + "Helper") ;
88             id( (String JavaDoc)helperClass.getDeclaredMethod("id", (Class JavaDoc[]) null).invoke( null, (Object JavaDoc[]) null ));
89             type =
90                 TypeCodeUtil.getTypeCode(myClass, this.loader, null, classId, this.logger );
91             try
92             {
93                 members = new org.omg.CORBA.StructMember JavaDoc[ type.member_count() ];
94                 for( int i = 0; i < members.length; i++ )
95                 {
96                     members[i] = new org.omg.CORBA.StructMember JavaDoc( type.member_name(i),
97                                                                  type.member_type(i),
98                                                                  null );
99                 }
100             }
101             catch( Exception JavaDoc e )
102             {
103                 this.logger.error("Caught Exception", e);
104             }
105
106             if (this.logger.isDebugEnabled())
107             {
108                 this.logger.debug("ExceptionDef: " + absolute_name);
109             }
110         }
111         catch ( Exception JavaDoc e )
112         {
113             this.logger.error("Caught Exception", e);
114             throw new INTF_REPOS JavaDoc( ErrorMsg.IR_Not_Implemented,
115                                   org.omg.CORBA.CompletionStatus.COMPLETED_NO);
116         }
117     }
118
119     /**
120      */

121
122     void define()
123     {
124         for( int i = 0; i < members.length; i++ )
125         {
126             members[i].type_def = IDLType.create( members[i].type,
127                                                   containing_repository,
128                                                   this.logger,
129                                                   this.poa);
130         }
131     }
132
133     /**
134      */

135
136     public org.omg.CORBA.ExceptionDescription JavaDoc describe_exception()
137     {
138         return new org.omg.CORBA.ExceptionDescription JavaDoc(name(),
139                                                       id(),
140                                                       org.omg.CORBA.ContainedHelper.narrow( defined_in ).id(),
141                                                       version(),
142                                                       type());
143     }
144
145     public org.omg.CORBA.TypeCode JavaDoc type()
146     {
147         if (type == null)
148         {
149             throw new INTF_REPOS JavaDoc ("Exception TypeCode is null");
150         }
151         return type;
152     }
153
154     public org.omg.CORBA.Contained JavaDoc lookup(java.lang.String JavaDoc search_name)
155     {
156         return null;
157     }
158
159
160     public org.omg.CORBA.StructMember JavaDoc[] members()
161     {
162         return members;
163     }
164
165
166     // write interface not supported!
167

168     public void members(org.omg.CORBA.StructMember JavaDoc[] a)
169     {
170     }
171
172
173     public org.omg.CORBA.ModuleDef JavaDoc create_module( String JavaDoc id, String JavaDoc name, String JavaDoc version)
174     {
175         return null;
176     }
177
178     public org.omg.CORBA.ConstantDef JavaDoc create_constant(java.lang.String JavaDoc id, java.lang.String JavaDoc name, java.lang.String JavaDoc version, org.omg.CORBA.IDLType JavaDoc type, org.omg.CORBA.Any JavaDoc value)
179     {
180         return null;
181     }
182
183     public org.omg.CORBA.StructDef JavaDoc create_struct( String JavaDoc id, String JavaDoc name, String JavaDoc version, /*StructMemberSeq*/ org.omg.CORBA.StructMember JavaDoc[] members){
184         return null;
185     }
186
187     public org.omg.CORBA.UnionDef JavaDoc create_union( String JavaDoc id, String JavaDoc name, String JavaDoc version, org.omg.CORBA.IDLType JavaDoc discriminator_type, /*UnionMemberSeq*/ org.omg.CORBA.UnionMember JavaDoc[] members){
188         return null;
189     }
190
191     public org.omg.CORBA.EnumDef JavaDoc create_enum( String JavaDoc id, String JavaDoc name, String JavaDoc version, String JavaDoc[] members){
192         return null;
193     }
194
195     public org.omg.CORBA.AliasDef JavaDoc create_alias( String JavaDoc id, String JavaDoc name, String JavaDoc version, org.omg.CORBA.IDLType JavaDoc original_type){
196         return null;
197     }
198
199     /**
200      * not supported
201      */

202
203     public org.omg.CORBA.ExceptionDef JavaDoc create_exception(java.lang.String JavaDoc id, java.lang.String JavaDoc name , java.lang.String JavaDoc version, org.omg.CORBA.StructMember JavaDoc[] member )
204     {
205         return null;
206     }
207
208     /**
209      * not supported
210      */

211
212     public org.omg.CORBA.InterfaceDef JavaDoc create_interface(
213                     String JavaDoc id,
214                     String JavaDoc name,
215                     String JavaDoc version,
216                     /*InterfaceDefSeq*/ org.omg.CORBA.InterfaceDef JavaDoc[] base_interfaces,
217                     boolean is_abstract )
218     {
219         return null;
220     }
221
222     /**
223      * not supported
224      */

225
226     public org.omg.CORBA.ValueBoxDef JavaDoc create_value_box(java.lang.String JavaDoc id,
227                                                       java.lang.String JavaDoc name,
228                                                       java.lang.String JavaDoc version,
229                                                       org.omg.CORBA.IDLType JavaDoc type)
230     {
231         return null;
232     }
233
234
235     /**
236      * not supported
237      */

238
239     public org.omg.CORBA.ValueDef JavaDoc create_value(
240                                      java.lang.String JavaDoc id,
241                                      java.lang.String JavaDoc name,
242                                      java.lang.String JavaDoc version,
243                                      boolean is_custom,
244                                      boolean is_abstract,
245                                      org.omg.CORBA.ValueDef JavaDoc base_value,
246                                      boolean is_truncatable,
247                                      org.omg.CORBA.ValueDef JavaDoc[] abstract_base_values,
248                                      org.omg.CORBA.InterfaceDef JavaDoc[] supported_interfaces,
249                                      org.omg.CORBA.Initializer JavaDoc[] initializers)
250     {
251         return null;
252     }
253
254
255     /**
256      * not supported
257      */

258
259     public org.omg.CORBA.NativeDef JavaDoc create_native(java.lang.String JavaDoc id,
260                                                  java.lang.String JavaDoc name,
261                                                  java.lang.String JavaDoc version)
262     {
263         return null;
264     }
265
266
267
268     // from IRObject
269

270     public org.omg.CORBA.DefinitionKind JavaDoc def_kind()
271     {
272         return org.omg.CORBA.DefinitionKind.dk_Exception;
273     }
274
275     public void destroy(){
276         throw new INTF_REPOS JavaDoc(ErrorMsg.IR_Not_Implemented,
277                                            org.omg.CORBA.CompletionStatus.COMPLETED_NO);
278     }
279
280
281     public /*ContainedSeq*/ org.omg.CORBA.Contained JavaDoc[] lookup_name(/*Identifier*/ String JavaDoc search_name, int levels_to_search, org.omg.CORBA.DefinitionKind JavaDoc limit_type, boolean exclude_inherited)
282     {
283         return null;
284     }
285
286     public /*DescriptionSeq*/ org.omg.CORBA.ContainerPackage.Description[] describe_contents(org.omg.CORBA.DefinitionKind JavaDoc limit_type, boolean exclude_inherited, int max_returned_objs){
287         return null;
288     }
289
290
291     public org.omg.CORBA.Contained JavaDoc[] contents(org.omg.CORBA.DefinitionKind JavaDoc limit_type,
292                                               boolean exclude_inherited)
293     {
294         Hashtable limited = new Hashtable();
295
296         // analog constants, exceptions etc.
297

298         for( Enumeration e = contained.elements(); e.hasMoreElements(); )
299         {
300             Contained c = (Contained)e.nextElement();
301             if( limit_type.value() == org.omg.CORBA.DefinitionKind._dk_all ||
302                 limit_type.value() == c.def_kind.value() )
303             {
304                 limited.put( c, "" );
305             }
306         }
307
308         org.omg.CORBA.Contained JavaDoc[] c = new org.omg.CORBA.Contained JavaDoc[limited.size()];
309         int i;
310         Enumeration e;
311         for( e = limited.keys(), i=0 ; e.hasMoreElements(); i++ )
312             c[i] = (org.omg.CORBA.Contained JavaDoc)e.nextElement();
313         return c;
314
315     }
316
317
318     // from Contained
319

320     public org.omg.CORBA.ContainedPackage.Description describe()
321     {
322         org.omg.CORBA.Any JavaDoc a = orb.create_any();
323         org.omg.CORBA.ExceptionDescription JavaDoc ed = describe_exception();
324         org.omg.CORBA.ExceptionDescriptionHelper.insert( a, ed );
325         return new org.omg.CORBA.ContainedPackage.Description( org.omg.CORBA.DefinitionKind.dk_Exception, a);
326     }
327
328 }
329
330
331
Popular Tags