Source Code Cross Referenced for JVelocity.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_ws » wsgen » generator » axis » 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_ws.wsgen.generator.axis 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS : Java(TM) OpenSource Application Server
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
017:         * USA
018:         *
019:         * Initial Developer : Guillaume Sauthier
020:         * --------------------------------------------------------------------------
021:         * $Id: JVelocity.java 5972 2004-12-16 09:46:37Z benoitf $
022:         * --------------------------------------------------------------------------
023:         */package org.objectweb.jonas_ws.wsgen.generator.axis;
024:
025:        import java.io.File;
026:        import java.io.FileWriter;
027:        import java.io.IOException;
028:
029:        import org.apache.velocity.Template;
030:        import org.apache.velocity.VelocityContext;
031:        import org.apache.velocity.app.VelocityEngine;
032:        import org.apache.velocity.runtime.RuntimeConstants;
033:
034:        import org.objectweb.jonas_lib.I18n;
035:
036:        import org.objectweb.jonas_ws.wsgen.WsGenException;
037:
038:        import org.objectweb.jonas.common.Log;
039:
040:        import org.objectweb.util.monolog.api.BasicLevel;
041:        import org.objectweb.util.monolog.api.Logger;
042:
043:        /**
044:         * Wrapper around Velocity tool.
045:         *
046:         * @author Guillaume Sauthier
047:         */
048:        public class JVelocity {
049:
050:            /** i18n */
051:            private static I18n i18n = I18n.getInstance(JVelocity.class);
052:
053:            /**
054:             * logger
055:             */
056:            private static Logger logger = Log
057:                    .getLogger(Log.JONAS_WSGEN_PREFIX);
058:
059:            /** Velocity Engine */
060:            private VelocityEngine vEngine;
061:
062:            /** Velocity Template */
063:            private Template template;
064:
065:            /**
066:             * Creates a new JVelocity instance using the given template.
067:             *
068:             * @param tmplName the template filename
069:             *
070:             * @exception WsGenException when error occurs during Velocity
071:             *            initialization.
072:             */
073:            public JVelocity(String tmplName) throws WsGenException {
074:                // Prepare Velocity Engine
075:                String jonasRoot = System.getProperty("install.root");
076:
077:                if (jonasRoot == null) {
078:                    String err = i18n.getMessage("JVelocity.constr.notset");
079:                    throw new WsGenException(err);
080:                }
081:
082:                String path2Tmpl = new String(jonasRoot + File.separatorChar
083:                        + "templates" + File.separatorChar + "wsgen"
084:                        + File.separatorChar + "generator" + File.separatorChar
085:                        + "axis");
086:
087:                // instanciate the engine
088:                vEngine = new VelocityEngine();
089:                vEngine.setProperty(RuntimeConstants.VM_LIBRARY, "");
090:                vEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
091:                vEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
092:                        path2Tmpl);
093:
094:                try {
095:                    vEngine.init();
096:                } catch (Exception e) {
097:                    String err = i18n
098:                            .getMessage("JVelocity.constr.initFailure");
099:                    throw new WsGenException(err, e);
100:                }
101:
102:                // Create the Template
103:                try {
104:                    template = vEngine.getTemplate(tmplName);
105:                } catch (Exception e) {
106:                    String err = i18n.getMessage("JVelocity.constr.tmplError",
107:                            tmplName);
108:                    throw new WsGenException(err, e);
109:                }
110:            }
111:
112:            /**
113:             * Generate the given file with the given VelocityContext.
114:             *
115:             * @param fs the output file
116:             * @param context VelocityContext
117:             *
118:             * @throws WsGenException when velocity generation fails
119:             */
120:            public void generate(File fs, VelocityContext context)
121:                    throws WsGenException {
122:                FileWriter fwriter = null;
123:
124:                try {
125:                    // Create before the parent directory
126:                    File fdir = fs.getParentFile();
127:
128:                    if (fdir != null) {
129:                        if (!fdir.exists()) {
130:                            if (!fdir.mkdirs()) {
131:                                String err = i18n.getMessage(
132:                                        "JVelocity.generate.directories", fdir
133:                                                .getPath());
134:                                throw new WsGenException(err);
135:                            }
136:                        }
137:                    }
138:
139:                    fwriter = new FileWriter(fs);
140:                } catch (IOException e) {
141:                    String err = i18n.getMessage("JVelocity.generate.file", fs);
142:                    throw new WsGenException(err, e);
143:                }
144:
145:                try {
146:                    template.merge(context, fwriter);
147:                } catch (Exception e) {
148:                    String err = i18n.getMessage("JVelocity.generate.cannot",
149:                            fs);
150:                    throw new WsGenException(err, e);
151:                }
152:
153:                try {
154:                    fwriter.flush();
155:                    fwriter.close();
156:                } catch (IOException e) {
157:                    // do nothing, just a warn
158:                    String err = i18n
159:                            .getMessage("JVelocity.generate.close", fs);
160:                    logger.log(BasicLevel.WARN, err);
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.