001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency.rule;
010:
011: /**
012: * @author Gennady Krizhevsky
013: */
014: public class RuleException extends Exception {
015: public static final String NL = "\r\n";
016:
017: private RuleException[] elementExceptions;
018: private String fieldName = "";
019: private String message = "";
020: private String detailedMessage = "";
021:
022: public RuleException(RuleException[] elementExceptions) {
023: this .elementExceptions = elementExceptions;
024: }
025:
026: public RuleException(String message) {
027: setMessage(message);
028: setDetailedMessage(message);
029: }
030:
031: public RuleException(String message, String detailedMessage) {
032: setMessage(message);
033: setDetailedMessage(detailedMessage);
034: }
035:
036: public RuleException(Throwable cause, String message) {
037: super (cause);
038: setMessage(message);
039: setDetailedMessage(message);
040: }
041:
042: public RuleException setMessage(String message) {
043: fillInStackTrace();
044: this .message = message == null ? "" : message;
045: return this ;
046: }
047:
048: public String getDetailedMessage() {
049: return detailedMessage;
050: }
051:
052: public RuleException setDetailedMessage(String detailedMessage) {
053: this .detailedMessage = detailedMessage;
054: return this ;
055: }
056:
057: public String getFieldName() {
058: return fieldName;
059: }
060:
061: public RuleException setFieldName(String fieldName) {
062: this .fieldName = fieldName;
063: return this ;
064: }
065:
066: public String getMessage() {
067: String localMessage = hasElementExceptions()
068: && !"".equals(message) ? message + NL : message;
069: return hasElementExceptions() ? localMessage + getFullMessage()
070: : localMessage;
071: }
072:
073: public boolean hasElementExceptions() {
074: return elementExceptions != null
075: && elementExceptions.length > 0;
076: }
077:
078: public void setElementExceptions(RuleException[] elementExceptions) {
079: this .elementExceptions = elementExceptions;
080: }
081:
082: public RuleException[] getElementExceptions() {
083: return elementExceptions;
084: }
085:
086: public String getFullMessage() {
087: return getFullMessage(elementExceptions, message);
088: }
089:
090: public String getFullDetailedMessage() {
091: return getFullDetailedMessage(elementExceptions, message);
092: }
093:
094: public static String getFullMessage(
095: RuleException[] elementExceptions, String message) {
096: StringBuffer buffer = new StringBuffer(message).append(NL);
097: if (elementExceptions != null && elementExceptions.length > 0) {
098: for (int i = 0; i < elementExceptions.length; i++) {
099: buffer.append(elementExceptions[i].getMessage())
100: .append(NL);
101: }
102: }
103: return buffer.toString();
104: }
105:
106: public static String getFullDetailedMessage(
107: RuleException[] elementExceptions, String message) {
108: StringBuffer buffer = new StringBuffer(message).append(NL);
109: if (elementExceptions != null && elementExceptions.length > 0) {
110: for (int i = 0; i < elementExceptions.length; i++) {
111: buffer
112: .append(
113: elementExceptions[i]
114: .getDetailedMessage()).append(
115: NL);
116: }
117: }
118: return buffer.toString();
119: }
120:
121: }
|