KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > mavenplugins > car > MavenConfigStore


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.mavenplugins.car;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.List JavaDoc;
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: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
43  */

44 public class MavenConfigStore
45     extends RepositoryConfigurationStore
46 {
47     public MavenConfigStore(Kernel kernel, String JavaDoc objectName, WritableListableRepository repository) {
48         super(kernel, objectName, repository);
49     }
50
51     public MavenConfigStore(WritableListableRepository repository) {
52         super(repository);
53     }
54
55     public File JavaDoc createNewConfigurationDir(Artifact configId) {
56         try {
57             File JavaDoc 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 JavaDoc metaInf = new File JavaDoc(tmpFile, "META-INF");
65             metaInf.mkdirs();
66             return tmpFile;
67         }
68         catch (IOException JavaDoc e) {
69             // doh why can't I throw this?
70
return null;
71         }
72     }
73
74     public void install(ConfigurationData configurationData) throws IOException JavaDoc, InvalidConfigException {
75         File JavaDoc source = configurationData.getConfigurationDir();
76         if (!source.isDirectory()) {
77             throw new InvalidConfigException("Source must be a directory: " + source);
78         }
79         
80         Artifact configId = configurationData.getId();
81         File JavaDoc targetFile = repository.getLocation(configId);
82         ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, null, targetFile);
83     }
84
85     public void uninstall(Artifact configID) throws NoSuchConfigException, IOException JavaDoc {
86         File JavaDoc targetFile = repository.getLocation(configID);
87         targetFile.delete();
88     }
89
90     public List JavaDoc listConfigurations() {
91         throw new UnsupportedOperationException JavaDoc();
92     }
93
94     public static final GBeanInfo GBEAN_INFO;
95
96     public static GBeanInfo getGBeanInfo() {
97         return GBEAN_INFO;
98     }
99
100     static {
101         GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(MavenConfigStore.class, "ConfigurationStore");
102         builder.addAttribute("kernel", Kernel.class, false);
103         builder.addAttribute("objectName", String JavaDoc.class, false);
104         builder.addReference("Repository", WritableListableRepository.class, "Repository");
105         builder.setConstructor(new String JavaDoc[]{"kernel", "objectName", "Repository"});
106         GBEAN_INFO = builder.getBeanInfo();
107     }
108 }
109
Popular Tags