KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > BaseUnicastRemoteService


1 package org.apache.turbine.services;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.rmi.RemoteException JavaDoc;
20 import java.rmi.server.UnicastRemoteObject JavaDoc;
21 import java.util.Properties JavaDoc;
22 import javax.servlet.ServletConfig JavaDoc;
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,v 1.6.2.2 2004/05/20 03:05:18 seade Exp $
33  */

34 public class BaseUnicastRemoteService extends UnicastRemoteObject JavaDoc
35         implements Service
36 {
37     protected Configuration configuration;
38     private boolean isInitialized;
39     private InitableBroker initableBroker;
40     private String JavaDoc name;
41     private ServiceBroker serviceBroker;
42
43     public BaseUnicastRemoteService()
44             throws RemoteException JavaDoc
45     {
46         isInitialized = false;
47         initableBroker = null;
48         name = null;
49         serviceBroker = null;
50     }
51
52     /**
53      * Returns the configuration of this service.
54      *
55      * @return The configuration of this service.
56      */

57     public Configuration getConfiguration()
58     {
59         if (name == null)
60         {
61             return null;
62         }
63         else
64         {
65             if (configuration == null)
66             {
67                 configuration = getServiceBroker().getConfiguration(name);
68             }
69             return configuration;
70         }
71     }
72
73     public void init(ServletConfig JavaDoc config)
74             throws InitializationException
75     {
76         setInit(true);
77     }
78
79     public void setInitableBroker(InitableBroker broker)
80     {
81         this.initableBroker = broker;
82     }
83
84     public InitableBroker getInitableBroker()
85     {
86         return initableBroker;
87     }
88
89     public void init(Object JavaDoc data)
90             throws InitializationException
91     {
92         init((ServletConfig JavaDoc) data);
93     }
94
95     public void init() throws InitializationException
96     {
97         setInit(true);
98     }
99
100     protected void setInit(boolean value)
101     {
102         isInitialized = value;
103     }
104
105     public boolean getInit()
106     {
107         return isInitialized;
108     }
109
110     /**
111      * Shuts down this service.
112      */

113     public void shutdown()
114     {
115         setInit(false);
116     }
117
118     public Properties JavaDoc getProperties()
119     {
120         return ConfigurationConverter.getProperties(getConfiguration());
121     }
122
123     public void setName(String JavaDoc name)
124     {
125         this.name = name;
126     }
127
128     public String JavaDoc getName()
129     {
130         return name;
131     }
132
133     public ServiceBroker getServiceBroker()
134     {
135         return serviceBroker;
136     }
137
138     public void setServiceBroker(ServiceBroker broker)
139     {
140         this.serviceBroker = broker;
141     }
142 }
143
Popular Tags