KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > repository > spi > RepositoryFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.wsmgmt.repository.spi;
24
25 import com.sun.enterprise.admin.wsmgmt.repository.impl.*;
26
27 /**
28  * This SPI mechanism allows RepositoryProvider instance. This repority provider
29  * can be queried for existence of web services.
30  * <br>
31  * Because the methods in the RepositoryFactory are all static, there is only
32  * one RepositoryFactory per Java VM at any one time. This ensures that there is
33  * a single source from which RepositoryProvider implementation is obtained.
34  * <br>
35  * Registering RepositoryProvider
36  * <br>
37  * The name of the provider is supplied on the command line. If no provider is
38  * specified, default implementation is assumed. Default provider class is
39  * com.sun.enterprise.admin.repository.impl.ApplicationServerRepositoryProvider.
40  * For example the following
41  * -Drepository.provider.classname=com.sun.web.WebServerRepositoryProvider
42  * would change the provider class to com.sun.web.WebServerRepositoryProvider.
43  */

44 public class RepositoryFactory {
45
46     /**
47      * Make RepositoryFactory private, only one sigleton object is available.
48      */

49     private RepositoryFactory () {
50     }
51
52     /**
53      * Returns the RepositoryFactory singleton.
54      *
55      * @return the RepositoryFactory instance
56      */

57     public static RepositoryFactory getRepositoryFactory() {
58         return new RepositoryFactory();
59     }
60
61     /**
62      * Returns the RepositoryProvider instance. If
63      * -Drepository.provider.classname is defined, that class is loaded and
64      * returned as the repository provider. If there is an error finding or
65      * loading the class, the default provider class is returned.
66      *
67      * @return RepositoryProvider implementation
68      * @throws IllegalAccessException - if the class or its nullary constructor
69      * is not accessible.
70      * InstantiationException - if this Class represents an abstract
71      * class,an interface, an array class, a
72      * primitive type, or void; or if the class * has no nullary constructor; or if the
73      * instantiation fails for some other
74      * reason.
75      * ClassCastException - if the provider implementation specified
76      * by -D does not implement the com.sun.
77      * enterprise.admin.wsmgmt.repository.spi.
78      * RepositoryProvider interface.
79      * ClassNotFoundException - if the provider implementation specified * by -D does could not be found by the
80      * class loader.
81      */

82     public static RepositoryProvider getRepositoryProvider()
83       throws InstantiationException JavaDoc, IllegalAccessException JavaDoc, ClassCastException JavaDoc,
84         ClassNotFoundException JavaDoc {
85        String JavaDoc implName = System.getProperty(REPOSITORY_PROVIDER_NAME);
86        if ( implName == null ) {
87             return new AppServRepositoryProvider();
88        } else {
89             Class JavaDoc repClass = Class.forName(implName);
90             Object JavaDoc o = repClass.newInstance();
91             return (RepositoryProvider)o;
92
93        }
94     }
95
96     /**
97      * Returns the WebServiceInfoProvider instance. If
98      * -Dwebserviceinfo.provider.classname is defined, that class is loaded and
99      * returned as the repository provider. If there is an error finding or
100      * loading the class, the default provider class is returned.
101      *
102      * @return WebServiceInfoProvider implementation
103      * @throws IllegalAccessException - if the class or its nullary constructor
104      * is not accessible.
105      * InstantiationException - if this Class represents an abstract
106      * class,an interface, an array class, a
107      * primitive type, or void; or if the class * has no nullary constructor; or if the
108      * instantiation fails for some other
109      * reason.
110      * ClassCastException - if the provider implementation specified
111      * by -D does not implement the com.sun.
112      * enterprise.admin.wsmgmt.repository.spi.
113      * RepositoryProvider interface.
114      * ClassNotFoundException - if the provider implementation specified * by -D does could not be found by the
115      * class loader.
116      */

117     public static WebServiceInfoProvider getWebServiceInfoProvider()
118      throws InstantiationException JavaDoc, IllegalAccessException JavaDoc, ClassCastException JavaDoc,
119      ClassNotFoundException JavaDoc {
120        String JavaDoc implName = System.getProperty(WEBSERVICE_INFO_PROVIDER_NAME);
121        if ( implName == null ) {
122             //return new AppServWebServiceInfoProvider();
123
Class JavaDoc repClass = Class.forName(AS_DEFAULT_PROVIDER);
124             return (WebServiceInfoProvider) repClass.newInstance();
125        } else {
126             Class JavaDoc repClass = Class.forName(implName);
127             return (WebServiceInfoProvider) repClass.newInstance();
128        }
129     }
130
131     /** Environment property name to customize Repository Provider */
132     public static final String JavaDoc REPOSITORY_PROVIDER_NAME =
133         "repository.provider.classname";
134
135     /** Environment property name to customize Web Service Info Provider */
136     public static final String JavaDoc WEBSERVICE_INFO_PROVIDER_NAME =
137         "webservice_info.provider.classname";
138     
139     private static final String JavaDoc AS_DEFAULT_PROVIDER =
140         "com.sun.enterprise.tools.common.AppServWebServiceInfoProvider";
141 }
142
Popular Tags