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 javax.servlet.ServletConfig;
023:
024: import org.apache.turbine.util.RunData;
025:
026: /**
027: * <p>This class provides a <code>Service</code> implementation that
028: * Services used in Turbine are required to extend. The
029: * functionality provided in addition to <code>BaseService</code>
030: * functionality is recognizing objects used in early initialization
031: * of <code>Services</code> in Turbine, and passing them to
032: * appropriate convenience methods. These methods should be overriden
033: * to provide desired initialization functionality.</p>
034: *
035: * <p><strong>Note!</strong><br>Remember to call
036: * <code>setInit(true)</code> after successful initialization.</p>
037: *
038: * <p><strong>Note!</strong><br>If you need to use another
039: * <code>Service</code> inside your early initialization, remember to
040: * request initialization of that <code>Service</code> before using
041: * it:</p>
042: *
043: * <pre><code>
044: * getServiceBroker().initClass("OtherService",data);
045: * OtherService service =
046: * (OtherService)getServiceBroker().getService("OtherService");
047: * </code></pre>
048: *
049: * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
050: * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
051: * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
052: * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
053: * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
054: * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
055: * @version $Id: TurbineBaseService.java 534527 2007-05-02 16:10:59Z tv $
056: */
057: public abstract class TurbineBaseService extends BaseService {
058: /**
059: * Performs early initialization. Overrides init() method in
060: * BaseService to detect objects used in Turbine's Service
061: * initialization and pass them to apropriate init() methods.
062: *
063: * @param data An Object to use for initialization activities.
064: * @exception InitializationException if initialization of this
065: * class was not successful.
066: */
067: public void init(Object data) throws InitializationException {
068: if (data instanceof ServletConfig) {
069: init((ServletConfig) data);
070: } else if (data instanceof RunData) {
071: init((RunData) data);
072: }
073: }
074:
075: /**
076: * Performs early initialization.
077: *
078: * @param config A ServletConfing to use for initialization
079: * activities.
080: * @exception InitializationException if initialization of this
081: * class was not successful.
082: * @deprecated Use init() instead
083: */
084: public void init(ServletConfig config)
085: throws InitializationException {
086: }
087:
088: /**
089: * Performs early initialization.
090: *
091: * @param data An RunData to use for initialization activities.
092: * @exception InitializationException if initialization of this
093: * class was not successful.
094: */
095: public void init(RunData data) throws InitializationException {
096: }
097:
098: /**
099: * Performs late initialization.
100: *
101: * If your class relies on early initialization, and the object it
102: * expects was not received, you can use late initialization to
103: * throw an exception and complain.
104: *
105: * @exception InitializationException, if initialization of this
106: * class was not successful.
107: */
108: public void init() throws InitializationException {
109: setInit(true);
110: }
111:
112: /**
113: * Returns to uninitialized state.
114: *
115: * You can use this method to release resources thet your Service
116: * allocated when Turbine shuts down.
117: */
118: public void shutdown() {
119: setInit(false);
120: }
121: }
|