001: /*
002: * $Id: ModuleException.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.util;
022:
023: import org.apache.struts.action.ActionMessage;
024:
025: /**
026: * Used for specialized exception handling.
027: */
028: public class ModuleException extends Exception {
029: protected String property = null;
030:
031: /**
032: * The ActionMessage associated with this exception.
033: *
034: * @since Struts 1.2
035: */
036: protected ActionMessage message = null;
037:
038: /**
039: * Construct an module exception with no replacement values.
040: *
041: * @param key Message key for this error message
042: */
043: public ModuleException(String key) {
044: super (key);
045: message = new ActionMessage(key);
046: }
047:
048: /**
049: * Construct an module exception with the specified replacement values.
050: *
051: * @param key Message key for this error message
052: * @param value First replacement value
053: */
054: public ModuleException(String key, Object value) {
055: super (key);
056: message = new ActionMessage(key, value);
057: }
058:
059: /**
060: * Construct an module exception with the specified replacement values.
061: *
062: * @param key Message key for this error message
063: * @param value0 First replacement value
064: * @param value1 Second replacement value
065: */
066: public ModuleException(String key, Object value0, Object value1) {
067: super (key);
068: message = new ActionMessage(key, value0, value1);
069: }
070:
071: /**
072: * Construct an module exception with the specified replacement values.
073: *
074: * @param key Message key for this error message
075: * @param value0 First replacement value
076: * @param value1 Second replacement value
077: * @param value2 Third replacement value
078: */
079: public ModuleException(String key, Object value0, Object value1,
080: Object value2) {
081: super (key);
082: message = new ActionMessage(key, value0, value1, value2);
083: }
084:
085: /**
086: * Construct an module exception with the specified replacement values.
087: *
088: * @param key Message key for this error message
089: * @param value0 First replacement value
090: * @param value1 Second replacement value
091: * @param value2 Third replacement value
092: * @param value3 Fourth replacement value
093: */
094: public ModuleException(String key, Object value0, Object value1,
095: Object value2, Object value3) {
096: super (key);
097: message = new ActionMessage(key, value0, value1, value2, value3);
098: }
099:
100: /**
101: * Construct an error with the specified replacement values.
102: *
103: * @param key Message key for this message
104: * @param values Array of replacement values
105: */
106: public ModuleException(String key, Object[] values) {
107: super (key);
108: message = new ActionMessage(key, values);
109: }
110:
111: /**
112: * Returns the property associated with the exception.
113: *
114: * @return Value of property.
115: */
116: public String getProperty() {
117: return (property != null) ? property : message.getKey();
118: }
119:
120: /**
121: * Set the property associated with the exception. It can be a name of the
122: * edit field, which 'caused' the exception.
123: */
124: public void setProperty(String property) {
125: this .property = property;
126: }
127:
128: /**
129: * Returns the error associated with the exception.
130: *
131: * @return Value of property error.
132: * @since Struts 1.2
133: */
134: public ActionMessage getActionMessage() {
135: return this.message;
136: }
137: }
|