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