KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > pluggable > PluggableFeatureFactoryImpl


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.server.pluggable;
24
25 import com.sun.enterprise.pluggable.PluggableFeatureFactoryBaseImpl;
26
27 import java.lang.reflect.InvocationHandler JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29 import java.lang.reflect.Proxy JavaDoc;
30 import java.util.Properties JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33
34 import com.sun.logging.LogDomains;
35
36 /**
37  * An implementation of PluggableFeatureFactory interface using dynamic
38  * proxies. This class does not directly implement the interface
39  * PluggableFeatureFactory, but an proxy instance implementing the interface
40  * can be obtained by a call to the static method getInstance(). In reality,
41  * this class implements InvocationHnalder interface used to handle method
42  * invocations on a dynamic proxy object.
43  */

44 public class PluggableFeatureFactoryImpl extends PluggableFeatureFactoryBaseImpl {
45     /**
46      * Name of the property class containing feature name and feature
47      * implementation class names.
48      */

49     private static final String JavaDoc DEFAULT_FEATURES_PROPERTY_CLASS =
50             "com.sun.enterprise.server.pluggable.PEPluggableFeatureImpl";
51
52     private static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
53
54     /**
55      * Private constructor. The public instances of this object are not
56      * available. The instance of this class is however used as invocation
57      * handler for dynamic proxy returned by static method getInstance().
58      */

59     public PluggableFeatureFactoryImpl(Logger JavaDoc logger) {
60         super(logger);
61     }
62
63     public static PluggableFeatureFactory getFactory() {
64         String JavaDoc featurePropClass = System.getProperty(
65                 PluggableFeatureFactory.PLUGGABLE_FEATURES_PROPERTY_NAME,
66                 DEFAULT_FEATURES_PROPERTY_CLASS);
67         _logger.log(Level.FINER, "featurePropClass: " + featurePropClass);
68         PluggableFeatureFactoryImpl featureFactoryImpl =
69             new PluggableFeatureFactoryImpl(_logger);
70         PluggableFeatureFactory featureFactory = (PluggableFeatureFactory)
71             featureFactoryImpl.getInstance(featurePropClass);
72         if (featureFactory == null) {
73             _logger.log(Level.WARNING,
74                     "j2eerunner.pluggable_feature_noinit", featurePropClass);
75         }
76         return featureFactory;
77     }
78
79     protected String JavaDoc getDefaultFeatureFactoryPropertyName() {
80         return System.getProperty(
81             PluggableFeatureFactory.PLUGGABLE_FEATURES_PROPERTY_NAME);
82     }
83
84     protected Object JavaDoc createFeatureFactory(InvocationHandler JavaDoc handler) {
85         return Proxy.newProxyInstance(
86                 PluggableFeatureFactory.class.getClassLoader(),
87                 new Class JavaDoc[] { PluggableFeatureFactory.class },
88                 handler);
89     }
90 }
91
Popular Tags