KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > spi > AntEvent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.tools.ant.module.spi;
21
22 import java.io.File JavaDoc;
23 import java.util.Set JavaDoc;
24 import org.apache.tools.ant.module.run.LoggerTrampoline;
25
26 /**
27  * One event delivered to an {@link AntLogger}.
28  * <p>
29  * Note that one event is shared across all listeners.
30  * </p>
31  * <p>
32  * The information available from the event represents a best effort to gather
33  * information from the Ant run. Some versions of Ant may not support all of
34  * these capabilities, in which case the event method will simply return null
35  * or whatever the documented fallback value is. For example, Ant 1.5 does
36  * not permit details of task structure to be introspected, but 1.6 does.
37  * </p>
38  * @author Jesse Glick
39  * @since org.apache.tools.ant.module/3 3.12
40  */

41 public final class AntEvent {
42
43     static {
44         LoggerTrampoline.ANT_EVENT_CREATOR = new LoggerTrampoline.Creator() {
45             public AntSession makeAntSession(LoggerTrampoline.AntSessionImpl impl) {
46                 throw new AssertionError JavaDoc();
47             }
48             public AntEvent makeAntEvent(LoggerTrampoline.AntEventImpl impl) {
49                 return new AntEvent(impl);
50             }
51             public TaskStructure makeTaskStructure(LoggerTrampoline.TaskStructureImpl impl) {
52                 throw new AssertionError JavaDoc();
53             }
54         };
55     }
56     
57     private final LoggerTrampoline.AntEventImpl impl;
58     private AntEvent(LoggerTrampoline.AntEventImpl impl) {
59         this.impl = impl;
60     }
61     
62     /**
63      * Error log level.
64      */

65     public static final int LOG_ERR = 0;
66     
67     /**
68      * Warning log level.
69      */

70     public static final int LOG_WARN = 1;
71     
72     /**
73      * Information log level.
74      */

75     public static final int LOG_INFO = 2;
76     
77     /**
78      * Verbose log level.
79      */

80     public static final int LOG_VERBOSE = 3;
81     
82     /**
83      * Debugging log level.
84      */

85     public static final int LOG_DEBUG = 4;
86     
87     /**
88      * Get the associated session.
89      * @return the session object
90      */

91     public AntSession getSession() {
92         return impl.getSession();
93     }
94     
95     /**
96      * Mark an event as consumed to advise other loggers not to handle it.
97      * @throws IllegalStateException if it was already consumed
98      */

99     public void consume() throws IllegalStateException JavaDoc {
100         impl.consume();
101     }
102     
103     /**
104      * Test whether this event has already been consumed by some other logger.
105      * @return true if it has already been consumed
106      */

107     public boolean isConsumed() {
108         return impl.isConsumed();
109     }
110     
111     /**
112      * Get the location of the Ant script producing this event.
113      * @return the script location, or null if unknown
114      */

115     public File JavaDoc getScriptLocation() {
116         return impl.getScriptLocation();
117     }
118     
119     /**
120      * Get the line number in {@link #getScriptLocation} corresponding to this event.
121      * Line numbers start at one.
122      * @return the line number, or -1 if unknown
123      */

124     public int getLine() {
125         return impl.getLine();
126     }
127     
128     /**
129      * Get the name of the target in {@link #getScriptLocation} producing this event.
130      * Some events occur outside targets and so there will be no target name.
131      * @return the target name (never empty), or null if unknown or inapplicable
132      */

133     public String JavaDoc getTargetName() {
134         return impl.getTargetName();
135     }
136     
137     /**
138      * Get the name of the task producing this event.
139      * XXX semantics w.r.t. namespaces, taskdefs, etc.?
140      * Some events occur outside of tasks and so there will be no name.
141      * @return the task name (never empty), or null if unknown or inapplicable
142      */

143     public String JavaDoc getTaskName() {
144         return impl.getTaskName();
145     }
146     
147     /**
148      * Get the configured XML structure of the task producing this event.
149      * Some events occur outside of tasks and so there will be no information.
150      * @return the task structure, or null if unknown or inapplicable
151      */

152     public TaskStructure getTaskStructure() {
153         return impl.getTaskStructure();
154     }
155     
156     /**
157      * Get the name of the message being logged.
158      * Applies only to {@link AntLogger#messageLogged}.
159      * @return the message, or null if inapplicable
160      */

161     public String JavaDoc getMessage() {
162         return impl.getMessage();
163     }
164     
165     /**
166      * Get the log level of the message.
167      * Applies only to {@link AntLogger#messageLogged}.
168      * Note that lower numbers are higher priority.
169      * @return the log level (e.g. LOG_INFO), or -1 if inapplicable
170      */

171     public int getLogLevel() {
172         return impl.getLogLevel();
173     }
174     
175     /**
176      * Get a terminating exception.
177      * Applies only to {@link AntLogger#buildFinished}
178      * and {@link AntLogger#buildInitializationFailed}.
179      * @return an exception ending the build, or null for normal completion or if inapplicable
180      */

181     public Throwable JavaDoc getException() {
182         return impl.getException();
183     }
184     
185     /**
186      * Get a property set on the current Ant project.
187      * @param name the property name
188      * @return its value, or null
189      */

190     public String JavaDoc getProperty(String JavaDoc name) {
191         return impl.getProperty(name);
192     }
193     
194     /**
195      * Get a set of property names defined on the current Ant project.
196      * @return a set of property names; may be empty but not null
197      */

198     public Set JavaDoc<String JavaDoc> getPropertyNames() {
199         return impl.getPropertyNames();
200     }
201     
202     /**
203      * Evaluate a string with possible substitutions according to defined properties.
204      * @param text the text to evaluate
205      * @return its value (may be the same as the incoming text), never null
206      * @see TaskStructure#getAttribute
207      * @see TaskStructure#getText
208      */

209     public String JavaDoc evaluate(String JavaDoc text) {
210         return impl.evaluate(text);
211     }
212     
213     @Override JavaDoc
214     public String JavaDoc toString() {
215         return impl.toString();
216     }
217     
218 }
219
Popular Tags