KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > dods > DodsGenerate


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.dods;
24
25 // Toolbox imports
26
import org.enhydra.tool.ToolBoxInfo;
27 import org.enhydra.tool.common.ToolException;
28 import org.enhydra.tool.common.FileUtil;
29 import org.enhydra.tool.common.PathHandle;
30 import org.enhydra.tool.common.event.ProgressListener;
31 import org.enhydra.tool.archive.ArchiveException;
32 import org.enhydra.tool.archive.ArchiveTool;
33 import org.enhydra.tool.archive.JarPlan;
34 import org.enhydra.tool.archive.WarPlan;
35
36 // Kelp imports
37
import org.enhydra.kelp.KelpInfo;
38 import org.enhydra.kelp.common.AbstractEchoGenerator;
39 import org.enhydra.kelp.common.Constants;
40 import org.enhydra.kelp.common.PathUtil;
41 import org.enhydra.kelp.common.PropUtil;
42 import org.enhydra.kelp.common.event.WriteEvent;
43 import org.enhydra.kelp.common.event.WriteListener;
44 import org.enhydra.kelp.common.node.OtterProject;
45 import org.enhydra.kelp.common.node.OtterNode;
46 import org.enhydra.kelp.common.node.OtterNodeFactory;
47 import org.enhydra.kelp.common.node.OtterTextFileNode;
48 import org.enhydra.kelp.common.node.OtterFolderNode;
49 import org.enhydra.kelp.common.node.OtterTemplateNode;
50
51 // Standard imports
52
import java.awt.Component JavaDoc;
53 import java.awt.Window JavaDoc;
54 import java.io.File JavaDoc;
55 import java.util.StringTokenizer JavaDoc;
56 import java.util.ResourceBundle JavaDoc;
57 import javax.swing.JOptionPane JavaDoc;
58 import org.enhydra.kelp.common.AbstractEchoBuilder;
59
60 //
61
public class DodsGenerate extends AbstractEchoBuilder {
62
63     static ResourceBundle JavaDoc res =
64         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
65

66     //
67
private OtterNode[] inputNodes = null;
68     private Window JavaDoc owner = null;
69     private boolean doneDialog = false;
70
71     public static void preBuild(Object JavaDoc source, OtterProject project,
72                                 WriteListener listener) {
73         PathHandle path = null;
74         WriteEvent event = null;
75
76         path = PathHandle.createPathHandle(project.getDeployRootPath());
77         if (!path.isDirectory()) {
78             path.getFile().mkdirs();
79             event = new WriteEvent(source, WriteEvent.OUTPUT,
80                                    "Created directory: " + path.getPath());
81             listener.onWrite(event);
82         }
83     }
84
85     public DodsGenerate() {
86         super(null);
87     }
88
89     public DodsGenerate(WriteListener listener) {
90         super(listener);
91     }
92
93     public DodsGenerate(WriteListener listener, boolean buffer) {
94         super(listener, buffer);
95     }
96
97     public void setInputNodes(OtterNode[] n) {
98         inputNodes = n;
99     }
100
101     public OtterNode[] getInputNodes() {
102         return inputNodes;
103     }
104
105     public void generate() {
106
107         Generator generator = null;
108
109
110         generator = new Generator(getWriteListener());
111         generator.setProject(getProject());
112         generator.setEcho(isEcho());
113         generator.buildInCurrentThread();
114
115     }
116
117     /**
118      * Make content, policy file, process templates, configure project for
119      * running enhydra and create archive.
120      */

121     public void buildImpl() {
122
123         Exception JavaDoc ex = null;
124
125         try {
126             echo(new String JavaDoc());
127             refreshProgress(5, res.getString("Generate_starting"));
128             echo(res.getString("_Generate_starting"));
129
130             if (isFresh()) {
131                 generate();
132             }
133             echo("--- Kelp Generator finished --- ");
134         } catch (Exception JavaDoc e) {
135             ex = e;
136             echo(ex);
137         }
138         refreshProgress(100, new String JavaDoc());
139         if (isDoneDialog()) {
140             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
141
142             if (ex == null) {
143                 buf.append("Generate Complete");
144             } else {
145                 buf.append("Exception during generate:\n");
146                 if (ex.getMessage() == null) {
147                     buf.append(ex.toString());
148                 } else {
149                     buf.append(ex.getMessage());
150                 }
151                 buf.append("\n");
152                 buf.append("See messages for more information.\n");
153             }
154             JOptionPane.showMessageDialog(getOwner(), buf.toString());
155         }
156     }
157
158     //
159

160     protected void setOwner(Window JavaDoc w) {
161         owner = w;
162     }
163
164     protected Window JavaDoc getOwner() {
165         return owner;
166     }
167
168     protected boolean isDoneDialog() {
169         boolean canDone = doneDialog;
170
171         if (getOwner() == null) {
172             canDone = false;
173         }
174         return canDone;
175     }
176
177     protected void setDoneDialog(boolean d) {
178         doneDialog = d;
179     }
180
181     //
182
//
183
private void invoke(AbstractEchoGenerator generator) {
184         ProgressListener[] pl = getProgressListeners();
185
186         if (pl != null) {
187             for (int i = 0; i < pl.length; i++) {
188                 generator.addProgressListener(pl[i]);
189             }
190         }
191         generator.setProject(getProject());
192         generator.setEcho(isEcho());
193         generator.buildInCurrentThread();
194         if (pl != null) {
195             for (int i = 0; i < pl.length; i++) {
196                 generator.removeProgressListener(pl[i]);
197             }
198         }
199     }
200
201 }
202
Popular Tags