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