1 23 24 package org.apache.slide.common; 25 26 import java.util.Hashtable ; 27 28 import org.apache.commons.transaction.util.LoggerFacade; 29 import org.apache.slide.authenticate.CredentialsToken; 30 import org.apache.commons.transaction.util.xa.AbstractXAResource; 31 import org.apache.slide.util.logger.Logger; 32 import org.apache.slide.util.logger.TxLogger; 33 34 39 public abstract class AbstractXAServiceBase extends AbstractXAResource implements Service { 40 41 42 44 protected String LOG_CHANNEL = this.getClass().getName(); 45 46 47 49 50 53 protected Namespace namespace; 54 55 56 protected Scope scope; 58 59 protected LoggerFacade loggerFacade = null; 60 61 63 64 65 68 public void setScope(Scope scope) { 69 this.scope = scope; 70 } 71 72 73 74 77 public void setNamespace(Namespace namespace) { 78 this.namespace = namespace; 79 } 80 81 82 85 public Logger getLogger() { 86 Logger logger = null; 87 if (namespace != null) { 88 logger = this.namespace.getLogger(); 89 } 90 if (logger == null) 91 logger = Domain.getLogger(); 92 return logger; 93 } 94 95 96 protected LoggerFacade getLoggerFacade() { 97 if (loggerFacade == null) { 98 loggerFacade = new TxLogger(getLogger(), LOG_CHANNEL); 99 } 100 return loggerFacade; 101 } 102 103 104 117 public abstract void setParameters(Hashtable parameters) 118 throws ServiceParameterErrorException, 119 ServiceParameterMissingException; 120 121 122 129 public void connect(CredentialsToken crdtoken) throws ServiceConnectionFailedException { 130 connect(); 131 } 132 133 134 135 140 public abstract void connect() 141 throws ServiceConnectionFailedException; 142 143 144 149 public abstract void disconnect() 150 throws ServiceDisconnectionFailedException; 151 152 153 161 public void initialize(NamespaceAccessToken token) 162 throws ServiceInitializationFailedException { 163 } 164 165 166 171 public abstract void reset() 172 throws ServiceResetFailedException; 173 174 175 181 public abstract boolean isConnected() 182 throws ServiceAccessException; 183 184 185 193 public boolean connectIfNeeded(CredentialsToken token) 194 throws ServiceConnectionFailedException, ServiceAccessException { 195 boolean result = true; 196 try { 197 result = !isConnected(); 198 } catch (ServiceAccessException e) { 199 } 201 if (result) { 202 connect(token); 203 } 204 return result; 205 } 206 207 208 209 216 public boolean connectIfNeeded() 217 throws ServiceConnectionFailedException, ServiceAccessException { 218 boolean result = true; 219 try { 220 result = !isConnected(); 221 } catch (ServiceAccessException e) { 222 } 224 if (result) { 225 connect(); 226 } 227 return result; 228 } 229 230 231 237 public boolean cacheResults() { 238 return true; 239 } 240 241 242 244 245 } 246 247 | Popular Tags |