KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > interfaces > InvalidValueException


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package hero.interfaces;
8
9 import java.util.Collection JavaDoc;
10
11 /**
12  * An instance of this class is thrown when a Value Object
13  * contains an invalid value. It parameters can then be used
14  * with {@link java.text.MessageFormat MessageFormat} to get
15  * right message. The message this exceptions contains is not
16  * the text but the key to get the right text from it.
17  *
18  * @author Andreas Schaefer
19  * @version $Revision: 1.1 $
20  **/

21 public class InvalidValueException
22    extends Exception JavaDoc
23 {
24    
25    // -------------------------------------------------------------------------
26
// Static
27
// -------------------------------------------------------------------------
28

29    // -------------------------------------------------------------------------
30
// Members
31
// -------------------------------------------------------------------------
32

33    private Object JavaDoc[] mParameters = new Object JavaDoc[ 0 ];
34
35    // -------------------------------------------------------------------------
36
// Constructor
37
// -------------------------------------------------------------------------
38

39    /**
40     * Constructor with a message handler and a list of parameters
41     *
42     * @param pMessageHandler Handler to lookup the right message
43     * @param pParameters One Parameter, array of parameters or a Collection
44     * of parameters or null
45     **/

46    public InvalidValueException( String JavaDoc pMessageHandler, Object JavaDoc pParameters )
47    {
48       super( pMessageHandler );
49       if( pParameters != null )
50       {
51          if( pParameters instanceof Collection JavaDoc )
52          {
53             mParameters = ( (Collection JavaDoc) pParameters ).toArray( new Object JavaDoc[ 0 ] );
54          }
55          else
56          {
57             if( pParameters instanceof Object JavaDoc[] )
58             {
59                mParameters = (Object JavaDoc[]) pParameters;
60             }
61             else
62             {
63                mParameters = new Object JavaDoc[] { pParameters };
64             }
65          }
66       }
67    }
68
69    // -------------------------------------------------------------------------
70
// Methods
71
// -------------------------------------------------------------------------
72

73    /**
74     * Returns the array of parameters coming along
75     *
76     * @return Array of parameters which are always defined but can be empty
77     **/

78    public Object JavaDoc[] getParameters()
79    {
80       return mParameters;
81    }
82    
83    /**
84     * Describes the instance and its content for debugging purpose
85     *
86     * @return Using the one from the super class
87     **/

88    public String JavaDoc toString()
89    {
90       return super.toString();
91    }
92
93    /**
94     * Determines if the given instance is the same as this instance
95     * based on its content. This means that it has to be of the same
96     * class ( or subclass ) and it has to have the same content
97     *
98     * @return Returns the equals value from the super class
99     **/

100    public boolean equals( Object JavaDoc pTest )
101    {
102       return super.equals( pTest );
103    }
104
105    /**
106     * Returns the hashcode of this instance
107     *
108     * @return Hashcode of the super class
109     **/

110    public int hashCode()
111    {
112       return super.hashCode();
113    }
114
115 }
116
Popular Tags