KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > config > spi > ConfigFactory


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.config.spi;
24
25
26 /**
27  * This SPI mechanism allows getting web services Management configuration. Thi
28  * provider can be implemented using any configuration storage mechanism
29  * underneath.
30  */

31 public class ConfigFactory {
32
33     /**
34      * Make ConfigFactory private, only one sigleton object is available.
35      */

36     private ConfigFactory () {
37     }
38
39     /**
40      * Returns the ConfigFactory singleton.
41      *
42      * @return the ConfigFactory instance
43      */

44     public static ConfigFactory getConfigFactory() {
45         return new ConfigFactory();
46     }
47
48     /**
49      * Returns the ConfigProvider instance. If
50      * -Dconfig.provider.classname is defined, that class is loaded and
51      * returned as the repository provider. If there is an error finding or
52      * loading the class, the default provider class is returned.
53      *
54      * @return RepositoryProvider implementation
55      * @throws IllegalAccessException - if the class or its nullary constructor
56      * is not accessible.
57      * InstantiationException - if this Class represents an abstract
58      * class,an interface, an array class, a
59      * primitive type, or void; or if the class * has no nullary constructor; or if the
60      * instantiation fails for some other
61      * reason.
62      * ClassCastException - if the provider implementation specified
63      * by -D does not implement the com.sun.
64      * enterprise.admin.wsmgmt.repository.spi.
65      * RepositoryProvider interface.
66      * ClassNotFoundException - if the provider implementation specified * by -D does could not be found by the
67      * class loader.
68      */

69     public ConfigProvider getConfigProvider()
70       throws InstantiationException JavaDoc, IllegalAccessException JavaDoc, ClassCastException JavaDoc,
71         ClassNotFoundException JavaDoc {
72        String JavaDoc implName = System.getProperty(CONFIG_PROVIDER_NAME);
73        if ( implName == null ) {
74             Class JavaDoc repClass = Class.forName(CONFIG_DEFAULT_PROVIDER);
75             Object JavaDoc o = repClass.newInstance();
76             return (ConfigProvider)o;
77        } else {
78             Class JavaDoc repClass = Class.forName(implName);
79             Object JavaDoc o = repClass.newInstance();
80             return (ConfigProvider)o;
81        }
82     }
83
84     /** Environment property name to customize Repository Provider */
85     public static final String JavaDoc CONFIG_PROVIDER_NAME =
86         "config.provider.classname";
87
88     public static final String JavaDoc CONFIG_DEFAULT_PROVIDER =
89         "com.sun.enterprise.admin.wsmgmt.config.impl.AppServConfigProvider";
90 }
91
Popular Tags