KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
27
28 import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 import com.sun.appserv.management.base.AMXDebug;
32
33 import com.sun.enterprise.config.ConfigContext;
34 import com.sun.enterprise.config.ConfigBean;
35 import com.sun.enterprise.config.ConfigException;
36 import com.sun.enterprise.config.ConfigFactory;
37
38 import com.sun.enterprise.config.impl.ConfigContextImpl;
39
40
41 /**
42  */

43 public final class ConfigDelegateFactory
44 {
45     private ConfigContext mConfigContext;
46     private final File JavaDoc mDomainXML;
47     
48     private static Map JavaDoc<File JavaDoc,ConfigDelegateFactory> mFactories;
49     
50         private
51     ConfigDelegateFactory(final File JavaDoc domainXML )
52         throws ConfigException
53     {
54         mDomainXML = domainXML;
55         mConfigContext = createConfigContext( mDomainXML );
56     }
57     
58         private void
59     debug( final Object JavaDoc o )
60     {
61         AMXDebug.getInstance().getOutput( "ConfigDelegateFactory" ).println( o );
62     }
63     
64         public static synchronized ConfigDelegateFactory
65     getInstance( final File JavaDoc domainXML )
66         throws ConfigException
67     {
68         if ( mFactories == null )
69         {
70             mFactories = new HashMap JavaDoc<File JavaDoc,ConfigDelegateFactory>();
71         }
72
73         ConfigDelegateFactory instance = mFactories.get( domainXML );
74         if ( instance == null )
75         {
76             instance = new ConfigDelegateFactory( domainXML );
77             mFactories.put( domainXML, instance );
78         }
79         
80         return instance;
81     }
82     
83         synchronized ConfigDelegate
84     createConfigDelegate( final ConfigBean configBean )
85         throws ConfigException
86     {
87         if ( getConfigContext() != configBean.getConfigContext() )
88         {
89             throw new IllegalArgumentException JavaDoc( "ConfigBean " +
90                 configBean.getXPath() + " has mismatched ConfigContext" );
91         }
92
93         return new ConfigDelegate( getConfigContext(), configBean );
94     }
95                
96         private ConfigContext
97     createConfigContext( final File JavaDoc domainXML )
98         throws ConfigException
99     {
100         setPreEnvironment();
101         
102         final ConfigContext ctx =
103             ConfigFactory.createConfigContext( domainXML.toString(),
104                 true, true, true );
105         
106         setPostEnvironment( ctx );
107         
108         return ctx;
109     }
110     
111         public ConfigContext
112     getConfigContext()
113     {
114         return mConfigContext;
115     }
116
117
118         private void
119     setPreEnvironment()
120     {
121         System.setProperty(
122               "com.sun.enterprise.config.config_environment_factory_class",
123               "com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory"
124          );
125     }
126
127         private void
128     setPostEnvironment( final ConfigContext ctx)
129     {
130         try
131         {
132             ((ConfigContextImpl)ctx).setXPathInAllBeans();
133         }
134         catch(ConfigException e)
135         {
136             throw new RuntimeException JavaDoc( e );
137         }
138     }
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
Popular Tags