KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > offline > ConfigBeanHelperFactory


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 package com.sun.enterprise.management.offline;
25
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28
29
30 import com.sun.appserv.management.base.AMXDebug;
31
32
33 import com.sun.enterprise.config.ConfigContext;
34 import com.sun.enterprise.config.ConfigBean;
35 import com.sun.enterprise.config.ConfigException;
36
37 import com.sun.enterprise.config.impl.ConfigContextImpl;
38
39
40 /**
41     Factory for creating ConfigBeanHelpers.
42     Although they can be instantiated directly, failure to use
43     the factory means that certain special cases won't be dealt with.
44  */

45 final class ConfigBeanHelperFactory
46 {
47     private final ConfigContext mConfigContext;
48     private final Map JavaDoc<String JavaDoc,ConfigBeanHelper> mHelperCache;
49
50     private static ConfigBeanHelperFactory INSTANCE = null;
51      
52     private static Map JavaDoc<ConfigContext,ConfigBeanHelperFactory> mFactories;
53     
54         private
55     ConfigBeanHelperFactory( final ConfigContext configContext)
56     {
57         mConfigContext = configContext;
58         mHelperCache = new HashMap JavaDoc<String JavaDoc,ConfigBeanHelper>();
59     }
60
61         private void
62     debug( final Object JavaDoc o )
63     {
64         AMXDebug.getInstance().getOutput( "ConfigBeanHelperFactory" ).println( o );
65     }
66     
67        protected void
68     sdebug( Object JavaDoc o )
69     {
70         debug( o );
71         System.out.println( "" + o );
72     }
73     
74         public static synchronized ConfigBeanHelperFactory
75     getInstance( final ConfigContext configContext )
76     {
77         if ( mFactories == null )
78         {
79             mFactories = new HashMap JavaDoc<ConfigContext,ConfigBeanHelperFactory>();
80         }
81
82         ConfigBeanHelperFactory instance = mFactories.get( configContext );
83         if ( instance == null )
84         {
85             instance = new ConfigBeanHelperFactory( configContext );
86             mFactories.put( configContext, instance );
87         }
88
89         return instance;
90     }
91     
92         private ConfigBeanHelper
93     createHelper( final String JavaDoc xPath )
94         throws ConfigException
95     {
96         ConfigBeanHelper helper = null;
97         final String JavaDoc type = ConfigBeanHelper._getType( xPath );
98         
99         final ConfigBean configBean = mConfigContext.exactLookup( xPath );
100         if ( configBean == null )
101         {
102             throw new IllegalArgumentException JavaDoc(
103                 "Null configBean returned for type: " + type );
104         }
105         
106         if ( "auth-realm".equals( type ) )
107         {
108             helper = new AuthRealmConfigBeanHelper( mConfigContext, configBean );
109         }
110         else if ( "security-map".equals( type ) )
111         {
112             helper = new SecurityMapConfigBeanHelper( mConfigContext, configBean );
113         }
114         else if ( "java-config".equals( type ) )
115         {
116             helper = new JavaConfigConfigBeanHelper( mConfigContext, configBean );
117         }
118         else
119         {
120             helper = new StdConfigBeanHelper( mConfigContext, configBean );
121         }
122         
123         debug( "CREATED: " + xPath );
124         
125         return helper;
126     }
127     
128         public ConfigBeanHelper
129     getHelper( final String JavaDoc xPath )
130         throws ConfigException
131     {
132         if ( xPath == null )
133         {
134             throw new IllegalArgumentException JavaDoc( "null xPath" );
135         }
136         
137         ConfigBeanHelper helper = mHelperCache.get( xPath );
138         
139         if ( helper == null )
140         {
141             helper = createHelper( xPath );
142             
143             mHelperCache.put( xPath, helper );
144         }
145         
146         return helper;
147     }
148
149         public ConfigBeanHelper
150     getHelper( final ConfigBean configBean )
151     {
152         try
153         {
154             return getHelper( configBean.getXPath() );
155         }
156         catch( Exception JavaDoc e )
157         {
158             throw new RuntimeException JavaDoc( e );
159         }
160     }
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Popular Tags