1 /* 2 * $Id$ 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 package org.apache.struts.util; 22 23 import org.apache.struts.action.ActionMessage; 24 25 /** 26 * Used for specialized exception handling. 27 */ 28 public class ModuleException extends Exception { 29 private static final long serialVersionUID = 623125126450529319L; 30 31 protected String property = null; 32 33 /** 34 * The ActionMessage associated with this exception. 35 * 36 * @since Struts 1.2 37 */ 38 protected ActionMessage message = null; 39 40 /** 41 * Construct an module exception with no replacement values. 42 * 43 * @param key Message key for this error message 44 */ 45 public ModuleException(String key) { 46 super(key); 47 message = new ActionMessage(key); 48 } 49 50 /** 51 * Construct an module exception with the specified replacement values. 52 * 53 * @param key Message key for this error message 54 * @param value First replacement value 55 */ 56 public ModuleException(String key, Object value) { 57 super(key); 58 message = new ActionMessage(key, value); 59 } 60 61 /** 62 * Construct an module exception with the specified replacement values. 63 * 64 * @param key Message key for this error message 65 * @param value0 First replacement value 66 * @param value1 Second replacement value 67 */ 68 public ModuleException(String key, Object value0, Object value1) { 69 super(key); 70 message = new ActionMessage(key, value0, value1); 71 } 72 73 /** 74 * Construct an module exception with the specified replacement values. 75 * 76 * @param key Message key for this error message 77 * @param value0 First replacement value 78 * @param value1 Second replacement value 79 * @param value2 Third replacement value 80 */ 81 public ModuleException(String key, Object value0, Object value1, 82 Object value2) { 83 super(key); 84 message = new ActionMessage(key, value0, value1, value2); 85 } 86 87 /** 88 * Construct an module exception with the specified replacement values. 89 * 90 * @param key Message key for this error message 91 * @param value0 First replacement value 92 * @param value1 Second replacement value 93 * @param value2 Third replacement value 94 * @param value3 Fourth replacement value 95 */ 96 public ModuleException(String key, Object value0, Object value1, 97 Object value2, Object value3) { 98 super(key); 99 message = new ActionMessage(key, value0, value1, value2, value3); 100 } 101 102 /** 103 * Construct an error with the specified replacement values. 104 * 105 * @param key Message key for this message 106 * @param values Array of replacement values 107 */ 108 public ModuleException(String key, Object[] values) { 109 super(key); 110 message = new ActionMessage(key, values); 111 } 112 113 /** 114 * Returns the property associated with the exception. 115 * 116 * @return Value of property. 117 */ 118 public String getProperty() { 119 return (property != null) ? property : message.getKey(); 120 } 121 122 /** 123 * Set the property associated with the exception. It can be a name of the 124 * edit field, which 'caused' the exception. 125 */ 126 public void setProperty(String property) { 127 this.property = property; 128 } 129 130 /** 131 * Returns the error associated with the exception. 132 * 133 * @return Value of property error. 134 * @since Struts 1.2 135 */ 136 public ActionMessage getActionMessage() { 137 return this.message; 138 } 139 }