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 */ 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.LinkedHashMap; 025 import java.util.LinkedHashSet; 026 import java.util.List; 027 import java.util.Map; 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: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 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<String> classPath = new LinkedHashSet<String>(); 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<String, ConfigurationData> childConfigurations = new LinkedHashMap<String, ConfigurationData>(); 071 072 /** 073 * Configurations owned by this configuration. This is only used for cascade-uninstall. 074 */ 075 private final Set<Artifact> ownedConfigurations = new LinkedHashSet<Artifact>(); 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<String> classPath, List<GBeanData> gbeans, Map<String, ConfigurationData> 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 * 156 * @return the time at which this configuration was created (or deployed) 157 */ 158 public long getCreated() { 159 return created; 160 } 161 162 public ConfigurationModuleType getModuleType() { 163 return moduleType; 164 } 165 166 public List getClassPath() { 167 return Collections.unmodifiableList(new ArrayList(classPath)); 168 } 169 170 public List getGBeans(ClassLoader classLoader) throws InvalidConfigException { 171 if (classLoader == null) throw new NullPointerException("classLoader is null"); 172 return gbeanState.getGBeans(classLoader); 173 } 174 175 public void addGBean(GBeanData gbeanData) { 176 if (gbeanData == null) throw new NullPointerException("gbeanData is null"); 177 gbeanState.addGBean(gbeanData); 178 } 179 180 public GBeanData addGBean(String name, GBeanInfo gbeanInfo) { 181 if (name == null) throw new NullPointerException("name is null"); 182 if (gbeanInfo == null) throw new NullPointerException("gbeanInfo is null"); 183 return gbeanState.addGBean(name, gbeanInfo, naming, environment); 184 } 185 186 public GBeanState getGbeanState() { 187 return gbeanState; 188 } 189 190 /** 191 * Gets a map of module name to ConfigurationData for nested 192 * configurations (as in, a WAR within an EAR, not dependencies between 193 * totally separate configurations). 194 */ 195 public Map<String, ConfigurationData> getChildConfigurations() { 196 return Collections.unmodifiableMap(childConfigurations); 197 } 198 199 public void addChildConfiguration(String moduleName, ConfigurationData configurationData) { 200 if (configurationData == null) throw new NullPointerException("configurationData is null"); 201 childConfigurations.put(moduleName, configurationData); 202 } 203 204 /** 205 * Gets the configurations owned by this configuration. This is only used 206 * for cascade-uninstall. 207 * 208 * @return the configurations owned by this configuration 209 */ 210 public Set<Artifact> getOwnedConfigurations() { 211 return Collections.unmodifiableSet(ownedConfigurations); 212 } 213 214 public void addOwnedConfigurations(Artifact id) { 215 if (id == null) throw new NullPointerException("id is null"); 216 if (!id.isResolved()) throw new IllegalArgumentException("id is not resolved: " + id); 217 ownedConfigurations.add(id); 218 } 219 220 public Environment getEnvironment() { 221 return environment; 222 } 223 224 public File getInPlaceConfigurationDir() { 225 return inPlaceConfigurationDir; 226 } 227 228 public File getConfigurationDir() { 229 return configurationDir; 230 } 231 232 public void setConfigurationDir(File configurationDir) { 233 if (configurationDir == null) throw new NullPointerException("configurationDir is null"); 234 this.configurationDir = configurationDir; 235 } 236 237 public Naming getNaming() { 238 return naming; 239 } 240 241 public void setNaming(Naming naming) { 242 this.naming = naming; 243 } 244 245 public boolean isAutoStart() { 246 return autoStart; 247 } 248 249 public void setAutoStart(boolean autoStart) { 250 this.autoStart = autoStart; 251 } 252 253 public ConfigurationStore getConfigurationStore() { 254 return configurationStore; 255 } 256 257 public void setConfigurationStore(ConfigurationStore configurationStore) { 258 if (configurationStore == null) throw new NullPointerException("configurationStore is null"); 259 this.configurationStore = configurationStore; 260 } 261 }