KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > apis > BuildAssertionException


1 /**
2  * $Id: BuildAssertionException.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2003-2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.apis;
30
31 import java.lang.reflect.Constructor JavaDoc;
32 import java.lang.reflect.Method JavaDoc;
33
34 import org.apache.tools.ant.BuildException;
35 import org.apache.tools.ant.Location;
36
37 /**
38  * Failed build assertion exception thrown by any application-controlled fixture and
39  * iteration verifying task like the AntX
40  * {@linkplain com.idaremedia.antx.condition.solo.AssertTask AssertTask AssertTask}.
41  *
42  * @since JWare/AntX 0.1
43  * @author ssmc, &copy;2003-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
44  * @version 0.5
45  * @.safety single
46  * @.group impl,infra
47  * @see BuildError
48  **/

49
50 public class BuildAssertionException extends BuildException
51 {
52     /**
53      * Creates new default build assertion exception.
54      **/

55     public BuildAssertionException()
56     {
57         super("Assertion Failed");
58         initJUnitLink();
59     }
60
61
62     /**
63      * Creates new custom build assertion exception.
64      * @param msg exception's human-readable message (non-null)
65      **/

66     public BuildAssertionException(String JavaDoc msg)
67     {
68         super(msg);
69         initJUnitLink();
70     }
71
72
73     /**
74      * Creates new custom build assertion exception with source
75      * location.
76      * @param msg exception's human-readable message (non-null)
77      * @param location build file location
78      **/

79     public BuildAssertionException(String JavaDoc msg, Location location)
80     {
81         super(msg,location);
82         initJUnitLink();
83     }
84
85
86     /**
87      * Creates new custom build assertion exception based
88      * on an existing exception (called the <i>cause</i>).
89      * @param msg exception's human-readable message (non-null)
90      * @param cause original problem (non-null)
91      **/

92     public BuildAssertionException(String JavaDoc msg, Throwable JavaDoc cause)
93     {
94         super(msg,cause);
95         initJUnitLink();
96     }
97
98
99     /**
100      * Creates new custom build assertion exception based
101      * on existing exception (called the <i>cause</i>) and build
102      * file location.
103      * @param msg exception's human-readable message (non-null)
104      * @param cause original problem (non-null)
105      * @param location build file location (non-null)
106      **/

107     public BuildAssertionException(String JavaDoc msg, Throwable JavaDoc cause,
108                                    Location location)
109     {
110         super(msg,cause,location);
111         initJUnitLink();
112     }
113
114
115     /**
116      * Creates new build assertion exception based on
117      * existing exception (called tehe <i>cause</i>).
118      * @param cause original problem (non-null)
119      **/

120     public BuildAssertionException(Throwable JavaDoc cause)
121     {
122         super(cause);
123         initJUnitLink();
124     }
125
126
127     /**
128      * Creates new build assertion exception based on
129      * existing exception (called the <i>cause</i>) and build
130      * file location.
131      * @param cause original problem (non-null)
132      * @param location build file location (non-null)
133      **/

134     public BuildAssertionException(Throwable JavaDoc cause, Location location)
135     {
136         super(cause,location);
137         initJUnitLink();
138     }
139
140
141
142     private static final Class JavaDoc[] AFE_SIG0= new Class JavaDoc[]{String JavaDoc.class};
143     private static final Class JavaDoc[] AFE_SIG1= new Class JavaDoc[]{Throwable JavaDoc.class};
144
145
146     /**
147      * Try to create a JUnit-link assertion that includes the
148      * real source of the assertion failure.
149      * @since JWare/AntX 0.4
150      **/

151     private void initJUnitLink()
152     {
153         try {
154             //@.impl Use this.toString() to capture location information
155
// directly in assertion exception message (ssmc).
156
Class JavaDoc c = Class.forName("junit.framework.AssertionFailedError");
157             Constructor JavaDoc ctor = c.getConstructor(AFE_SIG0);
158             m_linkJUnit = (Throwable JavaDoc)ctor.newInstance(new Object JavaDoc[]{toString()});
159             Method JavaDoc m= c.getMethod("initCause",AFE_SIG1);
160             m.invoke(m_linkJUnit, new Object JavaDoc[]{this});
161         } catch(Exception JavaDoc anyX) {/*burp*/}
162     }
163
164
165
166     /**
167      * Returns this exception's associated JUnit-related failure
168      * error. Will return <i>null</i> if was unable to create this
169      * link. If not <i>null</i> the returned throwable is of type
170      * <span class="src">junit.framework.AssertionFailedError</span>.
171      * @since JWare/AntX 0.4
172      **/

173     public final Throwable JavaDoc getJUnitLink()
174     {
175         return m_linkJUnit;
176     }
177
178
179     private Throwable JavaDoc m_linkJUnit;
180 }
181
182
183 /* end-of-BuildAssertionException.java */
184
Popular Tags