Source Code Cross Referenced for CodegenConfigLoader.java in  » Web-Services-AXIS2 » codegen-wsdl2java » org » apache » axis2 » wsdl » codegen » 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 » Web Services AXIS2 » codegen wsdl2java » org.apache.axis2.wsdl.codegen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.wsdl.codegen;
020:
021:        import org.apache.axis2.util.CommandLineOption;
022:        import org.apache.axis2.util.CommandLineOptionConstants;
023:        import org.apache.axis2.wsdl.i18n.CodegenMessages;
024:        import org.apache.axis2.wsdl.codegen.extension.XMLBeansExtension;
025:
026:        import java.io.File;
027:        import java.io.FileInputStream;
028:        import java.io.IOException;
029:        import java.util.HashMap;
030:        import java.util.Iterator;
031:        import java.util.Map;
032:        import java.util.Properties;
033:
034:        class CodegenConfigLoader implements  CommandLineOptionConstants {
035:
036:            public static void loadConfig(CodeGenConfiguration config,
037:                    Map optionMap) {
038:                String outputLocation = "."; //default output directory is the current working directory
039:                CommandLineOption commandLineOption = loadOption(
040:                        WSDL2JavaConstants.OUTPUT_LOCATION_OPTION,
041:                        WSDL2JavaConstants.OUTPUT_LOCATION_OPTION_LONG,
042:                        optionMap);
043:
044:                if (commandLineOption != null) {
045:                    outputLocation = commandLineOption.getOptionValue();
046:                }
047:                File outputLocationFile = new File(outputLocation);
048:                config.setOutputLocation(outputLocationFile);
049:
050:                //check and create the directories
051:                if (outputLocationFile.exists()) {
052:                    if (outputLocationFile.isFile()) {
053:                        throw new RuntimeException(CodegenMessages
054:                                .getMessage("options.notADirectoryException"));
055:                    }
056:                } else {
057:                    outputLocationFile.mkdirs();
058:                }
059:
060:                config.setServerSide(loadOption(
061:                        WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION,
062:                        WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION_LONG,
063:                        optionMap) != null);
064:                config
065:                        .setGenerateDeployementDescriptor(loadOption(
066:                                WSDL2JavaConstants.GENERATE_SERVICE_DESCRIPTION_OPTION,
067:                                WSDL2JavaConstants.GENERATE_SERVICE_DESCRIPTION_OPTION_LONG,
068:                                optionMap) != null);
069:                config.setWriteTestCase(loadOption(
070:                        WSDL2JavaConstants.GENERATE_TEST_CASE_OPTION,
071:                        WSDL2JavaConstants.GENERATE_TEST_CASE_OPTION_LONG,
072:                        optionMap) != null);
073:                config
074:                        .setSkipWriteWSDLs(loadOption(null,
075:                                WSDL2JavaConstants.NO_WSDLS_OPTION_LONG,
076:                                optionMap) != null);
077:                config.setSkipMessageReceiver(loadOption(null,
078:                        WSDL2JavaConstants.NO_MESSAGE_RECEIVER_OPTION_LONG,
079:                        optionMap) != null);
080:                config
081:                        .setSkipBuildXML(loadOption(null,
082:                                WSDL2JavaConstants.NO_BUILD_XML_OPTION_LONG,
083:                                optionMap) != null);
084:
085:                boolean asyncFlagPresent = (loadOption(
086:                        WSDL2JavaConstants.CODEGEN_ASYNC_ONLY_OPTION,
087:                        WSDL2JavaConstants.CODEGEN_ASYNC_ONLY_OPTION_LONG,
088:                        optionMap) != null);
089:                boolean syncFlagPresent = (loadOption(
090:                        WSDL2JavaConstants.CODEGEN_SYNC_ONLY_OPTION,
091:                        WSDL2JavaConstants.CODEGEN_SYNC_ONLY_OPTION_LONG,
092:                        optionMap) != null);
093:                if (asyncFlagPresent && !syncFlagPresent) {
094:                    config.setAsyncOn(true);
095:                    config.setSyncOn(false);
096:                }
097:                if (syncFlagPresent && !asyncFlagPresent) {
098:                    config.setAsyncOn(false);
099:                    config.setSyncOn(true);
100:                }
101:
102:                commandLineOption = loadOption(
103:                        WSDL2JavaConstants.PACKAGE_OPTION,
104:                        WSDL2JavaConstants.PACKAGE_OPTION_LONG, optionMap);
105:                if (commandLineOption != null) {
106:                    config.setPackageName(commandLineOption.getOptionValue());
107:                }
108:
109:                commandLineOption = loadOption(
110:                        WSDL2JavaConstants.STUB_LANGUAGE_OPTION,
111:                        WSDL2JavaConstants.STUB_LANGUAGE_OPTION_LONG, optionMap);
112:                if (commandLineOption != null) {
113:                    config
114:                            .setOutputLanguage(commandLineOption
115:                                    .getOptionValue());
116:                }
117:
118:                commandLineOption = loadOption(
119:                        WSDL2JavaConstants.DATA_BINDING_TYPE_OPTION,
120:                        WSDL2JavaConstants.DATA_BINDING_TYPE_OPTION_LONG,
121:                        optionMap);
122:                if (commandLineOption != null) {
123:                    config.setDatabindingType(commandLineOption
124:                            .getOptionValue());
125:                }
126:
127:                commandLineOption = loadOption(
128:                        WSDL2JavaConstants.UNPACK_CLASSES_OPTION,
129:                        WSDL2JavaConstants.UNPACK_CLASSES_OPTION_LONG,
130:                        optionMap);
131:                if (commandLineOption != null) {
132:                    config.setPackClasses(false);
133:                }
134:
135:                // source folder
136:                commandLineOption = loadOption(
137:                        WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION,
138:                        WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION_LONG,
139:                        optionMap);
140:                if (commandLineOption != null) {
141:                    config
142:                            .setSourceLocation(commandLineOption
143:                                    .getOptionValue());
144:                }
145:
146:                // resource folder
147:                commandLineOption = loadOption(
148:                        WSDL2JavaConstants.RESOURCE_FOLDER_OPTION,
149:                        WSDL2JavaConstants.RESOURCE_FOLDER_OPTION_LONG,
150:                        optionMap);
151:                if (commandLineOption != null) {
152:                    config.setResourceLocation(commandLineOption
153:                            .getOptionValue());
154:                }
155:
156:                commandLineOption = loadOption(
157:                        WSDL2JavaConstants.PORT_NAME_OPTION,
158:                        WSDL2JavaConstants.PORT_NAME_OPTION_LONG, optionMap);
159:                config
160:                        .setPortName(commandLineOption != null ? commandLineOption
161:                                .getOptionValue()
162:                                : null);
163:
164:                commandLineOption = loadOption(
165:                        WSDL2JavaConstants.SERVICE_NAME_OPTION,
166:                        WSDL2JavaConstants.SERVICE_NAME_OPTION_LONG, optionMap);
167:                config
168:                        .setServiceName(commandLineOption != null ? commandLineOption
169:                                .getOptionValue()
170:                                : null);
171:
172:                commandLineOption = loadOption(
173:                        WSDL2JavaConstants.REPOSITORY_PATH_OPTION,
174:                        WSDL2JavaConstants.REPOSITORY_PATH_OPTION_LONG,
175:                        optionMap);
176:                config
177:                        .setRepositoryPath(commandLineOption != null ? commandLineOption
178:                                .getOptionValue()
179:                                : null);
180:
181:                config.setServerSideInterface(loadOption(
182:                        WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION,
183:                        WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION_LONG,
184:                        optionMap) != null);
185:
186:                config
187:                        .setGenerateAll(loadOption(
188:                                WSDL2JavaConstants.GENERATE_ALL_OPTION,
189:                                WSDL2JavaConstants.GENERATE_ALL_OPTION_LONG,
190:                                optionMap) != null);
191:
192:                //populate the external mapping
193:                commandLineOption = loadOption(
194:                        WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION,
195:                        WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION_LONG,
196:                        optionMap);
197:                if (commandLineOption != null) {
198:                    try {
199:                        config.setTypeMappingFile(new File(commandLineOption
200:                                .getOptionValue()));
201:                    } catch (Exception e) {
202:                        throw new RuntimeException(CodegenMessages
203:                                .getMessage("options.nomappingFile"), e);
204:                    }
205:                }
206:
207:                // load the namespace to package list
208:                commandLineOption = loadOption(
209:                        WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION,
210:                        WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION_LONG,
211:                        optionMap);
212:                if (commandLineOption != null) {
213:                    //the syntax for the value of the namespaces and packages is
214:                    //to be a comma seperated list with uri=packagename,uri=packagename...
215:                    String value = commandLineOption.getOptionValue();
216:                    if (value != null) {
217:                        // Try treating the values as a name=value pair separated by comma's
218:                        if (value.indexOf('=') != -1) {
219:                            String valuepairs[] = value.split(",");
220:                            if (valuepairs.length > 0) {
221:                                //put them in the hash map
222:                                HashMap map = new HashMap(valuepairs.length);
223:                                for (int i = 0; i < valuepairs.length; i++) {
224:                                    String values[] = valuepairs[i].split("=");
225:                                    if (values.length == 2) {
226:                                        map.put(values[0], values[1]);
227:                                    }
228:                                }
229:                                config.setUri2PackageNameMap(map);
230:                            }
231:                        } else {
232:                            // Try loading the properties from the file specified
233:                            try {
234:                                Properties p = new Properties();
235:                                p.load(new FileInputStream(value));
236:                                config.setUri2PackageNameMap(p);
237:                            } catch (IOException e) {
238:                                throw new RuntimeException(CodegenMessages
239:                                        .getMessage("options.noFile", value), e);
240:                            }
241:                        }
242:                    }
243:                }
244:
245:                commandLineOption = loadOption(
246:                        WSDL2JavaConstants.UNWRAP_PARAMETERS,
247:                        WSDL2JavaConstants.UNWRAP_PARAMETERS_LONG, optionMap);
248:                if (commandLineOption != null) {
249:                    config.setParametersWrapped(false);
250:                }
251:
252:                commandLineOption = loadOption(
253:                        WSDL2JavaConstants.WSDL_VERSION_OPTION,
254:                        WSDL2JavaConstants.WSDL_VERSION_OPTION_LONG, optionMap);
255:                if (commandLineOption != null) {
256:                    String optionValue = commandLineOption.getOptionValue();
257:
258:                    if (WSDL2JavaConstants.WSDL_VERSION_2.equals(optionValue)
259:                            || WSDL2JavaConstants.WSDL_VERSION_2_OPTIONAL
260:                                    .equals(optionValue)) {
261:                        //users can say either 2.0 or 2 - we  just set it to the constant
262:                        config
263:                                .setWSDLVersion(WSDL2JavaConstants.WSDL_VERSION_2);
264:                    } //ignore the other cases - they'll be taken as 1.1
265:
266:                }
267:
268:                config
269:                        .setFlattenFiles(loadOption(
270:                                WSDL2JavaConstants.FLATTEN_FILES_OPTION,
271:                                WSDL2JavaConstants.FLATTEN_FILES_OPTION_LONG,
272:                                optionMap) != null);
273:
274:                commandLineOption = loadOption(
275:                        WSDL2JavaConstants.BACKWORD_COMPATIBILITY_OPTION,
276:                        WSDL2JavaConstants.BACKWORD_COMPATIBILITY_OPTION_LONG,
277:                        optionMap);
278:                if (commandLineOption != null) {
279:                    config.setBackwordCompatibilityMode(true);
280:                }
281:
282:                commandLineOption = loadOption(
283:                        WSDL2JavaConstants.SUPPRESS_PREFIXES_OPTION,
284:                        WSDL2JavaConstants.SUPPRESS_PREFIXES_OPTION_LONG,
285:                        optionMap);
286:                if (commandLineOption != null) {
287:                    config.setSuppressPrefixesMode(true);
288:                }
289:
290:                commandLineOption = loadOption(
291:                        XMLBeansExtension.XSDCONFIG_OPTION,
292:                        XMLBeansExtension.XSDCONFIG_OPTION_LONG, optionMap);
293:                if (commandLineOption != null) {
294:                    config.getProperties().put(
295:                            XMLBeansExtension.XSDCONFIG_OPTION,
296:                            commandLineOption.getOptionValue());
297:                }
298:
299:                // setting the overrid and all ports options
300:                config
301:                        .setAllPorts(loadOption(
302:                                WSDL2JavaConstants.All_PORTS_OPTION,
303:                                WSDL2JavaConstants.All_PORTS_OPTION_LONG,
304:                                optionMap) != null);
305:
306:                config
307:                        .setOverride(loadOption(
308:                                WSDL2JavaConstants.OVERRIDE_OPTION,
309:                                WSDL2JavaConstants.OVERRIDE_OPTION_LONG,
310:                                optionMap) != null);
311:
312:                // loop through the map and find parameters having the extra prefix.
313:                //put them in the property map
314:                Iterator keyIterator = optionMap.keySet().iterator();
315:                while (keyIterator.hasNext()) {
316:                    Object key = keyIterator.next();
317:                    CommandLineOption option = (CommandLineOption) optionMap
318:                            .get(key);
319:                    if (key.toString().startsWith(
320:                            WSDL2JavaConstants.EXTRA_OPTIONTYPE_PREFIX)) {
321:                        //add this to the property map
322:                        config
323:                                .getProperties()
324:                                .put(
325:                                        key
326:                                                .toString()
327:                                                .replaceFirst(
328:                                                        WSDL2JavaConstants.EXTRA_OPTIONTYPE_PREFIX,
329:                                                        ""),
330:                                        option.getOptionValue());
331:                    }
332:                }
333:
334:            }
335:
336:            private static CommandLineOption loadOption(String shortOption,
337:                    String longOption, Map options) {
338:                //short option gets precedence
339:                CommandLineOption option = null;
340:                if (longOption != null) {
341:                    option = (CommandLineOption) options.get(longOption);
342:                    if (option != null) {
343:                        return option;
344:                    }
345:                }
346:                if (shortOption != null) {
347:                    option = (CommandLineOption) options.get(shortOption);
348:                }
349:
350:                return option;
351:            }
352:
353:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.