Source Code Cross Referenced for OpDecl.java in  » Collaboration » JacORB » org » jacorb » idl » 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.idl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *        JacORB - a free Java ORB
003:         *
004:         *   Copyright (C) 1997-2004 Gerald Brose.
005:         *
006:         *   This library is free software; you can redistribute it and/or
007:         *   modify it under the terms of the GNU Library General Public
008:         *   License as published by the Free Software Foundation; either
009:         *   version 2 of the License, or (at your option) any later version.
010:         *
011:         *   This library is distributed in the hope that it will be useful,
012:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *   Library General Public License for more details.
015:         *
016:         *   You should have received a copy of the GNU Library General Public
017:         *   License along with this library; if not, write to the Free
018:         *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019:         */
020:
021:        package org.jacorb.idl;
022:
023:        import java.io.PrintWriter;
024:        import java.util.*;
025:
026:        /**
027:         * @author Gerald Brose
028:         * @version $Id: OpDecl.java,v 1.43 2006/08/03 08:01:14 alphonse.bendt Exp $
029:         */
030:
031:        public class OpDecl extends Declaration implements  Operation {
032:            public static final int NO_ATTRIBUTE = 0;
033:            public static final int ONEWAY = 1;
034:
035:            public int opAttribute; // either NO_ATTRIBUTE or ONEWAY
036:            public TypeSpec opTypeSpec;
037:            public Vector paramDecls;
038:            public RaisesExpr raisesExpr;
039:            public IdlSymbol myInterface;
040:
041:            public OpDecl(int num) {
042:                super (num);
043:                paramDecls = new Vector();
044:            }
045:
046:            /**
047:             *  Constructs a new OpDecl with the given characteristics.
048:             */
049:            public OpDecl(IdlSymbol myInterface, int opAttribute,
050:                    TypeSpec opTypeSpec, String name, List paramDecls,
051:                    RaisesExpr raisesExpr) {
052:                super (new_num());
053:                this .myInterface = myInterface;
054:                this .opAttribute = opAttribute;
055:                this .opTypeSpec = opTypeSpec;
056:                this .name = name;
057:                this .paramDecls = new Vector(paramDecls);
058:                this .raisesExpr = raisesExpr;
059:                setEnclosingSymbol(myInterface);
060:                this .pack_name = myInterface.full_name();
061:            }
062:
063:            /**
064:             *  Constructs a normal (not oneway) operation with void return type
065:             *  and no raises-Expression.
066:             */
067:            public OpDecl(IdlSymbol myInterface, String name, List paramDecls) {
068:                this (myInterface, NO_ATTRIBUTE, new VoidTypeSpec(new_num()),
069:                        name, paramDecls, new RaisesExpr(new_num()));
070:            }
071:
072:            public void setPackage(String s) {
073:                s = parser.pack_replace(s);
074:
075:                if (pack_name.length() > 0)
076:                    pack_name = s + "." + pack_name;
077:                else
078:                    pack_name = s;
079:                opTypeSpec.setPackage(s);
080:
081:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ((ParamDecl) e
082:                        .nextElement()).setPackage(s))
083:                    ;
084:                raisesExpr.setPackage(s);
085:            }
086:
087:            public void setEnclosingSymbol(IdlSymbol s) {
088:                if (logger.isDebugEnabled())
089:                    logger.debug("opDecl.setEnclosingSymbol " + s);
090:
091:                if (enclosing_symbol != null && enclosing_symbol != s)
092:                    throw new RuntimeException(
093:                            "Compiler Error: trying to reassign container for "
094:                                    + name);
095:                if (s == null)
096:                    throw new RuntimeException(
097:                            "Compiler Error: enclosing symbol is null!");
098:
099:                enclosing_symbol = s;
100:                raisesExpr.setEnclosingSymbol(s);
101:            }
102:
103:            public void parse() {
104:                if (enclosing_symbol == null)
105:                    throw new RuntimeException(
106:                            "Compiler Error: enclosing symbol in parse is null!");
107:
108:                myInterface = enclosing_symbol;
109:
110:                if (opAttribute == ONEWAY) {
111:                    if (!raisesExpr.empty())
112:                        parser.error("Oneway operation " + full_name()
113:                                + " may not define a raises clause.", token);
114:
115:                    if (!(opTypeSpec.typeSpec() instanceof  VoidTypeSpec))
116:                        parser.error("Oneway operation " + full_name()
117:                                + " may only define void as return type.",
118:                                token);
119:                }
120:
121:                try {
122:                    NameTable.define(full_name(), "operation");
123:                } catch (NameAlreadyDefined nad) {
124:                    parser.error("Operation " + full_name()
125:                            + " already defined", token);
126:                }
127:
128:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements();) {
129:                    ParamDecl param = (ParamDecl) e.nextElement();
130:
131:                    String typeN = (param.paramTypeSpec.typeName().indexOf(".") < 0 ? param.paramTypeSpec
132:                            .typeName()
133:                            : param.paramTypeSpec.typeName().substring(
134:                                    param.paramTypeSpec.typeName().lastIndexOf(
135:                                            ".") + 1));
136:
137:                    if (typeN.toUpperCase().equals(
138:                            param.simple_declarator.toString().toUpperCase())) {
139:                        parser.error("In operation " + full_name()
140:                                + " argument " + param.simple_declarator
141:                                + " clashes with type "
142:                                + param.paramTypeSpec.typeName());
143:                    }
144:
145:                    param.parse();
146:
147:                    try {
148:                        NameTable.define(full_name() + "."
149:                                + param.simple_declarator.name(), "argument");
150:                    } catch (NameAlreadyDefined nad) {
151:                        parser.error("Argument "
152:                                + param.simple_declarator.name()
153:                                + " already defined in operation "
154:                                + full_name(), token);
155:                    }
156:
157:                    if (param.paramAttribute != ParamDecl.MODE_IN) {
158:                        // for out and inout params
159:                        myInterface.addImportedNameHolder(param.paramTypeSpec
160:                                .holderName());
161:                    }
162:                    if (!(param.paramTypeSpec.typeSpec() instanceof  BaseType)) {
163:
164:                        if (logger.isInfoEnabled())
165:                            logger.info("classname: "
166:                                    + param.paramTypeSpec.typeSpec().getClass()
167:                                            .getName());
168:
169:                        myInterface.addImportedName(param.paramTypeSpec
170:                                .typeSpec().full_name(), param.paramTypeSpec
171:                                .typeSpec());
172:                    }
173:                    if (param.paramTypeSpec.typeSpec() instanceof  ConstrTypeSpec
174:                            && ((ConstrTypeSpec) param.paramTypeSpec.typeSpec()).c_type_spec instanceof  StructType
175:                            && ((StructType) ((ConstrTypeSpec) param.paramTypeSpec
176:                                    .typeSpec()).c_type_spec).exc == true) {
177:                        parser.error("Can't pass an exception as a parameter.");
178:                    }
179:                }
180:
181:                if (opTypeSpec.typeSpec() instanceof  ScopedName) {
182:                    TypeSpec ts = ((ScopedName) opTypeSpec.typeSpec())
183:                            .resolvedTypeSpec();
184:
185:                    if (ts != null)
186:                        opTypeSpec = ts;
187:
188:                    myInterface.addImportedName(opTypeSpec.typeName());
189:                }
190:                raisesExpr.parse();
191:            }
192:
193:            public void print(PrintWriter ps) {
194:                if (is_pseudo)
195:                    ps.print("\tpublic abstract " + opTypeSpec.toString());
196:                else
197:                    ps.print("\t" + opTypeSpec.toString());
198:                ps.print(" ");
199:                ps.print(name);
200:
201:                ps.print("(");
202:                Enumeration e = paramDecls.elements();
203:                if (e.hasMoreElements())
204:                    ((ParamDecl) e.nextElement()).print(ps);
205:
206:                for (; e.hasMoreElements();) {
207:                    ps.print(", ");
208:                    ((ParamDecl) e.nextElement()).print(ps);
209:                }
210:                ps.print(")");
211:                raisesExpr.print(ps);
212:                ps.println(";");
213:            }
214:
215:            /**
216:             * Writes the Stream-based Body of the Method for the stub
217:             */
218:            public void printStreamBody(PrintWriter ps, String classname,
219:                    String idl_name, boolean is_local, boolean is_abstract) {
220:                ps.println("\t\twhile(true)");
221:                ps.println("\t\t{");
222:                // remote part, not for locality constrained objects
223:                //
224:                if (!is_local) {
225:                    ps.println("\t\tif(! this._is_local())");
226:                    ps.println("\t\t{");
227:                    ps
228:                            .println("\t\t\torg.omg.CORBA.portable.InputStream _is = null;");
229:                    ps.println("\t\t\ttry");
230:                    ps.println("\t\t\t{");
231:                    ps
232:                            .print("\t\t\t\torg.omg.CORBA.portable.OutputStream _os = _request( \""
233:                                    + idl_name + "\",");
234:
235:                    if (opAttribute == NO_ATTRIBUTE)
236:                        ps.println(" true);");
237:                    else
238:                        ps.println(" false);");
239:
240:                    //  arguments..
241:
242:                    for (Enumeration e = paramDecls.elements(); e
243:                            .hasMoreElements();) {
244:                        ParamDecl p = ((ParamDecl) e.nextElement());
245:                        if (p.paramAttribute != ParamDecl.MODE_OUT)
246:                            ps.println("\t\t\t\t"
247:                                    + p.printWriteStatement("_os"));
248:                    }
249:
250:                    ps.println("\t\t\t\t_is = _invoke(_os);");
251:
252:                    if (opAttribute == 0
253:                            && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
254:                        ps.println("\t\t\t\t"
255:                                + opTypeSpec.toString()
256:                                + " _result = "
257:                                + opTypeSpec.typeSpec().printReadExpression(
258:                                        "_is") + ";");
259:                    }
260:
261:                    for (Enumeration e2 = paramDecls.elements(); e2
262:                            .hasMoreElements();) {
263:                        ParamDecl p = (ParamDecl) e2.nextElement();
264:                        if (p.paramAttribute != ParamDecl.MODE_IN) {
265:                            ps.println("\t\t\t\t" + p.simple_declarator
266:                                    + ".value = "
267:                                    + p.printReadExpression("_is") + ";");
268:                        }
269:                    }
270:
271:                    if (opAttribute == NO_ATTRIBUTE
272:                            && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
273:                        ps.println("\t\t\t\treturn _result;");
274:                    } else
275:                        ps.println("\t\t\t\treturn;");
276:
277:                    /* catch exceptions */
278:
279:                    ps.println("\t\t\t}");
280:                    ps
281:                            .println("\t\t\tcatch( org.omg.CORBA.portable.RemarshalException _rx ){}");
282:                    ps
283:                            .println("\t\t\tcatch( org.omg.CORBA.portable.ApplicationException _ax )");
284:                    ps.println("\t\t\t{");
285:                    ps.println("\t\t\t\tString _id = _ax.getId();");
286:
287:                    if (!raisesExpr.empty()) {
288:                        String[] exceptIds = raisesExpr.getExceptionIds();
289:                        String[] classNames = raisesExpr
290:                                .getExceptionClassNames();
291:                        ps.print("\t\t\t\t");
292:                        for (int i = 0; i < exceptIds.length; i++) {
293:                            if (i > 0) {
294:                                ps.print("\t\t\t\telse ");
295:                            }
296:                            ps.println("if( _id.equals(\"" + exceptIds[i]
297:                                    + "\"))");
298:                            ps.println("\t\t\t\t{");
299:                            ps.println("\t\t\t\t\tthrow " + classNames[i]
300:                                    + "Helper.read(_ax.getInputStream());");
301:                            ps.println("\t\t\t\t}");
302:                        }
303:                    }
304:                    ps
305:                            .println("\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + _id );");
306:                    ps.println("\t\t\t}");
307:                    ps.println("\t\t\tfinally");
308:                    ps.println("\t\t\t{");
309:                    ps.println("\t\t\t\tthis._releaseReply(_is);");
310:                    ps.println("\t\t\t}");
311:
312:                    ps.println("\t\t}");
313:                    // local part
314:                    ps.println("\t\telse");
315:                    ps.println("\t\t{");
316:                }
317:
318:                ps
319:                        .println("\t\t\torg.omg.CORBA.portable.ServantObject _so = _servant_preinvoke( \""
320:                                + idl_name + "\", _opsClass );");
321:
322:                ps.println("\t\t\tif( _so == null )");
323:                ps
324:                        .println("\t\t\t\tthrow new org.omg.CORBA.UNKNOWN(\"local invocations not supported!\");");
325:
326:                if (is_abstract) {
327:                    ps.println("\t\t\t" + classname + " _localServant = ("
328:                            + classname + ")_so.servant;");
329:                } else {
330:                    ps.println("\t\t\t" + classname
331:                            + "Operations _localServant = (" + classname
332:                            + "Operations)_so.servant;");
333:                }
334:
335:                if (opAttribute == 0
336:                        && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
337:                    ps.println("\t\t\t" + opTypeSpec.toString() + " _result;");
338:                }
339:
340:                ps.println("\t\t\ttry");
341:                ps.println("\t\t\t{");
342:
343:                if (opAttribute == 0
344:                        && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
345:                    ps.print("\t\t\t\t_result = ");
346:                } else {
347:                    ps.print("\t\t\t\t");
348:                }
349:
350:                ps.print("_localServant." + name + "(");
351:
352:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements();) {
353:                    ParamDecl p = ((ParamDecl) e.nextElement());
354:                    ps.print(p.simple_declarator.toString());
355:                    if (e.hasMoreElements())
356:                        ps.print(",");
357:                }
358:                ps.println(");");
359:
360:                ps.println("\t\t\t}");
361:                ps.println("\t\t\tfinally");
362:                ps.println("\t\t\t{");
363:                ps.println("\t\t\t\t_servant_postinvoke(_so);");
364:                ps.println("\t\t\t}");
365:
366:                if (opAttribute == 0
367:                        && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
368:                    ps.println("\t\t\treturn _result;");
369:                } else
370:                    ps.println("\t\t\treturn;");
371:
372:                if (!is_local)
373:                    ps.println("\t\t}\n");
374:
375:                ps.println("\t\t}\n"); // end while
376:            }
377:
378:            /**
379:             * Writes the DII-based Body of the Method for the stub
380:             */
381:            private void printDIIBody(PrintWriter ps, String classname,
382:                    String idl_name, boolean is_local, boolean is_abstract) {
383:                ps.println("\t\torg.omg.CORBA.Request _request = _request( \""
384:                        + idl_name + "\" );");
385:                ps.println("");
386:
387:                //set return type
388:                if (opAttribute == NO_ATTRIBUTE
389:                        && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
390:                    //old version
391:                    //ps.println( "\t\t_r.set_return_type(" + opTypeSpec.typeSpec().getTypeCodeExpression() + ");");
392:                    //new version, distinguishes different types
393:                    if (opTypeSpec.typeSpec() instanceof  BaseType) {
394:                        BaseType bt = (BaseType) opTypeSpec.typeSpec();
395:                        ps.println("\t\t_request.set_return_type( "
396:                                + bt.getTypeCodeExpression() + " );");
397:                    } else if (opTypeSpec.typeSpec() instanceof  StringType) {
398:                        StringType st = (StringType) opTypeSpec.typeSpec();
399:                        ps.println("\t\t_request.set_return_type( "
400:                                + st.getTypeCodeExpression() + " );");
401:                    } else {
402:                        try {
403:                            //if there is a helper-class, use it to get the TypeCode for the return value
404:                            String helperName = opTypeSpec.typeSpec()
405:                                    .helperName();
406:                            ps.println("\t\t_request.set_return_type("
407:                                    + helperName + ".type()" + ");");
408:                        } catch (NoHelperException e) {
409:                            //otherwise use typeCodeExpression
410:                            //(the old version)
411:                            ps.println("\t\t_request.set_return_type("
412:                                    + opTypeSpec.typeSpec()
413:                                            .getTypeCodeExpression() + ");");
414:                        }
415:                    }
416:                } else {
417:                    //return type void
418:                    ps
419:                            .println("\t\t_request.set_return_type(_orb().get_primitive_tc(org.omg.CORBA.TCKind.tk_void));");
420:                }
421:                ps.println("");
422:
423:                //put parameters into the request
424:                for (Enumeration e2 = paramDecls.elements(); e2
425:                        .hasMoreElements();) {
426:                    ParamDecl p = ((ParamDecl) e2.nextElement());
427:                    p.printAddArgumentStatement(ps, "_request");
428:                    ps.println("");
429:                }
430:
431:                //add exceptions
432:                if (!raisesExpr.empty()) {
433:                    String[] exceptions = raisesExpr.getExceptionClassNames();
434:                    for (int i = 0; i < exceptions.length; i++) {
435:                        ps.println("\t\t_request.exceptions().add("
436:                                + exceptions[i] + "Helper.type());");
437:                    }
438:                    ps.println("");
439:                }
440:
441:                //invoke
442:                ps.println("\t\t_request.invoke();");
443:                ps.println("");
444:
445:                //get Exception
446:                ps
447:                        .println("\t\tjava.lang.Exception _exception = _request.env().exception();");
448:                ps.println("\t\tif (_exception != null)");
449:                ps.println("\t\t{");
450:                if (!raisesExpr.empty()) {
451:                    ps
452:                            .println("\t\t\tif(_exception instanceof org.omg.CORBA.UnknownUserException)");
453:                    ps.println("\t\t\t{");
454:                    ps
455:                            .println("\t\t\t\torg.omg.CORBA.UnknownUserException _userException = (org.omg.CORBA.UnknownUserException) _exception;");
456:                    ps.print("\t\t\t\t");
457:                    String[] raisesExceptions = raisesExpr
458:                            .getExceptionClassNames();
459:                    for (int i = 0; i < raisesExceptions.length; i++) {
460:                        ps.println("if (_userException.except.type().equals("
461:                                + raisesExceptions[i] + "Helper.type()))");
462:                        ps.println("\t\t\t\t{");
463:                        ps.println("\t\t\t\t\tthrow " + raisesExceptions[i]
464:                                + "Helper.extract(_userException.except);");
465:                        ps.println("\t\t\t\t}");
466:                        ps.println("\t\t\t\telse");
467:                    }
468:                    ps.println("\t\t\t\t{");
469:                    ps.println("\t\t\t\t\tthrow new org.omg.CORBA.UNKNOWN();");
470:                    ps.println("\t\t\t\t}");
471:                    ps.println("\t\t\t}");
472:                }
473:
474:                ps
475:                        .println("\t\t\tthrow (org.omg.CORBA.SystemException) _exception;");
476:                ps.println("\t\t}");
477:                ps.println("");
478:
479:                //Get out and inout parameters!
480:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements();) {
481:                    ParamDecl p = ((ParamDecl) e.nextElement());
482:                    if (p.paramAttribute != ParamDecl.MODE_IN) {
483:                        p.printExtractArgumentStatement(ps);
484:                    }
485:                }
486:
487:                //get the result
488:                if (opAttribute == NO_ATTRIBUTE
489:                        && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
490:                    ps.println("\t\t" + opTypeSpec.toString() + " _result;");
491:                    opTypeSpec.typeSpec().printExtractResult(ps, "_result",
492:                            "_request.return_value()", opTypeSpec.toString());
493:                    ps.println("\t\treturn _result;");
494:                } else
495:                    ps.println("\t\treturn;");
496:            }
497:
498:            public void printMethod(PrintWriter ps, String classname,
499:                    boolean is_local, boolean is_abstract) {
500:                /* in some cases generated name have an underscore prepended for the
501:                   mapped java name. On the wire, we must use the original name */
502:
503:                String idl_name = (name.startsWith("_") ? name.substring(1)
504:                        : name);
505:
506:                ps
507:                        .print("\tpublic " + opTypeSpec.toString() + " " + name
508:                                + "(");
509:
510:                Enumeration e = paramDecls.elements();
511:                if (e.hasMoreElements())
512:                    ((ParamDecl) e.nextElement()).print(ps);
513:
514:                for (; e.hasMoreElements();) {
515:                    ps.print(", ");
516:                    ((ParamDecl) e.nextElement()).print(ps);
517:                }
518:
519:                ps.print(")");
520:                raisesExpr.print(ps);
521:                ps.println("\n\t{");
522:
523:                if (parser.generateDiiStubs) {
524:                    printDIIBody(ps, classname, idl_name, is_local, is_abstract);
525:                } else {
526:                    printStreamBody(ps, classname, idl_name, is_local,
527:                            is_abstract);
528:                }
529:
530:                ps.println("\t}\n"); // end method^M
531:            }
532:
533:            public void print_sendc_Method(PrintWriter ps, String classname) {
534:                /* in some cases generated name have an underscore prepended for the
535:                   mapped java name. On the wire, we must use the original name */
536:
537:                String idl_name = (name.startsWith("_") ? name.substring(1)
538:                        : name);
539:
540:                ps.print("\tpublic void sendc_" + name + "(");
541:
542:                ps.print("AMI_" + classname + "Handler ami_handler");
543:
544:                for (Iterator i = paramDecls.iterator(); i.hasNext();) {
545:                    ParamDecl p = (ParamDecl) i.next();
546:                    if (p.paramAttribute != ParamDecl.MODE_OUT) {
547:                        ps.print(", ");
548:                        p.asIn().print(ps);
549:                    }
550:                }
551:
552:                ps.print(")");
553:                ps.println("\n\t{");
554:                ps.println("\t\twhile(true)");
555:                ps.println("\t\t{");
556:                ps.println("\t\t\ttry");
557:                ps.println("\t\t\t{");
558:                ps
559:                        .print("\t\t\t\torg.omg.CORBA.portable.OutputStream _os = _request( \""
560:                                + idl_name + "\",");
561:
562:                if (opAttribute == NO_ATTRIBUTE)
563:                    ps.println(" true);");
564:                else
565:                    ps.println(" false);");
566:
567:                //  arguments..
568:
569:                for (Iterator i = paramDecls.iterator(); i.hasNext();) {
570:                    ParamDecl p = ((ParamDecl) i.next());
571:                    if (p.paramAttribute != ParamDecl.MODE_OUT)
572:                        ps.println("\t\t\t\t"
573:                                + p.asIn().printWriteStatement("_os"));
574:                }
575:
576:                ps
577:                        .println("\t\t\t\t((org.jacorb.orb.Delegate)_get_delegate()).invoke(this, _os, ami_handler);");
578:                ps.println("\t\t\t\treturn;");
579:
580:                /* catch exceptions */
581:
582:                ps.println("\t\t\t}");
583:                ps
584:                        .println("\t\t\tcatch( org.omg.CORBA.portable.RemarshalException _rx )");
585:                ps.println("\t\t\t{");
586:                ps.println("\t\t\t}");
587:
588:                ps
589:                        .println("\t\t\tcatch( org.omg.CORBA.portable.ApplicationException _ax )");
590:                ps.println("\t\t\t{");
591:                ps.println("\t\t\t}");
592:
593:                ps.println("\t\t}\n"); // end while
594:                ps.println("\t}\n"); // end method
595:            }
596:
597:            public void printDelegatedMethod(PrintWriter ps) {
598:                ps
599:                        .print("\tpublic " + opTypeSpec.toString() + " " + name
600:                                + "(");
601:
602:                Enumeration e = paramDecls.elements();
603:                if (e.hasMoreElements())
604:                    ((ParamDecl) e.nextElement()).print(ps);
605:
606:                for (; e.hasMoreElements();) {
607:                    ps.print(", ");
608:                    ((ParamDecl) e.nextElement()).print(ps);
609:                }
610:
611:                ps.print(")");
612:                raisesExpr.print(ps);
613:                ps.println("\n\t{");
614:
615:                if (opAttribute == NO_ATTRIBUTE
616:                        && !(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)) {
617:                    ps.print("\t\treturn ");
618:                }
619:
620:                ps.print("_delegate." + name + "(");
621:                e = paramDecls.elements();
622:                if (e.hasMoreElements())
623:                    ps.print(((ParamDecl) e.nextElement()).simple_declarator);
624:
625:                for (; e.hasMoreElements();) {
626:                    ps.print(",");
627:                    ps.print(((ParamDecl) e.nextElement()).simple_declarator);
628:                }
629:                ps.println(");");
630:                ps.println("\t}\n");
631:            }
632:
633:            public void printInvocation(PrintWriter ps) {
634:                if (!raisesExpr.empty()) {
635:                    ps.println("\t\t\ttry");
636:                    ps.println("\t\t\t{");
637:                }
638:
639:                /* read args */
640:
641:                int argc = 0;
642:                boolean holders = false;
643:
644:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements();) {
645:                    ParamDecl p = (ParamDecl) e.nextElement();
646:                    TypeSpec ts = p.paramTypeSpec.typeSpec();
647:
648:                    boolean is_wstring = ((ts instanceof  StringType) && (((StringType) ts)
649:                            .isWide()));
650:
651:                    boolean is_wchar = ((ts instanceof  CharType) && (((CharType) ts)
652:                            .isWide()));
653:
654:                    if (p.paramAttribute == ParamDecl.MODE_IN) {
655:                        ps.println("\t\t\t\t" + ts.toString() + " _arg"
656:                                + (argc++) + "="
657:                                + ts.printReadExpression("_input") + ";");
658:                    } else {
659:                        holders = true;
660:                        ps
661:                                .println("\t\t\t\t" + ts.holderName() + " _arg"
662:                                        + (argc++) + "= new " + ts.holderName()
663:                                        + "();");
664:                        if (p.paramAttribute == ParamDecl.MODE_INOUT) {
665:                            // wchars and wstrings are contained in CharHolder and
666:                            // StringHolder and so cannot be inserted via _read operation
667:                            // on holder. Instead value of holder needs to be set directly
668:                            // from correct type explicitly read from stream.
669:
670:                            if (is_wchar) {
671:                                ps.println("\t\t\t\t_arg" + (argc - 1)
672:                                        + ".value = _input.read_wchar ();");
673:                            } else if (is_wstring) {
674:                                ps.println("\t\t\t\t_arg" + (argc - 1)
675:                                        + ".value = _input.read_wstring ();");
676:                            } else {
677:                                ps.println("\t\t\t\t_arg" + (argc - 1)
678:                                        + "._read (_input);");
679:                            }
680:                        }
681:                    }
682:                }
683:
684:                boolean complex = (opTypeSpec.typeSpec() instanceof  ArrayTypeSpec)
685:                        || (opTypeSpec.typeSpec() instanceof  FixedPointType);
686:
687:                String write_str = null, write_str_prefix = null, write_str_suffix = null;
688:
689:                //  if( (!(opTypeSpec.typeSpec() instanceof VoidTypeSpec ))    || holders )
690:                //  {
691:                ps.println("\t\t\t\t_out = handler.createReply();");
692:                if (!(opTypeSpec.typeSpec() instanceof  VoidTypeSpec)
693:                        && !complex) {
694:                    write_str = opTypeSpec.typeSpec().printWriteStatement("**",
695:                            "_out");
696:                    int index = write_str.indexOf("**");
697:                    write_str_prefix = write_str.substring(0, index);
698:                    write_str_suffix = write_str.substring(index + 2);
699:                    ps.print("\t\t\t\t" + write_str_prefix);
700:                } else
701:                    ps.print("\t\t\t\t");
702:                //  }
703:
704:                if (complex)
705:                    ps.print(opTypeSpec.typeSpec().typeName() + " _result = ");
706:
707:                ps.print(name + "(");
708:
709:                for (int i = 0; i < argc; i++) {
710:                    ps.print("_arg" + i);
711:                    if (i < argc - 1)
712:                        ps.print(",");
713:                }
714:
715:                /*
716:
717:                Enumeration e = paramDecls.elements();
718:                if(e.hasMoreElements())
719:                {
720:                TypeSpec ts = ((ParamDecl)e.nextElement()).paramTypeSpec;
721:                ps.print(ts.printReadExpression("input"));
722:                }
723:
724:                for(; e.hasMoreElements();)
725:                {
726:                TypeSpec ts = ((ParamDecl)e.nextElement()).paramTypeSpec;
727:                ps.print("," + ts.printReadExpression("input"));
728:                }
729:                 */
730:
731:                if (!(opTypeSpec.typeSpec() instanceof  VoidTypeSpec))
732:                    ps.print(")");
733:
734:                if (!complex) {
735:                    if (opTypeSpec.typeSpec() instanceof  VoidTypeSpec)
736:                        ps.println(");");
737:                    else
738:                        ps.println(write_str_suffix);
739:                } else {
740:                    ps.println(";");
741:                    ps.println(opTypeSpec.typeSpec().printWriteStatement(
742:                            "_result", "_out"));
743:                }
744:
745:                /* write holder values */
746:
747:                argc = 0;
748:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements();) {
749:                    ParamDecl p = (ParamDecl) e.nextElement();
750:                    TypeSpec ts = p.paramTypeSpec;
751:                    if (p.paramAttribute != ParamDecl.MODE_IN) {
752:                        ps.println("\t\t\t\t"
753:                                + p.printWriteStatement(("_arg" + (argc)),
754:                                        "_out"));
755:                    }
756:                    argc++;
757:                }
758:
759:                if (!raisesExpr.empty()) {
760:                    ps.println("\t\t\t}");
761:                    String[] excepts = raisesExpr.getExceptionNames();
762:                    String[] classNames = raisesExpr.getExceptionClassNames();
763:                    for (int i = 0; i < excepts.length; i++) {
764:                        ps.println("\t\t\tcatch(" + excepts[i] + " _ex" + i
765:                                + ")");
766:                        ps.println("\t\t\t{");
767:                        ps
768:                                .println("\t\t\t\t_out = handler.createExceptionReply();");
769:                        ps.println("\t\t\t\t" + classNames[i]
770:                                + "Helper.write(_out, _ex" + i + ");");
771:                        ps.println("\t\t\t}");
772:                    }
773:                }
774:
775:            }
776:
777:            public String signature() {
778:                StringBuffer sb = new StringBuffer();
779:                sb.append(name + "(");
780:
781:                Enumeration e = paramDecls.elements();
782:                if (e.hasMoreElements())
783:                    sb.append(((ParamDecl) e.nextElement()).paramTypeSpec
784:                            .toString());
785:
786:                for (; e.hasMoreElements();) {
787:                    sb.append(","
788:                            + ((ParamDecl) e.nextElement()).paramTypeSpec
789:                                    .toString());
790:                }
791:                sb.append(")");
792:                return sb.toString();
793:            }
794:
795:            public String name() {
796:                return name;
797:            }
798:
799:            public String opName() {
800:                return name();
801:            }
802:
803:            public void printSignature(PrintWriter ps) {
804:                printSignature(ps, false);
805:            }
806:
807:            /**
808:             * @param printModifiers whether "public abstract" should be added
809:             */
810:            public void printSignature(PrintWriter ps, boolean printModifiers) {
811:                ps.print("\t");
812:                if (printModifiers)
813:                    ps.print("public abstract ");
814:
815:                ps.print(opTypeSpec.toString() + " " + name + "(");
816:
817:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements();) {
818:                    ((ParamDecl) e.nextElement()).print(ps);
819:                    if (e.hasMoreElements())
820:                        ps.print(", ");
821:                }
822:
823:                ps.print(")");
824:                raisesExpr.print(ps);
825:                ps.println(";");
826:            }
827:
828:            /**
829:             *    collect Interface Repository information in the argument hashtable
830:             */
831:
832:            public void getIRInfo(Hashtable irInfoTable) {
833:                StringBuffer sb = new StringBuffer();
834:
835:                TypeSpec ts = opTypeSpec.typeSpec();
836:
837:                if (ts instanceof  AliasTypeSpec) {
838:                    //             if( ((AliasTypeSpec)ts).originalType.typeSpec() instanceof FixedPointType )
839:                    //              {
840:                    sb.append(ts.full_name());
841:                    //             }
842:                }
843:                sb.append("(");
844:
845:                for (Enumeration e = paramDecls.elements(); e.hasMoreElements();) {
846:                    ParamDecl param = (ParamDecl) e.nextElement();
847:                    if (param.paramAttribute == ParamDecl.MODE_INOUT) {
848:                        sb
849:                                .append("inout:" + param.simple_declarator.name
850:                                        + " ");
851:                    } else if (param.paramAttribute == ParamDecl.MODE_OUT) {
852:                        sb.append("out:" + param.simple_declarator.name + " ");
853:                    } else
854:                        // MODE_IN
855:                        sb.append("in:" + param.simple_declarator.name + " ");
856:
857:                    ts = param.paramTypeSpec.typeSpec();
858:
859:                    if (ts instanceof  AliasTypeSpec) {
860:                        sb.append(ts.full_name());
861:                    }
862:
863:                    sb.append(",");
864:                }
865:
866:                if (paramDecls.size() > 0) {
867:                    // remove extra trailing ","
868:                    sb.deleteCharAt(sb.length() - 1);
869:                }
870:                sb.append(")");
871:
872:                if (opAttribute == ONEWAY)
873:                    sb.append("-oneway");
874:
875:                //       if( enter )
876:                irInfoTable.put(name, sb.toString());
877:
878:                if (logger.isDebugEnabled())
879:                    logger.debug("OpInfo for " + name + " : " + sb.toString());
880:            }
881:
882:            public void accept(IDLTreeVisitor visitor) {
883:                visitor.visitOpDecl(this);
884:            }
885:
886:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.