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.rmi.RemoteException;
20 import java.rmi.server.UnicastRemoteObject;
21 import java.util.Properties;
22 import javax.servlet.ServletConfig;
23
24 import org.apache.commons.configuration.Configuration;
25 import org.apache.commons.configuration.ConfigurationConverter;
26
27 /***
28 * A base implementation of an {@link java.rmi.server.UnicastRemoteObject}
29 * as a Turbine {@link org.apache.turbine.services.Service}.
30 *
31 * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
32 * @version $Id: BaseUnicastRemoteService.java 278822 2005-09-05 19:53:05Z henning $
33 */
34 public class BaseUnicastRemoteService extends UnicastRemoteObject
35 implements Service
36 {
37 /*** Serial Version UID */
38 private static final long serialVersionUID = -7775459623190960297L;
39
40 protected Configuration configuration;
41 private boolean isInitialized;
42 private InitableBroker initableBroker;
43 private String name;
44 private ServiceBroker serviceBroker;
45
46 public BaseUnicastRemoteService()
47 throws RemoteException
48 {
49 isInitialized = false;
50 initableBroker = null;
51 name = null;
52 serviceBroker = null;
53 }
54
55 /***
56 * Returns the configuration of this service.
57 *
58 * @return The configuration of this service.
59 */
60 public Configuration getConfiguration()
61 {
62 if (name == null)
63 {
64 return null;
65 }
66 else
67 {
68 if (configuration == null)
69 {
70 configuration = getServiceBroker().getConfiguration(name);
71 }
72 return configuration;
73 }
74 }
75
76 public void init(ServletConfig config)
77 throws InitializationException
78 {
79 setInit(true);
80 }
81
82 public void setInitableBroker(InitableBroker broker)
83 {
84 this.initableBroker = broker;
85 }
86
87 public InitableBroker getInitableBroker()
88 {
89 return initableBroker;
90 }
91
92 public void init(Object data)
93 throws InitializationException
94 {
95 init((ServletConfig) data);
96 }
97
98 public void init() throws InitializationException
99 {
100 setInit(true);
101 }
102
103 protected void setInit(boolean value)
104 {
105 isInitialized = value;
106 }
107
108 public boolean getInit()
109 {
110 return isInitialized;
111 }
112
113 /***
114 * Shuts down this service.
115 */
116 public void shutdown()
117 {
118 setInit(false);
119 }
120
121 public Properties getProperties()
122 {
123 return ConfigurationConverter.getProperties(getConfiguration());
124 }
125
126 public void setName(String name)
127 {
128 this.name = name;
129 }
130
131 public String getName()
132 {
133 return name;
134 }
135
136 public ServiceBroker getServiceBroker()
137 {
138 return serviceBroker;
139 }
140
141 public void setServiceBroker(ServiceBroker broker)
142 {
143 this.serviceBroker = broker;
144 }
145 }