1 package org.apache.turbine.services;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Properties;
23
24 import org.apache.commons.configuration.Configuration;
25 import org.apache.commons.configuration.ConfigurationConverter;
26
27 /***
28 * This class is a generic implementation of <code>Service</code>.
29 *
30 * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
31 * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
32 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
33 * @version $Id: BaseService.java 534527 2007-05-02 16:10:59Z tv $
34 */
35 public class BaseService
36 extends BaseInitable
37 implements Service
38 {
39 /*** A reference to the ServiceBroker that instantiated this object. */
40 protected ServiceBroker serviceBroker;
41
42 /*** The configuration for this service */
43 protected Configuration configuration;
44
45 /*** The name of this Service. */
46 protected String name;
47
48 /***
49 * Saves a reference to the ServiceBroker that instantiated this
50 * object, so that it can ask for its properties and access other
51 * Services.
52 *
53 * @param broker The ServiceBroker that instantiated this object.
54 */
55 public void setServiceBroker(ServiceBroker broker)
56 {
57 this.serviceBroker = broker;
58 }
59
60 /***
61 * ServiceBroker uses this method to pass a Service its name.
62 *
63 * @param name The name of this Service.
64 */
65 public void setName(String name)
66 {
67 this.name = name;
68 }
69
70 /***
71 * Returns the name of this service.
72 *
73 * @return The name of this Service.
74 */
75 public String getName()
76 {
77 return name;
78 }
79
80 /***
81 * Returns a ServiceBroker reference.
82 *
83 * @return The ServiceBroker that instantiated this object.
84 */
85 public ServiceBroker getServiceBroker()
86 {
87 return serviceBroker;
88 }
89
90 /***
91 * Returns the properties of this Service.
92 *
93 * @return The Properties of this Service.
94 */
95 public Properties getProperties()
96 {
97 return ConfigurationConverter.getProperties(getConfiguration());
98 }
99
100 /***
101 * Returns the configuration of this Service.
102 *
103 * @return The Configuration of this Service.
104 */
105 public Configuration getConfiguration()
106 {
107 if (name == null)
108 {
109 return null;
110 }
111
112 if (configuration == null)
113 {
114 configuration = getServiceBroker().getConfiguration(name);
115 }
116 return configuration;
117 }
118 }