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  
23  
24  import java.rmi.RemoteException;
25  import java.rmi.server.UnicastRemoteObject;
26  import java.util.Properties;
27  
28  import org.apache.commons.configuration2.Configuration;
29  import org.apache.commons.configuration2.ConfigurationConverter;
30  
31  
32  
33  
34  
35  
36  
37  public class BaseUnicastRemoteService extends UnicastRemoteObject
38          implements Service
39  {
40      
41  
42  
43      private static final long serialVersionUID = -7775459623190960297L;
44  
45      protected Configuration configuration;
46      private boolean isInitialized;
47      private InitableBroker initableBroker;
48      private String name;
49      private ServiceBroker serviceBroker;
50  
51      
52  
53  
54  
55      public BaseUnicastRemoteService()
56              throws RemoteException
57      {
58          isInitialized = false;
59          initableBroker = null;
60          name = null;
61          serviceBroker = null;
62      }
63  
64      
65  
66  
67  
68  
69      @Override
70      public Configuration getConfiguration()
71      {
72          if (name == null)
73          {
74              return null;
75          }
76          else
77          {
78              if (configuration == null)
79              {
80                  configuration = getServiceBroker().getConfiguration(name);
81              }
82              return configuration;
83          }
84      }
85  
86      @Override
87      public void setInitableBroker(InitableBroker broker)
88      {
89          this.initableBroker = broker;
90      }
91  
92      
93  
94  
95  
96      public InitableBroker getInitableBroker()
97      {
98          return initableBroker;
99      }
100 
101     @Override
102     public void init(Object data)
103             throws InitializationException
104     {
105         init();
106     }
107 
108     @Override
109     public void init() throws InitializationException
110     {
111         setInit(true);
112     }
113 
114     protected void setInit(boolean value)
115     {
116         isInitialized = value;
117     }
118 
119     @Override
120     public boolean getInit()
121     {
122         return isInitialized;
123     }
124 
125     
126 
127 
128     @Override
129     public void shutdown()
130     {
131         setInit(false);
132     }
133 
134     @Override
135     public Properties getProperties()
136     {
137         return ConfigurationConverter.getProperties(getConfiguration());
138     }
139 
140     @Override
141     public void setName(String name)
142     {
143         this.name = name;
144     }
145 
146     @Override
147     public String getName()
148     {
149         return name;
150     }
151 
152     
153 
154 
155 
156     public ServiceBroker getServiceBroker()
157     {
158         return serviceBroker;
159     }
160 
161     @Override
162     public void setServiceBroker(ServiceBroker broker)
163     {
164         this.serviceBroker = broker;
165     }
166 }