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.dods;
024:
025: // Toolbox imports
026: import org.enhydra.tool.ToolBoxInfo;
027: import org.enhydra.tool.common.ToolException;
028: import org.enhydra.tool.common.FileUtil;
029: import org.enhydra.tool.common.PathHandle;
030: import org.enhydra.tool.common.event.ProgressListener;
031: import org.enhydra.tool.archive.ArchiveException;
032: import org.enhydra.tool.archive.ArchiveTool;
033: import org.enhydra.tool.archive.JarPlan;
034: import org.enhydra.tool.archive.WarPlan;
035:
036: // Kelp imports
037: import org.enhydra.kelp.KelpInfo;
038: import org.enhydra.kelp.common.AbstractEchoGenerator;
039: import org.enhydra.kelp.common.Constants;
040: import org.enhydra.kelp.common.PathUtil;
041: import org.enhydra.kelp.common.PropUtil;
042: import org.enhydra.kelp.common.event.WriteEvent;
043: import org.enhydra.kelp.common.event.WriteListener;
044: import org.enhydra.kelp.common.node.OtterProject;
045: import org.enhydra.kelp.common.node.OtterNode;
046: import org.enhydra.kelp.common.node.OtterNodeFactory;
047: import org.enhydra.kelp.common.node.OtterTextFileNode;
048: import org.enhydra.kelp.common.node.OtterFolderNode;
049: import org.enhydra.kelp.common.node.OtterTemplateNode;
050:
051: // Standard imports
052: import java.awt.Component;
053: import java.awt.Window;
054: import java.io.File;
055: import java.util.StringTokenizer;
056: import java.util.ResourceBundle;
057: import javax.swing.JOptionPane;
058: import org.enhydra.kelp.common.AbstractEchoBuilder;
059:
060: //
061: public class DodsGenerate extends AbstractEchoBuilder {
062:
063: static ResourceBundle res = ResourceBundle
064: .getBundle("org.enhydra.kelp.common.Res"); // nores
065:
066: //
067: private OtterNode[] inputNodes = null;
068: private Window owner = null;
069: private boolean doneDialog = false;
070:
071: public static void preBuild(Object source, OtterProject project,
072: WriteListener listener) {
073: PathHandle path = null;
074: WriteEvent event = null;
075:
076: path = PathHandle.createPathHandle(project.getDeployRootPath());
077: if (!path.isDirectory()) {
078: path.getFile().mkdirs();
079: event = new WriteEvent(source, WriteEvent.OUTPUT,
080: "Created directory: " + path.getPath());
081: listener.onWrite(event);
082: }
083: }
084:
085: public DodsGenerate() {
086: super (null);
087: }
088:
089: public DodsGenerate(WriteListener listener) {
090: super (listener);
091: }
092:
093: public DodsGenerate(WriteListener listener, boolean buffer) {
094: super (listener, buffer);
095: }
096:
097: public void setInputNodes(OtterNode[] n) {
098: inputNodes = n;
099: }
100:
101: public OtterNode[] getInputNodes() {
102: return inputNodes;
103: }
104:
105: public void generate() {
106:
107: Generator generator = null;
108:
109: generator = new Generator(getWriteListener());
110: generator.setProject(getProject());
111: generator.setEcho(isEcho());
112: generator.buildInCurrentThread();
113:
114: }
115:
116: /**
117: * Make content, policy file, process templates, configure project for
118: * running enhydra and create archive.
119: */
120: public void buildImpl() {
121:
122: Exception ex = null;
123:
124: try {
125: echo(new String());
126: refreshProgress(5, res.getString("Generate_starting"));
127: echo(res.getString("_Generate_starting"));
128:
129: if (isFresh()) {
130: generate();
131: }
132: echo("--- Kelp Generator finished --- ");
133: } catch (Exception e) {
134: ex = e;
135: echo(ex);
136: }
137: refreshProgress(100, new String());
138: if (isDoneDialog()) {
139: StringBuffer buf = new StringBuffer();
140:
141: if (ex == null) {
142: buf.append("Generate Complete");
143: } else {
144: buf.append("Exception during generate:\n");
145: if (ex.getMessage() == null) {
146: buf.append(ex.toString());
147: } else {
148: buf.append(ex.getMessage());
149: }
150: buf.append("\n");
151: buf.append("See messages for more information.\n");
152: }
153: JOptionPane.showMessageDialog(getOwner(), buf.toString());
154: }
155: }
156:
157: //
158:
159: protected void setOwner(Window w) {
160: owner = w;
161: }
162:
163: protected Window getOwner() {
164: return owner;
165: }
166:
167: protected boolean isDoneDialog() {
168: boolean canDone = doneDialog;
169:
170: if (getOwner() == null) {
171: canDone = false;
172: }
173: return canDone;
174: }
175:
176: protected void setDoneDialog(boolean d) {
177: doneDialog = d;
178: }
179:
180: //
181: //
182: private void invoke(AbstractEchoGenerator generator) {
183: ProgressListener[] pl = getProgressListeners();
184:
185: if (pl != null) {
186: for (int i = 0; i < pl.length; i++) {
187: generator.addProgressListener(pl[i]);
188: }
189: }
190: generator.setProject(getProject());
191: generator.setEcho(isEcho());
192: generator.buildInCurrentThread();
193: if (pl != null) {
194: for (int i = 0; i < pl.length; i++) {
195: generator.removeProgressListener(pl[i]);
196: }
197: }
198: }
199:
200: }
|