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: *
021: */
022: package org.enhydra.kelp.common.importer;
023:
024: // ToolBox imports
025: import org.enhydra.tool.ToolBoxInfo;
026: import org.enhydra.tool.common.PathHandle;
027:
028: // Standard imports
029: import java.io.File;
030: import java.util.Vector;
031:
032: //
033: public class MakefileData {
034: private Vector docVector = new Vector();
035: private Vector itemVector = new Vector();
036: private String xmlcOptionFilePath = new String();
037: private String xmlcParams = new String();
038:
039: //
040: private String packPath = new String();
041: private String docPath = new String();
042: private String makeParentPath = new String();
043: private String sourcePath = new String();
044: private String rootPath = new String();
045:
046: protected MakefileData(String makeParent, String source) {
047: makeParentPath = PathHandle.createPathString(makeParent);
048: sourcePath = PathHandle.createPathString(source);
049: rootPath = sourcePath; // default
050: }
051:
052: protected String getMakeParentPath() {
053: return makeParentPath;
054: }
055:
056: protected String getSourcePath() {
057: return sourcePath;
058: }
059:
060: protected void readRootPath(String p) {
061: rootPath = PathHandle.createPathString(getMakeParentPath()
062: + File.separator + p);
063: }
064:
065: protected String getRootPath() {
066: return rootPath;
067: }
068:
069: protected void readXMLCOptionFilePath(String p) {
070: xmlcOptionFilePath = PathHandle
071: .createPathString(getMakeParentPath() + File.separator
072: + p);
073: }
074:
075: protected String getXMLCOptionFilePath() {
076: return xmlcOptionFilePath;
077: }
078:
079: protected void readPackagePath(String d) {
080: packPath = PathHandle.createPathString(sourcePath
081: + File.separator + d);
082: }
083:
084: protected String getPackagePath() {
085: return packPath;
086: }
087:
088: protected String getJavaPackage() {
089: String javaPack = new String();
090: PathHandle sourceHandle = null;
091: PathHandle packHandle = null;
092: int index = -1;
093:
094: sourceHandle = PathHandle.createPathHandle(getSourcePath());
095: packHandle = PathHandle.createPathHandle(getPackagePath());
096: if (sourceHandle.parentOf(packHandle)) {
097: index = packHandle.getPath()
098: .indexOf(sourceHandle.getPath());
099: if (index > -1) {
100: javaPack = packHandle.getPath().substring(
101: sourceHandle.getPath().length() + 1);
102: javaPack = javaPack.replace('/', '.');
103: }
104: }
105: return javaPack;
106: }
107:
108: protected void readDocPath(String p) {
109: int index = -1;
110:
111: index = p.indexOf(')');
112: if (index > 0) {
113: p = getRootPath() + p.substring(index + 1);
114: } else {
115: p = getMakeParentPath() + File.separator + p;
116: }
117: docPath = PathHandle.createPathString(p);
118: }
119:
120: protected String getDocPath() {
121: return docPath;
122: }
123:
124: protected void setXMLCParameters(String p) {
125: if (p == null) {
126: xmlcParams = new String();
127: } else {
128: xmlcParams = p.trim();
129: }
130: }
131:
132: protected String getXMLCParameters() {
133: return xmlcParams;
134: }
135:
136: protected void addSourceDocPath(String className) {
137: String docResourcePath = new String();
138: String docSourcePath = new String();
139:
140: if ((className != null) && (className.trim().length() > 0)) {
141: docResourcePath = createSourceDocPath(getMakeParentPath(),
142: className);
143: docSourcePath = createSourceDocPath(getDocPath(), className);
144: File f = new File(docResourcePath);
145:
146: if (f.exists()) {
147: docVector.addElement(docResourcePath);
148: } else {
149: f = new File(docSourcePath);
150: if (f.exists()) {
151: docVector.addElement(docSourcePath);
152: }
153: }
154: }
155: }
156:
157: private String createSourceDocPath(String parentPath,
158: String className) {
159: PathHandle handle = null;
160: String path = null;
161: String[] docTypes = ToolBoxInfo.getSupportedDocTypes();
162: StringBuffer newPath = new StringBuffer();
163: int extLength = 3;
164:
165: handle = PathHandle.createPathHandle(parentPath
166: + File.separator + className);
167: path = handle.getPath();
168: for (int i = 0; i < docTypes.length; i++) {
169: if (handle.endsWith(docTypes[i])) {
170: if (docTypes[i].length() > extLength) {
171: extLength = docTypes[i].length();
172: }
173: }
174: }
175: newPath.append(path.substring(0, path.length() - extLength));
176: newPath.append('.');
177: newPath.append(path.substring(path.length() - extLength)
178: .toLowerCase());
179: return newPath.toString();
180: }
181:
182: protected String[] getSourceDocPaths() {
183: String[] paths = new String[docVector.size()];
184:
185: paths = (String[]) docVector.toArray(paths);
186: return paths;
187: }
188:
189: protected boolean containSourceDoc(String inPath) {
190: String[] docs = new String[0];
191: PathHandle handle = null;
192: boolean contains = false;
193:
194: docs = getSourceDocPaths();
195: handle = PathHandle.createPathHandle(inPath);
196: for (int i = 0; i < docs.length; i++) {
197: if (handle.equals(docs[i])) {
198: contains = true;
199: break;
200: }
201: }
202: return contains;
203: }
204:
205: protected void addItem(String i, String o) {
206: MakeItemData data = new MakeItemData(i, o);
207:
208: itemVector.addElement(data);
209: }
210:
211: protected MakeItemData[] getItems() {
212: MakeItemData[] items = new MakeItemData[itemVector.size()];
213:
214: items = (MakeItemData[]) itemVector.toArray(items);
215: return items;
216: }
217:
218: protected boolean isSymbolic() {
219: boolean sym = false;
220:
221: if (isXMLC()) {
222: PathHandle packHandle = null;
223:
224: packHandle = PathHandle.createPathHandle(getPackagePath());
225: if (packHandle.equals(getMakeParentPath())) {
226:
227: // Not symbolic
228: } else {
229: sym = true;
230: }
231: }
232: return sym;
233: }
234:
235: protected boolean isXMLC() {
236: boolean is = false;
237: StringBuffer buf = new StringBuffer();
238:
239: buf.append(getXMLCOptionFilePath());
240: buf.append(getXMLCParameters());
241: buf.append(getDocPath());
242: if (buf.toString().trim().length() > 0) {
243: is = true;
244: } else if (getSourceDocPaths().length >= 1) {
245: is = true;
246: } else if (getItems().length >= 1) {
247: is = true;
248: }
249: return is;
250: }
251:
252: public String toString() {
253: StringBuffer buf = new StringBuffer();
254:
255: buf.append("makeParentPath: " + getMakeParentPath() + '\n'); // nores
256: buf.append("sourcePath: " + getSourcePath() + '\n'); // nores
257: buf.append("rootPath: " + getRootPath() + '\n'); // nores
258: buf.append("packagePath: " + getPackagePath() + '\n'); // nores
259: buf.append("xmlcOptionFilePath: " + getXMLCOptionFilePath()
260: + '\n'); // nores
261: buf.append("xmlcParameters: " + getXMLCParameters() + '\n'); // nores
262: buf.append("DocPath: " + getDocPath() + '\n'); // nores
263: String[] paths = getSourceDocPaths();
264:
265: for (int i = 0; i < paths.length; i++) {
266: buf.append("Class doc path: " + paths[i] + '\n'); // nores
267: }
268: MakeItemData[] ids = getItems();
269:
270: for (int i = 0; i < ids.length; i++) {
271: buf.append(ids[i].toString());
272: buf.append('\n');
273: }
274: return buf.toString();
275: }
276:
277: }
|