Source Code Cross Referenced for InterfaceGen.java in  » 6.0-JDK-Modules-com.sun » tools » com » sun » tools » corba » se » idl » toJavaPortable » 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 » 6.0 JDK Modules com.sun » tools » com.sun.tools.corba.se.idl.toJavaPortable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2001 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:        /*
026:         * COMPONENT_NAME: idl.toJava
027:         *
028:         * ORIGINS: 27
029:         *
030:         * Licensed Materials - Property of IBM
031:         * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
032:         * RMI-IIOP v1.0
033:         *
034:         * @(#)InterfaceGen.java	1.22 07/05/05
035:         */
036:
037:        package com.sun.tools.corba.se.idl.toJavaPortable;
038:
039:        // NOTES:
040:        // -The ctor should really throw an exception, but then it must have a
041:        //  throws clause. How much of a ripple effect is this?
042:        // -F46082.51<daz> Remove -stateful feature.
043:        // -D60929   <klr> Update for RTF2.4 changes
044:        // -D61056   <klr> Use Util.helperName
045:        // -D62014   <klr> Move const definitions from signature to operations interf.
046:        // -D62310   <klr> Fix declaration of interfaces extending abstract intf.
047:        // -D62023   <klr> Move const definitions back from operations to signature.
048:
049:        import java.io.PrintWriter;
050:        import java.util.Enumeration;
051:        import java.util.Hashtable;
052:        import java.util.Vector;
053:
054:        import com.sun.tools.corba.se.idl.GenFileStream;
055:        import com.sun.tools.corba.se.idl.ConstEntry;
056:        import com.sun.tools.corba.se.idl.InterfaceEntry;
057:        import com.sun.tools.corba.se.idl.InterfaceState;
058:        import com.sun.tools.corba.se.idl.MethodEntry;
059:        import com.sun.tools.corba.se.idl.PrimitiveEntry;
060:        import com.sun.tools.corba.se.idl.SequenceEntry;
061:        import com.sun.tools.corba.se.idl.StringEntry;
062:        import com.sun.tools.corba.se.idl.SymtabEntry;
063:        import com.sun.tools.corba.se.idl.TypedefEntry;
064:
065:        /**
066:         *
067:         **/
068:        public class InterfaceGen implements 
069:                com.sun.tools.corba.se.idl.InterfaceGen, JavaGenerator {
070:            /**
071:             * Public zero-argument constructor.
072:             **/
073:            public InterfaceGen() {
074:                //emit = ((Arguments)Compile.compiler.arguments).emit;
075:                //factories = (Factories)Compile.compiler.factories ();
076:            } // ctor
077:
078:            /**
079:             * Generate the interface and all the files associated with it.
080:             * Provides general algorithm for binding generation:
081:             * 1.) Initialize symbol table and symbol table entry members, common to all generators.
082:             * 2.) Generate the skeleton if required by calling generateSkeletn ()
083:             * 3.) Generate the holder by calling generateHolder ()
084:             * 4.) Generate the helper by calling generateHelper ()
085:             * 5.) Generate the stub if required by calling generateStub ()
086:             * 6.) Generate the interface by calling generateInterface ()
087:             **/
088:            public void generate(Hashtable symbolTable, InterfaceEntry i,
089:                    PrintWriter stream) {
090:                if (!isPseudo(i)) {
091:                    this .symbolTable = symbolTable;
092:                    this .i = i;
093:                    init();
094:
095:                    // for sun_local pragma, just generate the signature and operations interfaces
096:                    // for sun_localservant pragma, generate the Local Stubs, and Skel, should not
097:                    // have _invoke defined.
098:                    // for local (is_local()) case, generate only Helpers and Holder, where they
099:                    // have been modified to throw appropriate exceptions for read and write, and
100:                    // narrow is modified to not invoke _is_a
101:
102:                    if (!(i.isLocalSignature())) {
103:                        // generate the stubs and skeletons for non-local interfaces
104:                        if (!(i.isLocal())) {
105:                            // for local servant case just generate the skeleton, but
106:                            // for others generate the stubs also
107:                            generateSkeleton();
108:
109:                            // _REVISIT_, Whenever there is time restructure the code to
110:                            // encapsulate stub and skeleton generation.
111:
112:                            // If the option is -fallTie then generate the Tie class first
113:                            // and then generate the ImplBase class to make the generation
114:                            // complete for the Hierarchy.
115:                            Arguments theArguments = (Arguments) Compile.compiler.arguments;
116:                            if ((theArguments.TIEServer == true)
117:                                    && (theArguments.emit == theArguments.All)) {
118:                                theArguments.TIEServer = false;
119:                                // Generate the ImplBase class 
120:                                generateSkeleton();
121:                                // Revert in case file contains multiple interfaces
122:                                theArguments.TIEServer = true;
123:                            }
124:                            generateStub();
125:                        }
126:                        generateHolder();
127:                        generateHelper();
128:                    }
129:                    intfType = SIGNATURE;
130:                    generateInterface();
131:                    intfType = OPERATIONS;
132:                    generateInterface();
133:                    intfType = 0;
134:                }
135:            } // generate
136:
137:            /**
138:             * Initialize members unique to this generator.
139:             **/
140:            protected void init() {
141:                emit = ((Arguments) Compile.compiler.arguments).emit;
142:                factories = (Factories) Compile.compiler.factories();
143:            } // init
144:
145:            /**
146:             * Generate a Skeleton when the user does not want just the client-side code.
147:             **/
148:            protected void generateSkeleton() {
149:                // <f46082.51> Remove -stateful feature.
150:                // The Skeleton is generated only when the user doesn't want
151:                // JUST the client code OR when the interface is stateful
152:                //if (emit != Arguments.Client || i.state () != null)
153:                //  factories.skeleton ().generate (symbolTable, i);
154:                if (emit != Arguments.Client)
155:                    factories.skeleton().generate(symbolTable, i);
156:            } // generateSkeleton
157:
158:            /**
159:             * Generate a Stub when the user does not want just the server-side code.
160:             **/
161:            protected void generateStub() {
162:                // <klr> According to Simon on 10/28/98, we should generate stubs for
163:                // abstract interfaces too.
164:                if (emit != Arguments.Server /* && !i.isAbstract () */)
165:                    factories.stub().generate(symbolTable, i);
166:            } // generateStub
167:
168:            /**
169:             * Generate a Helper when the user does not want just the server-side code.
170:             **/
171:            protected void generateHelper() {
172:                if (emit != Arguments.Server)
173:                    factories.helper().generate(symbolTable, i);
174:            } // generateHelper
175:
176:            /**
177:             * Generate a Holder when the user does not want just the server-side code.
178:             **/
179:            protected void generateHolder() {
180:                if (emit != Arguments.Server)
181:                    factories.holder().generate(symbolTable, i);
182:            } // generateHolder
183:
184:            /**
185:             * Generate the interface. Provides general algorithm for binding generation:
186:             * 1.) Initialize members unique to this generator. - init ()
187:             * 2.) Open print stream - openStream ()
188:             * 3.) Write class heading (package, prologue, class statement, open curly - writeHeading ()
189:             * 4.) Write class body (member data and methods) - write*Body ()
190:             * 5.) Write class closing (close curly) - writeClosing ()
191:             * 6.) Close the print stream - closeStream ()
192:             *
193:             * For CORBA 2.3, interfaces are mapped to Operations and Signature
194:             * interfaces. The Operations interface contains the method definitions.
195:             * The Signature interface extends the Operations interface and adds
196:             * CORBA::Object. <klr>
197:             **/
198:            protected void generateInterface() {
199:                init();
200:                openStream();
201:                if (stream == null)
202:                    return;
203:                writeHeading();
204:                if (intfType == OPERATIONS)
205:                    writeOperationsBody();
206:                if (intfType == SIGNATURE)
207:                    writeSignatureBody();
208:                writeClosing();
209:                closeStream();
210:            } // generateInterface
211:
212:            /**
213:             *
214:             **/
215:            protected void openStream() {
216:                if (i.isAbstract() || intfType == SIGNATURE)
217:                    stream = Util.stream(i, ".java");
218:                else if (intfType == OPERATIONS)
219:                    stream = Util.stream(i, "Operations.java");
220:            } // openStream
221:
222:            /**
223:             *
224:             **/
225:            protected void writeHeading() {
226:                Util.writePackage(stream, i, Util.TypeFile);
227:                Util.writeProlog(stream, ((GenFileStream) stream).name());
228:
229:                // Transfer interface comment to target <31jul1997>.
230:                if (i.comment() != null)
231:                    i.comment().generate("", stream);
232:
233:                String className = i.name();
234:                //  if (((Arguments)Compile.compiler.arguments).TIEServer)
235:                //  {
236:                //    // For the delegate model, don't make interface a subclass of CORBA.Object
237:                //    stream.print ("public interface " + className);
238:                //    boolean firstTime = true;
239:                //    for (int ii = 0; ii < i.derivedFrom ().size (); ++ii)
240:                //    {
241:                //      SymtabEntry parent = (SymtabEntry)i.derivedFrom ().elementAt (ii);
242:                //      if (!parent.fullName ().equals ("org/omg/CORBA/Object"))
243:                //      {
244:                //        if (firstTime)
245:                //        {
246:                //          firstTime = false;
247:                //          stream.print (" extends ");
248:                //        }
249:                //        else
250:                //          stream.print (", ");
251:                //        stream.print (Util.javaName (parent));
252:                //      }
253:                //    }
254:                //    if (i.derivedFrom ().size () > 0)
255:                //      stream.print (", ");
256:                //    stream.print ("org.omg.CORBA.portable.IDLEntity ");
257:                //  }
258:                //
259:                //  else
260:                //  {
261:                if (intfType == SIGNATURE)
262:                    writeSignatureHeading();
263:                else if (intfType == OPERATIONS)
264:                    writeOperationsHeading();
265:                //  }
266:
267:                stream.println();
268:                stream.println('{');
269:            } // writeHeading
270:
271:            /**
272:             *
273:             **/
274:            protected void writeSignatureHeading() {
275:                String className = i.name();
276:                stream.print("public interface " + className + " extends "
277:                        + className + "Operations, ");
278:                boolean firstTime = true;
279:                boolean hasNonAbstractParent = false; // <d62310-klr>
280:                for (int k = 0; k < i.derivedFrom().size(); ++k) {
281:                    if (firstTime)
282:                        firstTime = false;
283:                    else
284:                        stream.print(", ");
285:                    InterfaceEntry parent = (InterfaceEntry) i.derivedFrom()
286:                            .elementAt(k);
287:                    stream.print(Util.javaName(parent));
288:                    if (!parent.isAbstract()) // <d62310-klr>
289:                        hasNonAbstractParent = true; // <d62310-klr>
290:                }
291:                // <d62310-klr> - begin
292:                // If this interface extends only abstract interfaces,
293:                // it should extend both org.omg.CORBA.Object and IDLEntity.
294:                if (!hasNonAbstractParent) {
295:                    stream
296:                            .print(", org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity ");
297:                } else {
298:                    // <d62310-klr> - end
299:                    // extends IDLEntity if there's only one default parent - CORBA.Object
300:                    if (i.derivedFrom().size() == 1)
301:                        stream.print(", org.omg.CORBA.portable.IDLEntity ");
302:                }
303:            } // writeSignatureHeading
304:
305:            /**
306:             *
307:             **/
308:            protected void writeOperationsHeading() {
309:                stream.print("public interface " + i.name());
310:                if (!i.isAbstract())
311:                    stream.print("Operations ");
312:                else {
313:                    // <d60929> - base abstract interfaces extend AbstractBase
314:                    // changed to IDLEntity by SCN per latest spec...
315:                    if (i.derivedFrom().size() == 0)
316:                        stream
317:                                .print(" extends org.omg.CORBA.portable.IDLEntity");
318:                }
319:
320:                boolean firstTime = true;
321:                for (int k = 0; k < i.derivedFrom().size(); ++k) {
322:                    InterfaceEntry parent = (InterfaceEntry) i.derivedFrom()
323:                            .elementAt(k);
324:                    String parentName = Util.javaName(parent);
325:
326:                    // ignore the default parent - CORBA.Object
327:                    if (parentName.equals("org.omg.CORBA.Object"))
328:                        continue;
329:
330:                    if (firstTime) {
331:                        firstTime = false;
332:                        stream.print(" extends ");
333:                    } else
334:                        stream.print(", ");
335:
336:                    // Don't append suffix Operations to the parents of abstract interface
337:                    // or to the abstract parents of regular interface
338:                    if (parent.isAbstract() || i.isAbstract())
339:                        stream.print(parentName);
340:                    else
341:                        stream.print(parentName + "Operations");
342:                }
343:            } // writeOperationsHeading
344:
345:            /**
346:             *
347:             **/
348:            protected void writeOperationsBody() {
349:                // Generate everything but constants
350:                Enumeration e = i.contained().elements();
351:                while (e.hasMoreElements()) {
352:                    SymtabEntry contained = (SymtabEntry) e.nextElement();
353:                    if (contained instanceof  MethodEntry) {
354:                        MethodEntry element = (MethodEntry) contained;
355:                        ((MethodGen) element.generator()).interfaceMethod(
356:                                symbolTable, element, stream);
357:                    } else if (!(contained instanceof  ConstEntry))
358:                        contained.generate(symbolTable, stream);
359:                }
360:            } // writeOperationsBody
361:
362:            /**
363:             *
364:             **/
365:            protected void writeSignatureBody() {
366:                // Generate only constants
367:                Enumeration e = i.contained().elements();
368:                while (e.hasMoreElements()) {
369:                    SymtabEntry contained = (SymtabEntry) e.nextElement();
370:                    if (contained instanceof  ConstEntry)
371:                        contained.generate(symbolTable, stream);
372:                }
373:            } // writeSignatureBody
374:
375:            /**
376:             *
377:             **/
378:            protected void writeClosing() {
379:                String intfName = i.name();
380:                if (!i.isAbstract() && intfType == OPERATIONS)
381:                    intfName = intfName + "Operations";
382:                stream.println("} // interface " + intfName);
383:            } // writeClosing
384:
385:            /**
386:             *
387:             **/
388:            protected void closeStream() {
389:                stream.close();
390:            } // closeStream
391:
392:            ///////////////
393:            // From JavaGenerator
394:
395:            // <f46082.51> Remove -stateful feature.
396:            /*
397:            public int helperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream)
398:            {
399:              InterfaceEntry i = (InterfaceEntry)entry;
400:              if (i.state () != null && i.state ().size () > 0)
401:                index = structHelperType (index, indent, tcoffsets, name, entry, stream);
402:              else
403:              {
404:                tcoffsets.set (entry);
405:                if (entry.fullName ().equals ("org/omg/CORBA/Object"))
406:                  stream.println (indent + name
407:                      + " = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_objref);");
408:                else
409:                  stream.println (indent + name
410:                      // <54697>
411:                      //+ " = org.omg.CORBA.ORB.init ().create_interface_tc (_id, "
412:                      + " = org.omg.CORBA.ORB.init ().create_interface_tc (" + Util.helperName (i, true) + ".id (), " // <d61056>
413:                      + '\"' + Util.stripLeadingUnderscores (entry.name ()) + "\");");
414:              }
415:              return index;
416:            } // helperType
417:             */
418:            public int helperType(int index, String indent,
419:                    TCOffsets tcoffsets, String name, SymtabEntry entry,
420:                    PrintWriter stream) {
421:                InterfaceEntry i = (InterfaceEntry) entry;
422:                tcoffsets.set(entry);
423:                if (entry.fullName().equals("org/omg/CORBA/Object"))
424:                    stream
425:                            .println(indent
426:                                    + name
427:                                    + " = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_objref);");
428:                else
429:                    stream
430:                            .println(indent
431:                                    + name
432:                                    // <54697>
433:                                    //+ " = org.omg.CORBA.ORB.init ().create_interface_tc (_id, "
434:                                    + " = org.omg.CORBA.ORB.init ().create_interface_tc ("
435:                                    + Util.helperName(i, true)
436:                                    + ".id (), " // <d61056>
437:                                    + '\"'
438:                                    + Util
439:                                            .stripLeadingUnderscores(entry
440:                                                    .name()) + "\");");
441:                return index;
442:            } // helperType
443:
444:            public int type(int index, String indent, TCOffsets tcoffsets,
445:                    String name, SymtabEntry entry, PrintWriter stream) {
446:                stream.println(indent + name + " = "
447:                        + Util.helperName(entry, true) + ".type ();"); // <d61056>
448:                return index;
449:            } // type
450:
451:            // <f46082.51> Remove -stateful feature.
452:            /*
453:            public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
454:            {
455:              InterfaceEntry i = (InterfaceEntry)entry;
456:              if (i.state () != null)
457:                structHelperRead (entryName, i, stream);
458:              else
459:              {
460:                if (i.isAbstract ())
461:                   stream.println ("    return narrow (((org.omg.CORBA_2_3.portable.InputStream)istream).read_abstract_interface (_" + i.name () + "Stub.class));"); // <d60929>
462:                else
463:                   stream.println ("    return narrow (istream.read_Object (_" + i.name () + "Stub.class));");
464:              }
465:            } // helperRead
466:
467:             */
468:            public void helperRead(String entryName, SymtabEntry entry,
469:                    PrintWriter stream) {
470:                InterfaceEntry i = (InterfaceEntry) entry;
471:                if (i.isAbstract())
472:                    stream
473:                            .println("    return narrow (((org.omg.CORBA_2_3.portable.InputStream)istream).read_abstract_interface (_"
474:                                    + i.name() + "Stub.class));"); // <d60929>
475:                else
476:                    stream.println("    return narrow (istream.read_Object (_"
477:                            + i.name() + "Stub.class));");
478:            } // helperRead
479:
480:            // <f46082.51> Remove -stateful feature.
481:            /*
482:            public void helperWrite (SymtabEntry entry, PrintWriter stream)
483:            {
484:              InterfaceEntry i = (InterfaceEntry)entry;
485:              if (i.state () != null)
486:                structHelperWrite (entry, stream);
487:              else
488:                write (0, "    ", "value", entry, stream);
489:            } // helperWrite
490:             */
491:            public void helperWrite(SymtabEntry entry, PrintWriter stream) {
492:                write(0, "    ", "value", entry, stream);
493:            } // helperWrite
494:
495:            // <f46082.51> Remove -stateful feature.
496:            /*
497:            public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
498:            {
499:              InterfaceEntry i = (InterfaceEntry)entry;
500:              if (i.state () != null)
501:                index = structRead (index, indent, name, i, stream);
502:              else
503:              {
504:                if (entry.fullName ().equals ("org/omg/CORBA/Object"))
505:                  stream.println (indent + name + " = istream.read_Object (_" + i.name () + "Stub.class);");
506:                else
507:                  stream.println (indent + name + " = " + Util.helperName (entry, false) + ".narrow (istream.read_Object (_" + i.name () + "Stub.class));"); // <d61056>
508:              }
509:              return index;
510:            } // read
511:             */
512:            public int read(int index, String indent, String name,
513:                    SymtabEntry entry, PrintWriter stream) {
514:                InterfaceEntry i = (InterfaceEntry) entry;
515:                if (entry.fullName().equals("org/omg/CORBA/Object"))
516:                    stream.println(indent + name + " = istream.read_Object (_"
517:                            + i.name() + "Stub.class);");
518:                else
519:                    stream.println(indent + name + " = "
520:                            + Util.helperName(entry, false)
521:                            + ".narrow (istream.read_Object (_" + i.name()
522:                            + "Stub.class));"); // <d61056>
523:                return index;
524:            } // read
525:
526:            // <f46082.51> Remove -stateful feature.
527:            /*
528:            public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
529:            {
530:              InterfaceEntry i = (InterfaceEntry)entry;
531:              if (i.state () != null)
532:                index = structWrite (index, indent, name, entry, stream);
533:              else
534:              {
535:                if (i.isAbstract ())
536:                   stream.println (indent + "((org.omg.CORBA_2_3.portable.OutputStream)ostream).write_abstract_interface ((java.lang.Object) " + name + ");"); // <d60929>
537:                else
538:                   stream.println (indent + "ostream.write_Object ((org.omg.CORBA.Object) " + name + ");");
539:              }
540:              return index;
541:            } // write
542:             */
543:            public int write(int index, String indent, String name,
544:                    SymtabEntry entry, PrintWriter stream) {
545:                InterfaceEntry i = (InterfaceEntry) entry;
546:                if (i.isAbstract())
547:                    stream
548:                            .println(indent
549:                                    + "((org.omg.CORBA_2_3.portable.OutputStream)ostream).write_abstract_interface ((java.lang.Object) "
550:                                    + name + ");"); // <d60929>
551:                else
552:                    stream.println(indent
553:                            + "ostream.write_Object ((org.omg.CORBA.Object) "
554:                            + name + ");");
555:                return index;
556:            } // write
557:
558:            // <f46082.51> Remove -stateful feature.
559:            /*
560:            // These methods are cobbled from StructGen.  Stateful interfaces
561:            // are sent across the wire as if they were structs, with the first
562:            // element being a string - the Java name of the class.
563:
564:            public int structHelperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream)
565:            {
566:              TCOffsets innerOffsets = new TCOffsets ();
567:              innerOffsets.set (entry);
568:              int offsetForStruct = innerOffsets.currentOffset ();
569:              InterfaceEntry i = (InterfaceEntry)entry;
570:              String membersName = "_members" + index++;
571:              Vector state = i.state ();
572:              stream.println (indent + "org.omg.CORBA.StructMember[] " + membersName + " = new org.omg.CORBA.StructMember [" + (state.size () + 1) + "];");
573:              String tcOfMembers = "_tcOf" + membersName;
574:              stream.println (indent + "org.omg.CORBA.TypeCode " + tcOfMembers + ';');
575:
576:              // The name string is the first element of the struct
577:              String memberName = "_name";
578:              StringEntry stringEntry = Compile.compiler.factory.stringEntry ();
579:              index = ((JavaGenerator)stringEntry.generator ()).helperType (index, indent, innerOffsets, tcOfMembers, stringEntry, stream);
580:              stream.println (indent + membersName + "[0] = new org.omg.CORBA.StructMember (");
581:              stream.println (indent + "  \"" + memberName + "\",");
582:              stream.println (indent + "  " + tcOfMembers + ',');
583:              stream.println (indent + "  null);");
584:              int offsetSoFar = innerOffsets.currentOffset ();
585:              innerOffsets = new TCOffsets ();
586:              innerOffsets.set (entry);
587:              innerOffsets.bumpCurrentOffset (offsetSoFar - offsetForStruct);
588:
589:              for (int idx = 0; idx < state.size (); ++idx)
590:              {
591:                TypedefEntry member = ((InterfaceState)state.elementAt (idx)).entry;
592:                memberName = member.name ();
593:                index = ((JavaGenerator)member.generator ()).helperType (index, indent, innerOffsets, tcOfMembers, member, stream);
594:                stream.println (indent + membersName + '[' + (idx + 1) + "] = new org.omg.CORBA.StructMember (");
595:                stream.println (indent + "  \"" + memberName + "\",");
596:                stream.println (indent + "  " + tcOfMembers + ',');
597:                stream.println (indent + "  null);");
598:                offsetSoFar = innerOffsets.currentOffset ();
599:                innerOffsets = new TCOffsets ();
600:                innerOffsets.set (entry);
601:                innerOffsets.bumpCurrentOffset (offsetSoFar - offsetForStruct);
602:              }
603:              tcoffsets.bumpCurrentOffset (innerOffsets.currentOffset ());
604:              stream.println (indent + name + " = org.omg.CORBA.ORB.init ().create_struct_tc (id (), \"" + entry.name () + "\", " + membersName + ");");
605:              return index;
606:            } // structHelperType
607:
608:            public void structHelperRead (String entryName, InterfaceEntry entry, PrintWriter stream)
609:            {
610:              String impl = implName ((InterfaceEntry)entry);
611:              stream.println ("      " + Util.javaStatefulName (entry) + " value = null;");
612:              structRead (0, "      ", "value", entry, stream);
613:              stream.println ("      return value;");
614:            } // structHelperRead
615:
616:            private String implName (InterfaceEntry entry)
617:            {
618:              String name;
619:              if (entry.container ().name ().equals (""))
620:                name =  '_' + entry.name () + "Impl";
621:              else
622:                name = Util.containerFullName (entry.container ()) + "._" + entry.name () + "Impl";
623:              return name.replace ('/', '.');
624:            } // implName
625:
626:            public int structRead (int index, String indent, String name, InterfaceEntry entry, PrintWriter stream)
627:            {
628:              // The first element will be the name of the Java implementation class.
629:              String stringName = "_name" + index++;
630:              stream.println (indent + "String " + stringName + " = istream.read_string ();");
631:              stream.println (indent + "try");
632:              stream.println (indent + "{");
633:              stream.println (indent + "  " + name + " = (" + Util.javaStatefulName (entry) + ")com.sun.CORBA.iiop.ORB.getImpl (" + stringName + ".replace ('/', '.'));");
634:              stream.println (indent + "}");
635:              stream.println (indent + "catch (Exception e)");
636:              stream.println (indent + "{");
637:              stream.println (indent + "  " + name + " = null;");
638:              stream.println (indent + "}");
639:              stream.println (indent + "if (" + name + " == null)");
640:              stream.println (indent + "  throw new org.omg.CORBA.NO_IMPLEMENT (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
641:              stream.println ();
642:
643:              stream.println (indent + "if (!" + stringName + ".equals (\"" + entry.fullName () + "\"))");
644:              stream.println (indent + '{');
645:              stream.println (indent + "  Class _cls = " + name + ".getClass ();");
646:              stream.println (indent + "  boolean _found = false;");
647:              stream.println (indent + "  while (!_found && _cls != null)");
648:              stream.println (indent + "  {");
649:              stream.println (indent + "    Class[] interfaces = _cls.getInterfaces ();");
650:              stream.println (indent + "    for (int i = 0; i < interfaces.length; ++i)");
651:              stream.println (indent + "      if (interfaces[i].getName ().indexOf (\"State\") > 0)");
652:              stream.println (indent + "      {");
653:              stream.println (indent + "        _cls = interfaces[i];");
654:              stream.println (indent + "        _found = true;");
655:              stream.println (indent + "        break;");
656:              stream.println (indent + "      }");
657:              stream.println (indent + "    if (!_found)");
658:              stream.println (indent + "      _cls = _cls.getSuperclass ();");
659:              stream.println (indent + "  }");
660:              stream.println (indent + "  if (_cls == null)");
661:              stream.println (indent + "    throw new org.omg.CORBA.NO_IMPLEMENT (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
662:              stream.println ();
663:              stream.println (indent + "  String _className = _cls.getName ();");
664:              stream.println (indent + "  int _index = _className.lastIndexOf ('.');");
665:              stream.println (indent + "  String _helperName = _className.substring (0, _index + 1) + _className.substring (_index + 2, _className.length () - 5) + \"Helper\"; // 5 == \"State\".length");
666:              stream.println (indent + "  try");
667:              stream.println (indent + "  {");
668:              stream.println (indent + "    Class _helperClass = Class.forName (_helperName);");
669:              stream.println (indent + "    Class[] _formalParms = new Class [1];");
670:              stream.println (indent + "    _formalParms[0] = Class.forName (\"org.omg.CORBA.portable.InputStream\");");
671:              stream.println (indent + "    java.lang.reflect.Method _read = _helperClass.getMethod (\"read\", _formalParms);");
672:              stream.println (indent + "    Object[] _actualParms = new Object [1];");
673:              stream.println (indent + "    _actualParms[0] = istream;");
674:              stream.println (indent + "      " + name + " = (" + Util.javaStatefulName (entry) + ")_read.invoke (null, _actualParms);");
675:              stream.println (indent + "  }");
676:              stream.println (indent + "  catch (Exception e)");
677:              stream.println (indent + "  {");
678:              stream.println (indent + "    throw new org.omg.CORBA.NO_IMPLEMENT (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
679:              stream.println (indent + "  }");
680:              stream.println (indent + '}');
681:
682:              // instantiate an implementation
683:              stream.println (indent + "else");
684:              stream.println (indent + '{');
685:
686:              // Load the state
687:              readState (index, indent, name, (InterfaceEntry)entry, stream);
688:
689:              stream.println (indent + '}');
690:              return index;
691:            } // structRead
692:
693:            private void readState (int index, String indent, String name, InterfaceEntry entry, PrintWriter stream)
694:            {
695:              // First write the state from all parents
696:              Enumeration e = entry.derivedFrom ().elements ();
697:              while (e.hasMoreElements ())
698:              {
699:                InterfaceEntry parent = (InterfaceEntry)e.nextElement ();
700:                if (parent.state () != null)
701:                {
702:                  if (parent.state ().size () > 0)
703:                    readState (index, indent, name, parent, stream);
704:                  break;
705:                }
706:              }
707:
708:              // Now write the state for the local entry
709:              e = entry.state ().elements ();
710:              while (e.hasMoreElements ())
711:              {
712:                TypedefEntry member = ((InterfaceState)e.nextElement ()).entry;
713:                String tmpName = '_' + member.name () + "Tmp";
714:                Util.writeInitializer (indent + "  ", tmpName, "", member, stream);
715:                if (!member.arrayInfo ().isEmpty () || member.type () instanceof SequenceEntry || member.type () instanceof PrimitiveEntry || member.type () instanceof StringEntry)
716:                  index = ((JavaGenerator)member.generator ()).read (index, indent + "  ", tmpName, member, stream);
717:                else
718:                  stream.println (indent + "  " + tmpName + " = " + Util.helperName (member.type (), true) + ".read (istream);"); // <d61056>
719:                stream.println (indent + "  " + name + '.' + member.name () + " (" + tmpName + ");");
720:              }
721:            } // readState
722:
723:            public void structHelperWrite (SymtabEntry entry, PrintWriter stream)
724:            {
725:              structWrite (0, "      ", "value", entry, stream);
726:            } // structHelperWrite
727:
728:            public int structWrite (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
729:            {
730:              // The first element of the struct must be the name of the real interface.
731:              stream.println (indent + "Class _cls = " + name + ".getClass ();");
732:              stream.println (indent + "boolean _found = false;");
733:              stream.println (indent + "while (!_found && _cls != null)");
734:              stream.println (indent + "{");
735:              stream.println (indent + "  Class[] interfaces = _cls.getInterfaces ();");
736:              stream.println (indent + "  for (int i = 0; i < interfaces.length; ++i)");
737:              stream.println (indent + "    if (interfaces[i].getName ().indexOf (\"State\") > 0)");
738:              stream.println (indent + "    {");
739:              stream.println (indent + "      _cls = interfaces[i];");
740:              stream.println (indent + "      _found = true;");
741:              stream.println (indent + "      break;");
742:              stream.println (indent + "    }");
743:              stream.println (indent + "  if (!_found)");
744:              stream.println (indent + "    _cls = _cls.getSuperclass ();");
745:              stream.println (indent + '}');
746:              stream.println ();
747:              stream.println (indent + "if (_cls == null)");
748:              stream.println (indent + "  throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
749:              stream.println ();
750:              stream.println (indent + "String _className = _cls.getName ();");
751:              stream.println (indent + "int _index = _className.lastIndexOf ('.');");
752:              stream.println (indent + "String _interfaceName = _className.substring (0, _index + 1) + _className.substring (_index + 2, _className.length () - 5); // 5 == \"State\".length");
753:              stream.println (indent + "ostream.write_string (_interfaceName.replace ('.', '/'));");
754:
755:              // If _className != Util.javaName (entry), then call that class's helper class.
756:              stream.println ();
757:              stream.println (indent + "if (!_interfaceName.equals (\"" + Util.javaName (entry) + "\"))");
758:              stream.println (indent + '{');
759:              stream.println (indent + "  try");
760:              stream.println (indent + "  {");
761:              stream.println (indent + "    Class _helperClass = Class.forName (_interfaceName + \"Helper\");");
762:              stream.println (indent + "    Class[] _formalParms = new Class [2];");
763:              stream.println (indent + "    _formalParms[0] = Class.forName (\"org.omg.CORBA.portable.OutputStream\");");
764:              stream.println (indent + "    _formalParms[1] = _cls;");
765:              stream.println (indent + "    java.lang.reflect.Method _write = _helperClass.getMethod (\"write\", _formalParms);");
766:              stream.println (indent + "    Object[] _actualParms = new Object [2];");
767:              stream.println (indent + "    _actualParms[0] = ostream;");
768:              stream.println (indent + "    _actualParms[1] = " + name + ';');
769:              stream.println (indent + "    _write.invoke (null, _actualParms);");
770:              stream.println (indent + "  }");
771:              stream.println (indent + "  catch (Exception e)");
772:              stream.println (indent + "  {");
773:              stream.println (indent + "    throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
774:              stream.println (indent + "  }");
775:              stream.println (indent + '}');
776:
777:              stream.println (indent + "else");
778:              stream.println (indent + '{');
779:
780:              writeState (index, indent, name, (InterfaceEntry)entry, stream);
781:
782:              stream.println (indent + '}');
783:              return index;
784:            } // structWrite
785:
786:            private void writeState (int index, String indent, String name, InterfaceEntry entry, PrintWriter stream)
787:            {
788:              // First write the state from all parents
789:              Enumeration e = entry.derivedFrom ().elements ();
790:              while (e.hasMoreElements ())
791:              {
792:                InterfaceEntry parent = (InterfaceEntry)e.nextElement ();
793:                if (parent.state () != null)
794:                {
795:                  if (parent.state ().size () > 0)
796:                    writeState (index, indent, name, parent, stream);
797:                  break;
798:                }
799:              }
800:
801:              // Now write the state for the local entry
802:              Vector members = entry.state ();
803:              for (int i = 0; i < members.size (); ++i)
804:              {
805:                TypedefEntry member = ((InterfaceState)members.elementAt (i)).entry;
806:                if (!member.arrayInfo ().isEmpty () || member.type () instanceof SequenceEntry || member.type () instanceof PrimitiveEntry || member.type () instanceof StringEntry)
807:                  index = ((JavaGenerator)member.generator ()).write (index, indent + "  ", name + '.' + member.name () + "()", member, stream);
808:                else
809:                  stream.println (indent + "  " + Util.helperName (member.type (), true) + ".write (ostream, " + name + '.' + member.name () + " ());"); // <d61056>
810:              }
811:            } // writeState
812:             */
813:
814:            /**
815:             * @return true if the entry is for a CORBA pseudo-object.
816:             **/
817:            private boolean isPseudo(InterfaceEntry i) {
818:                java.lang.String fullname = i.fullName();
819:                if (fullname.equalsIgnoreCase("CORBA/TypeCode"))
820:                    return true;
821:                if (fullname.equalsIgnoreCase("CORBA/Principal"))
822:                    return true;
823:                if (fullname.equalsIgnoreCase("CORBA/ORB"))
824:                    return true;
825:                if (fullname.equalsIgnoreCase("CORBA/Any"))
826:                    return true;
827:                if (fullname.equalsIgnoreCase("CORBA/Context"))
828:                    return true;
829:                if (fullname.equalsIgnoreCase("CORBA/ContextList"))
830:                    return true;
831:                if (fullname.equalsIgnoreCase("CORBA/DynamicImplementation"))
832:                    return true;
833:                if (fullname.equalsIgnoreCase("CORBA/Environment"))
834:                    return true;
835:                if (fullname.equalsIgnoreCase("CORBA/ExceptionList"))
836:                    return true;
837:                if (fullname.equalsIgnoreCase("CORBA/NVList"))
838:                    return true;
839:                if (fullname.equalsIgnoreCase("CORBA/NamedValue"))
840:                    return true;
841:                if (fullname.equalsIgnoreCase("CORBA/Request"))
842:                    return true;
843:                if (fullname.equalsIgnoreCase("CORBA/ServerRequest"))
844:                    return true;
845:                if (fullname.equalsIgnoreCase("CORBA/UserException"))
846:                    return true;
847:                return false;
848:            }
849:
850:            // From JavaGenerator
851:            ///////////////
852:
853:            protected int emit = 0;
854:            protected Factories factories = null;
855:
856:            protected Hashtable symbolTable = null;
857:            protected InterfaceEntry i = null;
858:            protected PrintWriter stream = null;
859:
860:            // <f46082.03, f46838.1/.2/.3> Modify access to protected.
861:            protected static final int SIGNATURE = 1;
862:            protected static final int OPERATIONS = 2;
863:            protected int intfType = 0;
864:        } // class InterfaceGen
w___w__w___.___j_a___va___2s.__c_o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.