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: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 037 */ 038 public class BasicClusterConfigurationStore implements ClusterConfigurationStore { 039 private final ConfigurationStore actualConfigurationStore; 040 041 public BasicClusterConfigurationStore(ConfigurationStore actualConfigurationStore) { 042 if (null == actualConfigurationStore) { 043 throw new IllegalArgumentException("actualConfigurationStore is required"); 044 } 045 this.actualConfigurationStore = actualConfigurationStore; 046 } 047 048 public void install(ConfigurationData configurationData, File packedConfigurationDir) 049 throws IOException, InvalidConfigException { 050 try { 051 File configurationDir = actualConfigurationStore.createNewConfigurationDir(configurationData.getId()); 052 053 DirectoryPackager directoryPackager = newDirectoryPackager(); 054 directoryPackager.unpack(configurationDir, packedConfigurationDir); 055 configurationData.setConfigurationDir(configurationDir); 056 057 actualConfigurationStore.install(configurationData); 058 } finally { 059 deleteDir(packedConfigurationDir); 060 } 061 } 062 063 public void uninstall(Artifact configId) throws NoSuchConfigException, IOException { 064 actualConfigurationStore.uninstall(configId); 065 } 066 067 protected void deleteDir(File packedConfigurationDir) { 068 IOUtil.recursiveDelete(packedConfigurationDir); 069 } 070 071 protected DirectoryPackager newDirectoryPackager() { 072 return new ZipDirectoryPackager(); 073 } 074 075 public static final GBeanInfo GBEAN_INFO; 076 077 public static final String GBEAN_J2EE_TYPE = "ClusterConfigurationStore"; 078 public static final String GBEAN_REF_CONF_STORE = "ConfigurationStore"; 079 080 static { 081 GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(BasicClusterConfigurationStore.class, GBEAN_J2EE_TYPE); 082 083 builder.addReference(GBEAN_REF_CONF_STORE, ConfigurationStore.class, "ConfigurationStore"); 084 085 builder.addInterface(ClusterConfigurationStore.class); 086 087 builder.setConstructor(new String[]{GBEAN_REF_CONF_STORE}); 088 089 GBEAN_INFO = builder.getBeanInfo(); 090 } 091 092 public static GBeanInfo getGBeanInfo() { 093 return GBEAN_INFO; 094 } 095 096 }