001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.system.main;
019
020 import java.io.BufferedReader;
021 import java.io.File;
022 import java.io.FileReader;
023 import java.io.IOException;
024 import java.util.ArrayList;
025 import java.util.List;
026
027 import org.apache.geronimo.kernel.GBeanNotFoundException;
028 import org.apache.geronimo.kernel.Kernel;
029 import org.apache.geronimo.kernel.repository.Artifact;
030 import org.apache.geronimo.system.serverinfo.ServerInfo;
031
032 /**
033 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
034 */
035 public class LocalServer extends CommandLine {
036
037 public LocalServer(String bootModule, String configListLocation) throws Exception {
038 startKernel(Artifact.create(bootModule));
039 Runtime.getRuntime().addShutdownHook(new Thread("Geronimo shutdown thread") {
040 public void run() {
041 getKernel().shutdown();
042 }
043 });
044 List configs = getConfigurationList(configListLocation);
045 loadConfigurations(configs);
046 }
047
048 public Kernel getKernel() {
049 return super.getKernel();
050 }
051
052 protected List getConfigurationList(String path) throws GBeanNotFoundException, IOException {
053 ServerInfo serverInfo = (ServerInfo) getKernel().getGBean(ServerInfo.class);
054 File configFile = serverInfo.resolve(path);
055 List modules = new ArrayList();
056 BufferedReader in = new BufferedReader(new FileReader(configFile));
057 try {
058 String artifactString;
059 while ((artifactString = in.readLine()) != null) {
060 artifactString = artifactString.trim();
061 if (!artifactString.startsWith("#") && artifactString.length() > 0) {
062 Artifact artifact = Artifact.create(artifactString);
063 modules.add(artifact);
064 }
065 }
066 } finally {
067 in.close();
068 }
069 return modules;
070 }
071
072 }