001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common;
024:
025: // AddinCore
026: import org.enhydra.kelp.common.Constants;
027: import org.enhydra.kelp.common.node.OtterFileNode;
028: import org.enhydra.kelp.common.event.WriteListener;
029:
030: // JDK
031: import java.util.StringTokenizer;
032:
033: /**
034: *
035: *
036: * @author Paul Mahar
037: */
038: abstract public class AbstractNodeBuilder extends AbstractEchoBuilder {
039: private OtterFileNode[] nodes = null;
040:
041: /**
042: * Create a CompileThread with listeners ready to
043: * recieve output from XMLC.
044: *
045: *
046: * @param listeners
047: * A listener implements an onWrite method that is called
048: * whenever XMLC writes output. The writes are captured
049: * for display in a wizard.
050: */
051: public AbstractNodeBuilder(WriteListener[] listeners) {
052: super ();
053: for (int i = 0; i < listeners.length; i++) {
054: addWriteListener(listeners[i]);
055: }
056: }
057:
058: public AbstractNodeBuilder(WriteListener listener, boolean buffer) {
059: super (listener, buffer);
060: }
061:
062: /**
063: * Determine what files were created and write out the
064: * build results to any registered listeners.
065: */
066: abstract public void printResults();
067:
068: /**
069: * Get the file nodes that are to be built.
070: */
071: public OtterFileNode[] getNodes() {
072: return nodes;
073: }
074:
075: /**
076: * Set the file nodes to compile.
077: */
078: public void setNodes(OtterFileNode[] n) {
079: nodes = n;
080: }
081:
082: public void printExceptions() {
083: StringTokenizer tokenizer = null;
084: int eCount = 0;
085: int totalCount = getNodes().length;
086:
087: for (int i = 0; i < totalCount; i++) {
088: if (getNodes()[i].isSelected()
089: && getNodes()[i].getException() != null) {
090: eCount++;
091: }
092: }
093: if (eCount > 0) {
094: getEchoWriter().println(new String());
095: getEchoWriter().println("Exception encountered:");
096: for (int i = 0; i < totalCount; i++) {
097: if (getNodes()[i].getException() != null) {
098: getEchoWriter().print(Constants.TAB4);
099: getEchoWriter().print(getNodes()[i].getFilePath());
100: getEchoWriter().println(':');
101: tokenizer = new StringTokenizer(getNodes()[i]
102: .getException().getMessage(),
103: Constants.NEWLINE);
104: while (tokenizer.hasMoreTokens()) {
105: getEchoWriter().println(tokenizer.nextToken());
106: }
107: }
108: }
109: }
110: }
111:
112: /**
113: * Sleep the thread for a given number of seconds.
114: *
115: *
116: * @param seconds
117: * How many seconds to sleep.
118: */
119: public void sleepInSeconds(double seconds) {
120: try {
121: Thread.sleep((int) (seconds * 1000));
122: } catch (InterruptedException e) {
123: }
124: }
125:
126: }
|