KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > BaseService


1 package org.apache.turbine.services;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Properties JavaDoc;
20
21 import org.apache.commons.configuration.Configuration;
22 import org.apache.commons.configuration.ConfigurationConverter;
23
24 /**
25  * This class is a generic implementation of <code>Service</code>.
26  *
27  * @author <a HREF="mailto:burton@apache.org">Kevin Burton</a>
28  * @author <a HREF="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
29  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
30  * @version $Id: BaseService.java,v 1.6.2.2 2004/05/20 03:05:18 seade Exp $
31  */

32 public class BaseService
33         extends BaseInitable
34         implements Service
35 {
36     /** A reference to the ServiceBroker that instantiated this object. */
37     protected ServiceBroker serviceBroker;
38
39     /** The configuration for this service */
40     protected Configuration configuration;
41
42     /** The name of this Service. */
43     protected String JavaDoc name;
44
45     /**
46      * Saves a reference to the ServiceBroker that instantiated this
47      * object, so that it can ask for its properties and access other
48      * Services.
49      *
50      * @param broker The ServiceBroker that instantiated this object.
51      */

52     public void setServiceBroker(ServiceBroker broker)
53     {
54         this.serviceBroker = broker;
55     }
56
57     /**
58      * ServiceBroker uses this method to pass a Service its name.
59      *
60      * @param name The name of this Service.
61      */

62     public void setName(String JavaDoc name)
63     {
64         this.name = name;
65     }
66
67     /**
68      * Returns the name of this service.
69      *
70      * @return The name of this Service.
71      */

72     public String JavaDoc getName()
73     {
74         return name;
75     }
76
77     /**
78      * Returns a ServiceBroker reference.
79      *
80      * @return The ServiceBroker that instantiated this object.
81      */

82     public ServiceBroker getServiceBroker()
83     {
84         return serviceBroker;
85     }
86
87     /**
88      * Returns the properties of this Service.
89      *
90      * @return The Properties of this Service.
91      */

92     public Properties JavaDoc getProperties()
93     {
94         return ConfigurationConverter.getProperties(getConfiguration());
95     }
96
97     /**
98      * Returns the configuration of this Service.
99      *
100      * @return The Configuration of this Service.
101      */

102     public Configuration getConfiguration()
103     {
104         if (name == null)
105         {
106             return null;
107         }
108
109         if (configuration == null)
110         {
111             configuration = getServiceBroker().getConfiguration(name);
112         }
113         return configuration;
114     }
115 }
116
Popular Tags