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.binding.jms.util;
030:
031: /**
032: * Base class that supports error handling.
033: *
034: * @author Sun Microsystems Inc.
035: */
036: public class UtilBase {
037: /**
038: * Exception.
039: */
040: private Exception mException;
041:
042: /**
043: * Error string.
044: */
045: private StringBuffer mError;
046: /**
047: * Warning string.
048: */
049: private StringBuffer mWarning;
050: /**
051: * Validity sttaus.
052: */
053: private boolean mValid = true;
054:
055: /**
056: * Creates a new UtilBase object.
057: */
058: public UtilBase() {
059: mError = new StringBuffer();
060: mWarning = new StringBuffer();
061: }
062:
063: /**
064: * Sets the error.
065: *
066: * @param err error string.
067: */
068: public void setError(String err) {
069: mValid = false;
070:
071: if (err != null) {
072: if (!err.trim().equals("")) {
073: mError.append("\nError : " + "Reason : " + err);
074: }
075: }
076: }
077:
078: /**
079: * Gets the error.
080: *
081: * @return error string.
082: */
083: public String getError() {
084: return mError.toString();
085: }
086:
087: /**
088: * Sets the exception.
089: *
090: * @param ex exception.
091: */
092: public void setException(Exception ex) {
093: mValid = false;
094: mException = ex;
095: mError.append(ex.getMessage());
096: }
097:
098: /**
099: * Gets the exception.
100: *
101: * @return exception.
102: */
103: public Exception getException() {
104: if (!mError.toString().trim().equals("")) {
105: mException = new Exception(mError.toString());
106: }
107:
108: return mException;
109: }
110:
111: /**
112: * Checks the validity.
113: *
114: * @return true if valid.
115: */
116: public boolean isValid() {
117: return mValid;
118: }
119:
120: /**
121: * Gets the warning.
122: *
123: * @return warning string.
124: */
125: public String getWarning() {
126: return mWarning.toString();
127: }
128:
129: /**
130: * Clears the error and warning.
131: */
132: public void clear() {
133: mException = null;
134: mValid = true;
135: mError = new StringBuffer();
136: mWarning = new StringBuffer();
137: }
138:
139: /**
140: * Sets the validity.
141: *
142: * @param valid true/false.
143: */
144: protected void setValid(boolean valid) {
145: mValid = valid;
146: }
147:
148: /**
149: * Sets the warning.
150: *
151: * @param warn warnign string.
152: */
153: protected void setWarning(String warn) {
154: if (warn != null) {
155: if (!warn.trim().equals("")) {
156: mWarning.append("\nWarning : " + "Reason : " + warn);
157: }
158: }
159: }
160: }
|