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