View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.geronimo.plugin.car;
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.List;
25  
26  import org.apache.geronimo.gbean.GBeanInfo;
27  import org.apache.geronimo.gbean.GBeanInfoBuilder;
28  import org.apache.geronimo.kernel.config.ConfigurationData;
29  import org.apache.geronimo.kernel.config.InvalidConfigException;
30  import org.apache.geronimo.kernel.config.NoSuchConfigException;
31  import org.apache.geronimo.kernel.repository.Artifact;
32  import org.apache.geronimo.kernel.repository.WritableListableRepository;
33  import org.apache.geronimo.kernel.Kernel;
34  import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
35  import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
36  
37  /**
38   * Implementation of ConfigurationStore that loads Configurations from a repository.
39   * This implementation is read-only on the assumption that a separate maven task will
40   * handle installation of a built package into the repository.
41   *
42   * @version $Rev: 451661 $ $Date: 2006-09-30 13:45:53 -0700 (Sat, 30 Sep 2006) $
43   */
44  public class MavenConfigStore
45      extends RepositoryConfigurationStore
46  {
47      public MavenConfigStore(Kernel kernel, String objectName, WritableListableRepository repository) {
48          super(kernel, objectName, repository);
49      }
50  
51      public MavenConfigStore(WritableListableRepository repository) {
52          super(repository);
53      }
54  
55      public File createNewConfigurationDir(Artifact configId) {
56          try {
57              File tmpFile = File.createTempFile("package", ".tmpdir");
58              tmpFile.delete();
59              tmpFile.mkdir();
60              if (!tmpFile.isDirectory()) {
61                  return null;
62              }
63              // create the meta-inf dir
64              File metaInf = new File(tmpFile, "META-INF");
65              metaInf.mkdirs();
66              return tmpFile;
67          }
68          catch (IOException e) {
69              // doh why can't I throw this?
70              return null;
71          }
72      }
73  
74      public void install(ConfigurationData configurationData) throws IOException, InvalidConfigException {
75          File source = configurationData.getConfigurationDir();
76          if (!source.isDirectory()) {
77              throw new InvalidConfigException("Source must be a directory: source=" + source);
78          }
79          Artifact configId = configurationData.getId();
80          File targetFile = repository.getLocation(configId);
81          ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, null, targetFile);
82      }
83  
84      public void uninstall(Artifact configID) throws NoSuchConfigException, IOException {
85          File targetFile = repository.getLocation(configID);
86          targetFile.delete();
87      }
88  
89      public List listConfigurations() {
90          throw new UnsupportedOperationException();
91      }
92  
93      public static final GBeanInfo GBEAN_INFO;
94  
95      public static GBeanInfo getGBeanInfo() {
96          return GBEAN_INFO;
97      }
98  
99      static {
100         GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(MavenConfigStore.class, "ConfigurationStore");
101         builder.addAttribute("kernel", Kernel.class, false);
102         builder.addAttribute("objectName", String.class, false);
103         builder.addReference("Repository", WritableListableRepository.class, "Repository");
104         builder.setConstructor(new String[]{"kernel", "objectName", "Repository"});
105         GBEAN_INFO = builder.getBeanInfo();
106     }
107 }