Source Code Cross Referenced for AxisWsClientGenerator.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:         * Copyright (C) 1999-2004 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:         * --------------------------------------------------------------------------
022:         * $Id: AxisWsClientGenerator.java 6661 2005-04-28 08:43:27Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas_ws.wsgen.generator.axis;
025:
026:        import java.io.File;
027:
028:        import org.w3c.dom.Document;
029:        import org.w3c.dom.Element;
030:
031:        import org.apache.velocity.VelocityContext;
032:
033:        import org.objectweb.jonas_lib.I18n;
034:        import org.objectweb.jonas_lib.genbase.GenBaseException;
035:        import org.objectweb.jonas_lib.genbase.archive.Archive;
036:        import org.objectweb.jonas_lib.genbase.archive.EjbJar;
037:        import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
038:        import org.objectweb.jonas_lib.genbase.archive.WebApp;
039:        import org.objectweb.jonas_lib.genbase.generator.Config;
040:        import org.objectweb.jonas_lib.genbase.utils.XMLUtils;
041:        import org.objectweb.jonas_lib.loader.AbsModuleClassLoader;
042:
043:        import org.objectweb.jonas_ws.deployment.api.MappingFile;
044:        import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
045:        import org.objectweb.jonas_ws.wsgen.WsGenException;
046:        import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier;
047:        import org.objectweb.jonas_ws.wsgen.generator.WsClientGenerator;
048:        import org.objectweb.jonas_ws.wsgen.generator.axis.wsdl2java.JOnASWSDL2Java;
049:
050:        import org.objectweb.util.monolog.api.BasicLevel;
051:
052:        /**
053:         * Generate WebServices client files dedicated to axis. <ul><li>
054:         * client-config.wsdd : if needed</li><li>java sources : from WSDL</li>
055:         * </ul>
056:         *
057:         * @author Guillaume sauthier
058:         */
059:        public class AxisWsClientGenerator extends WsClientGenerator {
060:
061:            /** unique JVelocity instance */
062:            private static JVelocity jvelocity = null;
063:
064:            /**
065:             * jonas-init-param name for client configuration file declaration
066:             */
067:            private static final String CLIENT_CONFIG = "axis.clientConfigFile";
068:
069:            /**
070:             * WSDD Extension suffix
071:             */
072:            private static final String WSDD_SUFFIX = ".wsdd";
073:
074:            /**
075:             * WSDD Extension prefix
076:             */
077:            private static final String WSDD_PREFIX = "deploy-client-";
078:
079:            /** count generated files to assure names unicity */
080:            private static int count = 0;
081:
082:            /** generated config file */
083:            private File generated = null;
084:
085:            /**
086:             * WEB-INF/ prefix
087:             */
088:            private static final String WEB_PREFIX = "WEB-INF/";
089:
090:            /**
091:             * I18n
092:             */
093:            private static I18n i18n = I18n
094:                    .getInstance(AxisWsClientGenerator.class);
095:
096:            /**
097:             * Creates a new AxisWsClientGenerator
098:             * @param config Generator Configuration
099:             * @param srd WebService Endpoint description
100:             * @param ddm Web DD Modifier
101:             * @param archive client archive containing WSDL
102:             * @throws GenBaseException When instanciation fails
103:             * @throws WsGenException When instanciation fails
104:             */
105:            public AxisWsClientGenerator(Config config, ServiceRefDesc srd,
106:                    WsClientDDModifier ddm, Archive archive)
107:                    throws GenBaseException, WsGenException {
108:                super (config, srd, ddm, archive);
109:
110:                // init velocity
111:                if (jvelocity == null) {
112:                    jvelocity = new JVelocity("deploy_client.vm");
113:                }
114:            }
115:
116:            /**
117:             * generate axis specific files
118:             * @throws WsGenException if WSDL cannot be found in archive
119:             */
120:            public void generate() throws WsGenException {
121:
122:                // the source generation is possible only when a
123:                // WSDL Definition is provided
124:                if ((getRef().getWsdlFileName() != null)
125:                        && !getRef().getServiceInterface().getName().equals(
126:                                "javax.xml.rpc.Service")) {
127:
128:                    try {
129:                        // classpath creation
130:                        J2EEArchive j2eeArchive = (J2EEArchive) getArchive();
131:                        AbsModuleClassLoader cl = (AbsModuleClassLoader) j2eeArchive
132:                                .getModuleClassloader();
133:                        getConfig().setClasspath(
134:                                getConfig().getClasspath() + cl.getClasspath());
135:
136:                        JOnASWSDL2Java jWsdl2Java = new JOnASWSDL2Java();
137:                        jWsdl2Java.run(this );
138:                        getLogger()
139:                                .log(BasicLevel.INFO,
140:                                        "Web Services Classes successfully generated by Axis.");
141:                    } catch (Exception e) {
142:                        String err = getI18n().getMessage(
143:                                "AxisWsClientGenerator.generate.WSDL2Java");
144:                        e.printStackTrace(System.err);
145:                        throw new WsGenException(err, e);
146:                    }
147:                }
148:
149:                // Client-config.wsdd ??
150:                // only if handlers are specified in ServiceRef
151:                // but if noConfig set to true, assume that
152:                // user configure himself the client. (expert)
153:                // Could we create configuration ?
154:                if (hasClientConfigFile(getRef())) {
155:                    // create deploy.wsdd
156:                    // use velocity template
157:                    // build a unique file name
158:                    String filename = WSDD_PREFIX + (count++) + WSDD_SUFFIX;
159:
160:                    VelocityContext vctx = VContextFactory.getContext(getRef());
161:
162:                    if (getLogger().isLoggable(BasicLevel.DEBUG)) {
163:                        getLogger().log(BasicLevel.DEBUG,
164:                                "Creating '" + filename + "'");
165:                    }
166:                    generated = new File(getSources(), filename);
167:
168:                    jvelocity.generate(generated, vctx);
169:
170:                }
171:                // End !noConfig
172:            }
173:
174:            /**
175:             * Returns true if given service-ref need a client configuration files
176:             * @param ref Service Ref
177:             * @return true if given service-ref need a client configuration files
178:             */
179:            private boolean hasClientConfigFile(ServiceRefDesc ref) {
180:                // no configuration asked
181:                if (getConfig().isNoConfig()) {
182:                    return false;
183:                }
184:
185:                MappingFile mf = ref.getMappingFile();
186:
187:                if (mf != null) {
188:                    // mapping file defined
189:                    if (mf.getXmlTypeMappings().hasNext()) {
190:                        // we have 1 mapping at least
191:                        return true;
192:                    } else {
193:                        // no mapping
194:                        // return true if ref has Handlers
195:                        return (ref.getHandlerRefs().size() != 0);
196:                    }
197:                } else {
198:                    // no mapping file
199:                    // return true if ref has Handlers
200:                    return (ref.getHandlerRefs().size() != 0);
201:                }
202:            }
203:
204:            /**
205:             * Add generated files in given archive
206:             * @param archive archive where generated fils will be added.
207:             * @throws WsGenException when files cannot be added
208:             */
209:            public void addFiles(Archive archive) throws WsGenException {
210:                if (archive instanceof  WebApp) {
211:                    archive.addDirectoryIn("WEB-INF/classes/", getClasses());
212:
213:                    if (generated != null) {
214:                        archive.addFileIn("WEB-INF/", generated);
215:
216:                        // ensure the optionnal descriptor exists
217:                        if (!getModifier().hasJonasServiceRef()) {
218:                            if (!getArchive().getContainedFiles().contains(
219:                                    "WEB-INF/jonas-web.xml")) {
220:                                // jonas-web.xml doesn't exists
221:                                createEmptyJonasWeb((J2EEArchive) archive);
222:                            }
223:                            Element jsr = getModifier().createJonasServiceRef(
224:                                    getRef().getServiceRefName());
225:                            // update
226:                            getModifier().setElement(jsr);
227:
228:                        }
229:
230:                        // add init param
231:                        getModifier().addJonasInitParam(CLIENT_CONFIG,
232:                                WEB_PREFIX + generated.getName());
233:                    }
234:                } else if (archive instanceof  EjbJar) {
235:                    archive.addDirectory(getClasses());
236:
237:                    if (generated != null) {
238:                        archive.addFileIn("META-INF/", generated);
239:
240:                        // ensure the optionnal descriptor exists
241:                        if (!getModifier().hasJonasServiceRef()) {
242:                            Element jsr = getModifier().createJonasServiceRef(
243:                                    getRef().getServiceRefName());
244:                            // update
245:                            getModifier().setElement(jsr);
246:                        }
247:
248:                        // add init param
249:                        getModifier().addJonasInitParam(CLIENT_CONFIG,
250:                                "META-INF/" + generated.getName());
251:                    }
252:                } else {
253:                    archive.addDirectory(getClasses());
254:
255:                    if (generated != null) {
256:                        archive.addFileIn("META-INF/", generated);
257:
258:                        // ensure the optionnal descriptor exists
259:                        if (!getModifier().hasJonasServiceRef()) {
260:                            if (!getArchive().getContainedFiles().contains(
261:                                    "META-INF/jonas-client.xml")) {
262:                                // jonas-client.xml doesn't exists
263:                                createEmptyJonasClient((J2EEArchive) archive);
264:                            }
265:                            Element jsr = getModifier().createJonasServiceRef(
266:                                    getRef().getServiceRefName());
267:                            // update
268:                            getModifier().setElement(jsr);
269:
270:                        }
271:
272:                        // add init param
273:                        getModifier().addJonasInitParam(CLIENT_CONFIG,
274:                                "META-INF/" + generated.getName());
275:                    }
276:                }
277:            }
278:
279:            /**
280:             * Add an empty jonas-web.xml in given J2EEArchive.
281:             * @param archive archive to be updated
282:             */
283:            private void createEmptyJonasWeb(J2EEArchive archive) {
284:                Document doc = XMLUtils.newJonasWeb();
285:                archive.getDescriptors().put("WEB-INF/jonas-web.xml", doc);
286:                getModifier().setDocument(doc);
287:            }
288:
289:            /**
290:             * Add an empty jonas-client.xml in given J2EEArchive.
291:             * @param archive archive to be updated
292:             */
293:            private void createEmptyJonasClient(J2EEArchive archive) {
294:                Document doc = XMLUtils.newJonasClient();
295:                archive.getDescriptors().put("META-INF/jonas-client.xml", doc);
296:                getModifier().setDocument(doc);
297:            }
298:
299:            /**
300:             * @return Returns the i18n.
301:             */
302:            public static I18n getI18n() {
303:                return i18n;
304:            }
305:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.