001: package org.apache.turbine.services;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License")
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import javax.servlet.ServletConfig;
020:
021: import org.apache.turbine.util.RunData;
022:
023: /**
024: * <p>This class provides a <code>Service</code> implementation that
025: * Services used in Turbine are required to extend. The
026: * functionality provided in addition to <code>BaseService</code>
027: * functionality is recognizing objects used in early initialization
028: * of <code>Services</code> in Turbine, and passing them to
029: * appropriate convenience methods. These methods should be overriden
030: * to provide desired initialization functionality.</p>
031: *
032: * <p><strong>Note!</strong><br>Remember to call
033: * <code>setInit(true)</code> after successful initialization.</p>
034: *
035: * <p><strong>Note!</strong><br>If you need to use another
036: * <code>Service</code> inside your early initialization, remember to
037: * request initialization of that <code>Service</code> before using
038: * it:</p>
039: *
040: * <pre><code>
041: * getServiceBroker().initClass("OtherService",data);
042: * OtherService service =
043: * (OtherService)getServiceBroker().getService("OtherService");
044: * </code></pre>
045: *
046: * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
047: * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
048: * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
049: * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
050: * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
051: * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
052: * @version $Id: TurbineBaseService.java 264148 2005-08-29 14:21:04Z henning $
053: */
054: public abstract class TurbineBaseService extends BaseService {
055: /**
056: * Performs early initialization. Overrides init() method in
057: * BaseService to detect objects used in Turbine's Service
058: * initialization and pass them to apropriate init() methods.
059: *
060: * @param data An Object to use for initialization activities.
061: * @exception InitializationException if initialization of this
062: * class was not successful.
063: */
064: public void init(Object data) throws InitializationException {
065: if (data instanceof ServletConfig) {
066: init((ServletConfig) data);
067: } else if (data instanceof RunData) {
068: init((RunData) data);
069: }
070: }
071:
072: /**
073: * Performs early initialization.
074: *
075: * @param config A ServletConfing to use for initialization
076: * activities.
077: * @exception InitializationException if initialization of this
078: * class was not successful.
079: * @deprecated Use init() instead
080: */
081: public void init(ServletConfig config)
082: throws InitializationException {
083: }
084:
085: /**
086: * Performs early initialization.
087: *
088: * @param data An RunData to use for initialization activities.
089: * @exception InitializationException if initialization of this
090: * class was not successful.
091: */
092: public void init(RunData data) throws InitializationException {
093: }
094:
095: /**
096: * Performs late initialization.
097: *
098: * If your class relies on early initialization, and the object it
099: * expects was not received, you can use late initialization to
100: * throw an exception and complain.
101: *
102: * @exception InitializationException, if initialization of this
103: * class was not successful.
104: */
105: public void init() throws InitializationException {
106: setInit(true);
107: }
108:
109: /**
110: * Returns to uninitialized state.
111: *
112: * You can use this method to release resources thet your Service
113: * allocated when Turbine shuts down.
114: */
115: public void shutdown() {
116: setInit(false);
117: }
118: }
|