openamf/src/java/org/openamf/invoker ServiceInvocationException.java,1.5,1.6

[email protected]
Newsgroups gmane.comp.java.openamf.cvs
Message-ID <[email protected]>
Update of /cvsroot/openamf/openamf/src/java/org/openamf/invoker
In directory sc8-pr-cvs1:/tmp/cvs-serv21427/src/java/org/openamf/invoker

Modified Files:
	ServiceInvocationException.java 
Log Message:
added abilty for the cause exception to override the code, level, description

Index: ServiceInvocationException.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/invoker/ServiceInvocationException.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ServiceInvocationException.java	8 May 2003 22:58:05 -0000	1.5
--- ServiceInvocationException.java	28 May 2003 01:02:42 -0000	1.6
***************
*** 1,4 ****
--- 1,8 ----
  package org.openamf.invoker;
  
+ import java.lang.reflect.Method;
+ 
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
  import org.openamf.AMFBody;
  import org.openamf.ServiceRequest;
***************
*** 7,10 ****
--- 11,16 ----
  public class ServiceInvocationException extends Exception {
  
+ 	private static final Log log = LogFactory.getLog(ServiceInvocationException.class);
+ 
  	protected AMFBody requestBody;
  	protected ServiceRequest request;
***************
*** 30,33 ****
--- 36,40 ----
  		this.request = request;
  	}
+ 	
  	public AMFError getAMFError() {
  		
***************
*** 43,49 ****
  		}		
  		
! 		amfError.setCode("SERVER.PROCESSING");
! 		amfError.setLevel("error");
! 		amfError.setType(stackTraceBuffer.toString());
  		
  		return amfError;
--- 50,60 ----
  		}		
  		
! 		log.debug(cause);
! 		
! 		amfError.setCode(getErrorValue(cause, "getCode", "SERVER.PROCESSING"));
! 		amfError.setLevel(getErrorValue(cause, "getError", "error"));
! 		amfError.setType(rootCause.getClass().toString());
! 		amfError.setDetails(stackTraceBuffer.toString());
! 		amfError.setDescription(getErrorValue(cause, "getDescription", rootCause.getMessage()));
  		
  		return amfError;
***************
*** 59,62 ****
--- 70,89 ----
  		}
  		
+ 	}
+ 	
+ 	private String getErrorValue(Throwable cause, String methodName, String defaultValue) {
+ 		
+ 		String value = null;
+ 		
+ 		try {
+ 			Method method = cause.getClass().getMethod(methodName, new Class[0]);
+ 			value = (String)method.invoke(cause, new Object[0]);
+ 		} catch (Exception e) {}
+ 		
+ 		if (value == null) {
+ 			value = defaultValue;
+ 		}
+ 		
+ 		return value;
  	}
  




-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.