View Javadoc

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