1 package org.apache.turbine.services;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Properties;
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 264148 2005-08-29 14:21:04Z henning $
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 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 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 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 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 }