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.util.Properties;
023:
024: import org.apache.commons.configuration.Configuration;
025: import org.apache.commons.configuration.ConfigurationConverter;
026:
027: /**
028: * This class is a generic implementation of <code>Service</code>.
029: *
030: * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
031: * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
032: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
033: * @version $Id: BaseService.java 534527 2007-05-02 16:10:59Z tv $
034: */
035: public class BaseService extends BaseInitable implements Service {
036: /** A reference to the ServiceBroker that instantiated this object. */
037: protected ServiceBroker serviceBroker;
038:
039: /** The configuration for this service */
040: protected Configuration configuration;
041:
042: /** The name of this Service. */
043: protected String name;
044:
045: /**
046: * Saves a reference to the ServiceBroker that instantiated this
047: * object, so that it can ask for its properties and access other
048: * Services.
049: *
050: * @param broker The ServiceBroker that instantiated this object.
051: */
052: public void setServiceBroker(ServiceBroker broker) {
053: this .serviceBroker = broker;
054: }
055:
056: /**
057: * ServiceBroker uses this method to pass a Service its name.
058: *
059: * @param name The name of this Service.
060: */
061: public void setName(String name) {
062: this .name = name;
063: }
064:
065: /**
066: * Returns the name of this service.
067: *
068: * @return The name of this Service.
069: */
070: public String getName() {
071: return name;
072: }
073:
074: /**
075: * Returns a ServiceBroker reference.
076: *
077: * @return The ServiceBroker that instantiated this object.
078: */
079: public ServiceBroker getServiceBroker() {
080: return serviceBroker;
081: }
082:
083: /**
084: * Returns the properties of this Service.
085: *
086: * @return The Properties of this Service.
087: */
088: public Properties getProperties() {
089: return ConfigurationConverter.getProperties(getConfiguration());
090: }
091:
092: /**
093: * Returns the configuration of this Service.
094: *
095: * @return The Configuration of this Service.
096: */
097: public Configuration getConfiguration() {
098: if (name == null) {
099: return null;
100: }
101:
102: if (configuration == null) {
103: configuration = getServiceBroker().getConfiguration(name);
104: }
105: return configuration;
106: }
107: }
|