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: */package org.apache.openejb.server;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.net.URI;
021: import java.util.Properties;
022:
023: import org.apache.openejb.OpenEJB;
024: import org.apache.openejb.core.ServerFederation;
025: import org.apache.openejb.loader.SystemInstance;
026: import org.apache.openejb.spi.Service;
027: import org.apache.openejb.util.PropertiesService;
028:
029: /**
030: * @org.apache.xbean.XBean element="server"
031: * description="OpenEJB Server"
032: *
033: * @version $Rev: 576056 $ $Date: 2007-09-16 00:14:42 -0700 $
034: */
035: public class Server implements Service {
036: // FIXME: Remove it completely once we ensure PropertiesService (below) works well
037: Properties props;
038:
039: private PropertiesService propertiesService;
040:
041: static Server server;
042: private ServiceManager manager;
043:
044: public static Server getServer() {
045: if (server == null) {
046: server = new Server();
047: }
048:
049: return server;
050: }
051:
052: // TODO: Remove it once init() suits our (initialisation) needs
053: public void init(Properties props) throws Exception {
054: this .props = props;
055:
056: SystemInstance system = SystemInstance.get();
057: File home = system.getHome().getDirectory();
058: system.setProperty("openejb.deployments.classpath.include",
059: ".*/" + home.getName() + "/lib/.*");
060: system.setProperty(
061: "openejb.deployments.classpath.require.descriptor",
062: "true");
063: system.setProperty(
064: "openejb.deployments.classpath.filter.systemapps",
065: "false");
066:
067: OpenEJB.init(props, new ServerFederation());
068:
069: if (System.getProperty("openejb.nobanner") == null) {
070: System.out.println("[init] OpenEJB Remote Server");
071: }
072:
073: if (manager == null) {
074: manager = ServiceManager.getManager();
075: }
076: manager.init();
077: }
078:
079: /**
080: * Copy of {@link #init(Properties)} to XBean-ize it
081: *
082: * @throws Exception
083: */
084: public void init() throws Exception {
085:
086: OpenEJB.init(propertiesService.getProperties(),
087: new ServerFederation());
088:
089: if (!propertiesService.isSet("openejb.nobanner")) {
090: System.out.println("[init] OpenEJB Remote Server");
091: }
092:
093: manager.init();
094: }
095:
096: public void start() throws Exception {
097: manager.start();
098: }
099:
100: public void stop() throws Exception {
101: manager.stop();
102: }
103:
104: public void addService(URI uri) {
105:
106: }
107:
108: public static class ServerServiceFactory {
109: public ServerService createService(URI location)
110: throws IOException {
111: return null;
112: }
113: }
114:
115: public void setServiceManager(ServiceManager serviceManager) {
116: this .manager = serviceManager;
117: }
118:
119: public void setPropertiesService(PropertiesService propertiesService) {
120: this.propertiesService = propertiesService;
121: }
122: }
|