1 23 24 package org.apache.slide.common; 25 26 import java.util.Hashtable ; 27 28 import org.apache.slide.authenticate.CredentialsToken; 29 import org.apache.slide.util.logger.Logger; 30 31 36 public abstract class AbstractServiceBase implements Service { 37 38 39 41 protected String LOG_CHANNEL = this.getClass().getName(); 42 43 44 46 47 50 protected Namespace namespace; 51 52 53 protected Scope scope; 55 56 57 59 60 61 64 public void setScope(Scope scope) { 65 this.scope = scope; 66 } 67 68 69 70 73 public void setNamespace(Namespace namespace) { 74 this.namespace = namespace; 75 } 76 77 78 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 107 public abstract void setParameters(Hashtable parameters) 108 throws ServiceParameterErrorException, 109 ServiceParameterMissingException; 110 111 112 119 public void connect(CredentialsToken crdtoken) throws ServiceConnectionFailedException { 120 connect(); 121 } 122 123 124 125 130 public abstract void connect() 131 throws ServiceConnectionFailedException; 132 133 134 139 public abstract void disconnect() 140 throws ServiceDisconnectionFailedException; 141 142 143 151 public void initialize(NamespaceAccessToken token) 152 throws ServiceInitializationFailedException { 153 } 154 155 156 161 public abstract void reset() 162 throws ServiceResetFailedException; 163 164 165 171 public abstract boolean isConnected() 172 throws ServiceAccessException; 173 174 175 183 public boolean connectIfNeeded(CredentialsToken token) 184 throws ServiceConnectionFailedException, ServiceAccessException { 185 boolean result = true; 186 try { 187 result = !isConnected(); 188 } catch (ServiceAccessException e) { 189 } 191 if (result) { 192 connect(token); 193 } 194 return result; 195 } 196 197 198 199 206 public boolean connectIfNeeded() 207 throws ServiceConnectionFailedException, ServiceAccessException { 208 boolean result = true; 209 try { 210 result = !isConnected(); 211 } catch (ServiceAccessException e) { 212 } 214 if (result) { 215 connect(); 216 } 217 return result; 218 } 219 220 221 227 public boolean cacheResults() { 228 return true; 229 } 230 231 232 234 235 } 236 237 | Popular Tags |