001: // Copyright (c) 2004-2005 Sun Microsystems Inc., All Rights Reserved.
002:
003: /*
004: * UtilBase.java
005: *
006: * SUN PROPRIETARY/CONFIDENTIAL.
007: * This software is the proprietary information of Sun Microsystems, Inc.
008: * Use is subject to license terms.
009: *
010: */
011: package com.sun.jbi.engine.sequencing.util;
012:
013: /**
014: * Base class for error/status reporting.
015: *
016: * @author Sun Microsystems, Inc.
017: */
018: public class UtilBase {
019: /**
020: * Exception.
021: */
022: private Exception mException;
023:
024: /**
025: * Error.
026: */
027: private StringBuffer mError;
028:
029: /**
030: * Warning.
031: */
032: private StringBuffer mWarning;
033:
034: /**
035: * Validity.
036: */
037: private boolean mValid = true;
038:
039: /**
040: * Creates a new UtilBase object.
041: */
042: public UtilBase() {
043: mError = new StringBuffer();
044: mWarning = new StringBuffer();
045: }
046:
047: /**
048: * Sets the error.
049: *
050: * @param err error string.
051: */
052: public void setError(String err) {
053: mValid = false;
054:
055: if (err != null) {
056: if (!err.trim().equals("")) {
057: mError.append("\nError : " + "Reason : " + err);
058: }
059: }
060: }
061:
062: /**
063: * Gets the error.
064: *
065: * @return error.
066: */
067: public String getError() {
068: return mError.toString();
069: }
070:
071: /**
072: * Sets the excpetion.
073: *
074: * @param ex exception.
075: */
076: public void setException(Exception ex) {
077: mValid = false;
078: mException = ex;
079: mError.append(ex.getMessage());
080: }
081:
082: /**
083: * Gets the exception.
084: *
085: * @return exception.
086: */
087: public Exception getException() {
088: if (!mError.toString().trim().equals("")) {
089: mException = new Exception(mError.toString());
090: }
091:
092: return mException;
093: }
094:
095: /**
096: * Validity.
097: *
098: * @return true if valid.
099: */
100: public boolean isValid() {
101: return mValid;
102: }
103:
104: /**
105: * Returns the warning.
106: *
107: * @return warning.
108: */
109: public String getWarning() {
110: return mWarning.toString();
111: }
112:
113: /**
114: *
115: */
116: public void clear() {
117: mException = null;
118: mValid = true;
119: mError = new StringBuffer();
120: mWarning = new StringBuffer();
121: }
122:
123: /**
124: * Sets the validity.
125: *
126: * @param valid true if valid.
127: */
128: protected void setValid(boolean valid) {
129: mValid = valid;
130: }
131:
132: /**
133: * Sets the warning.
134: *
135: * @param warn warning string.
136: */
137: protected void setWarning(String warn) {
138: if (warn != null) {
139: if (!warn.trim().equals("")) {
140: mWarning.append("\nWarning : " + "Reason : " + warn);
141: }
142: }
143: }
144: }
|