KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > AbstractNodeBuilder


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common;
24
25 // AddinCore
26
import org.enhydra.kelp.common.Constants;
27 import org.enhydra.kelp.common.ProgressBuilder;
28 import org.enhydra.kelp.common.node.OtterFileNode;
29 import org.enhydra.kelp.common.node.OtterProject;
30 import org.enhydra.kelp.common.event.WriteListener;
31
32 // JDK
33
import java.io.PrintWriter JavaDoc;
34 import java.io.File JavaDoc;
35 import java.util.StringTokenizer JavaDoc;
36
37 /**
38  *
39  *
40  * @author Paul Mahar
41  */

42 abstract public class AbstractNodeBuilder extends AbstractEchoBuilder {
43     private OtterFileNode[] nodes = null;
44
45     /**
46      * Create a CompileThread with listeners ready to
47      * recieve output from XMLC.
48      *
49      *
50      * @param listeners
51      * A listener implements an onWrite method that is called
52      * whenever XMLC writes output. The writes are captured
53      * for display in a wizard.
54      */

55     public AbstractNodeBuilder(WriteListener[] listeners) {
56         super();
57         for (int i = 0; i < listeners.length; i++) {
58             addWriteListener(listeners[i]);
59         }
60     }
61
62     public AbstractNodeBuilder(WriteListener listener, boolean buffer) {
63         super(listener, buffer);
64     }
65
66
67     /**
68      * Determine what files were created and write out the
69      * build results to any registered listeners.
70      */

71     abstract public void printResults();
72
73     /**
74      * Get the file nodes that are to be built.
75      */

76     public OtterFileNode[] getNodes() {
77         return nodes;
78     }
79
80     /**
81      * Set the file nodes to compile.
82      */

83     public void setNodes(OtterFileNode[] n) {
84         nodes = n;
85     }
86
87     public void printExceptions() {
88         StringTokenizer JavaDoc tokenizer = null;
89         int eCount = 0;
90         int totalCount = getNodes().length;
91
92         for (int i = 0; i < totalCount; i++) {
93             if (getNodes()[i].isSelected()
94                     && getNodes()[i].getException() != null) {
95                 eCount++;
96             }
97         }
98         if (eCount > 0) {
99             getEchoWriter().println(new String JavaDoc());
100             getEchoWriter().println("Exception encountered:");
101             for (int i = 0; i < totalCount; i++) {
102                 if (getNodes()[i].getException() != null) {
103                     getEchoWriter().print(Constants.TAB4);
104                     getEchoWriter().print(getNodes()[i].getFilePath());
105                     getEchoWriter().println(':');
106                     tokenizer =
107                         new StringTokenizer JavaDoc(getNodes()[i].getException().getMessage(),
108                                             Constants.NEWLINE);
109                     while (tokenizer.hasMoreTokens()) {
110                         getEchoWriter().println(tokenizer.nextToken());
111                     }
112                 }
113             }
114         }
115     }
116
117     /**
118      * Sleep the thread for a given number of seconds.
119      *
120      *
121      * @param seconds
122      * How many seconds to sleep.
123      */

124     public void sleepInSeconds(double seconds) {
125         try {
126             Thread.sleep((int) (seconds * 1000));
127         } catch (InterruptedException JavaDoc e) {}
128     }
129
130 }
131
Popular Tags