Source Code Cross Referenced for ConfigPropertyFileLoader.java in  » Web-Services-AXIS2 » codegen-wsdl2java » org » apache » axis2 » wsdl » util » 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.util 
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:
020:        package org.apache.axis2.wsdl.util;
021:
022:        import org.apache.axis2.wsdl.i18n.CodegenMessages;
023:
024:        import java.io.FileInputStream;
025:        import java.io.FileNotFoundException;
026:        import java.io.IOException;
027:        import java.io.InputStream;
028:        import java.net.URL;
029:        import java.util.Arrays;
030:        import java.util.Enumeration;
031:        import java.util.HashMap;
032:        import java.util.Iterator;
033:        import java.util.List;
034:        import java.util.Map;
035:        import java.util.Properties;
036:
037:        /** Loads the properties from the config properties. */
038:        public class ConfigPropertyFileLoader {
039:
040:            private static Map dbSupporterTemplateNameMap;
041:            private static String testObjectTemplateName;
042:            private static String srcFolderName;
043:            private static String resourceFolderName;
044:            private static String[] extensionClassNames;
045:            private static String[] postExtensionClassNames;
046:            private static String[] thirdPartySchemaNames;
047:            private static String[] languageTypes;
048:            private static String[] databindingFrameworkNames;
049:            private static String[] unwrapSuppoerteddatabindingFrameworkNames;
050:            private static String[] unwrapDirectdatabindingFrameworkNames;
051:
052:            private static Map languageEmitterMap;
053:            private static Map languageSpecificPropertiesMap;
054:            private static Map databindingFrameworkNameToExtensionMap;
055:
056:            private static String defaultLanguage;
057:            private static String defaultDBFrameworkName;
058:
059:            private static final String CODE_GEN_KEY_PREFIX = "codegen.extension";
060:            private static final String POST_CODE_GEN_KEY_PREFIX = "post.codegen.extension";
061:            private static final String THIRD_PARTY_SCHEMA_KEY_PREFIX = "codegen.thirdparty.schema";
062:            private static final String LANGUAGE_TYPE_KEY_PREFIX = "codegen.languages";
063:            private static final String DEFAULT_LANGUAGE_TYPE_KEY = "codegen.languages.default";
064:            private static final String EMITTER_CLASS_KEY = "codegen.emitters";
065:            private static final String DATA_BINDING_FRAMEWORK_NAME_KEY = "codegen.databinding.frameworks";
066:            private static final String DATA_BINDING_UNWRAP_SUPPORTED_FRAMEWORK_NAME_KEY = "codegen.databinding.unwrap.supported";
067:            private static final String DATA_BINDING_UNWRAP_DIRECT_FRAMEWORK_NAME_KEY = "codegen.databinding.unwrap.direct";
068:            private static final String DATA_BINDING_FRAMEWORK_DEFAULT_NAME_KEY = "codegen.databinding.frameworks.default";
069:            private static final String DATA_BINDING_FRAMEWORK_EXTENSION_NAME_KEY = "codegen.databinding.extensions";
070:            private static final String DATA_BINDING_TEMPLATE_NAME_KEY_PREFIX = "codegen.databinding.";
071:            private static final String DATA_BINDING_TEMPLATE_NAME_KEY_SUFFIX = "template";
072:            private static final String DATA_BINDING_TEST_OBJECT_TEMPLATE_NAME_KEY = "codegen.databinding.testobject.template";
073:            private static final String SOURCE_FOLDER_NAME_KEY = "codegen.general.src.name";
074:            private static final String RESOURCE_FOLDER_NAME_KEY = "codegen.general.resource.name";
075:
076:            public static final String DEFAULT_CODEGEN_CONFIG_PROPERTIES = "/org/apache/axis2/wsdl/codegen/codegen-config.properties";
077:
078:            /* Note - Should be a non regular expression character. If not it should be properly escaped */
079:            private static final String SEPARATOR_CHAR = ",";
080:
081:            /**
082:             * Loads a stream from the given
083:             *
084:             * @param propertiesReference
085:             * @throws FileNotFoundException
086:             */
087:            private static InputStream getStream(String propertiesReference)
088:                    throws FileNotFoundException {
089:                InputStream stream = ConfigPropertyFileLoader.class
090:                        .getResourceAsStream(propertiesReference);
091:                if (stream == null) {
092:                    URL url = ConfigPropertyFileLoader.class
093:                            .getResource(propertiesReference);
094:                    stream = new FileInputStream(url.toString());
095:                }
096:                return stream;
097:            }
098:
099:            static {
100:                loadAllProperties();
101:            }
102:
103:            public static void reload() {
104:                reset();
105:                loadAllProperties();
106:            }
107:
108:            private static void reset() {
109:                dbSupporterTemplateNameMap = new HashMap();
110:                testObjectTemplateName = null;
111:                extensionClassNames = null;
112:                thirdPartySchemaNames = null;
113:                languageTypes = null;
114:                databindingFrameworkNames = null;
115:                languageEmitterMap = null;
116:                languageSpecificPropertiesMap = null;
117:                databindingFrameworkNameToExtensionMap = null;
118:                defaultLanguage = null;
119:                defaultDBFrameworkName = null;
120:                srcFolderName = null;
121:                resourceFolderName = null;
122:
123:            }
124:
125:            private static void loadAllProperties() {
126:                try {
127:                    //look for the system property "org.apache.axis2.codegen.config" to for a property
128:                    //entry refering to the config properties
129:                    String property = System
130:                            .getProperty("org.apache.axis2.codegen.config");
131:                    InputStream stream;
132:
133:                    if (property != null) {
134:                        stream = getStream(property);
135:                    } else {
136:                        stream = getStream(DEFAULT_CODEGEN_CONFIG_PROPERTIES);
137:                    }
138:
139:                    if (stream == null) {
140:                        throw new RuntimeException(CodegenMessages
141:                                .getMessage("propfileload.generalException"));
142:                    }
143:
144:                    Properties props = new Properties();
145:                    props.load(stream);
146:
147:                    //create a new map for the lang specific properties
148:                    languageSpecificPropertiesMap = new HashMap();
149:
150:                    //create a new map for the databinding frameworks and their extensions
151:                    databindingFrameworkNameToExtensionMap = new HashMap();
152:
153:                    //load the extension class names
154:                    String tempString = props.getProperty(CODE_GEN_KEY_PREFIX);
155:                    if (tempString != null) {
156:                        extensionClassNames = tempString.split(SEPARATOR_CHAR);
157:
158:                    }
159:
160:                    //load the post extension class names
161:                    tempString = props.getProperty(POST_CODE_GEN_KEY_PREFIX);
162:                    if (tempString != null) {
163:                        postExtensionClassNames = tempString
164:                                .split(SEPARATOR_CHAR);
165:
166:                    }
167:                    //load the data binding framework names
168:                    tempString = props
169:                            .getProperty(DATA_BINDING_FRAMEWORK_NAME_KEY);
170:                    if (tempString != null) {
171:                        databindingFrameworkNames = tempString
172:                                .split(SEPARATOR_CHAR);
173:                    }
174:
175:                    //load the unwrap supported data binding framework names
176:                    tempString = props
177:                            .getProperty(DATA_BINDING_UNWRAP_SUPPORTED_FRAMEWORK_NAME_KEY);
178:                    if (tempString != null) {
179:                        unwrapSuppoerteddatabindingFrameworkNames = tempString
180:                                .split(SEPARATOR_CHAR);
181:                    }
182:
183:                    //load the unwrap supported data binding framework names
184:                    tempString = props
185:                            .getProperty(DATA_BINDING_UNWRAP_DIRECT_FRAMEWORK_NAME_KEY);
186:                    if (tempString != null) {
187:                        unwrapDirectdatabindingFrameworkNames = tempString
188:                                .split(SEPARATOR_CHAR);
189:                    }
190:
191:                    //load the source folder
192:                    tempString = props.getProperty(SOURCE_FOLDER_NAME_KEY);
193:                    if (tempString != null) {
194:                        srcFolderName = tempString;
195:                    }
196:
197:                    //load the resource folder name
198:                    tempString = props.getProperty(RESOURCE_FOLDER_NAME_KEY);
199:                    if (tempString != null) {
200:                        resourceFolderName = tempString;
201:                    }
202:
203:                    //populate the data binding framework name to extension name map
204:                    tempString = props
205:                            .getProperty(DATA_BINDING_FRAMEWORK_EXTENSION_NAME_KEY);
206:                    if (tempString != null) {
207:                        String[] frameworkExtensionNames = tempString
208:                                .split(SEPARATOR_CHAR);
209:
210:                        try {
211:                            for (int i = 0; i < frameworkExtensionNames.length; i++) {
212:                                databindingFrameworkNameToExtensionMap.put(
213:                                        databindingFrameworkNames[i],
214:                                        frameworkExtensionNames[i]);
215:                            }
216:                        } catch (ArrayIndexOutOfBoundsException e) {
217:                            throw new Exception(
218:                                    CodegenMessages
219:                                            .getMessage("propfileload.frameworkMismatch"));
220:                        }
221:
222:                    }
223:
224:                    //load the default framework name
225:                    tempString = props
226:                            .getProperty(DATA_BINDING_FRAMEWORK_DEFAULT_NAME_KEY);
227:
228:                    if (tempString == null
229:                            || !databindingFrameworkNameToExtensionMap
230:                                    .containsKey(tempString)) {
231:                        throw new Exception(CodegenMessages
232:                                .getMessage("propfileload.unknownFramework"));
233:                    }
234:                    defaultDBFrameworkName = tempString;
235:                    //load the third party schema names
236:                    tempString = props
237:                            .getProperty(THIRD_PARTY_SCHEMA_KEY_PREFIX);
238:                    if (tempString != null) {
239:                        thirdPartySchemaNames = tempString
240:                                .split(SEPARATOR_CHAR);
241:
242:                    }
243:
244:                    //populate the db supporter template names.
245:                    dbSupporterTemplateNameMap = new HashMap();
246:                    String key;
247:                    for (Iterator allProperties = props.keySet().iterator(); allProperties
248:                            .hasNext();) {
249:                        key = (String) allProperties.next();
250:                        if (key
251:                                .startsWith(DATA_BINDING_TEMPLATE_NAME_KEY_PREFIX)
252:                                && key
253:                                        .endsWith(DATA_BINDING_TEMPLATE_NAME_KEY_SUFFIX)) {
254:                            dbSupporterTemplateNameMap.put(key, props
255:                                    .getProperty(key));
256:                        }
257:
258:                    }
259:
260:                    testObjectTemplateName = props
261:                            .getProperty(DATA_BINDING_TEST_OBJECT_TEMPLATE_NAME_KEY);
262:
263:                    //load the language names
264:                    tempString = props.getProperty(LANGUAGE_TYPE_KEY_PREFIX);
265:                    if (tempString != null) {
266:                        languageTypes = tempString.split(SEPARATOR_CHAR);
267:
268:                        //load the language emitter map
269:                        tempString = props.getProperty(EMITTER_CLASS_KEY);
270:                        if (tempString == null) {
271:                            throw new Exception(CodegenMessages
272:                                    .getMessage("propfileload.emitterMissing"));
273:                        } else {
274:                            String[] tempClassNames = tempString
275:                                    .split(SEPARATOR_CHAR);
276:                            //populate the map
277:                            languageEmitterMap = new HashMap();
278:                            for (int i = 0; i < tempClassNames.length; i++) {
279:                                languageEmitterMap.put(languageTypes[i],
280:                                        tempClassNames[i]);
281:                            }
282:
283:                        }
284:                    }
285:
286:                    // load the default language
287:                    tempString = props.getProperty(DEFAULT_LANGUAGE_TYPE_KEY);
288:                    if (null == tempString
289:                            || !languageEmitterMap.containsKey(tempString)) {
290:                        throw new Exception(CodegenMessages
291:                                .getMessage("propfileload.unknownDefaultLang"));
292:                    }
293:                    defaultLanguage = tempString;
294:
295:                    // run through the language specific properties and populate the
296:                    // language specific property map
297:                    //
298:                    String languageType;
299:                    String tempkey;
300:                    HashMap langSpecificMap;
301:                    for (int i = 0; i < languageTypes.length; i++) {
302:                        languageType = languageTypes[i];
303:                        langSpecificMap = new HashMap();
304:                        Enumeration keyEnum = props.keys();
305:                        while (keyEnum.hasMoreElements()) {
306:                            tempkey = keyEnum.nextElement().toString();
307:                            if (tempkey.startsWith(languageType + ".")) {
308:                                langSpecificMap
309:                                        .put(tempkey, props.get(tempkey));
310:                            }
311:                        }
312:                        //now add this to the lang specific properties map
313:                        languageSpecificPropertiesMap.put(languageType,
314:                                langSpecificMap);
315:                    }
316:
317:                } catch (IOException e) {
318:                    throw new RuntimeException(e);
319:                } catch (Exception e) {
320:                    throw new RuntimeException(CodegenMessages
321:                            .getMessage("propfileload.generalException"), e);
322:                }
323:            }
324:
325:            /** @return the source folder name */
326:            public static String getResourceFolderName() {
327:                return resourceFolderName;
328:            }
329:
330:            /** @return the resource folder name */
331:            public static String getSrcFolderName() {
332:                return srcFolderName;
333:            }
334:
335:            /**
336:             * Gets the test object support template. This is used in the generated test class.
337:             *
338:             * @return Returns String.
339:             */
340:            public static String getTestObjectTemplateName() {
341:                return testObjectTemplateName;
342:            }
343:
344:            /**
345:             * Gets the databinder template names. This is the template that has the logic for creating the
346:             * databind supporters.
347:             *
348:             * @return Returns String.
349:             */
350:            public static Map getDbSupporterTemplatesMap() {
351:                return dbSupporterTemplateNameMap;
352:            }
353:
354:            /**
355:             * Gets the extension class names.
356:             *
357:             * @return Returns String[].
358:             */
359:            public static String[] getExtensionClassNames() {
360:                return extensionClassNames;
361:            }
362:
363:            /**
364:             * get the post extension class names
365:             *
366:             * @return Returns String[].
367:             */
368:            public static String[] getPostExtensionClassNames() {
369:                return postExtensionClassNames;
370:            }
371:
372:            /**
373:             * Gets the third party schema names list.
374:             *
375:             * @return Returns String[].
376:             */
377:            public static String[] getThirdPartySchemaNames() {
378:                return thirdPartySchemaNames;
379:            }
380:
381:            /**
382:             * Gets the language type names.
383:             *
384:             * @return Returns String[].
385:             */
386:            public static String[] getLanguageTypes() {
387:                return languageTypes;
388:            }
389:
390:            /**
391:             * Gets the emitter names map keys with the language name.
392:             *
393:             * @return Returns Map.
394:             */
395:            public static Map getLanguageEmitterMap() {
396:                return languageEmitterMap;
397:            }
398:
399:            /**
400:             * Get the list of unwrap supported data binding frameworks
401:             *
402:             * @return list
403:             */
404:            public static List getUnwrapSupportedFrameworkNames() {
405:                return Arrays.asList(unwrapSuppoerteddatabindingFrameworkNames);
406:            }
407:
408:            /**
409:             * Get the list of data binding frameworks that handle unwrapping directly.
410:             *
411:             * @return names
412:             */
413:            public static List getUnwrapDirectFrameworkNames() {
414:                return Arrays.asList(unwrapDirectdatabindingFrameworkNames);
415:            }
416:
417:            /**
418:             * Gets the default language name.
419:             *
420:             * @return Returns String.
421:             */
422:            public static String getDefaultLanguage() {
423:                return defaultLanguage;
424:            }
425:
426:            /**
427:             * Gets the language specific properties.
428:             *
429:             * @return Returns Map.
430:             */
431:            public static Map getLanguageSpecificPropertiesMap() {
432:                return languageSpecificPropertiesMap;
433:            }
434:
435:            /**
436:             * Gets the databinding framework names.
437:             *
438:             * @return Returns String[].
439:             */
440:            public static String[] getDatabindingFrameworkNames() {
441:                return databindingFrameworkNames;
442:            }
443:
444:            /**
445:             * Gets the extensions map for the databinding frameworks. The entries are keys by the framework
446:             * name.
447:             *
448:             * @return Returns Map.
449:             */
450:            public static Map getDatabindingFrameworkNameToExtensionMap() {
451:                return databindingFrameworkNameToExtensionMap;
452:            }
453:
454:            /**
455:             * Gets the default DB framwork name.
456:             *
457:             * @return Returns String.
458:             */
459:            public static String getDefaultDBFrameworkName() {
460:                return defaultDBFrameworkName;
461:            }
462:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.