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: import com.completex.objective.components.persistency.RuntimeValidationException;
012:
013: /**
014: * @author Gennady Krizhevsky
015: */
016: public class RuntimeRuleException extends RuntimeValidationException {
017: private static final String NL = RuleException.NL;
018: private RuleException[] elementExceptions;
019: private String fieldName = "";
020: private String message = "";
021: private String detailedMessage = "";
022:
023: public RuntimeRuleException(RuleException ruleException) {
024: if (ruleException != null) {
025: if (ruleException.hasElementExceptions()) {
026: this .elementExceptions = ruleException
027: .getElementExceptions();
028: } else {
029: setMessage(ruleException.getMessage());
030: setMessage(ruleException.getDetailedMessage());
031: }
032: }
033: }
034:
035: public RuntimeRuleException(RuleException[] elementExceptions) {
036: this .elementExceptions = elementExceptions;
037: }
038:
039: public RuntimeRuleException(String message) {
040: setMessage(message);
041: setDetailedMessage(message);
042: }
043:
044: public RuntimeRuleException(String message, String detailedMessage) {
045: setMessage(message);
046: setDetailedMessage(detailedMessage);
047: }
048:
049: public RuntimeRuleException(Throwable cause, String message) {
050: super (cause);
051: setMessage(message);
052: setDetailedMessage(message);
053: }
054:
055: public RuntimeRuleException setMessage(String message) {
056: fillInStackTrace();
057: this .message = message;
058: return this ;
059: }
060:
061: public String getDetailedMessage() {
062: return detailedMessage;
063: }
064:
065: public RuntimeRuleException setDetailedMessage(
066: String detailedMessage) {
067: this .detailedMessage = detailedMessage;
068: return this ;
069: }
070:
071: public String getFieldName() {
072: return fieldName;
073: }
074:
075: public RuntimeRuleException setFieldName(String fieldName) {
076: this .fieldName = fieldName;
077: return this ;
078: }
079:
080: public String getMessage() {
081: String localMessage = hasElementExceptions()
082: && !"".equals(message) ? message + NL : message;
083: return hasElementExceptions() ? localMessage + getFullMessage()
084: : localMessage;
085: }
086:
087: public boolean hasElementExceptions() {
088: return elementExceptions != null
089: && elementExceptions.length > 0;
090: }
091:
092: public void setElementExceptions(RuleException[] elementExceptions) {
093: this .elementExceptions = elementExceptions;
094: }
095:
096: public RuleException[] getElementExceptions() {
097: return elementExceptions;
098: }
099:
100: public String getFullMessage() {
101: return RuleException.getFullMessage(elementExceptions, message);
102: }
103:
104: public String getFullDetailedMessage() {
105: return RuleException.getFullDetailedMessage(elementExceptions,
106: message);
107: }
108:
109: }
|