KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > importer > MakefileData


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  *
21  */

22 package org.enhydra.kelp.common.importer;
23
24 // ToolBox imports
25
import org.enhydra.tool.ToolBoxInfo;
26 import org.enhydra.tool.common.PathHandle;
27
28 // Standard imports
29
import java.io.File JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 //
33
public class MakefileData {
34     private Vector JavaDoc docVector = new Vector JavaDoc();
35     private Vector JavaDoc itemVector = new Vector JavaDoc();
36     private String JavaDoc xmlcOptionFilePath = new String JavaDoc();
37     private String JavaDoc xmlcParams = new String JavaDoc();
38
39     //
40
private String JavaDoc packPath = new String JavaDoc();
41     private String JavaDoc docPath = new String JavaDoc();
42     private String JavaDoc makeParentPath = new String JavaDoc();
43     private String JavaDoc sourcePath = new String JavaDoc();
44     private String JavaDoc rootPath = new String JavaDoc();
45
46     protected MakefileData(String JavaDoc makeParent, String JavaDoc source) {
47         makeParentPath = PathHandle.createPathString(makeParent);
48         sourcePath = PathHandle.createPathString(source);
49         rootPath = sourcePath; // default
50
}
51
52     protected String JavaDoc getMakeParentPath() {
53         return makeParentPath;
54     }
55
56     protected String JavaDoc getSourcePath() {
57         return sourcePath;
58     }
59
60     protected void readRootPath(String JavaDoc p) {
61         rootPath = PathHandle.createPathString(getMakeParentPath()
62                                                + File.separator + p);
63     }
64
65     protected String JavaDoc getRootPath() {
66         return rootPath;
67     }
68
69     protected void readXMLCOptionFilePath(String JavaDoc p) {
70         xmlcOptionFilePath = PathHandle.createPathString(getMakeParentPath()
71                 + File.separator + p);
72     }
73
74     protected String JavaDoc getXMLCOptionFilePath() {
75         return xmlcOptionFilePath;
76     }
77
78     protected void readPackagePath(String JavaDoc d) {
79         packPath = PathHandle.createPathString(sourcePath + File.separator
80                                                + d);
81     }
82
83     protected String JavaDoc getPackagePath() {
84         return packPath;
85     }
86
87     protected String JavaDoc getJavaPackage() {
88         String JavaDoc javaPack = new String JavaDoc();
89         PathHandle sourceHandle = null;
90         PathHandle packHandle = null;
91         int index = -1;
92
93         sourceHandle = PathHandle.createPathHandle(getSourcePath());
94         packHandle = PathHandle.createPathHandle(getPackagePath());
95         if (sourceHandle.parentOf(packHandle)) {
96             index = packHandle.getPath().indexOf(sourceHandle.getPath());
97             if (index > -1) {
98                 javaPack =
99                     packHandle.getPath().substring(sourceHandle.getPath().length()
100                                                    + 1);
101                 javaPack = javaPack.replace('/', '.');
102             }
103         }
104         return javaPack;
105     }
106
107     protected void readDocPath(String JavaDoc p) {
108         int index = -1;
109
110         index = p.indexOf(')');
111         if (index > 0) {
112             p = getRootPath() + p.substring(index + 1);
113         } else {
114             p = getMakeParentPath() + File.separator + p;
115         }
116         docPath = PathHandle.createPathString(p);
117     }
118
119     protected String JavaDoc getDocPath() {
120         return docPath;
121     }
122
123     protected void setXMLCParameters(String JavaDoc p) {
124         if (p == null) {
125             xmlcParams = new String JavaDoc();
126         } else {
127             xmlcParams = p.trim();
128         }
129     }
130
131     protected String JavaDoc getXMLCParameters() {
132         return xmlcParams;
133     }
134
135     protected void addSourceDocPath(String JavaDoc className) {
136         String JavaDoc docResourcePath = new String JavaDoc();
137         String JavaDoc docSourcePath = new String JavaDoc();
138
139         if ((className != null) && (className.trim().length() > 0)) {
140             docResourcePath = createSourceDocPath(getMakeParentPath(),
141                                                   className);
142             docSourcePath = createSourceDocPath(getDocPath(), className);
143             File JavaDoc f = new File JavaDoc(docResourcePath);
144
145             if (f.exists()) {
146                 docVector.addElement(docResourcePath);
147             } else {
148                 f = new File JavaDoc(docSourcePath);
149                 if (f.exists()) {
150                     docVector.addElement(docSourcePath);
151                 }
152             }
153         }
154     }
155
156     private String JavaDoc createSourceDocPath(String JavaDoc parentPath, String JavaDoc className) {
157         PathHandle handle = null;
158         String JavaDoc path = null;
159         String JavaDoc[] docTypes = ToolBoxInfo.getSupportedDocTypes();
160         StringBuffer JavaDoc newPath = new StringBuffer JavaDoc();
161         int extLength = 3;
162
163         handle = PathHandle.createPathHandle(parentPath + File.separator
164                                              + className);
165         path = handle.getPath();
166         for (int i = 0; i < docTypes.length; i++) {
167             if (handle.endsWith(docTypes[i])) {
168                 if (docTypes[i].length() > extLength) {
169                     extLength = docTypes[i].length();
170                 }
171             }
172         }
173         newPath.append(path.substring(0, path.length() - extLength));
174         newPath.append('.');
175         newPath.append(path.substring(path.length()
176                                       - extLength).toLowerCase());
177         return newPath.toString();
178     }
179
180     protected String JavaDoc[] getSourceDocPaths() {
181         String JavaDoc[] paths = new String JavaDoc[docVector.size()];
182
183         paths = (String JavaDoc[]) docVector.toArray(paths);
184         return paths;
185     }
186
187     protected boolean containSourceDoc(String JavaDoc inPath) {
188         String JavaDoc[] docs = new String JavaDoc[0];
189         PathHandle handle = null;
190         boolean contains = false;
191
192         docs = getSourceDocPaths();
193         handle = PathHandle.createPathHandle(inPath);
194         for (int i = 0; i < docs.length; i++) {
195             if (handle.equals(docs[i])) {
196                 contains = true;
197                 break;
198             }
199         }
200         return contains;
201     }
202
203     protected void addItem(String JavaDoc i, String JavaDoc o) {
204         MakeItemData data = new MakeItemData(i, o);
205
206         itemVector.addElement(data);
207     }
208
209     protected MakeItemData[] getItems() {
210         MakeItemData[] items = new MakeItemData[itemVector.size()];
211
212         items = (MakeItemData[]) itemVector.toArray(items);
213         return items;
214     }
215
216     protected boolean isSymbolic() {
217         boolean sym = false;
218
219         if (isXMLC()) {
220             PathHandle packHandle = null;
221
222             packHandle = PathHandle.createPathHandle(getPackagePath());
223             if (packHandle.equals(getMakeParentPath())) {
224
225                 // Not symbolic
226
} else {
227                 sym = true;
228             }
229         }
230         return sym;
231     }
232
233     protected boolean isXMLC() {
234         boolean is = false;
235         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
236
237         buf.append(getXMLCOptionFilePath());
238         buf.append(getXMLCParameters());
239         buf.append(getDocPath());
240         if (buf.toString().trim().length() > 0) {
241             is = true;
242         } else if (getSourceDocPaths().length >= 1) {
243             is = true;
244         } else if (getItems().length >= 1) {
245             is = true;
246         }
247         return is;
248     }
249
250     public String JavaDoc toString() {
251         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
252
253         buf.append("makeParentPath: " + getMakeParentPath() + '\n'); // nores
254
buf.append("sourcePath: " + getSourcePath() + '\n'); // nores
255
buf.append("rootPath: " + getRootPath() + '\n'); // nores
256
buf.append("packagePath: " + getPackagePath() + '\n'); // nores
257
buf.append("xmlcOptionFilePath: " + getXMLCOptionFilePath() + '\n'); // nores
258
buf.append("xmlcParameters: " + getXMLCParameters() + '\n'); // nores
259
buf.append("DocPath: " + getDocPath() + '\n'); // nores
260
String JavaDoc[] paths = getSourceDocPaths();
261
262         for (int i = 0; i < paths.length; i++) {
263             buf.append("Class doc path: " + paths[i] + '\n'); // nores
264
}
265         MakeItemData[] ids = getItems();
266
267         for (int i = 0; i < ids.length; i++) {
268             buf.append(ids[i].toString());
269             buf.append('\n');
270         }
271         return buf.toString();
272     }
273
274 }
275
Popular Tags