KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > pluggable > EnvironmentFactory


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
24 /*
25  * EnvironmentFactory.java
26  *
27  * Created on January 9, 2004, 11:42 AM
28  */

29
30 package com.sun.enterprise.config.pluggable;
31
32 import com.sun.enterprise.config.ConfigRuntimeException;
33 import com.sun.enterprise.config.impl.ConfigEnvironmentImpl;
34 import com.sun.enterprise.config.impl.DefaultConfigBeanInterceptor;
35 import com.sun.enterprise.config.util.LocalStringsHelper;
36 import com.sun.enterprise.config.util.LoggerHelper;
37 /**
38  * provides a implementation of factory. Users can
39  * extend this class and implement required methods and set their
40  * class in environment variable ENVIRONMENT_FACTORY_CLASS. The
41  * statis create method in this class reads the variable and
42  * instantiates the class. Note that the implemented factory
43  * needs a no arg constructor
44  * @author sridatta
45  */

46 public class EnvironmentFactory {
47     
48    static final String JavaDoc ENVIRONMENT_FACTORY_CLASS =
49       "com.sun.enterprise.config.config_environment_factory_class";
50         
51     private static EnvironmentFactory _ENV = null;
52     
53     /** Creates a new instance of EnvironmentFactory */
54     public EnvironmentFactory() {
55     }
56     
57     public static synchronized EnvironmentFactory getEnvironmentFactory() {
58         if(_ENV == null) {
59            _ENV = createEnvironmentFactory();
60         }
61         return _ENV;
62     }
63         
64     private static EnvironmentFactory createEnvironmentFactory() {
65                                             
66         String JavaDoc factoryClassName = System.getProperty(ENVIRONMENT_FACTORY_CLASS);
67         
68         Class JavaDoc factoryClass;
69         try {
70             if(factoryClassName!= null && !"".equals(factoryClassName)) {
71                 factoryClass = Class.forName(factoryClassName);
72             } else {
73                 factoryClass = EnvironmentFactory.class;
74             }
75         }catch(Exception JavaDoc e) {
76             throw new ConfigRuntimeException(
77                     "error_loading_environment_factory_class",
78                     LocalStringsHelper.
79                         getString("error_loading_environment_factory_class"),
80                     e);
81         }
82         LoggerHelper.fine(
83             "com.sun.enterprise.config.pluggable.EnvironmentFactory.getEnvironmentFactory():" +
84                     "Factory Class is " + factoryClass);
85         
86         EnvironmentFactory result = null;
87         try {
88             result = (EnvironmentFactory) factoryClass.newInstance();
89         } catch(Exception JavaDoc e) {
90             throw new ConfigRuntimeException(
91                 "error_creating_environment_factory",
92                 LocalStringsHelper.
93                         getString("error_creating_environment_factory"),
94                 e);
95         }
96         
97         return result;
98     }
99     
100     /**
101      * creates a new configEnvironmentImpl with
102      * defaults
103      */

104     public ConfigEnvironment getConfigEnvironment() {
105         ConfigEnvironment ce = new ConfigEnvironmentImpl();
106         ce.setConfigBeanInterceptor(new DefaultConfigBeanInterceptor());
107         return ce;
108     }
109 }
110
Popular Tags