KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.*;
25 import java.util.*;
26
27 import org.omg.CORBA.IDLType JavaDoc;
28 import org.omg.CORBA.INTF_REPOS JavaDoc;
29 import org.omg.CORBA.ORB JavaDoc;
30 import org.omg.CORBA.TypeCode JavaDoc;
31 import org.omg.CORBA.InterfaceDefPackage.FullInterfaceDescription;
32 import org.omg.CORBA.ContainerPackage.*;
33 import org.omg.CORBA.OperationDescription JavaDoc;
34 import org.omg.CORBA.AttributeDescription JavaDoc;
35 import org.omg.CORBA.ConstantDescription JavaDoc;
36 import org.omg.PortableServer.POA JavaDoc;
37
38 import org.apache.avalon.framework.logger.Logger;
39
40 /**
41  * JacORB implementation of org.omg.CORBA.InterfaceDef
42  *
43  * @author Gerald Brose
44  * @version $Id: InterfaceDef.java,v 1.20 2004/10/18 13:12:41 simon.mcqueen Exp $
45  */

46
47 public class InterfaceDef
48     extends org.jacorb.ir.Contained
49     implements org.omg.CORBA.InterfaceDefOperations JavaDoc, ContainerType
50 {
51     protected static char fileSeparator =
52         System.getProperty("file.separator").charAt(0);
53
54     Class JavaDoc theClass;
55     private Class JavaDoc helperClass;
56     private Class JavaDoc signatureClass;
57
58     private org.omg.CORBA.TypeCode JavaDoc typeCode;
59     private OperationDef[] op_defs;
60     private org.omg.CORBA.OperationDescription JavaDoc[] operations;
61
62     // to be done !!
63
private boolean is_abstract = false;
64
65     private AttributeDef[] att_defs;
66     private org.omg.CORBA.AttributeDescription JavaDoc[] attributes;
67
68     private ConstantDef[] constant_defs;
69     private org.omg.CORBA.ConstantDescription JavaDoc[] constants;
70
71     private org.omg.CORBA.InterfaceDef JavaDoc[] base_interfaces;
72     private String JavaDoc [] base_names;
73     private FullInterfaceDescription fullDescription;
74     /** local references to contained objects */
75     private Hashtable containedLocals = new Hashtable();
76
77     /** CORBA references to contained objects */
78     private Hashtable contained = new Hashtable();
79
80     /* reference to my container as a contained object */
81     private org.omg.CORBA.Contained JavaDoc myContainer;
82     private org.omg.CORBA.InterfaceDef JavaDoc myReference;
83
84     private File my_dir;
85     private Hashtable op = new Hashtable();
86     private Hashtable att = new Hashtable();
87     private Hashtable my_const = new Hashtable();
88     private org.omg.CORBA.Contained JavaDoc [] classes;
89     private String JavaDoc path;
90     private String JavaDoc [] class_names;
91     private int size = 0;
92     private boolean defined = false;
93     private boolean loaded = false;
94
95     private Class JavaDoc containedClass = null;
96     private Class JavaDoc containerClass = null;
97
98     private ClassLoader JavaDoc loader;
99     private POA JavaDoc poa;
100     private Logger logger;
101
102     /**
103      * Class constructor
104      */

105
106     InterfaceDef( Class JavaDoc c,
107                   Class JavaDoc helperClass,
108                   String JavaDoc path,
109                   org.omg.CORBA.Container JavaDoc def_in,
110                   org.omg.CORBA.Repository JavaDoc ir,
111                   ClassLoader JavaDoc loader,
112                   POA JavaDoc poa,
113                   Logger logger)
114         throws INTF_REPOS JavaDoc
115     {
116         this.loader = loader;
117         this.poa = poa;
118         this.logger = logger;
119
120         if (ir == null)
121         {
122             throw new INTF_REPOS JavaDoc ("IR null!");
123         }
124
125         if (def_in == null)
126         {
127             throw new INTF_REPOS JavaDoc ("Defined_in null!");
128         }
129
130         def_kind = org.omg.CORBA.DefinitionKind.dk_Interface;
131         containing_repository = ir;
132         defined_in = def_in;
133         if( def_in.equals(ir) )
134             myContainer = null;
135         else
136             myContainer = org.omg.CORBA.ContainedHelper.narrow( defined_in );
137
138         this.path = path;
139
140         theClass = c;
141         String JavaDoc classId = c.getName();
142         this.helperClass = helperClass;
143
144         Hashtable irInfo= null;
145         Class JavaDoc irHelperClass = null;
146         try
147         {
148             irHelperClass =
149                 this.loader.loadClass( theClass.getName() + "IRHelper");
150             irInfo = (Hashtable)irHelperClass.getDeclaredField("irInfo").get(null);
151         }
152         catch( ClassNotFoundException JavaDoc e )
153         {
154             logger.error("No IR helper class for interface " +
155                          theClass.getName(), e);
156         }
157         catch( Exception JavaDoc e )
158         {
159             logger.error("Caught Exception", e);
160         }
161
162         if (irInfo == null)
163         {
164             throw new INTF_REPOS JavaDoc ("IR Info null!");
165         }
166
167         try
168         {
169             containedClass = this.loader.loadClass("org.omg.CORBA.Contained");
170             signatureClass = this.loader.loadClass(classId + "Operations");
171
172             id( (String JavaDoc)helperClass.getDeclaredMethod("id", (Class JavaDoc[]) null).invoke( null, (Object JavaDoc[]) null ) );
173             version( id().substring( id().lastIndexOf(':')));
174             typeCode = TypeCodeUtil.getTypeCode( c, null, this.logger );
175
176             full_name = classId.replace('.', '/');
177             if( classId.indexOf('.') > 0 )
178             {
179                 name = classId.substring( classId.lastIndexOf('.')+1);
180
181                 if (defined_in == null)
182                 {
183                     throw new INTF_REPOS JavaDoc ("InterfaceDef " + name + " path " + path +
184                                           " has no defined_in repository");
185                 }
186
187                 if( containedClass.isAssignableFrom( defined_in.getClass() ))
188                     absolute_name =
189                         ( myContainer != null ? myContainer.absolute_name() : "Global" )
190                         + "::" + name;
191                 else
192                     absolute_name = "::" + name;
193             }
194             else
195             {
196                 name = classId;
197                 defined_in = containing_repository;
198                 absolute_name = "::" + name;
199             }
200
201             if (this.logger.isDebugEnabled())
202             {
203                 this.logger.debug("InterfaceDef: " + absolute_name +
204                                   " path: " + path);
205             }
206
207             /* get directory for nested definitions' classes */
208             File f =
209                 new File( path + fileSeparator +
210                           classId.replace('.', fileSeparator) + "Package" );
211
212             if( f.exists() && f.isDirectory() )
213                 my_dir = f;
214
215
216         }
217         catch ( Exception JavaDoc e )
218         {
219             this.logger.error("Caught exception",e);
220             throw new INTF_REPOS JavaDoc( ErrorMsg.IR_Not_Implemented,
221                                                 org.omg.CORBA.CompletionStatus.COMPLETED_NO);
222         }
223     }
224
225
226
227     public void loadContents()
228     {
229         if (this.logger.isDebugEnabled())
230         {
231             this.logger.debug("Interface " +name+ " loading... ");
232         }
233
234         // read from the interface class (operations and atributes)
235
if (getReference() == null)
236         {
237             throw new INTF_REPOS JavaDoc ("getReference returns null");
238         }
239
240         myReference =
241             org.omg.CORBA.InterfaceDefHelper.narrow( getReference());
242
243         if (myReference == null)
244         {
245             throw new INTF_REPOS JavaDoc ("narrow failed for " + getReference ());
246         }
247
248         /* load nested definitions from interfacePackage directory */
249
250         String JavaDoc[] classes = null;
251
252         if( my_dir != null )
253         {
254             classes = my_dir.list( new IRFilenameFilter(".class") );
255
256             // load class files in this interface's Package directory
257
if( classes != null)
258             {
259                 for( int j = 0; j< classes.length; j++ )
260                 {
261                     try
262                     {
263                         if (this.logger.isDebugEnabled())
264                         {
265                             this.logger.debug(
266                                 "Interface " +name+ " tries " +
267                                 full_name.replace('.', fileSeparator) +
268                                 "Package" + fileSeparator +
269                                 classes[j].substring( 0, classes[j].indexOf(".class")) );
270                         }
271
272                         ClassLoader JavaDoc loader = getClass().getClassLoader();
273                         if( loader == null )
274                         {
275                             loader = this.loader;
276                         }
277
278                         Class JavaDoc cl =
279                             loader.loadClass(
280                                    ( full_name.replace('.', fileSeparator) +
281                                      "Package" + fileSeparator +
282                                      classes[j].substring( 0, classes[j].indexOf(".class"))
283                                      ).replace( fileSeparator, '/') );
284
285                         Contained containedObject =
286                             Contained.createContained( cl,
287                                                        path,
288                                                        myReference,
289                                                        containing_repository,
290                                                        this.logger,
291                                                        this.loader,
292                                                        this.poa);
293                         if( containedObject == null )
294                             continue;
295
296                         org.omg.CORBA.Contained JavaDoc containedRef =
297                             Contained.createContainedReference(containedObject,
298                                                                this.logger,
299                                                                this.poa);
300
301
302                         containedRef.move( myReference,
303                                            containedRef.name(),
304                                            containedRef.version() );
305
306                         if (this.logger.isDebugEnabled())
307                         {
308                             this.logger.debug("Interface " + full_name +
309                                               " loads "+ containedRef.name());
310                         }
311
312                         contained.put( containedRef.name() , containedRef );
313                         containedLocals.put( containedRef.name(), containedObject );
314
315                         if( containedObject instanceof ContainerType )
316                             ((ContainerType)containedObject).loadContents();
317
318                     }
319                     catch ( Exception JavaDoc e )
320                     {
321                         this.logger.error("Caught exception",e);
322                     }
323                 }
324             }
325         }
326
327         loaded = true;
328
329         if (this.logger.isDebugEnabled())
330         {
331             this.logger.debug("Interface " + name + " loaded");
332         }
333     }
334
335     void define()
336     {
337         if ( ! loaded)
338         {
339             throw new INTF_REPOS JavaDoc ("Interface " + name + " not loaded!");
340         }
341
342         if (this.logger.isDebugEnabled())
343         {
344             this.logger.debug("Interface " + name + " defining... ]");
345             this.logger.debug("Interface " +name+ " loads attributes/ops");
346         }
347
348         Vector ops = new Vector();
349         Vector atts = new Vector();
350         Hashtable irInfo= null;
351
352         Class JavaDoc irHelperClass = null;
353         try
354         {
355             irHelperClass =
356                 this.loader.loadClass( theClass.getName() + "IRHelper");
357             irInfo = (Hashtable)irHelperClass.getDeclaredField("irInfo").get(null);
358         }
359         catch( ClassNotFoundException JavaDoc e )
360         {
361             this.logger.error("!! No IR helper class for interface " +
362                               theClass.getName(), e);
363         }
364         catch( Exception JavaDoc e )
365         {
366             logger.error("Caught exception", e);
367         }
368
369         Method methods[] = signatureClass.getDeclaredMethods();
370
371         for( int i = 0; i < methods.length; i++ )
372         {
373             Object JavaDoc value = irInfo.get(methods[i].getName());
374             if( value == null || !((String JavaDoc)value).startsWith("attribute"))
375             {
376                 ops.addElement(
377                      new OperationDef( methods[i],
378                                        theClass,
379                                        irHelperClass,
380                                        myReference,
381                                        this.logger,
382                                        this.loader,
383                                        this.poa));
384             }
385             else
386             {
387                 if( ((String JavaDoc)value).startsWith("attribute") )
388                 {
389                     String JavaDoc attrDescr = (String JavaDoc)value;
390
391                     if( methods[i].getReturnType() == Void JavaDoc.class )
392                         continue;
393
394                     int idx = attrDescr.indexOf('-');
395                     String JavaDoc attrTypeName =
396                         attrDescr.substring( attrDescr.indexOf(";")+1);
397
398                     atts.addElement(
399                         new AttributeDef( methods[i],
400                                           attrTypeName,
401                                           ( idx > 0 ?
402                                             org.omg.CORBA.AttributeMode.ATTR_NORMAL :
403                                             org.omg.CORBA.AttributeMode.ATTR_READONLY ),
404                                           myReference,
405                                           containing_repository,
406                                           this.logger,
407                                           this.loader,
408                                           this.poa));
409                 }
410             }
411         }
412
413         if (this.logger.isDebugEnabled())
414         {
415             this.logger.debug("Interface " +name+ " defines ops");
416         }
417
418         op_defs = new OperationDef[ ops.size() ];
419         ops.copyInto( op_defs );
420         for( int i = 0; i < op_defs.length; i++ )
421         {
422             op_defs[i].move( myReference , op_defs[i].name(), version );
423             containedLocals.put( op_defs[i].name(), op_defs[i] );
424
425             try
426             {
427                 org.omg.CORBA.OperationDef JavaDoc operationRef =
428                     org.omg.CORBA.OperationDefHelper.narrow(
429                          this.poa.servant_to_reference(
430                                  new org.omg.CORBA.OperationDefPOATie( op_defs[i] )));
431                 contained.put( op_defs[i].name(), operationRef ) ;
432                 op_defs[i].setReference(operationRef);
433             }
434             catch( Exception JavaDoc e )
435             {
436                 this.logger.error("Caught exception",e);
437             }
438         }
439
440         if (this.logger.isDebugEnabled())
441         {
442             this.logger.debug("Interface " +name+ " defines attributes");
443         }
444
445         att_defs = new AttributeDef[ atts.size() ];
446         atts.copyInto( att_defs );
447
448         for( int i = 0; i < att_defs.length; i++ )
449         {
450             att_defs[i].move( myReference , att_defs[i].name(), version );
451             containedLocals.put( att_defs[i].name(), att_defs[i] );
452             try
453             {
454                 org.omg.CORBA.AttributeDef JavaDoc attribute =
455                     org.omg.CORBA.AttributeDefHelper.narrow(
456                           this.poa.servant_to_reference(
457                                new org.omg.CORBA.AttributeDefPOATie( att_defs[i] )));
458                 contained.put( att_defs[i].name(), attribute );
459                 att_defs[i].setReference( attribute );
460             }
461             catch( Exception JavaDoc e )
462             {
463                 this.logger.error("Caught exception",e);
464             }
465         }
466
467         /* constants */
468         if (this.logger.isDebugEnabled())
469         {
470             this.logger.debug("Interface " + name + " defines constants");
471         }
472
473         Field[] fields = theClass.getDeclaredFields();
474         constant_defs = new ConstantDef[ fields.length ];
475         for( int i = 0; i < constant_defs.length; i++ )
476         {
477             constant_defs[i] = new ConstantDef( fields[i],
478                                                 myReference,
479                                                 containing_repository,
480                                                 this.logger,
481                                                 this.poa);
482             constant_defs[i].move( myReference , constant_defs[i].name(), version );
483             containedLocals.put( constant_defs[i].name(), constant_defs[i] );
484             try
485             {
486                 org.omg.CORBA.ConstantDef JavaDoc constRef =
487                     org.omg.CORBA.ConstantDefHelper.narrow(
488                          this.poa.servant_to_reference(
489                              new org.omg.CORBA.ConstantDefPOATie( constant_defs[i] )));
490
491                 contained.put( constant_defs[i].name(), constRef ) ;
492                 constant_defs[i].setReference(constRef);
493             }
494             catch( Exception JavaDoc e )
495             {
496                 this.logger.error("Caught exception",e);
497             }
498         }
499
500         for( Enumeration e = containedLocals.elements();
501              e.hasMoreElements();
502              ((IRObject)e.nextElement()).define())
503             ;
504
505
506         /* get base interfaces */
507         Class JavaDoc class_interfaces [] = theClass.getInterfaces();
508         Hashtable si = new Hashtable();
509
510         Class JavaDoc objectClass = null;
511         try
512         {
513             objectClass = this.loader.loadClass( "org.omg.CORBA.Object");
514         }
515         catch( ClassNotFoundException JavaDoc cnfe )
516         {}
517
518         for( int i = 0; i < class_interfaces.length; i++ )
519         {
520             if( objectClass.isAssignableFrom( class_interfaces[i] ) &&
521                 !class_interfaces[i].getName().equals("org.omg.CORBA.Object") )
522             {
523                 si.put( class_interfaces[i], "");
524             }
525         }
526
527         Enumeration e = si.keys();
528         base_names = new String JavaDoc[ si.size() ];
529         int i = 0;
530         Vector v = new Vector();
531         while( e.hasMoreElements() )
532         {
533             try
534             {
535                 Class JavaDoc baseClass = (Class JavaDoc)e.nextElement();
536                 base_names[i] = baseClass.getName();
537                 Class JavaDoc helperClass =
538                     this.loader.loadClass( base_names[i] + "Helper");
539                 String JavaDoc baseId =
540                     (String JavaDoc)helperClass.getDeclaredMethod( "id", (Class JavaDoc[]) null).invoke(null, (Object JavaDoc[]) null);
541                 org.omg.CORBA.InterfaceDef JavaDoc base_interface =
542                     org.omg.CORBA.InterfaceDefHelper.narrow(
543                         containing_repository.lookup_id( baseId ));
544                 if( base_interface == null )
545                 {
546                     this.logger.error("Base interface def " +
547                                       baseId + " is null!!!");
548                 }
549                 else
550                 {
551                     v.addElement( base_interface );
552                 }
553
554                 i++;
555             }
556             catch( Exception JavaDoc exc )
557             {
558                 exc.printStackTrace();
559             }
560         }
561         base_interfaces = new org.omg.CORBA.InterfaceDef JavaDoc[ v.size() ];
562         v.copyInto( base_interfaces );
563
564         defined = true;
565         if (this.logger.isDebugEnabled())
566         {
567             this.logger.debug("Interface " + name + " defined ]");
568         }
569     }
570
571
572     public boolean is_abstract()
573     {
574         return false;
575     }
576
577     public void is_abstract(boolean arg)
578     {
579     }
580
581     /**
582      * @return an array containing interface definitions of the superclass and
583      * the interfaces extended by this class. Has length 0 if this class
584      * is Object.
585      */

586
587     public org.omg.CORBA.InterfaceDef JavaDoc[] base_interfaces()
588     {
589         return base_interfaces;
590     }
591
592     public FullInterfaceDescription describe_interface()
593     {
594         if ( ! defined)
595         {
596             throw new INTF_REPOS JavaDoc ("InterfaceDef " + name + " not defined.");
597         }
598
599         if( fullDescription == null )
600         {
601             String JavaDoc def_in = "IDL:Global:1.0";
602             if( defined_in instanceof org.omg.CORBA.Contained JavaDoc )
603                 def_in = ((org.omg.CORBA.Contained JavaDoc)defined_in).id();
604
605             /* before assembling descriptions, get hold of all super
606                types' FullInterfaceDescriptions */

607
608             FullInterfaceDescription [] baseDescriptions =
609                 new FullInterfaceDescription[ base_interfaces().length ];
610
611             for( int b = 0; b < base_interfaces.length; b++ )
612             {
613                 baseDescriptions[b] = base_interfaces[b].describe_interface();
614             }
615
616             /* build operation descriptions */
617
618             Hashtable ops = new Hashtable();
619
620             for( int c = 0; c < op_defs.length; c++ )
621             {
622                 OperationDescription JavaDoc operation = op_defs[c].describe_operation();
623                 ops.put( operation.name, operation );
624             }
625
626             /* get operation descriptions from super types, potentially duplicate
627                descriptions due to diamond inheritance are removed by hashing
628              */

629
630             for( int baseOps = 0; baseOps < baseDescriptions.length; baseOps++ )
631             {
632                 for( int bbaseOps = 0;
633                      bbaseOps < baseDescriptions[baseOps].operations.length;
634                      bbaseOps++ )
635                 {
636                     OperationDescription JavaDoc base_op =
637                         baseDescriptions[baseOps].operations[bbaseOps];
638
639                     if( !ops.containsKey( base_op.name ))
640                         ops.put( base_op.name, base_op );
641                 }
642             }
643
644             operations = new OperationDescription JavaDoc[ ops.size() ];
645
646             int opsCount = 0;
647             for( Enumeration e = ops.elements(); e.hasMoreElements(); opsCount++ )
648             {
649                 operations[ opsCount ] = (OperationDescription JavaDoc)e.nextElement();
650             }
651             ops.clear();
652
653             /* build attribute descriptions */
654             Hashtable atts = new Hashtable();
655
656             for( int a = 0; a < att_defs.length; a++ )
657             {
658                 AttributeDescription JavaDoc att = att_defs[a].describe_attribute();
659                 atts.put( att.name, att );
660             }
661
662             /* get attribute descriptions from super types */
663
664             for( int baseAtts = 0; baseAtts < baseDescriptions.length; baseAtts++ )
665             {
666                 for( int bbaseAtts = 0;
667                      bbaseAtts < baseDescriptions[ baseAtts ].attributes.length;
668                      bbaseAtts++ )
669                 {
670                     AttributeDescription JavaDoc base_att =
671                         baseDescriptions[ baseAtts ].attributes[ bbaseAtts ];
672
673                     if( !atts.containsKey( base_att.name ))
674                         atts.put( base_att.name, base_att );
675                 }
676             }
677
678             attributes = new AttributeDescription JavaDoc[ atts.size() ];
679
680             int attsCount = 0;
681             for( Enumeration e = atts.elements(); e.hasMoreElements(); attsCount++ )
682             {
683                 attributes[ attsCount ] = (AttributeDescription JavaDoc)e.nextElement();
684             }
685             atts.clear();
686
687             /* build constant descriptions */
688
689             constants = new org.omg.CORBA.ConstantDescription JavaDoc[ constant_defs.length ];
690             for( int b = 0; b < constant_defs.length; b++ )
691             {
692                 constants[b] = constant_defs[b].describe_constant();
693             }
694
695             if (operations == null)
696             {
697                 throw new INTF_REPOS JavaDoc ("operations null!");
698             }
699             if (attributes == null)
700             {
701                 throw new INTF_REPOS JavaDoc ("attributes null!");
702             }
703
704             fullDescription =
705                 new FullInterfaceDescription( name,
706                                               id,
707                                               def_in,
708                                               version,
709                                               operations,
710                                               attributes,
711                                               base_names,
712                                               typeCode,
713                                               is_abstract );
714         }
715         return fullDescription;
716     }
717
718
719     public boolean is_a( String JavaDoc interface_id )
720     {
721         if (this.logger.isDebugEnabled())
722         {
723             this.logger.debug("Is interface " + id() + " a " +
724                               interface_id + "?");
725         }
726
727         if( id().equals( interface_id ))
728             return true;
729
730         org.omg.CORBA.InterfaceDef JavaDoc[] bases = base_interfaces();
731         for( int i = 0; i < bases.length; i++ )
732         {
733             if( bases[i].is_a( interface_id ))
734                 return true;
735             if( bases[i].id().equals("IDL:omg.org/CORBA/Object:1.0"))
736                 continue;
737         }
738         if (this.logger.isDebugEnabled())
739         {
740             this.logger.debug( "Interface " + id() + " is not a " +
741                                interface_id );
742         }
743         return false;
744     }
745
746     // write methods on an InterfaceDef,
747
// these are not supported at the moment !!
748

749     public void base_interfaces( org.omg.CORBA.InterfaceDef JavaDoc[] a )
750     {
751         throw new INTF_REPOS JavaDoc(ErrorMsg.IR_Not_Implemented,
752                                            org.omg.CORBA.CompletionStatus.COMPLETED_NO);
753     }
754
755     public org.omg.CORBA.AttributeDef JavaDoc create_attribute( String JavaDoc id,
756                                                         String JavaDoc name,
757                                                         String JavaDoc version,
758                                                         IDLType type,
759                                                         org.omg.CORBA.AttributeMode JavaDoc mode
760                                                         )
761     {
762         throw new INTF_REPOS JavaDoc( ErrorMsg.IR_Not_Implemented,
763                                             org.omg.CORBA.CompletionStatus.COMPLETED_NO);
764     }
765
766     public org.omg.CORBA.OperationDef JavaDoc create_operation( String JavaDoc id,
767                                                        String JavaDoc name,
768                                                        String JavaDoc version,
769                                                        org.omg.CORBA.IDLType JavaDoc result,
770                                                        org.omg.CORBA.OperationMode JavaDoc mode,
771                                                        org.omg.CORBA.ParameterDescription JavaDoc[] params,
772                                                        org.omg.CORBA.ExceptionDef JavaDoc[] exceptions,
773                                                        String JavaDoc[] contexts
774                                                        )
775     {
776         throw new INTF_REPOS JavaDoc( ErrorMsg.IR_Not_Implemented,
777                                             org.omg.CORBA.CompletionStatus.COMPLETED_NO);
778     }
779
780
781     // from org.omg.CORBA.Container
782

783     public org.omg.CORBA.Contained JavaDoc lookup( String JavaDoc scopedname )
784     {
785         if (this.logger.isDebugEnabled())
786         {
787             this.logger.debug("Interface " + this.name +
788                               " lookup " + scopedname);
789         }
790
791         String JavaDoc top_level_name;
792         String JavaDoc rest_of_name;
793         String JavaDoc name;
794
795         if( scopedname.startsWith("::") )
796         {
797             name = scopedname.substring(2);
798         }
799         else
800             name = scopedname;
801
802         if( name.indexOf("::") > 0 )
803         {
804             top_level_name = name.substring( 0, name.indexOf("::") );
805             rest_of_name = name.substring( name.indexOf("::") + 2);
806         }
807         else
808         {
809             top_level_name = name;
810             rest_of_name = null;
811         }
812
813         try
814         {
815             org.omg.CORBA.Contained JavaDoc top =
816                 (org.omg.CORBA.Contained JavaDoc)contained.get( top_level_name );
817
818             if( top == null )
819             {
820                 if (this.logger.isDebugEnabled())
821                 {
822                     this.logger.debug("Interface " + this.name +
823                                              " top " + top_level_name +
824                                       " not found");
825                 }
826                 return null;
827             }
828
829             if( rest_of_name == null )
830             {
831                 return top;
832             }
833             else
834             {
835                 if( top instanceof org.omg.CORBA.Container JavaDoc)
836                 {
837                     return ((org.omg.CORBA.Container JavaDoc)top).lookup( rest_of_name );
838                 }
839                 else
840                 {
841                     if (this.logger.isDebugEnabled())
842                     {
843                         this.logger.debug("Interface " + this.name +
844                                           " " + scopedname + " not found ");
845                     }
846                     return null;
847                 }
848             }
849         }
850         catch( Exception JavaDoc e )
851         {
852             this.logger.error("Caught exception",e);
853             return null;
854         }
855
856     }
857
858     public org.omg.CORBA.Contained JavaDoc[] contents(org.omg.CORBA.DefinitionKind JavaDoc limit_type,
859                                               boolean exclude_inherited)
860     {
861         if ( ! defined)
862         {
863             throw new INTF_REPOS JavaDoc ("InterfaceDef " + name + " not defined.");
864         }
865
866         Hashtable limited = new Hashtable();
867
868         // analog constants, exceptions etc.
869

870         for( Enumeration e = contained.elements(); e.hasMoreElements(); )
871         {
872             org.omg.CORBA.Contained JavaDoc c = (org.omg.CORBA.Contained JavaDoc)e.nextElement();
873             if( limit_type.value() == org.omg.CORBA.DefinitionKind._dk_all ||
874                 limit_type.value() == c.def_kind().value() )
875             {
876                 limited.put( c, "" );
877             }
878         }
879
880         org.omg.CORBA.Contained JavaDoc[] c =
881             new org.omg.CORBA.Contained JavaDoc[limited.size()];
882
883         int i;
884         Enumeration e;
885         for( e = limited.keys(), i=0 ; e.hasMoreElements(); i++ )
886             c[i] = (org.omg.CORBA.Contained JavaDoc)e.nextElement();
887         return c;
888
889     }
890
891     public org.omg.CORBA.Contained JavaDoc[] lookup_name(String JavaDoc search_name,
892                                                  int levels_to_search,
893                                                  org.omg.CORBA.DefinitionKind JavaDoc limit_type,
894                                                  boolean exclude_inherited)
895     {
896        if( levels_to_search == 0 )
897             return null;
898
899         org.omg.CORBA.Contained JavaDoc[] c = contents( limit_type, exclude_inherited );
900         Hashtable found = new Hashtable();
901
902         for( int i = 0; i < c.length; i++)
903             if( c[i].name().equals( search_name ) )
904                 found.put( c[i], "" );
905
906         if( levels_to_search > 1 || levels_to_search < 0 )
907         {
908             // search up to a specific depth or indefinitely
909
for( int i = 0; i < c.length; i++)
910             {
911                 if( c[i] instanceof org.omg.CORBA.Container JavaDoc )
912                 {
913                     org.omg.CORBA.Contained JavaDoc[] tmp_seq =
914                         ((org.omg.CORBA.Container JavaDoc)c[i]).lookup_name( search_name,
915                                                                      levels_to_search-1,
916                                                                      limit_type,
917                                                                      exclude_inherited);
918                     if( tmp_seq != null )
919                         for( int j = 0; j < tmp_seq.length; j++)
920                             found.put( tmp_seq[j], "" );
921                 }
922             }
923         }
924
925
926         org.omg.CORBA.Contained JavaDoc[] result = new org.omg.CORBA.Contained JavaDoc[ found.size() ];
927         int idx = 0;
928
929         for( Enumeration e = found.keys(); e.hasMoreElements(); )
930             result[ idx++] = (org.omg.CORBA.Contained JavaDoc)e.nextElement();
931
932         return result;
933     }
934
935
936     public Description[] describe_contents(org.omg.CORBA.DefinitionKind JavaDoc limit_type,
937                                            boolean exclude_inherited,
938                                            int max_returned_objs)
939     {
940         return null;
941     }
942
943
944     // write interface not supported!
945

946     public org.omg.CORBA.ModuleDef JavaDoc create_module( String JavaDoc id,
947                                                   String JavaDoc name,
948                                                   String JavaDoc version)
949     {
950         return null;
951     }
952
953     public org.omg.CORBA.ConstantDef JavaDoc create_constant( /*RepositoryId*/ String JavaDoc id,
954                                                       /*Identifier*/ String JavaDoc name,
955                                                       /*VersionSpec*/ String JavaDoc version,
956                                                       IDLType type, org.omg.CORBA.Any JavaDoc value)
957     {
958         return null;
959     }
960
961     public org.omg.CORBA.StructDef JavaDoc create_struct(/*RepositoryId*/ String JavaDoc id,
962                                                  /*Identifier*/ String JavaDoc name,
963                                                  /*VersionSpec*/ String JavaDoc version,
964                                                  /*StructMemberSeq*/ org.omg.CORBA.StructMember JavaDoc[] members)
965     {
966         return null;
967     }
968
969     public org.omg.CORBA.UnionDef JavaDoc create_union( /*RepositoryId*/ String JavaDoc id,
970                                                 /*Identifier*/ String JavaDoc name,
971                                                 /*VersionSpec*/ String JavaDoc version,
972                                                 org.omg.CORBA.IDLType JavaDoc discriminator_type,
973                                                 /*UnionMemberSeq*/ org.omg.CORBA.UnionMember JavaDoc[] members)
974     {
975         return null;
976     }
977
978     public org.omg.CORBA.EnumDef JavaDoc create_enum(/*RepositoryId*/ String JavaDoc id,
979                                              /*Identifier*/ String JavaDoc name,
980                                              /*VersionSpec*/ String JavaDoc version,
981                                              /*EnumMemberSeq*/ /*Identifier*/ String JavaDoc[] members)
982     {
983         return null;
984     }
985
986     public org.omg.CORBA.AliasDef JavaDoc create_alias(/*RepositoryId*/ String JavaDoc id,
987                                                /*Identifier*/ String JavaDoc name,
988                                                /*VersionSpec*/ String JavaDoc version,
989                                                org.omg.CORBA.IDLType JavaDoc original_type)
990     {
991         return null;
992     }
993
994
995     /**
996      * not supported
997      */

998
999     public org.omg.CORBA.ExceptionDef JavaDoc create_exception(String JavaDoc id,
1000                                                       String JavaDoc name ,
1001                                                       String JavaDoc version,
1002                                                       org.omg.CORBA.StructMember JavaDoc[] member )
1003    {
1004        return null;
1005    }
1006
1007    /**
1008     * not supported
1009     */

1010
1011    public org.omg.CORBA.InterfaceDef JavaDoc create_interface(/*RepositoryId*/ String JavaDoc id,
1012                                                       /*Identifier*/ String JavaDoc name,
1013                                                       /*VersionSpec*/ String JavaDoc version,
1014                                                       /*InterfaceDefSeq*/ org.omg.CORBA.InterfaceDef JavaDoc[] base_interfaces,
1015                                                       boolean is_abstract )
1016    {
1017        return null;
1018    }
1019
1020    /**
1021     * not supported
1022     */

1023
1024    public org.omg.CORBA.ValueBoxDef JavaDoc create_value_box(String JavaDoc id,
1025                                                      String JavaDoc name,
1026                                                      String JavaDoc version,
1027                                                      org.omg.CORBA.IDLType JavaDoc type)
1028    {
1029        return null;
1030    }
1031
1032
1033    /**
1034     * not supported
1035     */

1036
1037    public org.omg.CORBA.ValueDef JavaDoc create_value(String JavaDoc id,
1038                                                String JavaDoc name,
1039                                                String JavaDoc version,
1040                                                boolean is_custom,
1041                                                boolean is_abstract,
1042                                                org.omg.CORBA.ValueDef JavaDoc base_value,
1043                                                boolean is_truncatable,
1044                                                org.omg.CORBA.ValueDef JavaDoc[] abstract_base_values,
1045                                                org.omg.CORBA.InterfaceDef JavaDoc[] supported_interfaces,
1046                                                org.omg.CORBA.Initializer JavaDoc[] initializers)
1047    {
1048        return null;
1049    }
1050
1051
1052    /**
1053     * not supported
1054     */

1055
1056    public org.omg.CORBA.NativeDef JavaDoc create_native(String JavaDoc id,
1057                                                 String JavaDoc name,
1058                                                 String JavaDoc version)
1059    {
1060        return null;
1061    }
1062
1063    // from Contained
1064

1065    public org.omg.CORBA.ContainedPackage.Description describe()
1066    {
1067        if ( ! defined)
1068        {
1069            throw new INTF_REPOS JavaDoc ("InterfaceDef " + name + " not defined.");
1070        }
1071
1072        org.omg.CORBA.Any JavaDoc a = orb.create_any();
1073
1074        String JavaDoc def_in = null;
1075
1076        if( myContainer == null )
1077            def_in = "Global";
1078        else
1079            def_in = myContainer.id();
1080
1081        org.omg.CORBA.InterfaceDescriptionHelper.insert( a,
1082                                new org.omg.CORBA.InterfaceDescription JavaDoc( name,
1083                                                                        id,
1084                                                                        def_in,
1085                                                                        version,
1086                                                                        base_names,
1087                                                                        false )
1088                );
1089        return new org.omg.CORBA.ContainedPackage.Description(
1090                         org.omg.CORBA.DefinitionKind.dk_Interface, a);
1091    }
1092
1093    // from IRObject
1094

1095    public void destroy()
1096    {
1097        containedLocals.clear();
1098        contained.clear();
1099    }
1100
1101    // from IDLType
1102

1103    public org.omg.CORBA.TypeCode JavaDoc type()
1104    {
1105        return typeCode;
1106    }
1107}
1108
Popular Tags