Source Code Cross Referenced for BuilderConfiguration.java in  » Database-ORM » castor » org » exolab » castor » builder » 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 » Database ORM » castor » org.exolab.castor.builder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Redistribution and use of this software and associated documentation
003:         * ("Software"), with or without modification, are permitted provided
004:         * that the following conditions are met:
005:         *
006:         * 1. Redistributions of source code must retain copyright
007:         *    statements and notices.  Redistributions must also contain a
008:         *    copy of this document.
009:         *
010:         * 2. Redistributions in binary form must reproduce the
011:         *    above copyright notice, this list of conditions and the
012:         *    following disclaimer in the documentation and/or other
013:         *    materials provided with the distribution.
014:         *
015:         * 3. The name "Exolab" must not be used to endorse or promote
016:         *    products derived from this Software without prior written
017:         *    permission of Intalio, Inc.  For written permission,
018:         *    please contact info@exolab.org.
019:         *
020:         * 4. Products derived from this Software may not be called "Exolab"
021:         *    nor may "Exolab" appear in their names without prior written
022:         *    permission of Intalio, Inc. Exolab is a registered
023:         *    trademark of Intalio, Inc.
024:         *
025:         * 5. Due credit should be given to the Exolab Project
026:         *    (http://www.exolab.org/).
027:         *
028:         * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
029:         * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
030:         * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
031:         * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
032:         * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
033:         * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
034:         * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
035:         * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
036:         * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
037:         * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
039:         * OF THE POSSIBILITY OF SUCH DAMAGE.
040:         *
041:         * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved.
042:         *
043:         *
044:         * $Id: BuilderConfiguration.java 6908 2007-03-29 08:22:29Z wguttmn $
045:         */
046:        package org.exolab.castor.builder;
047:
048:        //--Castor imports
049:        import java.io.File;
050:        import java.io.FileInputStream;
051:        import java.io.InputStream;
052:        import java.util.Enumeration;
053:        import java.util.Hashtable;
054:        import java.util.Properties;
055:        import java.util.StringTokenizer;
056:
057:        import org.exolab.castor.util.Configuration;
058:        import org.exolab.castor.util.LocalConfiguration;
059:        import org.exolab.castor.xml.JavaNaming;
060:
061:        /**
062:         * The configuration for the SourceGenerator.
063:         *
064:         * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
065:         * @author <a href="mailto:blandin@intalio.com">Arnaud Blandin</a>
066:         * @version $Revision: 6908 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
067:         */
068:        public class BuilderConfiguration {
069:            /** String representation of directory self pointer. */
070:            private static final String SELF_DIRECTORY = "./";
071:
072:            /** Length of string representation of directory self pointer. */
073:            private static final int SELF_DIRECTORY_LENGTH = SELF_DIRECTORY
074:                    .length();
075:
076:            /** String representation of directory parent pointer. */
077:            private static final String PARENT_DIRECTORY = "../";
078:
079:            /** Length of string representation of directory parent pointer. */
080:            private static final int PARENT_DIRECTORY_LENGTH = PARENT_DIRECTORY
081:                    .length();
082:
083:            /**
084:             * Names of properties used in the configuration file.
085:             */
086:            public static class Property {
087:                /**
088:                 * Property specifying whether or not to generate source code for bound
089:                 * properties. Currently all properties will be treated as bound
090:                 * properties if this flag is set to true. A value of 'true' enables
091:                 * bound properties.
092:                 *
093:                 * <pre>
094:                 * org.exolab.castor.builder.boundproperties
095:                 * </pre>
096:                 */
097:                public static final String BOUND_PROPERTIES = "org.exolab.castor.builder.boundproperties";
098:
099:                /**
100:                 * Property specifying whether to implement EnumeratedTypeAccess
101:                 * interface for all generated enumerated type classes.
102:                 *
103:                 * <pre>
104:                 * org.exolab.castor.builder.enumTypeAccessInterface
105:                 * </pre>
106:                 */
107:                public static final String ENUM_TYPE_ACCESS_INTERFACE = "org.exolab.castor.builder.enumTypeAccessInterface";
108:
109:                /**
110:                 * Property specifying whether or not to generate source code for extra
111:                 * collection methods.
112:                 *
113:                 * <pre>
114:                 * org.exolab.castor.builder.extraCollectionMethods
115:                 * </pre>
116:                 */
117:                public static final String EXTRA_COLLECTION_METHODS = "org.exolab.castor.builder.extraCollectionMethods";
118:
119:                /**
120:                 * Property specifying the super class for all generated classes.
121:                 *
122:                 * <pre>
123:                 * org.exolab.castor.builder.superclass
124:                 * </pre>
125:                 */
126:                public static final String SUPER_CLASS = "org.exolab.castor.builder.superclass";
127:
128:                /**
129:                 * Property specifying how element's and type's are mapped into a Java
130:                 * class hierarchy by the Source Generator. The value must contain one
131:                 * of the following. 'element' outputs a Java class hierarchy based on
132:                 * element names used in the XML Schema. This is the default. 'type'
133:                 * outputs a Java class hierarchy based on the type information defined
134:                 * in the XML Schema.
135:                 *
136:                 * <pre>
137:                 * org.exolab.castor.builder.javaclassmapping
138:                 * </pre>
139:                 */
140:                public static final String JAVA_CLASS_MAPPING = "org.exolab.castor.builder.javaclassmapping";
141:
142:                /**
143:                 * Property listing mapping between XML namespaces and Java packages.
144:                 */
145:                public static final String NAMESPACE_PACKAGES_OLD = "org.exolab.castor.builder.nspackages";
146:
147:                /**
148:                 * Property listing mapping between XML namespaces and Java packages.
149:                 */
150:                public static final String NAMESPACE_PACKAGES = "org.exolab.castor.xml.nspackages";
151:
152:                /**
153:                 * Property specifying if we want to have the equals method generated
154:                 * for each generated class.
155:                 */
156:                public static final String EQUALS_METHOD = "org.exolab.castor.builder.equalsmethod";
157:
158:                /**
159:                 * Property specifying if we want to use Wrapper Objects instead of
160:                 * primitives (eg java.lang.Float instead of float).
161:                 */
162:                public static final String WRAPPER = "org.exolab.castor.builder.primitivetowrapper";
163:
164:                /**
165:                 * Property specifying if we want to have a 'public static final String'
166:                 * generated for each attribute and element name used within a class
167:                 * descriptor.
168:                 */
169:                public static final String CLASS_DESC_FIELD_NAMES = "org.exolab.castor.builder.classdescfieldnames";
170:
171:                /**
172:                 * Property specifying whether the Java sources generated should be 1.4
173:                 * or 5.0 compliant.
174:                 */
175:                public static final String JAVA_VERSION = "org.exolab.castor.builder.javaVersion";
176:
177:                /**
178:                 * The name of the configuration file.
179:                 *
180:                 * <pre>
181:                 * castor.properties
182:                 * </pre>
183:                 */
184:                public static final String CONFIG_FILENAME_PROPERTY = "castorbuilder.properties";
185:
186:                /**
187:                 * Maximum number of constant definitions within one file. This property
188:                 * is used to allow the user to configure the maximum number of
189:                 * constant definitions (within a Java class as generated as a result of
190:                 * an enumeration); default is 1000. Is this number if exceeded, no constants
191:                 * will be generated anymore.
192:                 *
193:                 * <pre>
194:                 * org.exolab.castor.builder.maxNumberOfConstants
195:                 * </pre>
196:                 */
197:                public static final String MAX_CONSTANTS_PROPERTY = "org.exolab.castor.builder.maxNumberOfConstants";
198:
199:                /**
200:                 * Resource to load from the JAR file to load our defaults.
201:                 */
202:                static final String RESOURCE_NAME = "/org/exolab/castor/builder/castorbuilder.properties";
203:
204:                /**
205:                 * Registered class name conflict resolution strategies.
206:                 *
207:                 * <pre>
208:                 * org.exolab.castor.builder.nameConflictStrategies
209:                 * </pre>
210:                 */
211:                public static final String NAME_CONFLICT_STRATEGIES = "org.exolab.castor.builder.nameConflictStrategies";
212:
213:                /**
214:                 * Property specifying whether automatic class name conflict resolution
215:                 * should be used or not; defaults to false.
216:                 *
217:                 * <pre>
218:                 * org.exolab.castor.builder.automaticConflictResolution
219:                 * </pre>
220:                 */
221:                public static final String AUTOMATIC_CONFLICT_RESOLUTION = "org.exolab.castor.builder.automaticConflictResolution";
222:
223:                /**
224:                 * Property specifying the 'string' used in type strategy to be inserted 
225:                 * between the actual element name and the type name (during automatic class name 
226:                 * conflict resolution); defaults to 'By'.
227:                 *
228:                 * <pre>
229:                 * org.exolab.castor.builder.automaticConflictResolutionTypeSuffix
230:                 * </pre>
231:                 */
232:                public static final String AUTOMATIC_CONFLICT_RESOLUTION_TYPE_SUFFIX = "org.exolab.castor.builder.automaticConflictResolutionTypeSuffix";
233:            } //--Property
234:
235:            /**
236:             * String value of false.
237:             */
238:            private static final String FALSE = "false";
239:
240:            /**
241:             * String value of true.
242:             */
243:            private static final String TRUE = "true";
244:
245:            /**
246:             * String value of element binding property.
247:             */
248:            private static final String ELEMENT_VALUE = "element";
249:
250:            /**
251:             * String value of type binding property.
252:             */
253:            private static final String TYPE_VALUE = "type";
254:
255:            /**
256:             * The default properties loaded from the configuration file.
257:             */
258:            private Properties _defaultProps = null;
259:
260:            /**
261:             * Our properties after all configuration has been loaded.
262:             */
263:            private Properties _localProps = null;
264:
265:            /**
266:             * Namespace URL to Java package mapping.
267:             */
268:            private Hashtable _nspackages = new Hashtable();
269:
270:            /**
271:             * schemaLocation to Java package mapping.
272:             */
273:            private Hashtable _locpackages = new Hashtable();
274:
275:            //------------------/
276:
277:            /**
278:             * Creates a default BuilderConfiguration.
279:             */
280:            public BuilderConfiguration() {
281:                super ();
282:                getDefault();
283:                _localProps = new Properties(_defaultProps);
284:            } //-- BuilderConfiguration
285:
286:            /**
287:             * Returns the default configuration file. Changes to the returned
288:             * properties set will affect all Castor functions relying on the default
289:             * configuration.
290:             *
291:             * @return The default configuration
292:             */
293:            public final synchronized Properties getDefault() {
294:                if (_defaultProps == null) {
295:                    load();
296:                }
297:                return _defaultProps;
298:            } //-- getDefault
299:
300:            /**
301:             * Returns a property from the default configuration file. Equivalent to
302:             * calling <tt>getProperty</tt> on the result of {@link #getDefault}.
303:             *
304:             * @param name
305:             *            The property name
306:             * @param defValue
307:             *            The property's default value
308:             * @return The property's value
309:             */
310:            public final String getProperty(final String name,
311:                    final String defValue) {
312:                return _localProps.getProperty(name, defValue);
313:            } //-- getProperty
314:
315:            /**
316:             * Returns true if bound properties are enabled.
317:             * <p>
318:             * Enabling bound properties is controlled via the
319:             * org.exolab.castor.builder.boundproperties item in the
320:             * castorbuilder.properties file. The value is either 'true' or 'false'.
321:             *
322:             * @return true if bound properties are enabled.
323:             */
324:            public final boolean boundPropertiesEnabled() {
325:                return TRUE.equalsIgnoreCase(_localProps
326:                        .getProperty(Property.BOUND_PROPERTIES));
327:            } //-- boundPropertiesEnabled
328:
329:            /**
330:             * Returns true if we generate an 'equals' method for each generated class.
331:             * <p>
332:             * Enabling this property is controlled via the
333:             * org.exolab.castor.builder.equalsmethod item in the
334:             * castorbuilder.properties file. The value is either 'true' or 'false'.
335:             *
336:             * @return true if bound properties are enabled.
337:             */
338:            public final boolean equalsMethod() {
339:                return TRUE.equalsIgnoreCase(_localProps
340:                        .getProperty(Property.EQUALS_METHOD));
341:            } //-- equalsMethod
342:
343:            /**
344:             * Sets the 'equalsmethod' property.
345:             *
346:             * @param equals The value we want to use.
347:             */
348:            public final void setEqualsMethod(final boolean equals) {
349:                String value = (equals) ? TRUE : FALSE;
350:                _localProps.setProperty(Property.EQUALS_METHOD, value);
351:            } //-- setEqualsMethod
352:
353:            /**
354:             * Returns true if we generate a 'public static final String' for the name
355:             * of each attribute and element described by the class descriptor
356:             * <p>
357:             * Enabling this property is controlled via the
358:             * org.exolab.castor.builder.classdescfieldnames item in the
359:             * castorbuilder.properties file. The value is either 'true' or 'false'.
360:             *
361:             * @return true if bound properties are enabled.
362:             */
363:            public final boolean classDescFieldNames() {
364:                return _localProps.getProperty(Property.CLASS_DESC_FIELD_NAMES,
365:                        "").equalsIgnoreCase(TRUE);
366:            } //-- classDescFieldNames
367:
368:            /**
369:             * Returns true if extra methods for collection fields should be generated.
370:             * Such methods include set/get methods for the actual collection in
371:             * addition to the array methods.
372:             * <p>
373:             * Enabling extra collection methods is controlled via the
374:             * org.exolab.castor.builder.extraCollectionMethods property in the
375:             * castorbuilder.properties file. The value is either 'true' or 'false'.
376:             *
377:             * @return true if extra collection methods are enabled.
378:             */
379:            public final boolean generateExtraCollectionMethods() {
380:                return _localProps.getProperty(
381:                        Property.EXTRA_COLLECTION_METHODS, "")
382:                        .equalsIgnoreCase(TRUE);
383:            } //-- generateExtraCollectionMethods
384:
385:            /**
386:             * Sets the 'classDescFieldNames' property.
387:             *
388:             * @param classDescFieldNames
389:             *            the value we want to ues
390:             */
391:            public final void setClassDescFieldNames(
392:                    final boolean classDescFieldNames) {
393:                String value = (classDescFieldNames) ? TRUE : FALSE;
394:                _localProps.setProperty(Property.CLASS_DESC_FIELD_NAMES, value);
395:            } //-- setClassDescFieldNames
396:
397:            /**
398:             * Returns true if primitive types have to be used as Objects (eg.
399:             * replacing <code>float</code> by <code>java.lang.Float</code>).
400:             * @return true if primitive types have to be used as Objects.
401:             */
402:            public final boolean usePrimitiveWrapper() {
403:                return _localProps.getProperty(Property.WRAPPER, "")
404:                        .equalsIgnoreCase(TRUE);
405:            } //-- usePrimitiveWrapper
406:
407:            /**
408:             * Sets the 'primitivetowrapper' property.
409:             *
410:             * @param wrapper the value we want to use.
411:             */
412:            public final void setPrimitiveWrapper(final boolean wrapper) {
413:                String value = (wrapper) ? TRUE : FALSE;
414:                _localProps.setProperty(Property.WRAPPER, value);
415:            } //-- setPrimitiveWrapper
416:
417:            /**
418:             * Returns true if we generate the implements EnumeratedTypeAccess interface
419:             * for enumerated type classes. The value is either 'true' or 'false'
420:             *
421:             * @return true if use enumerated type interface is enabled
422:             */
423:            public final boolean useEnumeratedTypeInterface() {
424:                return TRUE.equalsIgnoreCase(_localProps
425:                        .getProperty(Property.ENUM_TYPE_ACCESS_INTERFACE));
426:            } //-- useEnumeratedTypeInterface
427:
428:            /**
429:             * Returns true if we generate the implements EnumeratedTypeAccess interface
430:             * for enumerated type classes. The value is either 'true' or 'false'
431:             *
432:             * @return true if use enumerated type interface is enabled
433:             */
434:            public final boolean useJava50() {
435:                return "5.0".equalsIgnoreCase(_localProps.getProperty(
436:                        Property.JAVA_VERSION, "1.4"));
437:            } //-- useEnumeratedTypeInterface
438:
439:            /**
440:             * Returns the maximum number of static constant definitions that are
441:             * acceptable within one class file; default is 1000.
442:             *
443:             * @return the maximum number of static constant definitions acceptable within
444:             *    one class file
445:             */
446:            public final int getMaximumNumberOfConstants() {
447:                String property = _localProps.getProperty(
448:                        Property.MAX_CONSTANTS_PROPERTY, "1000");
449:                return Integer.valueOf(property).intValue();
450:            }
451:
452:            /**
453:             * Sets the 'enumTypeAccessInterface' property.
454:             *
455:             * @param flag the value we want to use
456:             */
457:            public final void setUseEnumeratedTypeInterface(final boolean flag) {
458:                String value = (flag) ? TRUE : FALSE;
459:                _localProps.setProperty(Property.ENUM_TYPE_ACCESS_INTERFACE,
460:                        value);
461:            } //-- setUseEnumeratedTypeInterface
462:
463:            /**
464:             * Tests the org.exolab.castor.builder.javaclassmapping property for the
465:             * 'element' value.
466:             *
467:             * @return True if the Source Generator is mapping schema elements to Java
468:             *         classes.
469:             */
470:            public boolean mappingSchemaElement2Java() {
471:                String value = _localProps.getProperty(
472:                        Property.JAVA_CLASS_MAPPING, "");
473:                return ELEMENT_VALUE.equalsIgnoreCase(value);
474:            } //-- mappingSchemaElement2Java
475:
476:            /**
477:             * Tests the org.exolab.castor.builder.javaclassmapping property for the 'type' value.
478:             *
479:             * @return True if the Source Generator is mapping schema types to Java classes.
480:             */
481:            public boolean mappingSchemaType2Java() {
482:                String value = _localProps.getProperty(
483:                        Property.JAVA_CLASS_MAPPING, "");
484:                return TYPE_VALUE.equalsIgnoreCase(value);
485:            } //-- mappingSchemaType2Java
486:
487:            /**
488:             * Overrides the current set of properties with the given properties. Once
489:             * the properties are set, only a copy will be uses, so any changes to the
490:             * given properties file after the fact will go unnoticed.
491:             *
492:             * @param properties
493:             *            the Properties file
494:             */
495:            public final void setDefaultProperties(final Properties properties) {
496:                Properties defaults = null;
497:                if (properties == null) {
498:                    defaults = _defaultProps;
499:                } else {
500:                    defaults = new Properties(_defaultProps);
501:                    Enumeration enumeration = properties.keys();
502:                    while (enumeration.hasMoreElements()) {
503:                        String name = (String) enumeration.nextElement();
504:                        defaults
505:                                .setProperty(name, properties.getProperty(name));
506:                    }
507:                }
508:                _localProps = new Properties(defaults);
509:                processNamespacePackageMappings(_localProps.getProperty(
510:                        Property.NAMESPACE_PACKAGES_OLD, ""));
511:                processNamespacePackageMappings(_localProps.getProperty(
512:                        Property.NAMESPACE_PACKAGES, ""));
513:            } //-- setDefaultProperties
514:
515:            /**
516:             * Sets the namespace to package mapping.
517:             *
518:             * @param ns the namespace URI to map
519:             * @param packageName the package name
520:             */
521:            public final void setNamespacePackageMapping(final String ns,
522:                    final String packageName) {
523:                _nspackages.put(ns, packageName);
524:            } //-- setNamespcaePackageMapping
525:
526:            /**
527:             * Sets the schemaLocation to package mapping.
528:             *
529:             * @param schemaLocation the schemaLocation to map
530:             * @param packageName the package name to map to
531:             */
532:            public final void setLocationPackageMapping(
533:                    final String schemaLocation, final String packageName) {
534:                _locpackages.put(schemaLocation, packageName);
535:            }
536:
537:            /**
538:             * Called by {@link #getDefault} to load the configuration the first time.
539:             * Will not complain about inability to load configuration file from one of
540:             * the default directories, but if it cannot find the JAR's configuration
541:             * file, will throw a run time exception.
542:             */
543:            protected final synchronized void load() {
544:                if (_defaultProps == null) {
545:                    //-- load defaults from JAR
546:                    _defaultProps = Configuration.loadProperties(
547:                            Property.RESOURCE_NAME,
548:                            Property.CONFIG_FILENAME_PROPERTY);
549:
550:                    //-- load local defaults
551:
552:                    boolean found = false;
553:
554:                    // Get overriding configuration from the classpath, ignore if not found.
555:                    // If found, merge any existing properties.
556:                    try {
557:                        InputStream is = SourceGenerator.class
558:                                .getResourceAsStream("/"
559:                                        + Property.CONFIG_FILENAME_PROPERTY);
560:                        if (is != null) {
561:                            found = true;
562:                            _defaultProps.load(is);
563:                            is.close();
564:                        }
565:                    } catch (Exception except) {
566:                        //-- do nothing
567:                    }
568:
569:                    //-- if not found, either it doesn't exist, or "." is not part of the
570:                    //-- class path, try looking at local working directory
571:                    if (!found) {
572:                        try {
573:                            File file = new File(
574:                                    Property.CONFIG_FILENAME_PROPERTY);
575:                            if (file.exists() && file.canRead()) {
576:                                InputStream is = new FileInputStream(file);
577:                                _defaultProps.load(is);
578:                                is.close();
579:                            }
580:                        } catch (Exception except) {
581:                            //-- do nothing
582:                        }
583:                    }
584:                }
585:
586:                Configuration rtconf = LocalConfiguration.getInstance();
587:
588:                // Parse XML namespace and package list from both castor.properties and
589:                // castorbuilder.properties
590:                processNamespacePackageMappings(rtconf.getProperty(
591:                        Property.NAMESPACE_PACKAGES_OLD, ""));
592:                processNamespacePackageMappings(rtconf.getProperty(
593:                        Property.NAMESPACE_PACKAGES, ""));
594:                processNamespacePackageMappings(_defaultProps.getProperty(
595:                        Property.NAMESPACE_PACKAGES_OLD, ""));
596:                processNamespacePackageMappings(_defaultProps.getProperty(
597:                        Property.NAMESPACE_PACKAGES, ""));
598:
599:                //-- backward compatibility with 0.9.3.9
600:                String prop = _defaultProps.getProperty(
601:                        JavaNaming.UPPER_CASE_AFTER_UNDERSCORE_PROPERTY, null);
602:                if (prop != null) {
603:                    JavaNaming.upperCaseAfterUnderscore = Boolean.valueOf(prop)
604:                            .booleanValue();
605:                }
606:            } //-- load
607:
608:            /**
609:             * Gets a Java package to an XML namespace URL.
610:             * @param nsURL the XML namespace URL to convert into a Java package name
611:             * @return a Java package name
612:             */
613:            public final String lookupPackageByNamespace(final String nsURL) {
614:                String namespaceURL = (nsURL == null) ? "" : nsURL;
615:
616:                // Lookup Java package via NS
617:                String javaPackage = (String) _nspackages.get(namespaceURL);
618:                if (javaPackage == null) {
619:                    return "";
620:                }
621:                return javaPackage;
622:            } //-- lookupPackageNamespace
623:
624:            /**
625:             * Converts a schema location into a Java package.
626:             *
627:             * @param schemaLocation
628:             *            the Schema location to use to look up the Java package
629:             * @return a Java package name
630:             */
631:            public final String lookupPackageByLocation(
632:                    final String schemaLocation) {
633:                if (schemaLocation == null) {
634:                    return "";
635:                }
636:
637:                // Lookup Java package via schemaLocation
638:                //--Full path
639:                String javaPackage = (String) _locpackages.get(schemaLocation);
640:                if (javaPackage == null) {
641:                    String cleanedSchemaLocation = schemaLocation;
642:                    //--maybe a relative schemaLocation was given
643:                    while (schemaLocation.startsWith(".")) {
644:                        if (schemaLocation.startsWith(SELF_DIRECTORY)) {
645:                            cleanedSchemaLocation = schemaLocation
646:                                    .substring(SELF_DIRECTORY_LENGTH);
647:                        } else if (schemaLocation.startsWith(PARENT_DIRECTORY)) {
648:                            cleanedSchemaLocation = schemaLocation
649:                                    .substring(PARENT_DIRECTORY_LENGTH);
650:                        }
651:                    }
652:                    Enumeration keys = _locpackages.keys();
653:                    boolean found = false;
654:                    while (keys.hasMoreElements() && !found) {
655:                        String key = (String) keys.nextElement();
656:                        if (cleanedSchemaLocation.endsWith(key)) {
657:                            javaPackage = (String) _locpackages.get(key);
658:                            found = true;
659:                        }
660:                    }
661:                    if (javaPackage == null) {
662:                        javaPackage = "";
663:                    }
664:                }
665:
666:                return javaPackage;
667:            } //-- lookupPackageLocation
668:
669:            /**
670:             * processes the given String which contains namespace-to-package mappings.
671:             *
672:             * @param mappings the namespace-to-package mappings
673:             */
674:            protected final void processNamespacePackageMappings(
675:                    final String mappings) {
676:                if (mappings == null) {
677:                    return;
678:                }
679:
680:                StringTokenizer tokens = new StringTokenizer(mappings, ",");
681:                while (tokens.hasMoreTokens()) {
682:                    String token = tokens.nextToken();
683:                    int sepIdx = token.indexOf('=');
684:                    if (sepIdx < 0) {
685:                        continue;
686:                    }
687:
688:                    String ns = token.substring(0, sepIdx).trim();
689:                    String javaPackage = token.substring(sepIdx + 1).trim();
690:                    _nspackages.put(ns, javaPackage);
691:                }
692:            } //-- processNamespacePackageMappings
693:
694:            /**
695:             * indicates whether automatic class name conflict resolution during 
696:             * XML code generation should take place or not.
697:             * @return True if automatic mode should be used.
698:             */
699:            public boolean isAutomaticConflictResolution() {
700:                String automaticConflictResolutionProperty = _localProps
701:                        .getProperty(Property.AUTOMATIC_CONFLICT_RESOLUTION,
702:                                "false");
703:                return "true"
704:                        .equalsIgnoreCase(automaticConflictResolutionProperty);
705:            }
706:
707:            /**
708:             * Returns the type 'suffix' used for the type strategy during automatic class name 
709:             * conflict resolution during XML code generation; default to "" unless a value is specified.
710:             * @return The type suffix to be inserted between element name and type name
711:             */
712:            public String getAutomaticConflictResolutionTypeSuffix() {
713:                return _localProps.getProperty(
714:                        Property.AUTOMATIC_CONFLICT_RESOLUTION_TYPE_SUFFIX, "");
715:            }
716:
717:        } //-- BuilderProperties
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.