KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > common > AbstractServiceBase


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/AbstractServiceBase.java,v 1.12 2004/07/28 09:38:23 ib Exp $
3  * $Revision: 1.12 $
4  * $Date: 2004/07/28 09:38:23 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.common;
25
26 import java.util.Hashtable JavaDoc;
27
28 import org.apache.slide.authenticate.CredentialsToken;
29 import org.apache.slide.util.logger.Logger;
30
31 /**
32  * Slide Service abstract implementation.
33  *
34  * @version $Revision: 1.12 $
35  */

36 public abstract class AbstractServiceBase implements Service {
37     
38     
39     // -------------------------------------------------------------- Constants
40

41     protected String JavaDoc LOG_CHANNEL = this.getClass().getName();
42     
43     
44     // ----------------------------------------------------- Instance Variables
45

46     
47     /**
48      * Namespace.
49      */

50     protected Namespace namespace;
51     
52     
53     // the scope of this store as specified in domain.xml
54
protected Scope scope;
55     
56     
57     // -------------------------------------------------------- Service Methods
58

59     
60     
61     /**
62      * Set the scope of the store as specified in domain.xml.
63      */

64     public void setScope(Scope scope) {
65         this.scope = scope;
66     }
67     
68     
69     
70     /**
71      * Namespace setter.
72      */

73     public void setNamespace(Namespace namespace) {
74         this.namespace = namespace;
75     }
76     
77     
78     /**
79      * Logger accessor.
80      */

81     public Logger getLogger() {
82         Logger logger = null;
83         if (namespace != null) {
84             logger = this.namespace.getLogger();
85         }
86         if (logger == null)
87             logger = Domain.getLogger();
88         return logger;
89     }
90     
91     
92     
93     
94     /**
95      * Initializes the service with a set of parameters. Those could be :
96      * <li>User name, login info
97      * <li>Host name on which to connect
98      * <li>Remote port
99      * <li>JDBC driver whoich is to be used :-)
100      * <li>Anything else ...
101      *
102      * @param parameters Hashtable containing the parameters' names
103      * and associated values
104      * @exception ServiceParameterErrorException Incorrect service parameter
105      * @exception ServiceParameterMissingException Service parameter missing
106      */

107     public abstract void setParameters(Hashtable JavaDoc parameters)
108         throws ServiceParameterErrorException,
109         ServiceParameterMissingException;
110     
111     
112     /**
113      * Connects to the underlying data source (if any is needed).
114      * Compatibility implementation for the previous store implementations
115      *
116      * @param crdtoken the slide token containing e.g. the credential
117      * @exception ServiceConnectionFailedException Connection failed
118      */

119     public void connect(CredentialsToken crdtoken) throws ServiceConnectionFailedException {
120         connect();
121     }
122     
123     
124     
125     /**
126      * Connects to the underlying data source (if any is needed).
127      *
128      * @exception ServiceConnectionFailedException Connection failed
129      */

130     public abstract void connect()
131         throws ServiceConnectionFailedException;
132     
133     
134     /**
135      * Disconnects from the underlying data source.
136      *
137      * @exception ServiceDisconnectionFailedException Disconnection failed
138      */

139     public abstract void disconnect()
140         throws ServiceDisconnectionFailedException;
141     
142     
143     /**
144      * Initializes service.
145      *
146      * @param token Namespace access token, needed if the service needs to
147      * access objects or data within the namespace during its initialization
148      * @exception ServiceInitializationFailedException May throw an exception
149      * if the service has already been initialized before
150      */

151     public void initialize(NamespaceAccessToken token)
152         throws ServiceInitializationFailedException {
153     }
154     
155     
156     /**
157      * Deletes service underlying data source, if possible (and meaningful).
158      *
159      * @exception ServiceResetFailedException Reset failed
160      */

161     public abstract void reset()
162         throws ServiceResetFailedException;
163     
164     
165     /**
166      * This function tells whether or not the service is connected.
167      *
168      * @return boolean true if we are connected
169      * @exception ServiceAccessException Service access error
170      */

171     public abstract boolean isConnected()
172         throws ServiceAccessException;
173     
174     
175     /**
176      * Connects to the service, if we were not previously connected.
177      *
178      * @param token the Credeantials token containing e.g. the credential
179      * @return boolean true if we were not already connected
180      * @exception ServiceAccessException Unspecified service access error
181      * @exception ServiceConnectionFailedException Connection failed
182      */

183     public boolean connectIfNeeded(CredentialsToken token)
184         throws ServiceConnectionFailedException, ServiceAccessException {
185         boolean result = true;
186         try {
187             result = !isConnected();
188         } catch (ServiceAccessException e) {
189             // Ignore : Will try to reconnect
190
}
191         if (result) {
192             connect(token);
193         }
194         return result;
195     }
196     
197     
198     
199     /**
200      * Connects to the service, if we were not previously connected.
201      *
202      * @return boolean true if we were not already connected
203      * @exception ServiceAccessException Unspecified service access error
204      * @exception ServiceConnectionFailedException Connection failed
205      */

206     public boolean connectIfNeeded()
207         throws ServiceConnectionFailedException, ServiceAccessException {
208         boolean result = true;
209         try {
210             result = !isConnected();
211         } catch (ServiceAccessException e) {
212             // Ignore : Will try to reconnect
213
}
214         if (result) {
215             connect();
216         }
217         return result;
218     }
219     
220     
221     /**
222      * Indicates whether or not the objects managed by this service should be
223      * cached. Caching is enabled by default.
224      *
225      * @return boolean True if results should be cached
226      */

227     public boolean cacheResults() {
228         return true;
229     }
230     
231     
232     // ----------------------------------------------------- XAResource Mathods
233

234     
235 }
236
237
Popular Tags