KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > Bootstrap


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.deployment;
19
20 import java.io.File JavaDoc;
21 import java.util.jar.Attributes JavaDoc;
22 import java.util.jar.Manifest JavaDoc;
23
24 import org.apache.geronimo.deployment.service.ServiceConfigBuilder;
25 import org.apache.geronimo.deployment.util.DeploymentUtil;
26 import org.apache.geronimo.deployment.xbeans.ConfigurationDocument;
27 import org.apache.geronimo.deployment.xbeans.ConfigurationType;
28 import org.apache.geronimo.kernel.config.ConfigurationData;
29 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
30 import org.apache.geronimo.system.configuration.LocalConfigStore;
31 import org.apache.geronimo.system.main.CommandLineManifest;
32 import org.apache.geronimo.system.repository.ReadOnlyRepository;
33
34 /**
35  * Helper class to bootstrap the Geronimo deployer.
36  *
37  * @version $Rev: 169154 $ $Date: 2005-05-08 12:35:23 -0700 (Sun, 08 May 2005) $
38  */

39 public class Bootstrap {
40     private String JavaDoc deployerJar;
41     private String JavaDoc storeDir;
42     private String JavaDoc repositoryDir;
43     private String JavaDoc deployerSystemPlan;
44     private String JavaDoc j2eeDeployerPlan;
45     private String JavaDoc deployerClassPath;
46     private String JavaDoc deployerEndorsedDirs;
47     private String JavaDoc deployerGBean;
48     private String JavaDoc deploymentFactory;
49
50     public String JavaDoc getDeployerJar() {
51         return deployerJar;
52     }
53
54     public void setDeployerJar(String JavaDoc deployerJar) {
55         this.deployerJar = deployerJar;
56     }
57
58     public String JavaDoc getStoreDir() {
59         return storeDir;
60     }
61
62     public void setStoreDir(String JavaDoc storeDir) {
63         this.storeDir = storeDir;
64     }
65
66     public String JavaDoc getRepositoryDir() {
67         return repositoryDir;
68     }
69
70     public void setRepositoryDir(String JavaDoc repositoryDir) {
71         this.repositoryDir = repositoryDir;
72     }
73
74     public String JavaDoc getDeployerSystemPlan() {
75         return deployerSystemPlan;
76     }
77
78     public void setDeployerSystemPlan(String JavaDoc deployerSystemPlan) {
79         this.deployerSystemPlan = deployerSystemPlan;
80     }
81
82     public String JavaDoc getJ2eeDeployerPlan() {
83         return j2eeDeployerPlan;
84     }
85
86     public void setJ2eeDeployerPlan(String JavaDoc j2eeDeployerPlan) {
87         this.j2eeDeployerPlan = j2eeDeployerPlan;
88     }
89
90     public String JavaDoc getDeployerClassPath() {
91         return deployerClassPath;
92     }
93
94     public void setDeployerClassPath(String JavaDoc deployerClassPath) {
95         this.deployerClassPath = deployerClassPath;
96     }
97
98     public String JavaDoc getDeployerEndorsedDirs() {
99         return deployerEndorsedDirs;
100     }
101
102     public void setDeployerEndorsedDirs(String JavaDoc deployerEndorsedDirs) {
103         this.deployerEndorsedDirs = deployerEndorsedDirs;
104     }
105
106     public String JavaDoc getDeployerGBean() {
107         return deployerGBean;
108     }
109
110     public void setDeployerGBean(String JavaDoc deployerGBean) {
111         this.deployerGBean = deployerGBean;
112     }
113
114     public String JavaDoc getDeploymentFactory() {
115         return deploymentFactory;
116     }
117
118     public void setDeploymentFactory(String JavaDoc deploymentFactory) {
119         this.deploymentFactory = deploymentFactory;
120     }
121
122     public void bootstrap() throws Exception JavaDoc {
123         ClassLoader JavaDoc oldCL = Thread.currentThread().getContextClassLoader();
124         Thread.currentThread().setContextClassLoader(Bootstrap.class.getClassLoader());
125         try {
126             // parse the deployment-system and j2ee-deployer plans
127
ConfigurationType deployerSystemConfig = ConfigurationDocument.Factory.parse(new File JavaDoc(deployerSystemPlan)).getConfiguration();
128             ConfigurationType j2eeDeployerConfig = ConfigurationDocument.Factory.parse(new File JavaDoc(j2eeDeployerPlan)).getConfiguration();
129
130             // create the service builder, repository and config store objects
131
LocalConfigStore configStore = new LocalConfigStore(new File JavaDoc(storeDir));
132             ReadOnlyRepository repository = new ReadOnlyRepository(new File JavaDoc(repositoryDir));
133
134             //TODO should the defaultParentId be null??
135
ServiceConfigBuilder builder = new ServiceConfigBuilder(null, repository);
136
137             // create the manifext
138
Manifest JavaDoc manifest = new Manifest JavaDoc();
139             Attributes JavaDoc mainAttributes = manifest.getMainAttributes();
140             mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
141             mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(), "org.apache.geronimo.deployment.cli.DeployTool");
142             mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), deployerClassPath);
143             mainAttributes.putValue(CommandLineManifest.MAIN_GBEAN.toString(), deployerGBean);
144             mainAttributes.putValue(CommandLineManifest.MAIN_METHOD.toString(), "deploy");
145             mainAttributes.putValue(CommandLineManifest.CONFIGURATIONS.toString(), j2eeDeployerConfig.getConfigId());
146             mainAttributes.putValue(CommandLineManifest.ENDORSED_DIRS.toString(), deployerEndorsedDirs);
147
148             // attribute that indicates to a JSR-88 tool that we have a Deployment factory
149
mainAttributes.putValue("J2EE-DeploymentFactory-Implementation-Class", deploymentFactory);
150
151             // write the deployer system out to a jar
152

153             // create a temp directory to build into
154
File JavaDoc configurationDir = null;
155             try {
156                 configurationDir = configStore.createNewConfigurationDir();
157
158                 // build the deployer-system configuration into the configurationDir
159
ConfigurationData configurationData = builder.buildConfiguration(deployerSystemConfig, null, configurationDir);
160
161                 ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, manifest, configurationDir, new File JavaDoc(deployerJar));
162
163                 // install the configuration
164
configStore.install(configurationData, configurationDir);
165             } catch (Throwable JavaDoc e) {
166                 DeploymentUtil.recursiveDelete(configurationDir);
167                 if (e instanceof Error JavaDoc) {
168                     throw (Error JavaDoc) e;
169                 } else if (e instanceof Exception JavaDoc) {
170                     throw (Exception JavaDoc) e;
171                 }
172                 throw new Error JavaDoc(e);
173             }
174             
175             //get the domain and server from the parent xml config
176
String JavaDoc domain = deployerSystemConfig.getDomain();
177             String JavaDoc server = deployerSystemConfig.getServer();
178
179             // build and install the j2ee-deployer configuration
180
try {
181                 configurationDir = configStore.createNewConfigurationDir();
182
183                 // build the j2ee-deployer configuration into the configurationDir
184
ConfigurationData configurationData = builder.buildConfiguration(j2eeDeployerConfig, domain, server, configurationDir);
185
186                 // install the configuration
187
configStore.install(configurationData, configurationDir);
188             } catch (Throwable JavaDoc e) {
189                 DeploymentUtil.recursiveDelete(configurationDir);
190                 if (e instanceof Error JavaDoc) {
191                     throw (Error JavaDoc) e;
192                 } else if (e instanceof Exception JavaDoc) {
193                     throw (Exception JavaDoc) e;
194                 }
195                 throw new Error JavaDoc(e);
196             }
197         } finally {
198             Thread.currentThread().setContextClassLoader(oldCL);
199         }
200     }
201 }
202
Popular Tags