KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > FactoryFinder


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis2.om;
17
18 import org.apache.axis2.soap.SOAPFactory;
19
20
21 /**
22  * Class FactoryFinder
23  */

24 class FactoryFinder {
25     private static final String JavaDoc DEFAULT_OM_FACTORY_CLASS_NAME =
26             "org.apache.axis2.om.impl.llom.factory.OMLinkedListImplFactory";
27     private static final String JavaDoc DEFAULT_SOAP11_FACTORY_CLASS_NAME =
28             "org.apache.axis2.soap.impl.llom.soap11.SOAP11Factory";
29     private static final String JavaDoc DEFAULT_SOAP12_FACTORY_CLASS_NAME =
30             "org.apache.axis2.soap.impl.llom.soap12.SOAP12Factory";
31
32     private static final String JavaDoc OM_FACTORY_NAME_PROPERTY = "om.factory";
33     private static final String JavaDoc SOAP11_FACTORY_NAME_PROPERTY = "soap11.factory";
34     private static final String JavaDoc SOAP12_FACTORY_NAME_PROPERTY = "soap12.factory";
35
36
37     /**
38      *
39      * @param loader
40      * @return
41      * @throws OMFactoryException
42      */

43
44
45     private static Object JavaDoc findFactory(ClassLoader JavaDoc loader, String JavaDoc factoryClass, String JavaDoc systemPropertyName)
46             throws OMFactoryException {
47
48         String JavaDoc factoryClassName = factoryClass;
49
50         //first look for a java system property
51
if (System.getProperty(systemPropertyName) != null) {
52             factoryClassName = systemPropertyName;
53         }
54         ;
55
56         Object JavaDoc factory = null;
57         try {
58             if (loader == null) {
59                 factory = Class.forName(factoryClassName).newInstance();
60             } else {
61                 factory = loader.loadClass(factoryClassName).newInstance();
62             }
63         } catch (Exception JavaDoc e) {
64             throw new OMFactoryException(e);
65         }
66         return factory;
67     }
68
69     /**
70      * The searching for the factory class happens in the following order
71      * 1. look for a system property called <b>soap11.factory</b>. this can be set by
72      * passing the -Dsoap11.factory="classname"
73      * 2. Pick the default factory class.
74      * it is the class hardcoded at the constant DEFAULT_SOAP11_FACTORY_CLASS_NAME
75      *
76      * @param loader
77      * @return
78      * @throws OMFactoryException
79      */

80     public static SOAPFactory findSOAP11Factory(ClassLoader JavaDoc loader)
81             throws OMFactoryException {
82         return (SOAPFactory) findFactory(loader, DEFAULT_SOAP11_FACTORY_CLASS_NAME, SOAP11_FACTORY_NAME_PROPERTY);
83     }
84
85     /**
86      * The searching for the factory class happens in the following order
87      * 1. look for a system property called <b>soap12.factory</b>. this can be set by
88      * passing the -Dsoap12.factory="classname"
89      * 2. Pick the default factory class.
90      * it is the class hardcoded at the constant DEFAULT_SOAP12_FACTORY_CLASS_NAME
91      *
92      * @param loader
93      * @return
94      * @throws OMFactoryException
95      */

96     public static SOAPFactory findSOAP12Factory(ClassLoader JavaDoc loader)
97             throws OMFactoryException {
98         return (SOAPFactory) findFactory(loader, DEFAULT_SOAP12_FACTORY_CLASS_NAME, SOAP12_FACTORY_NAME_PROPERTY);
99     }
100
101     /**
102      * The searching for the factory class happens in the following order
103      * 1. look for a system property called <b>om.factory</b>. this can be set by
104      * passing the -Dom.factory="classname"
105      * 2. Pick the default factory class.
106      * it is the class hardcoded at the constant DEFAULT_OM_FACTORY_CLASS_NAME
107      *
108      * @param loader
109      * @return
110      * @throws OMFactoryException
111      */

112     public static OMFactory findOMFactory(ClassLoader JavaDoc loader)
113             throws OMFactoryException {
114         return (OMFactory) findFactory(loader, DEFAULT_OM_FACTORY_CLASS_NAME, OM_FACTORY_NAME_PROPERTY);
115     }
116 }
117
Popular Tags