KickJava   Java API By Example, From Geeks To Geeks.

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


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 // Kelp imports
26
import org.enhydra.kelp.common.AbstractEchoBuilder;
27 import org.enhydra.kelp.common.PathUtil;
28 import org.enhydra.kelp.common.event.WriteListener;
29 import org.enhydra.kelp.common.node.OtterTemplateNode;
30 import org.enhydra.kelp.common.node.OtterFileNode;
31 import org.enhydra.kelp.common.node.OtterNode;
32 import org.enhydra.kelp.common.node.OtterNodeFactory;
33
34 // ToolBox imports
35
import org.enhydra.tool.common.FileUtil;
36 import org.enhydra.tool.common.PathHandle;
37 import org.enhydra.tool.common.Template;
38 import org.enhydra.tool.common.ToolException;
39 import org.enhydra.tool.configure.ConfigTool;
40 import org.enhydra.tool.common.event.ProgressListener;
41
42 // Standard imports
43
import java.awt.Component JavaDoc;
44 import java.io.File JavaDoc;
45 import java.util.ArrayList JavaDoc;
46 import java.util.Arrays JavaDoc;
47 import java.util.ResourceBundle JavaDoc;
48
49 import java.io.*;
50 import javax.swing.*;
51 import org.enhydra.dods.xslt.*;
52 import org.enhydra.kelp.common.AbstractEchoBuilder;
53
54 import org.enhydra.dods.generator.DODSGenerator;
55 import org.enhydra.dods.Common;
56
57 //
58
public class DodsBuilder extends AbstractEchoBuilder {
59
60     static ResourceBundle JavaDoc res =
61         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
62
private File JavaDoc[] builtTemplates = new File JavaDoc[0];
63     private File JavaDoc[] builtPassthrough = new File JavaDoc[0];
64     private OtterNode[] nodes = null;
65     private Component JavaDoc owner = null;
66
67     public DodsBuilder(WriteListener listener) {
68         super(listener);
69     }
70
71     protected void buildImpl() throws ToolException {
72
73     Exception JavaDoc ex = null;
74
75     try {
76         DODSGenerator generator = new DODSGenerator();
77
78         String JavaDoc strDodsRootPath = getProject().getDodsRootPath();
79         if(strDodsRootPath.endsWith("/")) {
80            strDodsRootPath = strDodsRootPath.substring(0, strDodsRootPath.length()-1);
81         }
82            generator.setOutputDir(strDodsRootPath);
83
84
85         generator.setDoml(getProject().getDomlFilePath());
86
87         generator.setAction(getProject().getDodsParameters()); //default
88

89         if(getProject().getDocumentationHtml().equals("html")) {
90           generator.setHtml(true);
91         } else {
92           generator.setHtml(false);
93         }
94
95         if(getProject().getDocumentationPdf().equals("pdf")) {
96           generator.setPdf(true);
97         } else {
98           generator.setPdf(false);
99         }
100
101         if(getProject().getDocumentationXmi().equals("xmi"))
102           generator.setXmi(true);
103         else
104           generator.setXmi(false);
105
106         if(getProject().getDocumentationPtl().equals("ptl")) {
107           generator.setPtl(true);
108         } else {
109           generator.setPtl(false);
110         }
111
112         generator.setTemplateSet(getProject().getTemplateSet());
113
114       Common.setDomlFile(getProject().getDomlFilePath());
115       Common.setProjectRoot(getProject().getRootPath());
116
117       Process JavaDoc process = generator.generateAll(true);
118
119       java.io.InputStream JavaDoc inputstream = process.getInputStream();
120       BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
121       java.io.InputStream JavaDoc inputstream1 = process.getErrorStream();
122       BufferedReader bufferedreader1 = new BufferedReader(new InputStreamReader(inputstream1));
123
124       String JavaDoc str1="";
125       String JavaDoc str2="";
126       (new ErrorReader(bufferedreader1,this)).start();
127
128       int i = 1;
129       while((str1 = bufferedreader.readLine()) != null) {
130         if (isFresh()) {
131           echo(str1);
132           if(i<90) {
133             refreshProgress(i, "Generating Dods files");
134           }
135           i=i+2;
136         } else {
137             process.destroy();
138             refreshProgress(100, "");
139             echo("Process has been terminated");
140             return;
141         }
142       }
143
144       process.waitFor();
145       int k = process.exitValue();
146
147     String JavaDoc dodsRootPath = getProject().getDodsRootPath();
148     if(dodsRootPath.endsWith("/"))
149       dodsRootPath=dodsRootPath.substring(0,dodsRootPath.length()-1);
150
151     String JavaDoc[] sourcePath = getProject().getSourcePathArray();
152     boolean isFind = false;
153     for(int j=0;j<sourcePath.length;j++) {
154
155       if(dodsRootPath.equalsIgnoreCase(sourcePath[j]))
156         isFind=true;
157     }
158     if(!isFind) {
159       String JavaDoc[] newSourcePath = new String JavaDoc[sourcePath.length+1];
160       for(int j=0;j<sourcePath.length;j++) {
161         newSourcePath[j] = sourcePath[j];
162         }
163       newSourcePath[sourcePath.length] = getProject().getDodsRootPath();
164      getProject().setSourcePathArray(newSourcePath);
165     }
166
167
168
169     } catch(Exception JavaDoc e) {
170       ex = e;
171     }
172
173   }
174
175     public Component JavaDoc getOwner() {
176         return owner;
177     }
178
179     private String JavaDoc getEnhydraPath() {
180       return getProject().getEnhydraPath();
181     }
182
183     private String JavaDoc getProjectJavaPath() {
184       return getProject().getProjectJavaPath();
185     }
186
187 }
188
Popular Tags