View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  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;
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.LinkedHashSet;
25  import java.util.List;
26  import java.util.Map;
27  import java.util.LinkedHashMap;
28  import java.util.Set;
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: 397307 $ $Date: 2006-04-26 14:32:30 -0700 (Wed, 26 Apr 2006) $
38   */
39  public class ConfigurationData implements Serializable {
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 classPath = new LinkedHashSet();
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 childConfigurations = new LinkedHashMap();
71  
72      /**
73       * Configurations owned by this configuration.  This is only used for cascade-uninstall.
74       */
75      private final Set ownedConfigurations = new LinkedHashSet();
76  
77      /**
78       * The base file of the configuation
79       */
80      private transient File configurationDir;
81      
82      /**
83       * The base file of an in-place configuration
84       */
85      private File 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("environment is null");
108         if (environment.getConfigId() == null) throw new NullPointerException("environment.configId is null");
109         if (naming == null) throw new NullPointerException("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 classPath, List gbeans, Map childConfigurations, Environment environment, File configurationDir, File inPlaceConfigurationDir, Naming naming) {
127         if (naming == null) throw new NullPointerException("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("environment is null");
143         if (environment.getConfigId() == null) throw new NullPointerException("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 getClassPath() {
166         return Collections.unmodifiableList(new ArrayList(classPath));
167     }
168 
169     public List getGBeans(ClassLoader classLoader) throws InvalidConfigException {
170         if (classLoader == null) throw new NullPointerException("classLoader is null");
171         return gbeanState.getGBeans(classLoader);
172     }
173 
174     public void addGBean(GBeanData gbeanData) {
175         if (gbeanData == null) throw new NullPointerException("gbeanData is null");
176         gbeanState.addGBean(gbeanData);
177     }
178 
179     public GBeanData addGBean(String name, GBeanInfo gbeanInfo) {
180         if (name == null) throw new NullPointerException("name is null");
181         if (gbeanInfo == null) throw new NullPointerException("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 getChildConfigurations() {
195         return Collections.unmodifiableMap(childConfigurations);
196     }
197 
198     public void addChildConfiguration(ConfigurationData configurationData) {
199         if (configurationData == null) throw new NullPointerException("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 getOwnedConfigurations() {
210         return Collections.unmodifiableSet(ownedConfigurations);
211     }
212 
213     public void addOwnedConfigurations(Artifact id) {
214         if (id == null) throw new NullPointerException("id is null");
215         if (!id.isResolved()) throw new IllegalArgumentException("id is not resolved: " + id);
216         ownedConfigurations.add(id);
217     }
218 
219     public Environment getEnvironment() {
220         return environment;
221     }
222 
223 	public File getInPlaceConfigurationDir() {
224 		return inPlaceConfigurationDir;
225 	}
226 
227     public File getConfigurationDir() {
228         return configurationDir;
229     }
230 
231     public void setConfigurationDir(File configurationDir) {
232         if (configurationDir == null) throw new NullPointerException("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("configurationStore is null");
258         this.configurationStore = configurationStore;
259     }
260 }