001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.kernel.config;
017:
018: import java.io.File;
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collections;
022: import java.util.LinkedHashMap;
023: import java.util.LinkedHashSet;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Set;
027:
028: import org.apache.geronimo.gbean.GBeanData;
029: import org.apache.geronimo.gbean.GBeanInfo;
030: import org.apache.geronimo.kernel.Naming;
031: import org.apache.geronimo.kernel.repository.Artifact;
032: import org.apache.geronimo.kernel.repository.Environment;
033:
034: /**
035: * @version $Rev: 604588 $ $Date: 2007-12-16 01:41:36 -0800 (Sun, 16 Dec 2007) $
036: */
037: public class ConfigurationData implements Serializable {
038: private static final long serialVersionUID = 4324193220056650732L;
039:
040: /**
041: * The time at which this configuration was created.
042: */
043: private final long created = System.currentTimeMillis();
044:
045: /**
046: * Identifies the type of configuration (WAR, RAR et cetera)
047: */
048: private final ConfigurationModuleType moduleType;
049:
050: /**
051: * Defines the configuration id, parent configurations, and classpath
052: */
053: private final Environment environment;
054:
055: /**
056: * List of URIs in this configuration's classpath. These are for the classes directly included in the configuration
057: */
058: private final LinkedHashSet<String> classPath = new LinkedHashSet<String>();
059:
060: /**
061: * The gbeans contained in this configuration
062: */
063: private final GBeanState gbeanState;
064:
065: /**
066: * Child configurations of this configuration
067: */
068: private final Map<String, ConfigurationData> childConfigurations = new LinkedHashMap<String, ConfigurationData>();
069:
070: /**
071: * Configurations owned by this configuration. This is only used for cascade-uninstall.
072: */
073: private final Set<Artifact> ownedConfigurations = new LinkedHashSet<Artifact>();
074:
075: /**
076: * The base file of the configuation
077: */
078: private transient File configurationDir;
079:
080: /**
081: * The base file of an in-place configuration
082: */
083: private File inPlaceConfigurationDir;
084:
085: /**
086: * Should this configuraiton be autoStarted
087: */
088: private boolean autoStart = true;
089:
090: /**
091: * The naming system
092: */
093: private transient Naming naming;
094:
095: /**
096: * The configuration store from which this configuration was loaded, or null if it was not loaded from a configuration store.
097: */
098: private transient ConfigurationStore configurationStore;
099:
100: public ConfigurationData(Artifact configId, Naming naming,
101: GBeanState gbeanState) {
102: this (new Environment(configId), naming, gbeanState);
103: }
104:
105: public ConfigurationData(Environment environment, Naming naming,
106: GBeanState gbeanState) {
107: if (environment == null)
108: throw new NullPointerException("environment is null");
109: if (environment.getConfigId() == null)
110: throw new NullPointerException(
111: "environment.configId is null");
112: if (naming == null)
113: throw new NullPointerException("naming is null");
114:
115: this .environment = environment;
116: this .naming = naming;
117: this .gbeanState = gbeanState;
118:
119: this .moduleType = ConfigurationModuleType.CAR;
120: }
121:
122: public ConfigurationData(Artifact configId, Naming naming) {
123: this (new Environment(configId), naming);
124: }
125:
126: public ConfigurationData(Environment environment, Naming naming) {
127: this (null, null, null, null, environment, null, null, naming);
128: }
129:
130: public ConfigurationData(ConfigurationModuleType moduleType,
131: LinkedHashSet<String> classPath, List<GBeanData> gbeans,
132: Map<String, ConfigurationData> childConfigurations,
133: Environment environment, File configurationDir,
134: File inPlaceConfigurationDir, Naming naming) {
135: if (naming == null)
136: throw new NullPointerException("naming is null");
137: this .naming = naming;
138: if (moduleType != null) {
139: this .moduleType = moduleType;
140: } else {
141: this .moduleType = ConfigurationModuleType.CAR;
142: }
143: if (classPath != null) {
144: this .classPath.addAll(classPath);
145: }
146: gbeanState = ConfigurationUtil.newGBeanState(gbeans);
147: if (childConfigurations != null) {
148: this .childConfigurations.putAll(childConfigurations);
149: }
150:
151: if (environment == null)
152: throw new NullPointerException("environment is null");
153: if (environment.getConfigId() == null)
154: throw new NullPointerException(
155: "environment.configId is null");
156: this .environment = environment;
157: this .configurationDir = configurationDir;
158: this .inPlaceConfigurationDir = inPlaceConfigurationDir;
159: }
160:
161: public Artifact getId() {
162: return environment.getConfigId();
163: }
164:
165: /**
166: * Gets the time at which this configuration was created (or deployed).
167: *
168: * @return the time at which this configuration was created (or deployed)
169: */
170: public long getCreated() {
171: return created;
172: }
173:
174: public ConfigurationModuleType getModuleType() {
175: return moduleType;
176: }
177:
178: public List getClassPath() {
179: return Collections.unmodifiableList(new ArrayList(classPath));
180: }
181:
182: public List getGBeans(ClassLoader classLoader)
183: throws InvalidConfigException {
184: if (classLoader == null)
185: throw new NullPointerException("classLoader is null");
186: return gbeanState.getGBeans(classLoader);
187: }
188:
189: public void addGBean(GBeanData gbeanData) {
190: if (gbeanData == null)
191: throw new NullPointerException("gbeanData is null");
192: gbeanState.addGBean(gbeanData);
193: }
194:
195: public GBeanData addGBean(String name, GBeanInfo gbeanInfo) {
196: if (name == null)
197: throw new NullPointerException("name is null");
198: if (gbeanInfo == null)
199: throw new NullPointerException("gbeanInfo is null");
200: return gbeanState
201: .addGBean(name, gbeanInfo, naming, environment);
202: }
203:
204: public GBeanState getGbeanState() {
205: return gbeanState;
206: }
207:
208: /**
209: * Gets a map of module name to ConfigurationData for nested
210: * configurations (as in, a WAR within an EAR, not dependencies between
211: * totally separate configurations).
212: */
213: public Map<String, ConfigurationData> getChildConfigurations() {
214: return Collections.unmodifiableMap(childConfigurations);
215: }
216:
217: public void addChildConfiguration(String moduleName,
218: ConfigurationData configurationData) {
219: if (configurationData == null)
220: throw new NullPointerException("configurationData is null");
221: childConfigurations.put(moduleName, configurationData);
222: }
223:
224: /**
225: * Gets the configurations owned by this configuration. This is only used
226: * for cascade-uninstall.
227: *
228: * @return the configurations owned by this configuration
229: */
230: public Set<Artifact> getOwnedConfigurations() {
231: return Collections.unmodifiableSet(ownedConfigurations);
232: }
233:
234: public void addOwnedConfigurations(Artifact id) {
235: if (id == null)
236: throw new NullPointerException("id is null");
237: if (!id.isResolved())
238: throw new IllegalArgumentException("id is not resolved: "
239: + id);
240: ownedConfigurations.add(id);
241: }
242:
243: public Environment getEnvironment() {
244: return environment;
245: }
246:
247: public File getInPlaceConfigurationDir() {
248: return inPlaceConfigurationDir;
249: }
250:
251: public File getConfigurationDir() {
252: return configurationDir;
253: }
254:
255: public void setConfigurationDir(File configurationDir) {
256: if (configurationDir == null)
257: throw new NullPointerException("configurationDir is null");
258: this .configurationDir = configurationDir;
259: }
260:
261: public Naming getNaming() {
262: return naming;
263: }
264:
265: public void setNaming(Naming naming) {
266: this .naming = naming;
267: }
268:
269: public boolean isAutoStart() {
270: return autoStart;
271: }
272:
273: public void setAutoStart(boolean autoStart) {
274: this .autoStart = autoStart;
275: }
276:
277: public ConfigurationStore getConfigurationStore() {
278: return configurationStore;
279: }
280:
281: public void setConfigurationStore(
282: ConfigurationStore configurationStore) {
283: if (configurationStore == null)
284: throw new NullPointerException("configurationStore is null");
285: this.configurationStore = configurationStore;
286: }
287: }
|