001: package org.apache.turbine.services;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.rmi.RemoteException;
023: import java.rmi.server.UnicastRemoteObject;
024: import java.util.Properties;
025: import javax.servlet.ServletConfig;
026:
027: import org.apache.commons.configuration.Configuration;
028: import org.apache.commons.configuration.ConfigurationConverter;
029:
030: /**
031: * A base implementation of an {@link java.rmi.server.UnicastRemoteObject}
032: * as a Turbine {@link org.apache.turbine.services.Service}.
033: *
034: * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
035: * @version $Id: BaseUnicastRemoteService.java 534527 2007-05-02 16:10:59Z tv $
036: */
037: public class BaseUnicastRemoteService extends UnicastRemoteObject
038: implements Service {
039: /** Serial Version UID */
040: private static final long serialVersionUID = -7775459623190960297L;
041:
042: protected Configuration configuration;
043: private boolean isInitialized;
044: private InitableBroker initableBroker;
045: private String name;
046: private ServiceBroker serviceBroker;
047:
048: public BaseUnicastRemoteService() throws RemoteException {
049: isInitialized = false;
050: initableBroker = null;
051: name = null;
052: serviceBroker = null;
053: }
054:
055: /**
056: * Returns the configuration of this service.
057: *
058: * @return The configuration of this service.
059: */
060: public Configuration getConfiguration() {
061: if (name == null) {
062: return null;
063: } else {
064: if (configuration == null) {
065: configuration = getServiceBroker().getConfiguration(
066: name);
067: }
068: return configuration;
069: }
070: }
071:
072: public void init(ServletConfig config)
073: throws InitializationException {
074: setInit(true);
075: }
076:
077: public void setInitableBroker(InitableBroker broker) {
078: this .initableBroker = broker;
079: }
080:
081: public InitableBroker getInitableBroker() {
082: return initableBroker;
083: }
084:
085: public void init(Object data) throws InitializationException {
086: init((ServletConfig) data);
087: }
088:
089: public void init() throws InitializationException {
090: setInit(true);
091: }
092:
093: protected void setInit(boolean value) {
094: isInitialized = value;
095: }
096:
097: public boolean getInit() {
098: return isInitialized;
099: }
100:
101: /**
102: * Shuts down this service.
103: */
104: public void shutdown() {
105: setInit(false);
106: }
107:
108: public Properties getProperties() {
109: return ConfigurationConverter.getProperties(getConfiguration());
110: }
111:
112: public void setName(String name) {
113: this .name = name;
114: }
115:
116: public String getName() {
117: return name;
118: }
119:
120: public ServiceBroker getServiceBroker() {
121: return serviceBroker;
122: }
123:
124: public void setServiceBroker(ServiceBroker broker) {
125: this.serviceBroker = broker;
126: }
127: }
|