KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > tests > FakeErrorTask


1 /**
2  * $Id: FakeErrorTask.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2003 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.tests;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Task;
33
34 import com.idaremedia.antx.ErrorSnapshot;
35 import com.idaremedia.antx.helpers.Strings;
36 import com.idaremedia.antx.helpers.Tk;
37
38 /**
39  * Test helper task that creates an exception or ErrorSnapshot and saves the current
40  * project as a reference. Usually defined &lt;fakeerror&gt;
41  * <p>
42  * <b>Examples:</b><pre>
43  * <fakeerror errid="the.err" message="I'm dying here"/>
44  * <fakeerror errid="err.snapshot" snapshot="yes"/>
45  * <fakeerror errid="err.snapshot" snapshot="yes" properties="is.debug,is.opt"/>
46  * </pre>
47  *
48  * @since JWare/AntX 0.3
49  * @author ssmc, &copy;2003 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
50  * @version 0.5
51  * @.safety single
52  * @.group impl,test,helper
53  **/

54
55 public class FakeErrorTask extends Task
56 {
57     public FakeErrorTask()
58     {
59     }
60
61     public void setErrId(String JavaDoc refid)
62     {
63         m_errId = refid;
64     }
65
66     public String JavaDoc getErrId()
67     {
68         return m_errId;
69     }
70
71     public void setMsg(String JavaDoc msg)
72     {
73         m_msg = msg;
74     }
75
76     public final void setMessage(String JavaDoc msg)
77     {
78         setMsg(msg);
79     }
80
81     public String JavaDoc getMsg()
82     {
83         return m_msg;
84     }
85
86     public void setSnapshot(boolean isErrSnapshot)
87     {
88         m_isThrownX = !isErrSnapshot;
89     }
90
91     public boolean isThrown()
92     {
93         return m_isThrownX;
94     }
95
96     public boolean isSnapshot()
97     {
98         return !m_isThrownX;
99     }
100
101     public void setProperties(String JavaDoc nameList)
102     {
103         m_propertiesNameList = nameList;
104     }
105
106     public String JavaDoc getProperties()
107     {
108         return m_propertiesNameList;
109     }
110
111     public void execute()
112     {
113         if (m_isThrownX) {
114             BuildException X = new BuildException(getMsg(),getLocation());
115             getProject().addReference(getErrId(),X);
116         } else {
117             ErrorSnapshot X = new ErrorSnapshot(this);
118             X.setName(getErrId());
119             X.setComment(getMsg());
120             if (getProperties()!=null) {
121                 String JavaDoc lc = Tk.lowercaseFrom(getProperties());
122                 if (Strings.ALL.equals(lc)) {
123                     X.captureAllProperties();
124                 } else if (Strings.USER.equals(lc)) {
125                     X.captureUserProperties();
126                 } else {
127                     X.captureProperties(getProperties());
128                 }
129             }
130             getProject().addReference(getErrId(),X);
131         }
132     }
133
134     private String JavaDoc m_errId = "the.err";
135     private boolean m_isThrownX = true;
136     private String JavaDoc m_msg = "Aarrrghh";
137     private String JavaDoc m_propertiesNameList;
138 }
139
140 /* end-of-BarfFactoryTask.java */
141
Popular Tags