001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)UtilBase.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.engine.sequencing.util;
030:
031: /**
032: * Base class for error/status reporting.
033: *
034: * @author Sun Microsystems, Inc.
035: */
036: public class UtilBase {
037: /**
038: * Exception.
039: */
040: private Exception mException;
041:
042: /**
043: * Error.
044: */
045: private StringBuffer mError;
046:
047: /**
048: * Warning.
049: */
050: private StringBuffer mWarning;
051:
052: /**
053: * Validity.
054: */
055: private boolean mValid = true;
056:
057: /**
058: * Creates a new UtilBase object.
059: */
060: public UtilBase() {
061: mError = new StringBuffer();
062: mWarning = new StringBuffer();
063: }
064:
065: /**
066: * Sets the error.
067: *
068: * @param err error string.
069: */
070: public void setError(String err) {
071: mValid = false;
072:
073: if (err != null) {
074: if (!err.trim().equals("")) {
075: mError.append("\nError : " + "Reason : " + err);
076: }
077: }
078: }
079:
080: /**
081: * Gets the error.
082: *
083: * @return error.
084: */
085: public String getError() {
086: return mError.toString();
087: }
088:
089: /**
090: * Sets the excpetion.
091: *
092: * @param ex exception.
093: */
094: public void setException(Exception ex) {
095: mValid = false;
096: mException = ex;
097: mError.append(ex.getMessage());
098: }
099:
100: /**
101: * Gets the exception.
102: *
103: * @return exception.
104: */
105: public Exception getException() {
106: if (!mError.toString().trim().equals("")) {
107: mException = new Exception(mError.toString());
108: }
109:
110: return mException;
111: }
112:
113: /**
114: * Validity.
115: *
116: * @return true if valid.
117: */
118: public boolean isValid() {
119: return mValid;
120: }
121:
122: /**
123: * Returns the warning.
124: *
125: * @return warning.
126: */
127: public String getWarning() {
128: return mWarning.toString();
129: }
130:
131: /**
132: *
133: */
134: public void clear() {
135: mException = null;
136: mValid = true;
137: mError = new StringBuffer();
138: mWarning = new StringBuffer();
139: }
140:
141: /**
142: * Sets the validity.
143: *
144: * @param valid true if valid.
145: */
146: protected void setValid(boolean valid) {
147: mValid = valid;
148: }
149:
150: /**
151: * Sets the warning.
152: *
153: * @param warn warning string.
154: */
155: protected void setWarning(String warn) {
156: if (warn != null) {
157: if (!warn.trim().equals("")) {
158: mWarning.append("\nWarning : " + "Reason : " + warn);
159: }
160: }
161: }
162: }
|