001 /** 002 * 003 * Copyright 2003-2004 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 */ 017 018 package org.apache.geronimo.kernel.config; 019 020 import java.io.File; 021 import java.io.Serializable; 022 import java.util.ArrayList; 023 import java.util.Collections; 024 import java.util.LinkedHashSet; 025 import java.util.List; 026 import java.util.Map; 027 import java.util.LinkedHashMap; 028 import java.util.Set; 029 030 import org.apache.geronimo.gbean.GBeanData; 031 import org.apache.geronimo.gbean.GBeanInfo; 032 import org.apache.geronimo.kernel.Naming; 033 import org.apache.geronimo.kernel.repository.Artifact; 034 import org.apache.geronimo.kernel.repository.Environment; 035 036 /** 037 * @version $Rev: 397307 $ $Date: 2006-04-26 14:32:30 -0700 (Wed, 26 Apr 2006) $ 038 */ 039 public class ConfigurationData implements Serializable { 040 private static final long serialVersionUID = 4324193220056650732L; 041 042 /** 043 * The time at which this configuration was created. 044 */ 045 private final long created = System.currentTimeMillis(); 046 047 /** 048 * Identifies the type of configuration (WAR, RAR et cetera) 049 */ 050 private final ConfigurationModuleType moduleType; 051 052 /** 053 * Defines the configuration id, parent configurations, and classpath 054 */ 055 private final Environment environment; 056 057 /** 058 * List of URIs in this configuration's classpath. These are for the classes directly included in the configuration 059 */ 060 private final LinkedHashSet classPath = new LinkedHashSet(); 061 062 /** 063 * The gbeans contained in this configuration 064 */ 065 private final GBeanState gbeanState; 066 067 /** 068 * Child configurations of this configuration 069 */ 070 private final Map childConfigurations = new LinkedHashMap(); 071 072 /** 073 * Configurations owned by this configuration. This is only used for cascade-uninstall. 074 */ 075 private final Set ownedConfigurations = new LinkedHashSet(); 076 077 /** 078 * The base file of the configuation 079 */ 080 private transient File configurationDir; 081 082 /** 083 * The base file of an in-place configuration 084 */ 085 private File inPlaceConfigurationDir; 086 087 /** 088 * Should this configuraiton be autoStarted 089 */ 090 private boolean autoStart = true; 091 092 /** 093 * The naming system 094 */ 095 private transient Naming naming; 096 097 /** 098 * The configuration store from which this configuration was loaded, or null if it was not loaded from a configuration store. 099 */ 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 }