KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > jobs > EchoJob


1 package org.oddjob.jobs;
2
3 import java.io.Serializable JavaDoc;
4
5 import org.oddjob.util.OddjobConfigException;
6
7 /**
8  * @oddjob.description Echo text to the console.
9  *
10  * @oddjob.example
11  *
12  * <pre>
13  * &lt;echo name="Greeting Job" text="Hello World"/&gt;
14  * </pre>
15  *
16  * @oddjob.example
17  *
18  * <pre>
19  * &lt;sequential&gt;
20  * &lt;copy id="copy" name="Copy from a file to a buffer"
21  * from="stuff.txt"&gt;
22  * &lt;output&gt;
23  * &lt;buffer/&gt;
24  * &lt;/output&gt;
25  * &lt;/copy&gt;
26  * &lt;echo name="What's in the file?" text="${copy.output}"/&gt;
27  * &lt;/sequential&gt;
28  * </pre>
29  *
30  */

31 public class EchoJob
32 implements Runnable JavaDoc, Serializable JavaDoc {
33     private static final long serialVersionUID = 20051130;
34         
35     /**
36      * @oddjob.property
37      * @oddjob.description A name, can be any text.
38      * @oddjob.required No.
39      */

40     private String JavaDoc name;
41
42     /**
43      * @oddjob.property
44      * @oddjob.description The text to display.
45      * @oddjob.required No, text can be nested instead.
46      */

47     volatile private String JavaDoc text;
48     
49     /**
50      * Get the name.
51      *
52      * @return The name.
53      */

54     public String JavaDoc getName() {
55         return name;
56     }
57     
58     /**
59      * Set the name
60      *
61      * @param name The name.
62      */

63     public void setName(String JavaDoc name) {
64         this.name = name;
65     }
66     
67     /**
68      * Get the text.
69      *
70      * @return The text.
71      */

72     public String JavaDoc getText() {
73         return text;
74     }
75     
76     /**
77      * Set the text.
78      *
79      * @param The text.
80      */

81     public void setText(String JavaDoc text) {
82         this.text = text;
83     }
84
85     /**
86      * Add text to existing text.
87      *
88      * @param text Text to add.
89      */

90     public void addText(String JavaDoc text) {
91         this.text += text;
92     }
93
94     /*
95      * (non-Javadoc)
96      * @see java.lang.Runnable#run()
97      */

98     public void run() {
99         if (text == null) {
100             throw new OddjobConfigException("No text to echo.");
101         }
102         System.out.println(text);
103     }
104     
105     /*
106      * (non-Javadoc)
107      * @see java.lang.Object#toString()
108      */

109     public String JavaDoc toString() {
110         if (name == null) {
111             return "Echo to Console";
112         }
113         return name;
114     }
115 }
116
Popular Tags