KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > mavenplugin > StartServer


1 /**
2  *
3  * Copyright 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.mavenplugin;
19
20 import java.io.File JavaDoc;
21 import java.io.ObjectInputStream JavaDoc;
22 import java.net.URI JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.MalformedObjectNameException JavaDoc;
30
31 import org.apache.geronimo.gbean.GBeanData;
32 import org.apache.geronimo.kernel.KernelFactory;
33 import org.apache.geronimo.kernel.Kernel;
34 import org.apache.geronimo.kernel.config.ConfigurationManager;
35 import org.apache.geronimo.kernel.config.ConfigurationUtil;
36 import org.apache.geronimo.kernel.config.Configuration;
37 import org.apache.geronimo.kernel.config.InvalidConfigException;
38 import org.apache.geronimo.kernel.log.GeronimoLogging;
39 import org.apache.geronimo.system.url.GeronimoURLFactory;
40
41 /**
42  *
43  *
44  * @version $Rev: 169154 $ $Date: 2005-05-08 12:35:23 -0700 (Sun, 08 May 2005) $
45  *
46  * */

47 public class StartServer {
48
49     static {
50         // This MUST be done before the first log is acquired
51
GeronimoLogging.initialize(GeronimoLogging.INFO);
52
53         // Install our url factory
54
GeronimoURLFactory.install();
55     }
56
57     private String JavaDoc geronimoHome;
58     private String JavaDoc kernelName;
59     private String JavaDoc domainName;
60     private String JavaDoc configs;
61
62     public String JavaDoc getGeronimoHome() {
63         return geronimoHome;
64     }
65
66     public void setGeronimoHome(String JavaDoc geronimoHome) {
67         this.geronimoHome = geronimoHome;
68     }
69
70     public String JavaDoc getKernelName() {
71         return kernelName;
72     }
73
74     public void setKernelName(String JavaDoc kernelName) {
75         this.kernelName = kernelName;
76     }
77
78     public String JavaDoc getDomainName() {
79         return domainName;
80     }
81
82     public void setDomainName(String JavaDoc domainName) {
83         this.domainName = domainName;
84     }
85
86     public String JavaDoc getConfigs() {
87         return configs;
88     }
89
90     public void setConfigs(String JavaDoc configs) {
91         this.configs = configs;
92     }
93
94     public void execute() throws Exception JavaDoc {
95         System.setProperty("geronimo.base.dir", getGeronimoHome());
96         List JavaDoc configList = new ArrayList JavaDoc();
97         for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(configs); st.hasMoreTokens();) {
98             configList.add(new URI JavaDoc(st.nextToken()));
99         }
100         File JavaDoc root = new File JavaDoc(getGeronimoHome());
101         URL JavaDoc systemURL = new File JavaDoc(root, "bin/server.jar").toURL();
102         URL JavaDoc configURL = new URL JavaDoc("jar:" + systemURL.toString() + "!/META-INF/config.ser");
103         GBeanData configuration = new GBeanData();
104         ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(configURL.openStream());
105         try {
106             configuration.readExternal(ois);
107         } finally {
108             ois.close();
109         }
110         URI JavaDoc configurationId = (URI JavaDoc) configuration.getAttribute("id");
111         ObjectName JavaDoc configName = Configuration.getConfigurationObjectName(configurationId);
112         configuration.setName(configName);
113
114         // build a basic kernel without a configuration-store, our configuration store is
115
Kernel kernel = KernelFactory.newInstance().createKernel(getKernelName());
116         kernel.boot();
117
118         kernel.loadGBean(configuration, this.getClass().getClassLoader());
119         kernel.setAttribute(configName, "baseURL", systemURL);
120         kernel.startRecursiveGBean(configName);
121
122         // load the rest of the configuration listed on the command line
123
ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
124         for (Iterator JavaDoc i = configList.iterator(); i.hasNext();) {
125             URI JavaDoc configID = (URI JavaDoc) i.next();
126             List JavaDoc list = configurationManager.loadRecursive(configID);
127             for (Iterator JavaDoc iterator = list.iterator(); iterator.hasNext();) {
128                 ObjectName JavaDoc name = (ObjectName JavaDoc) iterator.next();
129                 kernel.startRecursiveGBean(name);
130                 System.out.println("started gbean: " + name);
131             }
132         }
133
134
135     }
136 }
137
Popular Tags