KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > kernel > config > ConfigurationData


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.kernel.config;
19
20 import java.io.File JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.LinkedHashSet JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.LinkedHashMap JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import org.apache.geronimo.gbean.GBeanData;
31 import org.apache.geronimo.gbean.GBeanInfo;
32 import org.apache.geronimo.kernel.Naming;
33 import org.apache.geronimo.kernel.repository.Artifact;
34 import org.apache.geronimo.kernel.repository.Environment;
35
36 /**
37  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
38  */

39 public class ConfigurationData implements Serializable JavaDoc {
40     private static final long serialVersionUID = 4324193220056650732L;
41
42     /**
43      * The time at which this configuration was created.
44      */

45     private final long created = System.currentTimeMillis();
46
47     /**
48      * Identifies the type of configuration (WAR, RAR et cetera)
49      */

50     private final ConfigurationModuleType moduleType;
51
52     /**
53      * Defines the configuration id, parent configurations, and classpath
54      */

55     private final Environment environment;
56
57     /**
58      * List of URIs in this configuration's classpath. These are for the classes directly included in the configuration
59      */

60     private final LinkedHashSet JavaDoc classPath = new LinkedHashSet JavaDoc();
61
62     /**
63      * The gbeans contained in this configuration
64      */

65     private final GBeanState gbeanState;
66
67     /**
68      * Child configurations of this configuration
69      */

70     private final Map JavaDoc childConfigurations = new LinkedHashMap JavaDoc();
71
72     /**
73      * Configurations owned by this configuration. This is only used for cascade-uninstall.
74      */

75     private final Set JavaDoc ownedConfigurations = new LinkedHashSet JavaDoc();
76
77     /**
78      * The base file of the configuation
79      */

80     private transient File JavaDoc configurationDir;
81     
82     /**
83      * The base file of an in-place configuration
84      */

85     private File JavaDoc inPlaceConfigurationDir;
86
87     /**
88      * Should this configuraiton be autoStarted
89      */

90     private boolean autoStart = true;
91
92     /**
93      * The naming system
94      */

95     private transient Naming naming;
96
97     /**
98      * The configuration store from which this configuration was loaded, or null if it was not loaded from a configuration store.
99      */

100     private transient ConfigurationStore configurationStore;
101
102     public ConfigurationData(Artifact configId, Naming naming, GBeanState gbeanState) {
103         this(new Environment(configId), naming, gbeanState);
104     }
105
106     public ConfigurationData(Environment environment, Naming naming, GBeanState gbeanState) {
107         if (environment == null) throw new NullPointerException JavaDoc("environment is null");
108         if (environment.getConfigId() == null) throw new NullPointerException JavaDoc("environment.configId is null");
109         if (naming == null) throw new NullPointerException JavaDoc("naming is null");
110
111         this.environment = environment;
112         this.naming = naming;
113         this.gbeanState = gbeanState;
114
115         this.moduleType = ConfigurationModuleType.CAR;
116     }
117
118     public ConfigurationData(Artifact configId, Naming naming) {
119         this(new Environment(configId), naming);
120     }
121
122     public ConfigurationData(Environment environment, Naming naming) {
123         this(null, null, null, null, environment, null, null, naming);
124     }
125
126     public ConfigurationData(ConfigurationModuleType moduleType, LinkedHashSet JavaDoc classPath, List JavaDoc gbeans, Map JavaDoc childConfigurations, Environment environment, File JavaDoc configurationDir, File JavaDoc inPlaceConfigurationDir, Naming naming) {
127         if (naming == null) throw new NullPointerException JavaDoc("naming is null");
128         this.naming = naming;
129         if (moduleType != null) {
130             this.moduleType = moduleType;
131         } else {
132             this.moduleType = ConfigurationModuleType.CAR;
133         }
134         if (classPath != null) {
135             this.classPath.addAll(classPath);
136         }
137         gbeanState = ConfigurationUtil.newGBeanState(gbeans);
138         if (childConfigurations != null) {
139             this.childConfigurations.putAll(childConfigurations);
140         }
141
142         if (environment == null) throw new NullPointerException JavaDoc("environment is null");
143         if (environment.getConfigId() == null) throw new NullPointerException JavaDoc("environment.configId is null");
144         this.environment = environment;
145         this.configurationDir = configurationDir;
146         this.inPlaceConfigurationDir = inPlaceConfigurationDir;
147     }
148
149     public Artifact getId() {
150         return environment.getConfigId();
151     }
152
153     /**
154      * Gets the time at which this configuration was created (or deployed).
155      * @return the time at which this configuration was created (or deployed)
156      */

157     public long getCreated() {
158         return created;
159     }
160
161     public ConfigurationModuleType getModuleType() {
162         return moduleType;
163     }
164
165     public List JavaDoc getClassPath() {
166         return Collections.unmodifiableList(new ArrayList JavaDoc(classPath));
167     }
168
169     public List JavaDoc getGBeans(ClassLoader JavaDoc classLoader) throws InvalidConfigException {
170         if (classLoader == null) throw new NullPointerException JavaDoc("classLoader is null");
171         return gbeanState.getGBeans(classLoader);
172     }
173
174     public void addGBean(GBeanData gbeanData) {
175         if (gbeanData == null) throw new NullPointerException JavaDoc("gbeanData is null");
176         gbeanState.addGBean(gbeanData);
177     }
178
179     public GBeanData addGBean(String JavaDoc name, GBeanInfo gbeanInfo) {
180         if (name == null) throw new NullPointerException JavaDoc("name is null");
181         if (gbeanInfo == null) throw new NullPointerException JavaDoc("gbeanInfo is null");
182         return gbeanState.addGBean(name, gbeanInfo, naming, environment);
183     }
184
185     public GBeanState getGbeanState() {
186         return gbeanState;
187     }
188
189     /**
190      * Gets a map of Artifact (config ID) to ConfigurationData for nested
191      * configurations (as in, a WAR within an EAR, not dependencies between
192      * totally separate configurations).
193      */

194     public Map JavaDoc getChildConfigurations() {
195         return Collections.unmodifiableMap(childConfigurations);
196     }
197
198     public void addChildConfiguration(ConfigurationData configurationData) {
199         if (configurationData == null) throw new NullPointerException JavaDoc("configurationData is null");
200         childConfigurations.put(configurationData.getId(), configurationData);
201     }
202
203     /**
204      * Gets the configurations owned by this configuration. This is only used
205      * for cascade-uninstall.
206      *
207      * @return the configurations owned by this configuration
208      */

209     public Set JavaDoc getOwnedConfigurations() {
210         return Collections.unmodifiableSet(ownedConfigurations);
211     }
212
213     public void addOwnedConfigurations(Artifact id) {
214         if (id == null) throw new NullPointerException JavaDoc("id is null");
215         if (!id.isResolved()) throw new IllegalArgumentException JavaDoc("id is not resolved: " + id);
216         ownedConfigurations.add(id);
217     }
218
219     public Environment getEnvironment() {
220         return environment;
221     }
222
223     public File JavaDoc getInPlaceConfigurationDir() {
224         return inPlaceConfigurationDir;
225     }
226
227     public File JavaDoc getConfigurationDir() {
228         return configurationDir;
229     }
230
231     public void setConfigurationDir(File JavaDoc configurationDir) {
232         if (configurationDir == null) throw new NullPointerException JavaDoc("configurationDir is null");
233         this.configurationDir = configurationDir;
234     }
235
236     public Naming getNaming() {
237         return naming;
238     }
239
240     public void setNaming(Naming naming) {
241         this.naming = naming;
242     }
243
244     public boolean isAutoStart() {
245         return autoStart;
246     }
247
248     public void setAutoStart(boolean autoStart) {
249         this.autoStart = autoStart;
250     }
251
252     public ConfigurationStore getConfigurationStore() {
253         return configurationStore;
254     }
255
256     public void setConfigurationStore(ConfigurationStore configurationStore) {
257         if (configurationStore == null) throw new NullPointerException JavaDoc("configurationStore is null");
258         this.configurationStore = configurationStore;
259     }
260 }
261
Popular Tags