1 23 24 package org.apache.slide.common; 25 26 import java.io.PrintWriter ; 27 import java.io.StringWriter ; 28 import org.apache.slide.common.Domain; 29 import org.apache.slide.util.Messages; 30 import org.apache.slide.util.logger.Logger; 31 32 37 public class ServiceAccessException extends SlideException { 38 39 private static final String CHANNEL = "org.apache.slide.common.ServiceAccessException"; 40 private static final int DEBUG = Logger.DEBUG; 41 private static Logger LOGGER = Domain.getLogger(); 42 43 44 private Throwable nestedException = null; 45 46 48 54 public ServiceAccessException(Service service, String cause) { 55 super(Messages.format 56 (ServiceAccessException.class.getName(), service, computeCause(cause)), false); 57 58 if (LOGGER.isEnabled(CHANNEL, DEBUG)) { 59 StringWriter sw = new StringWriter (); 60 printStackTrace( new PrintWriter (sw, true) ); LOGGER.log( sw.toString(), CHANNEL, DEBUG ); 62 } 63 } 64 65 71 public ServiceAccessException(Service service, Throwable e) { 72 this(service, computeCause(e)); 73 nestedException = e; 74 } 75 76 82 private static String computeCause(String delieveredCause, Throwable e) { 83 String result = delieveredCause; 84 if (delieveredCause == null || delieveredCause.equals("")) { 85 StringWriter sw = new StringWriter (); 86 e.printStackTrace(new PrintWriter (sw, true)); result = sw.toString(); 88 } 89 return result; 90 } 91 92 97 private static String computeCause(String delieveredCause) { 98 if (delieveredCause == null || delieveredCause.equals("")) { 99 return "cause is empty"; 100 } else { 101 return delieveredCause; 102 } 103 } 104 105 110 private static String computeCause(Throwable e) { 111 return computeCause(e.getMessage(), e); 112 } 113 114 117 public Throwable getCauseException() { 118 return nestedException; 119 } 120 121 } 122 | Popular Tags |