Source Code Cross Referenced for InterfaceDef.java in  » Collaboration » JacORB » org » jacorb » ir » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » JacORB » org.jacorb.ir 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.io.File;
024:        import java.lang.reflect.Field;
025:        import java.lang.reflect.Method;
026:        import java.util.Enumeration;
027:        import java.util.Hashtable;
028:        import java.util.Vector;
029:
030:        import org.apache.avalon.framework.logger.Logger;
031:        import org.omg.CORBA.AttributeDescription;
032:        import org.omg.CORBA.IDLType;
033:        import org.omg.CORBA.INTF_REPOS;
034:        import org.omg.CORBA.OperationDescription;
035:        import org.omg.CORBA.ContainerPackage.Description;
036:        import org.omg.CORBA.InterfaceDefPackage.FullInterfaceDescription;
037:        import org.omg.PortableServer.POA;
038:
039:        /**
040:         * JacORB implementation of org.omg.CORBA.InterfaceDef
041:         *
042:         * @author Gerald Brose
043:         * @version $Id: InterfaceDef.java,v 1.22 2006/06/15 16:43:14 alphonse.bendt Exp $
044:         */
045:
046:        public class InterfaceDef extends org.jacorb.ir.Contained implements 
047:                org.omg.CORBA.InterfaceDefOperations, ContainerType {
048:            Class theClass;
049:            private Class signatureClass;
050:
051:            private org.omg.CORBA.TypeCode typeCode;
052:            private OperationDef[] op_defs;
053:            private org.omg.CORBA.OperationDescription[] operations;
054:
055:            // to be done !!
056:            private boolean is_abstract = false;
057:
058:            private AttributeDef[] att_defs;
059:            private org.omg.CORBA.AttributeDescription[] attributes;
060:
061:            private ConstantDef[] constant_defs;
062:            private org.omg.CORBA.ConstantDescription[] constants;
063:
064:            private org.omg.CORBA.InterfaceDef[] base_interfaces;
065:            private String[] base_names;
066:            private FullInterfaceDescription fullDescription;
067:            /** local references to contained objects */
068:            private Hashtable containedLocals = new Hashtable();
069:
070:            /** CORBA references to contained objects */
071:            private Hashtable contained = new Hashtable();
072:
073:            /* reference to my container as a contained object */
074:            private org.omg.CORBA.Contained myContainer;
075:            private org.omg.CORBA.InterfaceDef myReference;
076:
077:            private File my_dir;
078:            private String path;
079:            private boolean defined = false;
080:            private boolean loaded = false;
081:
082:            private Class containedClass = null;
083:
084:            private ClassLoader loader;
085:            private POA poa;
086:            private Logger logger;
087:
088:            /**
089:             * Class constructor
090:             */
091:
092:            InterfaceDef(Class c, Class helperClass, String path,
093:                    org.omg.CORBA.Container def_in,
094:                    org.omg.CORBA.Repository ir, ClassLoader loader, POA poa,
095:                    Logger logger) throws INTF_REPOS {
096:                this .loader = loader;
097:                this .poa = poa;
098:                this .logger = logger;
099:
100:                if (ir == null) {
101:                    throw new INTF_REPOS("IR null!");
102:                }
103:
104:                if (def_in == null) {
105:                    throw new INTF_REPOS("Defined_in null!");
106:                }
107:
108:                def_kind = org.omg.CORBA.DefinitionKind.dk_Interface;
109:                containing_repository = ir;
110:                defined_in = def_in;
111:                if (def_in.equals(ir))
112:                    myContainer = null;
113:                else
114:                    myContainer = org.omg.CORBA.ContainedHelper
115:                            .narrow(defined_in);
116:
117:                this .path = path;
118:
119:                theClass = c;
120:                String classId = c.getName();
121:
122:                Hashtable irInfo = null;
123:                Class irHelperClass = null;
124:                try {
125:                    irHelperClass = this .loader.loadClass(theClass.getName()
126:                            + "IRHelper");
127:                    irInfo = (Hashtable) irHelperClass.getDeclaredField(
128:                            "irInfo").get(null);
129:                } catch (ClassNotFoundException e) {
130:                    logger.error("No IR helper class for interface "
131:                            + theClass.getName(), e);
132:                } catch (Exception e) {
133:                    logger.error("Caught Exception", e);
134:                }
135:
136:                if (irInfo == null) {
137:                    throw new INTF_REPOS("IR Info null!");
138:                }
139:
140:                try {
141:                    containedClass = this .loader
142:                            .loadClass("org.omg.CORBA.Contained");
143:                    signatureClass = this .loader.loadClass(classId
144:                            + "Operations");
145:
146:                    id((String) helperClass.getDeclaredMethod("id",
147:                            (Class[]) null).invoke(null, (Object[]) null));
148:                    version(id().substring(id().lastIndexOf(':')));
149:                    typeCode = TypeCodeUtil.getTypeCode(c, null, this .logger);
150:
151:                    full_name = classId;
152:                    if (classId.indexOf('.') > 0) {
153:                        name = classId.substring(classId.lastIndexOf('.') + 1);
154:
155:                        if (defined_in == null) {
156:                            throw new INTF_REPOS("InterfaceDef " + name
157:                                    + " path " + path
158:                                    + " has no defined_in repository");
159:                        }
160:
161:                        if (containedClass.isAssignableFrom(defined_in
162:                                .getClass()))
163:                            absolute_name = (myContainer != null ? myContainer
164:                                    .absolute_name() : "Global")
165:                                    + "::" + name;
166:                        else
167:                            absolute_name = "::" + name;
168:                    } else {
169:                        name = classId;
170:                        defined_in = containing_repository;
171:                        absolute_name = "::" + name;
172:                    }
173:
174:                    if (this .logger.isDebugEnabled()) {
175:                        this .logger.debug("InterfaceDef: " + absolute_name
176:                                + " path: " + path);
177:                    }
178:
179:                    /* get directory for nested definitions' classes */
180:                    File f = new File(path + fileSeparator
181:                            + classId.replace('.', fileSeparator) + "Package");
182:
183:                    if (f.exists() && f.isDirectory()) {
184:                        my_dir = f;
185:                    }
186:                } catch (Exception e) {
187:                    this .logger.error("Caught exception", e);
188:                    throw new INTF_REPOS(ErrorMsg.IR_Not_Implemented,
189:                            org.omg.CORBA.CompletionStatus.COMPLETED_NO);
190:                }
191:            }
192:
193:            public void loadContents() {
194:                if (this .logger.isDebugEnabled()) {
195:                    this .logger.debug("Interface " + name + " loading... ");
196:                }
197:
198:                // read from the interface class (operations and atributes)
199:                if (getReference() == null) {
200:                    throw new INTF_REPOS("getReference returns null");
201:                }
202:
203:                myReference = org.omg.CORBA.InterfaceDefHelper
204:                        .narrow(getReference());
205:
206:                if (myReference == null) {
207:                    throw new INTF_REPOS("narrow failed for " + getReference());
208:                }
209:
210:                /* load nested definitions from interfacePackage directory */
211:
212:                String[] classes = null;
213:
214:                if (my_dir != null) {
215:                    classes = my_dir.list(new IRFilenameFilter(".class"));
216:
217:                    // load class files in this interface's Package directory
218:                    if (classes != null) {
219:                        for (int j = 0; j < classes.length; j++) {
220:                            try {
221:                                if (this .logger.isDebugEnabled()) {
222:                                    this .logger
223:                                            .debug("Interface "
224:                                                    + name
225:                                                    + " tries "
226:                                                    + full_name
227:                                                    + "Package."
228:                                                    + classes[j]
229:                                                            .substring(
230:                                                                    0,
231:                                                                    classes[j]
232:                                                                            .indexOf(".class")));
233:                                }
234:
235:                                ClassLoader loader = getClass()
236:                                        .getClassLoader();
237:                                if (loader == null) {
238:                                    loader = this .loader;
239:                                }
240:
241:                                Class cl = loader.loadClass((full_name
242:                                        + "Package." + classes[j].substring(0,
243:                                        classes[j].indexOf(".class"))));
244:
245:                                Contained containedObject = Contained
246:                                        .createContained(cl, path, myReference,
247:                                                containing_repository,
248:                                                this .logger, this .loader,
249:                                                this .poa);
250:                                if (containedObject == null)
251:                                    continue;
252:
253:                                org.omg.CORBA.Contained containedRef = Contained
254:                                        .createContainedReference(
255:                                                containedObject, this .logger,
256:                                                this .poa);
257:
258:                                containedRef.move(myReference, containedRef
259:                                        .name(), containedRef.version());
260:
261:                                if (this .logger.isDebugEnabled()) {
262:                                    this .logger.debug("Interface " + full_name
263:                                            + " loads " + containedRef.name());
264:                                }
265:
266:                                contained
267:                                        .put(containedRef.name(), containedRef);
268:                                containedLocals.put(containedRef.name(),
269:                                        containedObject);
270:
271:                                if (containedObject instanceof  ContainerType)
272:                                    ((ContainerType) containedObject)
273:                                            .loadContents();
274:
275:                            } catch (Exception e) {
276:                                this .logger.error("Caught exception", e);
277:                            }
278:                        }
279:                    }
280:                }
281:
282:                loaded = true;
283:
284:                if (this .logger.isDebugEnabled()) {
285:                    this .logger.debug("Interface " + name + " loaded");
286:                }
287:            }
288:
289:            void define() {
290:                if (!loaded) {
291:                    throw new INTF_REPOS("Interface " + name + " not loaded!");
292:                }
293:
294:                if (this .logger.isDebugEnabled()) {
295:                    this .logger.debug("Interface " + name + " defining... ]");
296:                    this .logger.debug("Interface " + name
297:                            + " loads attributes/ops");
298:                }
299:
300:                Vector ops = new Vector();
301:                Vector atts = new Vector();
302:                Hashtable irInfo = null;
303:
304:                Class irHelperClass = null;
305:                try {
306:                    irHelperClass = this .loader.loadClass(theClass.getName()
307:                            + "IRHelper");
308:                    irInfo = (Hashtable) irHelperClass.getDeclaredField(
309:                            "irInfo").get(null);
310:                } catch (ClassNotFoundException e) {
311:                    this .logger.error("!! No IR helper class for interface "
312:                            + theClass.getName(), e);
313:                } catch (Exception e) {
314:                    logger.error("Caught exception", e);
315:                }
316:
317:                Method methods[] = signatureClass.getDeclaredMethods();
318:
319:                for (int i = 0; i < methods.length; i++) {
320:                    Object value = irInfo.get(methods[i].getName());
321:                    if (value == null
322:                            || !((String) value).startsWith("attribute")) {
323:                        ops.addElement(new OperationDef(methods[i], theClass,
324:                                irHelperClass, myReference, this .logger,
325:                                this .loader, this .poa));
326:                    } else {
327:                        if (((String) value).startsWith("attribute")) {
328:                            String attrDescr = (String) value;
329:
330:                            if (methods[i].getReturnType() == Void.class)
331:                                continue;
332:
333:                            int idx = attrDescr.indexOf('-');
334:                            String attrTypeName = attrDescr.substring(attrDescr
335:                                    .indexOf(";") + 1);
336:
337:                            atts
338:                                    .addElement(new AttributeDef(
339:                                            methods[i],
340:                                            attrTypeName,
341:                                            (idx > 0 ? org.omg.CORBA.AttributeMode.ATTR_NORMAL
342:                                                    : org.omg.CORBA.AttributeMode.ATTR_READONLY),
343:                                            myReference, containing_repository,
344:                                            this .logger, this .loader, this .poa));
345:                        }
346:                    }
347:                }
348:
349:                if (this .logger.isDebugEnabled()) {
350:                    this .logger.debug("Interface " + name + " defines ops");
351:                }
352:
353:                op_defs = new OperationDef[ops.size()];
354:                ops.copyInto(op_defs);
355:                for (int i = 0; i < op_defs.length; i++) {
356:                    op_defs[i].move(myReference, op_defs[i].name(), version);
357:                    containedLocals.put(op_defs[i].name(), op_defs[i]);
358:
359:                    try {
360:                        org.omg.CORBA.OperationDef operationRef = org.omg.CORBA.OperationDefHelper
361:                                .narrow(this .poa
362:                                        .servant_to_reference(new org.omg.CORBA.OperationDefPOATie(
363:                                                op_defs[i])));
364:                        contained.put(op_defs[i].name(), operationRef);
365:                        op_defs[i].setReference(operationRef);
366:                    } catch (Exception e) {
367:                        this .logger.error("Caught exception", e);
368:                    }
369:                }
370:
371:                if (this .logger.isDebugEnabled()) {
372:                    this .logger.debug("Interface " + name
373:                            + " defines attributes");
374:                }
375:
376:                att_defs = new AttributeDef[atts.size()];
377:                atts.copyInto(att_defs);
378:
379:                for (int i = 0; i < att_defs.length; i++) {
380:                    att_defs[i].move(myReference, att_defs[i].name(), version);
381:                    containedLocals.put(att_defs[i].name(), att_defs[i]);
382:                    try {
383:                        org.omg.CORBA.AttributeDef attribute = org.omg.CORBA.AttributeDefHelper
384:                                .narrow(this .poa
385:                                        .servant_to_reference(new org.omg.CORBA.AttributeDefPOATie(
386:                                                att_defs[i])));
387:                        contained.put(att_defs[i].name(), attribute);
388:                        att_defs[i].setReference(attribute);
389:                    } catch (Exception e) {
390:                        this .logger.error("Caught exception", e);
391:                    }
392:                }
393:
394:                /* constants */
395:                if (this .logger.isDebugEnabled()) {
396:                    this .logger.debug("Interface " + name
397:                            + " defines constants");
398:                }
399:
400:                Field[] fields = theClass.getDeclaredFields();
401:                constant_defs = new ConstantDef[fields.length];
402:                for (int i = 0; i < constant_defs.length; i++) {
403:                    constant_defs[i] = new ConstantDef(fields[i], myReference,
404:                            containing_repository, this .logger, this .poa);
405:                    constant_defs[i].move(myReference, constant_defs[i].name(),
406:                            version);
407:                    containedLocals.put(constant_defs[i].name(),
408:                            constant_defs[i]);
409:                    try {
410:                        org.omg.CORBA.ConstantDef constRef = org.omg.CORBA.ConstantDefHelper
411:                                .narrow(this .poa
412:                                        .servant_to_reference(new org.omg.CORBA.ConstantDefPOATie(
413:                                                constant_defs[i])));
414:
415:                        contained.put(constant_defs[i].name(), constRef);
416:                        constant_defs[i].setReference(constRef);
417:                    } catch (Exception e) {
418:                        this .logger.error("Caught exception", e);
419:                    }
420:                }
421:
422:                for (Enumeration e = containedLocals.elements(); e
423:                        .hasMoreElements(); ((IRObject) e.nextElement())
424:                        .define())
425:                    ;
426:
427:                /* get base interfaces */
428:                Class class_interfaces[] = theClass.getInterfaces();
429:                Hashtable si = new Hashtable();
430:
431:                Class objectClass = null;
432:                try {
433:                    objectClass = this .loader.loadClass("org.omg.CORBA.Object");
434:                } catch (ClassNotFoundException cnfe) {
435:                }
436:
437:                for (int i = 0; i < class_interfaces.length; i++) {
438:                    if (objectClass.isAssignableFrom(class_interfaces[i])
439:                            && !class_interfaces[i].getName().equals(
440:                                    "org.omg.CORBA.Object")) {
441:                        si.put(class_interfaces[i], "");
442:                    }
443:                }
444:
445:                Enumeration e = si.keys();
446:                base_names = new String[si.size()];
447:                int i = 0;
448:                Vector v = new Vector();
449:                while (e.hasMoreElements()) {
450:                    try {
451:                        Class baseClass = (Class) e.nextElement();
452:                        base_names[i] = baseClass.getName();
453:                        Class helperClass = this .loader.loadClass(base_names[i]
454:                                + "Helper");
455:                        String baseId = (String) helperClass.getDeclaredMethod(
456:                                "id", (Class[]) null).invoke(null,
457:                                (Object[]) null);
458:                        org.omg.CORBA.InterfaceDef base_interface = org.omg.CORBA.InterfaceDefHelper
459:                                .narrow(containing_repository.lookup_id(baseId));
460:                        if (base_interface == null) {
461:                            this .logger.error("Base interface def " + baseId
462:                                    + " is null!!!");
463:                        } else {
464:                            v.addElement(base_interface);
465:                        }
466:
467:                        i++;
468:                    } catch (Exception exc) {
469:                        logger.error("unexpected exception", exc);
470:                    }
471:                }
472:                base_interfaces = new org.omg.CORBA.InterfaceDef[v.size()];
473:                v.copyInto(base_interfaces);
474:
475:                defined = true;
476:                if (this .logger.isDebugEnabled()) {
477:                    this .logger.debug("Interface " + name + " defined ]");
478:                }
479:            }
480:
481:            public boolean is_abstract() {
482:                return false;
483:            }
484:
485:            public void is_abstract(boolean arg) {
486:            }
487:
488:            /**
489:             * @return  an array containing interface definitions of the superclass and
490:             * the interfaces extended by this class. Has length 0 if this class
491:             * is Object.
492:             */
493:
494:            public org.omg.CORBA.InterfaceDef[] base_interfaces() {
495:                return base_interfaces;
496:            }
497:
498:            public FullInterfaceDescription describe_interface() {
499:                if (!defined) {
500:                    throw new INTF_REPOS("InterfaceDef " + name
501:                            + " not defined.");
502:                }
503:
504:                if (fullDescription == null) {
505:                    String def_in = "IDL:Global:1.0";
506:                    if (defined_in instanceof  org.omg.CORBA.Contained)
507:                        def_in = ((org.omg.CORBA.Contained) defined_in).id();
508:
509:                    /* before  assembling descriptions, get hold  of all super
510:                       types' FullInterfaceDescriptions */
511:
512:                    FullInterfaceDescription[] baseDescriptions = new FullInterfaceDescription[base_interfaces().length];
513:
514:                    for (int b = 0; b < base_interfaces.length; b++) {
515:                        baseDescriptions[b] = base_interfaces[b]
516:                                .describe_interface();
517:                    }
518:
519:                    /* build operation descriptions */
520:
521:                    Hashtable ops = new Hashtable();
522:
523:                    for (int c = 0; c < op_defs.length; c++) {
524:                        OperationDescription operation = op_defs[c]
525:                                .describe_operation();
526:                        ops.put(operation.name, operation);
527:                    }
528:
529:                    /* get operation descriptions from super types, potentially duplicate
530:                       descriptions due to diamond inheritance are removed by hashing
531:                     */
532:
533:                    for (int baseOps = 0; baseOps < baseDescriptions.length; baseOps++) {
534:                        for (int bbaseOps = 0; bbaseOps < baseDescriptions[baseOps].operations.length; bbaseOps++) {
535:                            OperationDescription base_op = baseDescriptions[baseOps].operations[bbaseOps];
536:
537:                            if (!ops.containsKey(base_op.name))
538:                                ops.put(base_op.name, base_op);
539:                        }
540:                    }
541:
542:                    operations = new OperationDescription[ops.size()];
543:
544:                    int opsCount = 0;
545:                    for (Enumeration e = ops.elements(); e.hasMoreElements(); opsCount++) {
546:                        operations[opsCount] = (OperationDescription) e
547:                                .nextElement();
548:                    }
549:                    ops.clear();
550:
551:                    /* build attribute descriptions */
552:                    Hashtable atts = new Hashtable();
553:
554:                    for (int a = 0; a < att_defs.length; a++) {
555:                        AttributeDescription att = att_defs[a]
556:                                .describe_attribute();
557:                        atts.put(att.name, att);
558:                    }
559:
560:                    /* get attribute descriptions from super types */
561:
562:                    for (int baseAtts = 0; baseAtts < baseDescriptions.length; baseAtts++) {
563:                        for (int bbaseAtts = 0; bbaseAtts < baseDescriptions[baseAtts].attributes.length; bbaseAtts++) {
564:                            AttributeDescription base_att = baseDescriptions[baseAtts].attributes[bbaseAtts];
565:
566:                            if (!atts.containsKey(base_att.name))
567:                                atts.put(base_att.name, base_att);
568:                        }
569:                    }
570:
571:                    attributes = new AttributeDescription[atts.size()];
572:
573:                    int attsCount = 0;
574:                    for (Enumeration e = atts.elements(); e.hasMoreElements(); attsCount++) {
575:                        attributes[attsCount] = (AttributeDescription) e
576:                                .nextElement();
577:                    }
578:                    atts.clear();
579:
580:                    /* build constant descriptions */
581:
582:                    constants = new org.omg.CORBA.ConstantDescription[constant_defs.length];
583:                    for (int b = 0; b < constant_defs.length; b++) {
584:                        constants[b] = constant_defs[b].describe_constant();
585:                    }
586:
587:                    if (operations == null) {
588:                        throw new INTF_REPOS("operations null!");
589:                    }
590:                    if (attributes == null) {
591:                        throw new INTF_REPOS("attributes null!");
592:                    }
593:
594:                    fullDescription = new FullInterfaceDescription(name, id,
595:                            def_in, version, operations, attributes,
596:                            base_names, typeCode, is_abstract);
597:                }
598:                return fullDescription;
599:            }
600:
601:            public boolean is_a(String interface_id) {
602:                if (this .logger.isDebugEnabled()) {
603:                    this .logger.debug("Is interface " + id() + "  a "
604:                            + interface_id + "?");
605:                }
606:
607:                if (id().equals(interface_id))
608:                    return true;
609:
610:                org.omg.CORBA.InterfaceDef[] bases = base_interfaces();
611:                for (int i = 0; i < bases.length; i++) {
612:                    if (bases[i].is_a(interface_id))
613:                        return true;
614:                    if (bases[i].id().equals("IDL:omg.org/CORBA/Object:1.0"))
615:                        continue;
616:                }
617:                if (this .logger.isDebugEnabled()) {
618:                    this .logger.debug("Interface " + id() + " is not a "
619:                            + interface_id);
620:                }
621:                return false;
622:            }
623:
624:            // write methods on an InterfaceDef,
625:            // these are not supported at the moment !!
626:
627:            public void base_interfaces(org.omg.CORBA.InterfaceDef[] a) {
628:                throw new INTF_REPOS(ErrorMsg.IR_Not_Implemented,
629:                        org.omg.CORBA.CompletionStatus.COMPLETED_NO);
630:            }
631:
632:            public org.omg.CORBA.AttributeDef create_attribute(String id,
633:                    String name, String version, IDLType type,
634:                    org.omg.CORBA.AttributeMode mode) {
635:                throw new INTF_REPOS(ErrorMsg.IR_Not_Implemented,
636:                        org.omg.CORBA.CompletionStatus.COMPLETED_NO);
637:            }
638:
639:            public org.omg.CORBA.OperationDef create_operation(String id,
640:                    String name, String version, org.omg.CORBA.IDLType result,
641:                    org.omg.CORBA.OperationMode mode,
642:                    org.omg.CORBA.ParameterDescription[] params,
643:                    org.omg.CORBA.ExceptionDef[] exceptions, String[] contexts) {
644:                throw new INTF_REPOS(ErrorMsg.IR_Not_Implemented,
645:                        org.omg.CORBA.CompletionStatus.COMPLETED_NO);
646:            }
647:
648:            // from org.omg.CORBA.Container
649:
650:            public org.omg.CORBA.Contained lookup(String scopedname) {
651:                if (this .logger.isDebugEnabled()) {
652:                    this .logger.debug("Interface " + this .name + " lookup "
653:                            + scopedname);
654:                }
655:
656:                String top_level_name;
657:                String rest_of_name;
658:                String name;
659:
660:                if (scopedname.startsWith("::")) {
661:                    name = scopedname.substring(2);
662:                } else
663:                    name = scopedname;
664:
665:                if (name.indexOf("::") > 0) {
666:                    top_level_name = name.substring(0, name.indexOf("::"));
667:                    rest_of_name = name.substring(name.indexOf("::") + 2);
668:                } else {
669:                    top_level_name = name;
670:                    rest_of_name = null;
671:                }
672:
673:                try {
674:                    org.omg.CORBA.Contained top = (org.omg.CORBA.Contained) contained
675:                            .get(top_level_name);
676:
677:                    if (top == null) {
678:                        if (this .logger.isDebugEnabled()) {
679:                            this .logger.debug("Interface " + this .name
680:                                    + " top " + top_level_name + " not found");
681:                        }
682:                        return null;
683:                    }
684:
685:                    if (rest_of_name == null) {
686:                        return top;
687:                    }
688:
689:                    if (top instanceof  org.omg.CORBA.Container) {
690:                        return ((org.omg.CORBA.Container) top)
691:                                .lookup(rest_of_name);
692:                    }
693:
694:                    if (this .logger.isDebugEnabled()) {
695:                        this .logger.debug("Interface " + this .name + " "
696:                                + scopedname + " not found ");
697:                    }
698:                    return null;
699:                } catch (Exception e) {
700:                    this .logger.error("Caught exception", e);
701:                    return null;
702:                }
703:
704:            }
705:
706:            public org.omg.CORBA.Contained[] contents(
707:                    org.omg.CORBA.DefinitionKind limit_type,
708:                    boolean exclude_inherited) {
709:                if (!defined) {
710:                    throw new INTF_REPOS("InterfaceDef " + name
711:                            + " not defined.");
712:                }
713:
714:                Hashtable limited = new Hashtable();
715:
716:                // analog constants, exceptions etc.
717:
718:                for (Enumeration e = contained.elements(); e.hasMoreElements();) {
719:                    org.omg.CORBA.Contained c = (org.omg.CORBA.Contained) e
720:                            .nextElement();
721:                    if (limit_type.value() == org.omg.CORBA.DefinitionKind._dk_all
722:                            || limit_type.value() == c.def_kind().value()) {
723:                        limited.put(c, "");
724:                    }
725:                }
726:
727:                org.omg.CORBA.Contained[] c = new org.omg.CORBA.Contained[limited
728:                        .size()];
729:
730:                int i;
731:                Enumeration e;
732:                for (e = limited.keys(), i = 0; e.hasMoreElements(); i++)
733:                    c[i] = (org.omg.CORBA.Contained) e.nextElement();
734:                return c;
735:
736:            }
737:
738:            public org.omg.CORBA.Contained[] lookup_name(String search_name,
739:                    int levels_to_search,
740:                    org.omg.CORBA.DefinitionKind limit_type,
741:                    boolean exclude_inherited) {
742:                if (levels_to_search == 0)
743:                    return null;
744:
745:                org.omg.CORBA.Contained[] c = contents(limit_type,
746:                        exclude_inherited);
747:                Hashtable found = new Hashtable();
748:
749:                for (int i = 0; i < c.length; i++)
750:                    if (c[i].name().equals(search_name))
751:                        found.put(c[i], "");
752:
753:                if (levels_to_search > 1 || levels_to_search < 0) {
754:                    // search up to a specific depth or indefinitely
755:                    for (int i = 0; i < c.length; i++) {
756:                        if (c[i] instanceof  org.omg.CORBA.Container) {
757:                            org.omg.CORBA.Contained[] tmp_seq = ((org.omg.CORBA.Container) c[i])
758:                                    .lookup_name(search_name,
759:                                            levels_to_search - 1, limit_type,
760:                                            exclude_inherited);
761:                            if (tmp_seq != null)
762:                                for (int j = 0; j < tmp_seq.length; j++)
763:                                    found.put(tmp_seq[j], "");
764:                        }
765:                    }
766:                }
767:
768:                org.omg.CORBA.Contained[] result = new org.omg.CORBA.Contained[found
769:                        .size()];
770:                int idx = 0;
771:
772:                for (Enumeration e = found.keys(); e.hasMoreElements();)
773:                    result[idx++] = (org.omg.CORBA.Contained) e.nextElement();
774:
775:                return result;
776:            }
777:
778:            public Description[] describe_contents(
779:                    org.omg.CORBA.DefinitionKind limit_type,
780:                    boolean exclude_inherited, int max_returned_objs) {
781:                return null;
782:            }
783:
784:            // write interface not supported!
785:
786:            public org.omg.CORBA.ModuleDef create_module(String id,
787:                    String name, String version) {
788:                return null;
789:            }
790:
791:            public org.omg.CORBA.ConstantDef create_constant(
792:                    /*RepositoryId*/String id,
793:                    /*Identifier*/String name,
794:                    /*VersionSpec*/String version, IDLType type,
795:                    org.omg.CORBA.Any value) {
796:                return null;
797:            }
798:
799:            public org.omg.CORBA.StructDef create_struct(
800:                    /*RepositoryId*/String id,
801:                    /*Identifier*/String name,
802:                    /*VersionSpec*/String version,
803:                    /*StructMemberSeq*/org.omg.CORBA.StructMember[] members) {
804:                return null;
805:            }
806:
807:            public org.omg.CORBA.UnionDef create_union(
808:                    /*RepositoryId*/String id,
809:                    /*Identifier*/String name,
810:                    /*VersionSpec*/String version,
811:                    org.omg.CORBA.IDLType discriminator_type,
812:                    /*UnionMemberSeq*/org.omg.CORBA.UnionMember[] members) {
813:                return null;
814:            }
815:
816:            public org.omg.CORBA.EnumDef create_enum(
817:                    /*RepositoryId*/String id,
818:                    /*Identifier*/String name,
819:                    /*VersionSpec*/String version,
820:                    /*EnumMemberSeq*//*Identifier*/String[] members) {
821:                return null;
822:            }
823:
824:            public org.omg.CORBA.AliasDef create_alias(
825:                    /*RepositoryId*/String id,
826:                    /*Identifier*/String name,
827:                    /*VersionSpec*/String version,
828:                    org.omg.CORBA.IDLType original_type) {
829:                return null;
830:            }
831:
832:            /**
833:             * not supported
834:             */
835:
836:            public org.omg.CORBA.ExceptionDef create_exception(String id,
837:                    String name, String version,
838:                    org.omg.CORBA.StructMember[] member) {
839:                return null;
840:            }
841:
842:            /**
843:             * not supported
844:             */
845:
846:            public org.omg.CORBA.InterfaceDef create_interface(
847:                    /*RepositoryId*/String id,
848:                    /*Identifier*/String name,
849:                    /*VersionSpec*/String version,
850:                    /*InterfaceDefSeq*/org.omg.CORBA.InterfaceDef[] base_interfaces,
851:                    boolean is_abstract) {
852:                return null;
853:            }
854:
855:            /**
856:             * not supported
857:             */
858:
859:            public org.omg.CORBA.ValueBoxDef create_value_box(String id,
860:                    String name, String version, org.omg.CORBA.IDLType type) {
861:                return null;
862:            }
863:
864:            /**
865:             * not supported
866:             */
867:
868:            public org.omg.CORBA.ValueDef create_value(String id, String name,
869:                    String version, boolean is_custom, boolean is_abstract,
870:                    org.omg.CORBA.ValueDef base_value, boolean is_truncatable,
871:                    org.omg.CORBA.ValueDef[] abstract_base_values,
872:                    org.omg.CORBA.InterfaceDef[] supported_interfaces,
873:                    org.omg.CORBA.Initializer[] initializers) {
874:                return null;
875:            }
876:
877:            /**
878:             * not supported
879:             */
880:
881:            public org.omg.CORBA.NativeDef create_native(String id,
882:                    String name, String version) {
883:                return null;
884:            }
885:
886:            // from Contained
887:
888:            public org.omg.CORBA.ContainedPackage.Description describe() {
889:                if (!defined) {
890:                    throw new INTF_REPOS("InterfaceDef " + name
891:                            + " not defined.");
892:                }
893:
894:                org.omg.CORBA.Any a = orb.create_any();
895:
896:                String def_in = null;
897:
898:                if (myContainer == null)
899:                    def_in = "Global";
900:                else
901:                    def_in = myContainer.id();
902:
903:                org.omg.CORBA.InterfaceDescriptionHelper.insert(a,
904:                        new org.omg.CORBA.InterfaceDescription(name, id,
905:                                def_in, version, base_names, false));
906:                return new org.omg.CORBA.ContainedPackage.Description(
907:                        org.omg.CORBA.DefinitionKind.dk_Interface, a);
908:            }
909:
910:            // from IRObject
911:
912:            public void destroy() {
913:                containedLocals.clear();
914:                contained.clear();
915:            }
916:
917:            // from IDLType
918:
919:            public org.omg.CORBA.TypeCode type() {
920:                return typeCode;
921:            }
922:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.