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


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
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:         * Initial developer(s): Nicolas Christin
022:         * Contributor(s): ______________________________________.
023:         *
024:         * --------------------------------------------------------------------------
025:         * $Id: NewBean.java 4408 2004-03-19 14:31:54Z sauthieg $
026:         * --------------------------------------------------------------------------
027:         */
028:
029:        package org.objectweb.jonas.newbean;
030:
031:        import java.io.FileWriter;
032:        import java.io.IOException;
033:        import java.util.HashMap;
034:
035:        import org.apache.velocity.VelocityContext;
036:        import org.apache.velocity.app.VelocityEngine;
037:        import org.apache.velocity.exception.MethodInvocationException;
038:        import org.apache.velocity.exception.ParseErrorException;
039:        import org.apache.velocity.exception.ResourceNotFoundException;
040:
041:        /**
042:         * This class is a “bean generator”. It uses Velocity and
043:         * a set of template files to generate some files that can serve as a
044:         * startup point for the developpement of a new bean.
045:         */
046:        public class NewBean {
047:
048:            private static final int EXIT_SUCCESS = 0;
049:            private static final int EXIT_FAILURE = 1;
050:
051:            private VelocityEngine vEngine = null;
052:            private VelocityContext vContext = null;
053:
054:            private NewBean() {
055:
056:                // Creates and initializes a Velocity engine
057:                vEngine = new VelocityEngine();
058:                vEngine.setProperty(VelocityEngine.VM_LIBRARY, "");
059:                vEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
060:                vEngine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH,
061:                        System.getProperty("install.root") + "/" + "templates"
062:                                + "/" + "newbean");
063:                try {
064:                    vEngine.init();
065:                } catch (Exception e) {
066:                    fatalError("unable to initilise Velocity engine (" + e
067:                            + ")");
068:                }
069:
070:                // Creates a Velocity context and populates it by walking
071:                // through the parameter set
072:                vContext = new VelocityContext();
073:                ParameterSet parameterSet = new ParameterSet(vContext);
074:                parameterSet.walkThrough();
075:
076:                // Generates files
077:                generate();
078:
079:            }
080:
081:            /**
082:             * Generates files for this new bean.
083:             */
084:            private void generate() {
085:
086:                // Gets some useful information from Velocity's context
087:                final Integer MESSAGE_DRIVEN_BEAN = (Integer) vContext
088:                        .get("MESSAGE_DRIVEN_BEAN");
089:                String beanName = (String) vContext.get("beanName");
090:                String beanType = (String) vContext.get("beanType");
091:                String pkgName = (String) vContext.get("pkgName");
092:                String jarName = (String) vContext.get("jarName");
093:                Integer beanFlavor = (Integer) vContext.get("beanFlavor");
094:
095:                System.out.println("Creating bean " + beanName + " (type "
096:                        + beanType + ") in package " + pkgName);
097:
098:                // Generates bean files
099:                try {
100:                    boolean isClientToGenerate = true;
101:                    generate("ejb-jar.vm", jarName + ".xml");
102:                    generate("jonas-ejb-jar.vm", "jonas-" + jarName + ".xml");
103:                    if (beanFlavor != MESSAGE_DRIVEN_BEAN) {
104:                        String local = "";
105:                        Boolean isLocal = (Boolean) vContext.get("isLocal");
106:                        if (isLocal.booleanValue()) {
107:                            local = "Local";
108:                            isClientToGenerate = false;
109:                        }
110:                        generate("remote.vm", beanName + local + ".java");
111:                        generate("home.vm", beanName + local + "Home.java");
112:                    }
113:                    generate("bean.vm", beanName + beanType + ".java");
114:                    if (isClientToGenerate) {
115:                        generate("client.vm", beanName + "Client.java");
116:                    }
117:                    generate("build.vm", "build.xml");
118:                    System.out
119:                            .println("Your bean files have been created. You can now customize them.");
120:                } catch (Exception e) {
121:                    error(e.toString());
122:                }
123:
124:            }
125:
126:            /**
127:             * Generates a file from the specified template.
128:             * @param templateFileName the name of the template file
129:             * @param targetFileName the name of the generated file
130:             */
131:            private void generate(String templateFileName, String targetFileName)
132:                    throws Exception, IOException, ResourceNotFoundException,
133:                    ParseErrorException, MethodInvocationException {
134:                FileWriter fileWriter = null;
135:                fileWriter = new FileWriter(targetFileName);
136:                vEngine.mergeTemplate(templateFileName, vContext, fileWriter);
137:                fileWriter.close();
138:            }
139:
140:            public static HashMap commandLine = new HashMap();
141:
142:            private static void putCmdArgsInHashmap(String[] args) {
143:                for (int i = 0; i < args.length; i++) {
144:                    String key = args[i];
145:                    if (key.startsWith("-")) {
146:                        String val = null;
147:                        if (i + 1 < args.length && !args[i + 1].startsWith("-")) {
148:                            val = args[i + 1];
149:                            i++;
150:                        }
151:                        commandLine.put(key, val);
152:                    }
153:                }
154:            }
155:
156:            public static void main(String[] args) {
157:
158:                if (args.length > 0) {
159:                    // save the command line arguments so that we don't
160:                    // have to be interactive when called from JOPE
161:                    putCmdArgsInHashmap(args);
162:                }
163:
164:                new NewBean();
165:            }
166:
167:            /**
168:             * Display the specified error message.
169:             * @param errMsg the error message to display
170:             */
171:            static void error(String errMsg) {
172:                System.err.println("NewBean error: " + errMsg);
173:            }
174:
175:            /**
176:             * Display the specified error message and exits with an
177:             * EXIT_FAILURE status.
178:             * @param errMsg the error message to display
179:             */
180:            static void fatalError(String errMsg) {
181:                System.err.println("NewBean fatal error: " + errMsg);
182:                System.exit(EXIT_FAILURE);
183:            }
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.