01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.schema.util;
20:
21: import org.apache.axis2.schema.SchemaCompiler;
22: import org.apache.axis2.schema.SchemaConstants;
23: import org.apache.axis2.schema.typemap.TypeMap;
24: import org.apache.axis2.schema.writer.BeanWriter;
25:
26: import java.util.Properties;
27:
28: /**
29: * Loads the properties for the schema compiler.
30: */
31: public class SchemaPropertyLoader {
32: private static String beanTemplate = null;
33: private static BeanWriter beanWriterInstance = null;
34: private static TypeMap typeMapperInstance = null;
35: private static Properties propertyMap;
36:
37: private static final String ADB_PROPERTY_FILE_KEY = "org.apache.adb.properties";
38:
39: static {
40: try {
41: //load the properties
42: Properties props = new Properties();
43: String schemaPropFilename = System
44: .getProperty(ADB_PROPERTY_FILE_KEY);
45: if (schemaPropFilename == null) {
46: // there was no system property .load the default
47: props
48: .load(SchemaCompiler.class
49: .getResourceAsStream(SchemaConstants.SchemaPropertyNames.SCHEMA_COMPILER_PROPERTIES));
50: } else {
51: props.load(SchemaCompiler.class
52: .getResourceAsStream(schemaPropFilename));
53: }
54:
55: String beanWriterClassName = props
56: .getProperty(SchemaConstants.SchemaPropertyNames.BEAN_WRITER_KEY);
57: if (beanWriterClassName != null) {
58: beanWriterInstance = (BeanWriter) Class.forName(
59: beanWriterClassName).newInstance();
60: }
61:
62: String typeMapperClassName = props
63: .getProperty(SchemaConstants.SchemaPropertyNames.BEAN_WRITER_TYPEMAP_KEY);
64: if (typeMapperClassName != null) {
65: typeMapperInstance = (TypeMap) Class.forName(
66: typeMapperClassName).newInstance();
67: }
68:
69: beanTemplate = props
70: .getProperty(SchemaConstants.SchemaPropertyNames.BEAN_WRITER_TEMPLATE_KEY);
71:
72: //set the props as the property map
73: propertyMap = props;
74: } catch (Exception e) {
75: throw new RuntimeException(e);
76: }
77:
78: }
79:
80: /**
81: * Exposes the whole property set
82: * @return Returns Properties.
83: */
84: public static Properties getPropertyMap() {
85: return propertyMap;
86: }
87:
88: public static String getBeanTemplate() {
89: return beanTemplate;
90: }
91:
92: public static BeanWriter getBeanWriterInstance() {
93: return beanWriterInstance;
94: }
95:
96: public static TypeMap getTypeMapperInstance() {
97: return typeMapperInstance;
98: }
99: }
|