Source Code Cross Referenced for StructGen.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:         * @(#)StructGen.java	1.22 07/05/05
035:         */
036:
037:        package com.sun.tools.corba.se.idl.toJavaPortable;
038:
039:        // NOTES:
040:        // - Think about arrays (and sequences?) as members
041:        //   - A sequence must be converted to an array, but a memory of the
042:        //     max size must be retained.
043:        // - After demarshalling an IOR, think about how to deal with the exceptions.
044:        // - The demarshall method should be throwing a ClientException,
045:        //   but should it, really?
046:        // -D60929   <klr> Update for RTF2.4 changes
047:        // -D61056   <klr> Use Util.helperName
048:        // -D62023   <klr> Use corbaLevel in read/write generation
049:        // -D59437   <daz> Modify read() to enit qualified name of value box helper. 
050:
051:        import java.io.File;
052:        import java.io.PrintWriter;
053:        import java.util.Enumeration;
054:        import java.util.Hashtable;
055:        import java.util.Vector;
056:
057:        import com.sun.tools.corba.se.idl.GenFileStream;
058:        import com.sun.tools.corba.se.idl.EnumEntry;
059:        import com.sun.tools.corba.se.idl.InterfaceEntry;
060:        import com.sun.tools.corba.se.idl.PrimitiveEntry;
061:        import com.sun.tools.corba.se.idl.SequenceEntry;
062:        import com.sun.tools.corba.se.idl.StringEntry;
063:        import com.sun.tools.corba.se.idl.StructEntry;
064:        import com.sun.tools.corba.se.idl.SymtabEntry;
065:        import com.sun.tools.corba.se.idl.TypedefEntry;
066:        import com.sun.tools.corba.se.idl.ValueEntry;
067:        import com.sun.tools.corba.se.idl.ValueBoxEntry;
068:        import com.sun.tools.corba.se.idl.InterfaceState;
069:
070:        /**
071:         *
072:         **/
073:        public class StructGen implements  com.sun.tools.corba.se.idl.StructGen,
074:                JavaGenerator {
075:            /**
076:             * Public zero-argument constructor.
077:             **/
078:            public StructGen() {
079:            } // ctor
080:
081:            /**
082:             * Constructor for ExceptionGen.
083:             **/
084:            protected StructGen(boolean exception) {
085:                this IsReallyAnException = exception;
086:            } // ctor
087:
088:            /**
089:             *
090:             **/
091:            public void generate(Hashtable symbolTable, StructEntry s,
092:                    PrintWriter str) {
093:                this .symbolTable = symbolTable;
094:                this .s = s;
095:                //init ();
096:
097:                openStream();
098:                if (stream == null)
099:                    return;
100:                generateHelper();
101:                generateHolder();
102:                writeHeading();
103:                writeBody();
104:                writeClosing();
105:                closeStream();
106:                generateContainedTypes();
107:            } // generate
108:
109:            /**
110:             * Initialize members unique to this generator.
111:             **/
112:            protected void init() {
113:            } // init
114:
115:            /**
116:             *
117:             **/
118:            protected void openStream() {
119:                stream = Util.stream(s, ".java");
120:            } // openStream
121:
122:            /**
123:             *
124:             **/
125:            protected void generateHelper() {
126:                ((Factories) Compile.compiler.factories()).helper().generate(
127:                        symbolTable, s);
128:            } // generateHelper
129:
130:            /**
131:             *
132:             **/
133:            protected void generateHolder() {
134:                ((Factories) Compile.compiler.factories()).holder().generate(
135:                        symbolTable, s);
136:            } // generateHolder
137:
138:            /**
139:             *
140:             **/
141:            protected void writeHeading() {
142:                Util.writePackage(stream, s);
143:                Util.writeProlog(stream, ((GenFileStream) stream).name());
144:
145:                if (s.comment() != null)
146:                    s.comment().generate("", stream);
147:
148:                stream.print("public final class " + s.name());
149:                if (this IsReallyAnException)
150:                    stream.print(" extends org.omg.CORBA.UserException");
151:                else
152:                    stream
153:                            .print(" implements org.omg.CORBA.portable.IDLEntity");
154:                stream.println();
155:                stream.println("{");
156:            } // writeHeading
157:
158:            /**
159:             *
160:             **/
161:            protected void writeBody() {
162:                writeMembers();
163:                writeCtors();
164:            } // writeBody
165:
166:            /**
167:             *
168:             **/
169:            protected void writeClosing() {
170:                stream.println("} // class " + s.name());
171:            } // writeClosing
172:
173:            /**
174:             *
175:             **/
176:            protected void closeStream() {
177:                stream.close();
178:            } // closeStream
179:
180:            /**
181:             *
182:             **/
183:            protected void generateContainedTypes() {
184:                // Generate all of the contained types
185:                Enumeration e = s.contained().elements();
186:                while (e.hasMoreElements()) {
187:                    SymtabEntry entry = (SymtabEntry) e.nextElement();
188:
189:                    // Don't generate contained entries if they are sequences.
190:                    // Sequences are unnamed and since they translate to arrays,
191:                    // no classes are generated for them, not even holders in this
192:                    // case since they cannot be accessed outside of this struct.
193:
194:                    if (!(entry instanceof  SequenceEntry))
195:                        entry.generate(symbolTable, stream);
196:                }
197:            } // generateContainedTypes
198:
199:            /**
200:             *
201:             **/
202:            protected void writeMembers() {
203:                // Write members and populate quality arrays
204:                int size = s.members().size();
205:                memberIsPrimitive = new boolean[size];
206:                memberIsInterface = new boolean[size];
207:                memberIsTypedef = new boolean[size];
208:                for (int i = 0; i < s.members().size(); ++i) {
209:                    SymtabEntry member = (SymtabEntry) s.members().elementAt(i);
210:                    memberIsPrimitive[i] = member.type() instanceof  PrimitiveEntry;
211:                    memberIsInterface[i] = member.type() instanceof  InterfaceEntry;
212:                    memberIsTypedef[i] = member.type() instanceof  TypedefEntry;
213:                    Util.fillInfo(member);
214:                    // Transfer member comment to target <31jul1997>.
215:                    if (member.comment() != null)
216:                        member.comment().generate("  ", stream);
217:                    Util.writeInitializer("  public ", member.name(), "",
218:                            member, stream);
219:                }
220:            } // writeMembers
221:
222:            /**
223:             *
224:             **/
225:            protected void writeCtors() {
226:                // Write default ctor
227:                stream.println();
228:                stream.println("  public " + s.name() + " ()");
229:                stream.println("  {");
230:                // fixed mapping for exceptions
231:                if (this IsReallyAnException)
232:                    stream.println("    super(" + s.name() + "Helper.id());");
233:                stream.println("  } // ctor");
234:                writeInitializationCtor(true);
235:                if (this IsReallyAnException) {
236:                    // for exception according to mapping we should always
237:                    // have a full constructor
238:                    writeInitializationCtor(false);
239:                }
240:            }
241:
242:            private void writeInitializationCtor(boolean init) {
243:                // Write initialization ctor
244:                if (!init || (s.members().size() > 0)) {
245:                    stream.println();
246:                    stream.print("  public " + s.name() + " (");
247:                    boolean firstTime = true;
248:                    if (!init) {
249:                        stream.print("String $reason");
250:                        firstTime = false;
251:                    }
252:
253:                    for (int i = 0; i < s.members().size(); ++i) {
254:                        SymtabEntry member = (SymtabEntry) s.members()
255:                                .elementAt(i);
256:                        if (firstTime)
257:                            firstTime = false;
258:                        else
259:                            stream.print(", ");
260:                        stream.print(Util.javaName(member) + " _"
261:                                + member.name());
262:                    }
263:                    stream.println(")");
264:                    stream.println("  {");
265:                    // fixed mapping for exceptions
266:                    if (this IsReallyAnException) {
267:                        if (init)
268:                            stream.println("    super(" + s.name()
269:                                    + "Helper.id());");
270:                        else
271:                            stream.println("    super(" + s.name()
272:                                    + "Helper.id() + \"  \" + $reason);");
273:                    }
274:                    for (int i = 0; i < s.members().size(); ++i) {
275:                        SymtabEntry member = (SymtabEntry) s.members()
276:                                .elementAt(i);
277:                        stream.println("    " + member.name() + " = _"
278:                                + member.name() + ";");
279:                    }
280:                    stream.println("  } // ctor");
281:                }
282:                stream.println();
283:            } // writeInitializationCtor
284:
285:            ///////////////
286:            // From JavaGenerator
287:
288:            public int helperType(int index, String indent,
289:                    TCOffsets tcoffsets, String name, SymtabEntry entry,
290:                    PrintWriter stream) {
291:                TCOffsets innerOffsets = new TCOffsets();
292:                innerOffsets.set(entry);
293:                int offsetForStruct = innerOffsets.currentOffset();
294:                StructEntry s = (StructEntry) entry;
295:                String membersName = "_members" + index++;
296:                stream.println(indent + "org.omg.CORBA.StructMember[] "
297:                        + membersName + " = new org.omg.CORBA.StructMember ["
298:                        + s.members().size() + "];");
299:                String tcOfMembers = "_tcOf" + membersName;
300:                stream.println(indent + "org.omg.CORBA.TypeCode " + tcOfMembers
301:                        + " = null;");
302:                for (int i = 0; i < s.members().size(); ++i) {
303:                    TypedefEntry member = (TypedefEntry) s.members().elementAt(
304:                            i);
305:                    String memberName = member.name();
306:                    // Generate and assign member TypeCode to tcofMembers
307:                    index = ((JavaGenerator) member.generator()).type(index,
308:                            indent, innerOffsets, tcOfMembers, member, stream);
309:                    stream.println(indent + membersName + '[' + i
310:                            + "] = new org.omg.CORBA.StructMember (");
311:                    stream.println(indent + "  \""
312:                            + Util.stripLeadingUnderscores(memberName) + "\",");
313:                    stream.println(indent + "  " + tcOfMembers + ',');
314:                    stream.println(indent + "  null);");
315:                    int offsetSoFar = innerOffsets.currentOffset();
316:                    innerOffsets = new TCOffsets();
317:                    innerOffsets.set(entry);
318:                    innerOffsets.bumpCurrentOffset(offsetSoFar
319:                            - offsetForStruct);
320:
321:                }
322:                tcoffsets.bumpCurrentOffset(innerOffsets.currentOffset());
323:                // <54697>
324:                //stream.println (indent + name + " = org.omg.CORBA.ORB.init ().create_struct_tc (id (), \"" + Util.stripLeadingUnderscores (entry.name ()) + "\", " + membersName + ");");
325:                stream.println(indent + name
326:                        + " = org.omg.CORBA.ORB.init ().create_"
327:                        + (this IsReallyAnException ? "exception" : "struct")
328:                        + "_tc (" + Util.helperName(s, true) + ".id (), \""
329:                        + Util.stripLeadingUnderscores(entry.name()) + "\", "
330:                        + membersName + ");"); // <d61056>
331:                return index;
332:            } // helperType
333:
334:            public int type(int index, String indent, TCOffsets tcoffsets,
335:                    String name, SymtabEntry entry, PrintWriter stream) {
336:                stream.println(indent + name + " = "
337:                        + Util.helperName(entry, true) + ".type ();"); // <d61056>
338:                return index;
339:            } // type
340:
341:            public void helperRead(String entryName, SymtabEntry entry,
342:                    PrintWriter stream) {
343:                stream.println("    " + entryName + " value = new " + entryName
344:                        + " ();");
345:                read(0, "    ", "value", entry, stream);
346:                stream.println("    return value;");
347:            } // helperRead
348:
349:            public int read(int index, String indent, String name,
350:                    SymtabEntry entry, PrintWriter stream) {
351:                if (this IsReallyAnException) {
352:                    stream.println(indent
353:                            + "// read and discard the repository ID");
354:                    stream.println(indent + "istream.read_string ();");
355:                }
356:
357:                Enumeration e = ((StructEntry) entry).members().elements();
358:                while (e.hasMoreElements()) {
359:                    TypedefEntry member = (TypedefEntry) e.nextElement();
360:                    SymtabEntry mType = member.type();
361:
362:                    if (!member.arrayInfo().isEmpty()
363:                            || mType instanceof  SequenceEntry
364:                            || mType instanceof  PrimitiveEntry
365:                            || mType instanceof  StringEntry
366:                            || mType instanceof  TypedefEntry)
367:                        index = ((JavaGenerator) member.generator()).read(
368:                                index, indent, name + '.' + member.name(),
369:                                member, stream);
370:                    else if (mType instanceof  ValueBoxEntry) {
371:                        // call read_value instead of Helper.read for the value
372:                        Vector st = ((ValueBoxEntry) mType).state();
373:                        TypedefEntry vbMember = ((InterfaceState) st
374:                                .elementAt(0)).entry;
375:                        SymtabEntry vbType = vbMember.type();
376:
377:                        String jName = null;
378:                        String jHelper = null;
379:
380:                        if (vbType instanceof  SequenceEntry
381:                                || vbType instanceof  StringEntry
382:                                || !vbMember.arrayInfo().isEmpty()) {
383:                            jName = Util.javaName(vbType); // name of mapped Java type
384:                            // <d59437> REVISIT.  Typename info. now correct for value boxes, so
385:                            // these two cases may be obsolete.  See UnionGen.read().
386:                            //jHelper = Util.helperName (vbType, false);  // <d61056>
387:                            jHelper = Util.helperName(mType, true);
388:                        } else {
389:                            jName = Util.javaName(mType); // name of mapped Java class
390:                            // <d59437>
391:                            //jHelper = Util.helperName (mType, false);  // <d61056>
392:                            jHelper = Util.helperName(mType, true);
393:                        }
394:                        // <d62023> Call xHelper.read() for valueboxes for RTF2.4
395:                        if (Util.corbaLevel(2.4f, 99.0f))
396:                            stream.println(indent + name + '.' + member.name()
397:                                    + " = (" + jName + ") " + jHelper
398:                                    + ".read (istream);");
399:                        else
400:                            stream
401:                                    .println(indent
402:                                            + name
403:                                            + '.'
404:                                            + member.name()
405:                                            + " = ("
406:                                            + jName
407:                                            + ") ((org.omg.CORBA_2_3.portable.InputStream)istream).read_value ("
408:                                            + jHelper + ".get_instance ());"); // <d60929> <d61056>
409:                    }
410:                    // <d62023-klr> for corbaLevel 2.4 and up, use Helper.read like
411:                    // everything else
412:                    else if ((mType instanceof  ValueEntry)
413:                            && !Util.corbaLevel(2.4f, 99.0f)) // <d62023>
414:                    {
415:                        // call read_value instead of Helper.read for the value
416:                        stream
417:                                .println(indent
418:                                        + name
419:                                        + '.'
420:                                        + member.name()
421:                                        + " = ("
422:                                        + Util.javaName(mType)
423:                                        + ") ((org.omg.CORBA_2_3.portable.InputStream)istream).read_value ("
424:                                        + Util.helperName(mType, false)
425:                                        + ".get_instance ());"); // <d60929> // <d61056>
426:                    } else
427:                        stream.println(indent + name + '.' + member.name()
428:                                + " = " + Util.helperName(member.type(), true)
429:                                + ".read (istream);"); // <d61056>
430:                }
431:                return index;
432:            } // read
433:
434:            public void helperWrite(SymtabEntry entry, PrintWriter stream) {
435:                write(0, "    ", "value", entry, stream);
436:            } // helperWrite
437:
438:            public int write(int index, String indent, String name,
439:                    SymtabEntry entry, PrintWriter stream) {
440:                if (this IsReallyAnException) {
441:                    stream.println(indent + "// write the repository ID");
442:                    stream.println(indent + "ostream.write_string (id ());");
443:                }
444:
445:                Vector members = ((StructEntry) entry).members();
446:                for (int i = 0; i < members.size(); ++i) {
447:                    TypedefEntry member = (TypedefEntry) members.elementAt(i);
448:                    SymtabEntry mType = member.type();
449:
450:                    if (!member.arrayInfo().isEmpty()
451:                            || mType instanceof  SequenceEntry
452:                            || mType instanceof  TypedefEntry
453:                            || mType instanceof  PrimitiveEntry
454:                            || mType instanceof  StringEntry)
455:                        index = ((JavaGenerator) member.generator()).write(
456:                                index, "    ", name + '.' + member.name(),
457:                                member, stream);
458:
459:                    // <d62023-klr> for corbaLevel 2.4 and up, use Helper.write like
460:                    //		everything else
461:                    else if ((mType instanceof  ValueEntry || mType instanceof  ValueBoxEntry)
462:                            && !Util.corbaLevel(2.4f, 99.0f)) { // <d62023>
463:                        stream
464:                                .println(indent
465:                                        + "((org.omg.CORBA_2_3.portable.OutputStream)ostream).write_value ((java.io.Serializable) " // <d60929>
466:                                        + name + '.' + member.name() + ", "
467:                                        + Util.helperName(member.type(), true) // <d61056>
468:                                        + ".get_instance ());"); // <d61056>
469:                    } else
470:                        stream.println(indent
471:                                + Util.helperName(member.type(), true)
472:                                + ".write (ostream, " + name + '.'
473:                                + member.name() + ");"); // <d61056>
474:                }
475:                return index;
476:            } // write
477:
478:            // From JavaGenerator
479:            ///////////////
480:
481:            protected Hashtable symbolTable = null;
482:            protected StructEntry s = null;
483:            protected PrintWriter stream = null;
484:
485:            protected boolean this IsReallyAnException = false;
486:            private boolean[] memberIsPrimitive;
487:            private boolean[] memberIsInterface;
488:            private boolean[] memberIsTypedef;
489:        } // class StructGen
w___ww.__jav___a_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.