KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > BaseService


1 package org.apache.fulcrum;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" and
29  * "Apache Turbine" must not be used to endorse or promote products
30  * derived from this software without prior written permission. For
31  * written permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * "Apache Turbine", nor may "Apache" appear in their name, without
35  * prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import org.apache.commons.configuration.Configuration;
58 import org.apache.log4j.Category;
59
60 /**
61  * This class is a generic implementation of <code>Service</code>.
62  *
63  * @author <a HREF="mailto:burton@apache.org">Kevin Burton</a>
64  * @author <a HREF="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
65  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
66  * @author <a HREF="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
67  * @author <a HREF="mailto:leonardr@segfault.org">Leonard Richardson</a>
68  * @author <a HREF="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
69  * @version $Id: BaseService.java,v 1.1 2004/11/12 10:25:48 epugh Exp $
70  */

71 public abstract class BaseService implements Service
72 {
73     /**
74      * Initialization status of this class.
75      */

76     protected boolean isInitialized = false;
77
78     /**
79      * A reference to the ServiceBroker that instantiated this object.
80      */

81     protected ServiceBroker serviceBroker;
82
83     /**
84      * Configuration for this service.
85      */

86     protected Configuration configuration;
87
88     /**
89      * The name of this Service.
90      */

91     protected String JavaDoc name;
92
93     /**
94      * Implement this method with your own service initiailization
95      * code. Remember to call <code>setInit(true)</code> on proper
96      * service initialization.
97      *
98      * @see org.apache.fulcrum.Service#init()
99      * @see org.apache.fulcrum.BaseService#setInit(boolean)
100      */

101     public abstract void init() throws InitializationException;
102
103     /**
104      * Returns an Initable to uninitialized state.
105      *
106      * Calls setInit(flase) to mark that we are no longer in initialized
107      * state.
108      */

109     public void shutdown()
110     {
111         setInit(false);
112     }
113
114     /**
115      * Returns initialization status.
116      *
117      * @return True if the service is initialized.
118      * @see org.apache.fulcrum.Service#isInitialized()
119      * @deprecated use isInitialized() which uses proper bean semantics.
120      */

121     public boolean getInit()
122     {
123         return isInitialized();
124     }
125
126     /**
127      * Returns either <code>Initialized</code> or
128      * <code>Uninitialized</code>, depending upon {@link
129      * org.apache.fulcrum.Service} innitialization state.
130      *
131      * @see org.apache.fulcrum.Service#getStatus()
132      */

133     public String JavaDoc getStatus() throws ServiceException
134     {
135         return (isInitialized() ? "Initialized" : "Uninitialized");
136     }
137
138     /**
139      * @see org.apache.fulcrum.Service#isInitialized()
140      */

141     public boolean isInitialized()
142     {
143         return isInitialized;
144     }
145
146     /**
147      * Sets initailization status.
148      *
149      * @param value The new initialization status.
150      */

151     protected void setInit(boolean value)
152     {
153         this.isInitialized = value;
154     }
155
156     /**
157      * ServiceBroker uses this method to pass a Service its name.
158      *
159      * @param name The name of this Service.
160      */

161     public void setName(String JavaDoc name)
162     {
163         this.name = name;
164     }
165
166     /**
167      * Returns the name of this service.
168      *
169      * @return The name of this Service.
170      */

171     public String JavaDoc getName()
172     {
173         return name;
174     }
175
176     /**
177      * Saves a reference to the ServiceBroker that instantiated this
178      * object, so that it can ask for its properties and access other
179      * Services.
180      *
181      * @param broker The ServiceBroker that instantiated this object.
182      */

183     public void setServiceBroker(ServiceBroker broker)
184     {
185         this.serviceBroker = broker;
186     }
187
188     /**
189      * Returns a ServiceBroker reference.
190      *
191      * @return The ServiceBroker that instantiated this object.
192      */

193     public ServiceBroker getServiceBroker()
194     {
195         return serviceBroker;
196     }
197
198     /**
199      * Returns the configuration of this Service.
200      *
201      * @return The Configuration of this Service.
202      */

203     public Configuration getConfiguration()
204     {
205         if (name == null)
206         {
207             return null;
208         }
209
210         if (configuration == null)
211         {
212             configuration = getServiceBroker().getConfiguration(name);
213         }
214
215         return configuration;
216     }
217
218     /**
219      * @see org.apache.fulcrum.ServiceBroker#getServiceObject(String)
220      */

221     public Object JavaDoc getServiceObject(String JavaDoc name)
222     {
223         return getServiceBroker().getServiceObject(name);
224     }
225
226     /**
227      * @see org.apache.fulcrum.ServiceBroker#getRealPath(String)
228      */

229     public String JavaDoc getRealPath(String JavaDoc path)
230     {
231         return getServiceBroker().getRealPath(path);
232     }
233
234     /**
235      * @see org.apache.fulcrum.Service#getCategory()
236      */

237     public Category getCategory()
238     {
239         return getServiceBroker().getCategory();
240     }
241 }
242
Popular Tags