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 org.apache.turbine.pipeline.PipelineData;
    25  import org.apache.turbine.util.RunData;
    26
    27  /**
    28   * <p>This class provides a <code>Service</code> implementation that
    29   * Services used in Turbine are required to extend.  The
    30   * functionality provided in addition to <code>BaseService</code>
    31   * functionality is recognizing objects used in early initialization
    32   * of <code>Services</code> in Turbine, and passing them to
    33   * appropriate convenience methods.  These methods should be overriden
    34   * to provide desired initialization functionality.</p>
    35   *
    36   * <p><strong>Note!</strong><br>Remember to call
    37   * <code>setInit(true)</code> after successful initialization.</p>
    38   *
    39   * <p><strong>Note!</strong><br>If you need to use another
    40   * <code>Service</code> inside your early initialization, remember to
    41   * request initialization of that <code>Service</code> before using
    42   * it:</p>
    43   *
    44   * <pre><code>
    45   * getServiceBroker().initClass("OtherService",data);
    46   * OtherService service =
    47   *         (OtherService)getServiceBroker().getService("OtherService");
    48   * </code></pre>
    49   *
    50   * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
    51   * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
    52   * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
    53   * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
    54   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    55   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    56   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    57   * @version $Id: TurbineBaseService.java 1078552 2011-03-06 19:58:46Z tv $
    58   */
    59  public abstract class TurbineBaseService
    60          extends BaseService
    61  {
    62      /**
    63       * Performs early initialization.  Overrides init() method in
    64       * BaseService to detect objects used in Turbine's Service
    65       * initialization and pass them to apropriate init() methods.
    66       *
    67       * @param data An Object to use for initialization activities.
    68       * @exception InitializationException if initialization of this
    69       * class was not successful.
    70       */
    71      @Override
    72      public void init(Object data)
    73              throws InitializationException
    74      {
    75          if (data instanceof RunData)
    76          {
    77              init((RunData) data);
    78          }
    79          else if (data instanceof PipelineData)
    80          {
    81              init((PipelineData) data);
    82          }
    83      }
    84
    85      /**
    86       * Performs early initialization.
    87       *
    88       * @deprecated Use the PipelineData version instead.
    89       * @param data An RunData to use for initialization activities.
    90       * @exception InitializationException if initialization of this
    91       * class was not successful.
    92       */
    93      @Deprecated
    94      public void init(RunData data) throws InitializationException
    95      {
    96          // empty
    97      }
    98
    99      /**
    100      * Performs early initialization.
    101      *
    102      * @param data A PipelineData to use for initialization activities.
    103      * @exception InitializationException if initialization of this
    104      * class was not successful.
    105      */
    106     public void init(PipelineData data) throws InitializationException
    107     {
    108         // empty
    109     }
    110
    111
    112     /**
    113      * Performs late initialization.
    114      *
    115      * If your class relies on early initialization, and the object it
    116      * expects was not received, you can use late initialization to
    117      * throw an exception and complain.
    118      *
    119      * @exception InitializationException, if initialization of this
    120      * class was not successful.
    121      */
    122     @Override
    123     public void init() throws InitializationException
    124     {
    125         setInit(true);
    126     }
    127
    128     /**
    129      * Returns to uninitialized state.
    130      *
    131      * You can use this method to release resources thet your Service
    132      * allocated when Turbine shuts down.
    133      */
    134     @Override
    135     public void shutdown()
    136     {
    137         setInit(false);
    138     }
    139 }