View Javadoc

1   /* Generated by Together */
2   
3   package org.opensync.tools.exception;
4   
5   import org.opensync.tools.*;
6   
7   /***	Catch AssetPlus specific Exceptions
8   */
9   public class OpenSyncException extends Exception{
10  
11  
12  	protected String errorCode;
13  	protected String errorMsg;
14      protected String usrMsg = new String();
15  
16      private Throwable cause = null;
17  
18  
19  	/***
20  	* Creates an APException class with the error code.
21  	* @param errorCode Error code for which this exception was generated.
22  	*/
23  	public OpenSyncException(String errorCode)
24  	{
25  		this.errorCode = errorCode;
26  	}
27  
28  
29  	public OpenSyncException(String errorCode, Throwable cause)
30  	{
31  		this.errorCode = errorCode;
32  		this.cause = cause;
33  	}
34  
35  	/***
36  	* Creates an APException class with the error code.
37  	* @param errorCode Error code for which this exception was generated.
38  	*/
39  	public OpenSyncException(Throwable cause)
40  	{
41  		this.cause = cause;
42  	}
43  
44  	/***
45  	* Returns the error code.
46  	* @return returns the code.
47  	*/
48  	public String getCode()
49  	{
50  		return errorCode;
51  	}
52  
53  
54  	public Throwable getCause()
55  	{
56      	return cause;
57    	}
58  
59  
60  
61  	/***
62  	* Returns the user message associated with this error.
63  	* @return Returns the message associated with this error.
64  	*/
65      public String getUserMessage(String errorCode,String lang)
66      {
67      	if(Utils.debug) System.out.println("errorCode : " + errorCode + " lang : " + lang);
68  		//USE DICOREADER HERE TO GET THE APPROPRIATE MESSAGE
69          usrMsg =  DicoReader.getLabelDicoByKey(lang, errorCode);
70  
71          // Exception details
72          if (cause!=null) {
73            String msg = cause.getMessage();
74            String translatedMsg = DicoReader.getLabelDicoByKey(lang, msg);
75            //if ((msg!=null) && (!msg.equals("")) && (!msg.equals(translatedMsg))) usrMsg += " - " + translatedMsg;
76            if ((msg!=null) && (!msg.equals(""))) {
77              if (!msg.equals(translatedMsg)) usrMsg += " - " + translatedMsg;
78              if (cause.getMessage() != null && cause.getMessage() != "") usrMsg += "\n - " + cause.getMessage();
79            }
80          }
81  
82          if(Utils.debug) System.out.println("Got user msg : "+ usrMsg);
83          return usrMsg;
84  	}
85  
86  	/***
87  	* default action method.
88  	*/
89  	public void log()
90  	{
91  		//System.out.println(getMessage());
92  	}
93  
94  	/***
95  	* default action method.
96  	*/
97  	public void action()
98  	{
99  		log();
100 	}
101 
102 }