Source Code Cross Referenced for Generator.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_lib » genclientstub » generator » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_lib.genclientstub.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2004-2007 Bull S.A.S.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or 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:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: Generator.java 10094 2007-03-23 16:15:39Z sauthieg $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas_lib.genclientstub.generator;
025:
026:        import java.io.File;
027:        import java.util.ArrayList;
028:        import java.util.Iterator;
029:
030:        import org.objectweb.carol.util.configuration.ConfigurationRepository;
031:        import org.objectweb.common.Cmd;
032:        import org.objectweb.fastrmic.RMIC;
033:        import org.objectweb.jonas_lib.I18n;
034:        import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
035:        import org.objectweb.jonas_lib.genbase.GenBaseException;
036:        import org.objectweb.jonas_lib.genbase.archive.Archive;
037:        import org.objectweb.jonas_lib.genbase.archive.Client;
038:        import org.objectweb.jonas_lib.genbase.archive.EjbJar;
039:        import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
040:        import org.objectweb.jonas_lib.genbase.archive.WebApp;
041:        import org.objectweb.jonas_lib.genbase.generator.AbsGenerator;
042:        import org.objectweb.jonas_lib.genbase.generator.Config;
043:        import org.objectweb.jonas_lib.genclientstub.ClientStubGenException;
044:        import org.objectweb.jonas_lib.loader.AbsModuleClassLoader;
045:        import org.objectweb.util.monolog.api.BasicLevel;
046:
047:        /**
048:         * Generator used to generate Stubs for clients
049:         * @author Florent Benoit
050:         */
051:        public class Generator extends AbsGenerator {
052:
053:            /**
054:             * i18n
055:             */
056:            private static I18n i18n = I18n.getInstance(Generator.class);
057:
058:            /**
059:             * EjbRef used for this generator
060:             */
061:            private EjbRefDesc ejbRef = null;
062:
063:            /**
064:             * Class used if no ejbRef is given
065:             */
066:            private String intfStubClassName = null;
067:
068:            /**
069:             * Archive used by the modifier
070:             */
071:            private Archive archive = null;
072:
073:            /**
074:             * Creates a new Generator with the given Config.
075:             * @param config internal configuration object.
076:             * @param ejbRef reference to the ejb on which we want create the stub
077:             * @param intfStubClassName name of the interface
078:             * @param archive given ejbjar, webapp, ...
079:             * @throws GenBaseException When sources and target temporary directory
080:             *         cannot be created
081:             */
082:            public Generator(Config config, EjbRefDesc ejbRef,
083:                    String intfStubClassName, Archive archive)
084:                    throws GenBaseException {
085:                super (config);
086:                this .ejbRef = ejbRef;
087:                this .intfStubClassName = intfStubClassName;
088:                this .archive = archive;
089:            }
090:
091:            /**
092:             * Generate stub files.
093:             * @throws ClientStubGenException When generation fails.
094:             */
095:            public void generate() throws ClientStubGenException {
096:
097:                try {
098:                    //URL[] urls = null;
099:                    String archiveClasspath = null;
100:
101:                    J2EEArchive arch = (J2EEArchive) this .archive;
102:                    AbsModuleClassLoader loader = (AbsModuleClassLoader) arch
103:                            .getModuleClassloader();
104:
105:                    archiveClasspath = loader.getClasspath();
106:
107:                    // itf class
108:                    String itfClass = null;
109:                    if (ejbRef != null) {
110:                        itfClass = ejbRef.getHome();
111:                    } else {
112:                        itfClass = intfStubClassName;
113:                    }
114:
115:                    // TODO Now try to load the class and check if stub is here
116:
117:                    // Add to the rmic Classpath all the lib and classes of the archive
118:                    String classpath = getConfig().getClasspath()
119:                            + File.separator + archiveClasspath;
120:
121:                    // Get current protocol
122:                    String rmiName = ConfigurationRepository
123:                            .getCurrentConfiguration().getProtocol().getName();
124:
125:                    if (rmiName.equalsIgnoreCase("iiop")) {
126:                        Cmd iiopCmd = new Cmd(getConfig().getJavaHomeBin()
127:                                + getConfig().getNameRmic());
128:                        iiopCmd.addArgument("-classpath");
129:                        iiopCmd.addArgument(classpath);
130:                        iiopCmd.addArgument("-iiop");
131:                        iiopCmd.addArgument("-poa");
132:                        iiopCmd.addArgument("-always");
133:                        iiopCmd.addArgument("-keepgenerated");
134:                        iiopCmd.addArgument("-g");
135:
136:                        iiopCmd.addArgument("-d");
137:                        iiopCmd.addArgument(getClasses().getCanonicalPath());
138:                        iiopCmd.addArguments(getConfig().getJavacOpts());
139:
140:                        // add itf class as arg name
141:                        iiopCmd.addArgument(itfClass);
142:
143:                        if (getLogger().isLoggable(BasicLevel.DEBUG)) {
144:                            getLogger().log(BasicLevel.DEBUG,
145:                                    "Running '" + iiopCmd.toString() + "'");
146:                        }
147:                        if (iiopCmd.run()) {
148:                            getLogger()
149:                                    .log(
150:                                            BasicLevel.INFO,
151:                                            "Client stubs for classname '"
152:                                                    + itfClass
153:                                                    + "' successfully generated for protocol 'iiop'.");
154:                        } else {
155:                            String err = i18n
156:                                    .getMessage("Generator.generate.error");
157:                            getLogger().log(BasicLevel.ERROR, err);
158:                            throw new ClientStubGenException(err);
159:                        }
160:
161:                    } else if ("jrmp".equalsIgnoreCase(rmiName)
162:                            || "irmi".equalsIgnoreCase(rmiName)) {
163:                        Cmd jrmpCmd = new Cmd(getConfig().getJavaHomeBin()
164:                                + getConfig().getNameRmic());
165:                        jrmpCmd.addArgument("-classpath");
166:                        jrmpCmd.addArgument(classpath);
167:                        jrmpCmd.addArgument("-keepgenerated");
168:                        jrmpCmd.addArgument("-g");
169:                        jrmpCmd.addArgument("-d");
170:                        jrmpCmd.addArgument(getClasses().getCanonicalPath());
171:                        jrmpCmd.addArguments(getConfig().getJavacOpts());
172:
173:                        // add itf class as arg name
174:                        jrmpCmd.addArgument(itfClass);
175:
176:                        ArrayList args = new ArrayList();
177:                        boolean skip = true;
178:                        for (Iterator it = jrmpCmd.getCommandLine(); it
179:                                .hasNext();) {
180:                            Object o = it.next();
181:                            if (skip) {
182:                                skip = false;
183:                                continue;
184:                            }
185:                            args.add(o);
186:                        }
187:
188:                        // Build the stub using Fast RMIC
189:                        String[] a = (String[]) args.toArray(new String[] {});
190:                        RMIC rmic = new RMIC(a);
191:
192:                        if (rmic.run()) {
193:                            getLogger()
194:                                    .log(
195:                                            BasicLevel.INFO,
196:                                            "Client stubs for classname '"
197:                                                    + itfClass
198:                                                    + "' successfully generated for protocol '"
199:                                                    + rmiName + "'.");
200:                        } else {
201:                            String err = i18n
202:                                    .getMessage("Generator.generate.error");
203:                            getLogger().log(BasicLevel.ERROR, err);
204:                            throw new ClientStubGenException(err, rmic
205:                                    .getException());
206:                        }
207:
208:                    }
209:
210:                } catch (Exception e) {
211:                    String err = i18n.getMessage("Generator.generate.error");
212:                    getLogger().log(BasicLevel.ERROR, err);
213:                    throw new ClientStubGenException(err, e);
214:                }
215:
216:            }
217:
218:            /**
219:             * Compile generated java files into classes directory. Do nothing in case
220:             * of clientstub generator as all classes are generated
221:             * @throws ClientStubGenException When compilation fails
222:             */
223:            public void compile() throws ClientStubGenException {
224:            }
225:
226:            /**
227:             * Add generated files into an Archive
228:             * @param archive the archive destination of generated files.
229:             * @throws ClientStubGenException When files cannot be added in the given
230:             *         Archive.
231:             */
232:            public void addFiles(Archive archive) throws ClientStubGenException {
233:                if (archive instanceof  WebApp) {
234:                    archive.addDirectoryIn("WEB-INF/classes/", getClasses());
235:                } else if (archive instanceof  EjbJar) {
236:                    archive.addDirectory(getClasses());
237:                } else if (archive instanceof  Client) {
238:                    archive.addDirectory(getClasses());
239:                }
240:            }
241:
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.