View Javadoc

    1   package org.apache.turbine.services;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import java.util.Properties;
    25
    26  import org.apache.commons.configuration.Configuration;
    27  import org.apache.commons.configuration.ConfigurationConverter;
    28
    29  /**
    30   * This class is a generic implementation of <code>Service</code>.
    31   *
    32   * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
    33   * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
    34   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    35   * @version $Id: BaseService.java 615328 2008-01-25 20:25:05Z tv $
    36   */
    37  public class BaseService
    38          extends BaseInitable
    39          implements Service
    40  {
    41      /** A reference to the ServiceBroker that instantiated this object. */
    42      protected ServiceBroker serviceBroker;
    43
    44      /** The configuration for this service */
    45      protected Configuration configuration;
    46
    47      /** The name of this Service. */
    48      protected String name;
    49
    50      /**
    51       * Saves a reference to the ServiceBroker that instantiated this
    52       * object, so that it can ask for its properties and access other
    53       * Services.
    54       *
    55       * @param broker The ServiceBroker that instantiated this object.
    56       */
    57      public void setServiceBroker(ServiceBroker broker)
    58      {
    59          this.serviceBroker = broker;
    60      }
    61
    62      /**
    63       * ServiceBroker uses this method to pass a Service its name.
    64       *
    65       * @param name The name of this Service.
    66       */
    67      public void setName(String name)
    68      {
    69          this.name = name;
    70      }
    71
    72      /**
    73       * Returns the name of this service.
    74       *
    75       * @return The name of this Service.
    76       */
    77      public String getName()
    78      {
    79          return name;
    80      }
    81
    82      /**
    83       * Returns a ServiceBroker reference.
    84       *
    85       * @return The ServiceBroker that instantiated this object.
    86       */
    87      public ServiceBroker getServiceBroker()
    88      {
    89          return serviceBroker;
    90      }
    91
    92      /**
    93       * Returns the properties of this Service.
    94       *
    95       * @return The Properties of this Service.
    96       */
    97      public Properties getProperties()
    98      {
    99          return ConfigurationConverter.getProperties(getConfiguration());
    100     }
    101
    102     /**
    103      * Returns the configuration of this Service.
    104      *
    105      * @return The Configuration of this Service.
    106      */
    107     public Configuration getConfiguration()
    108     {
    109         if (name == null)
    110         {
    111             return null;
    112         }
    113
    114         if (configuration == null)
    115         {
    116             configuration = getServiceBroker().getConfiguration(name);
    117         }
    118         return configuration;
    119     }
    120 }