001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.farm.deployment;
021:
022: import java.io.File;
023: import java.io.IOException;
024:
025: import org.apache.geronimo.gbean.GBeanInfo;
026: import org.apache.geronimo.gbean.GBeanInfoBuilder;
027: import org.apache.geronimo.kernel.config.ConfigurationData;
028: import org.apache.geronimo.kernel.config.ConfigurationStore;
029: import org.apache.geronimo.kernel.config.IOUtil;
030: import org.apache.geronimo.kernel.config.InvalidConfigException;
031: import org.apache.geronimo.kernel.config.NoSuchConfigException;
032: import org.apache.geronimo.kernel.repository.Artifact;
033:
034: /**
035: *
036: * @version $Rev:$ $Date:$
037: */
038: public class BasicClusterConfigurationStore implements
039: ClusterConfigurationStore {
040: private final ConfigurationStore actualConfigurationStore;
041:
042: public BasicClusterConfigurationStore(
043: ConfigurationStore actualConfigurationStore) {
044: if (null == actualConfigurationStore) {
045: throw new IllegalArgumentException(
046: "actualConfigurationStore is required");
047: }
048: this .actualConfigurationStore = actualConfigurationStore;
049: }
050:
051: public void install(ConfigurationData configurationData,
052: File packedConfigurationDir) throws IOException,
053: InvalidConfigException {
054: try {
055: File configurationDir = actualConfigurationStore
056: .createNewConfigurationDir(configurationData
057: .getId());
058:
059: DirectoryPackager directoryPackager = newDirectoryPackager();
060: directoryPackager.unpack(configurationDir,
061: packedConfigurationDir);
062: configurationData.setConfigurationDir(configurationDir);
063:
064: actualConfigurationStore.install(configurationData);
065: } finally {
066: deleteDir(packedConfigurationDir);
067: }
068: }
069:
070: public void uninstall(Artifact configId)
071: throws NoSuchConfigException, IOException {
072: actualConfigurationStore.uninstall(configId);
073: }
074:
075: protected void deleteDir(File packedConfigurationDir) {
076: IOUtil.recursiveDelete(packedConfigurationDir);
077: }
078:
079: protected DirectoryPackager newDirectoryPackager() {
080: return new ZipDirectoryPackager();
081: }
082:
083: public static final GBeanInfo GBEAN_INFO;
084:
085: public static final String GBEAN_J2EE_TYPE = "ClusterConfigurationStore";
086: public static final String GBEAN_REF_CONF_STORE = "ConfigurationStore";
087:
088: static {
089: GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(
090: BasicClusterConfigurationStore.class, GBEAN_J2EE_TYPE);
091:
092: builder.addReference(GBEAN_REF_CONF_STORE,
093: ConfigurationStore.class, "ConfigurationStore");
094:
095: builder.addInterface(ClusterConfigurationStore.class);
096:
097: builder.setConstructor(new String[] { GBEAN_REF_CONF_STORE });
098:
099: GBEAN_INFO = builder.getBeanInfo();
100: }
101:
102: public static GBeanInfo getGBeanInfo() {
103: return GBEAN_INFO;
104: }
105:
106: }
|