001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.ide.classpath;
025:
026: import java.io.File;
027: import java.io.FileFilter;
028: import java.util.ArrayList;
029:
030: import org.eclipse.core.runtime.IPath;
031: import org.eclipse.core.runtime.Path;
032: import org.eclipse.jdt.core.IClasspathContainer;
033: import org.eclipse.jdt.core.IClasspathEntry;
034: import org.eclipse.jdt.core.JavaCore;
035: import org.eclipse.ui.plugin.AbstractUIPlugin;
036:
037: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
038: import com.bostechcorp.cbesb.ui.ide.Activator;
039:
040: public abstract class AbstractClasspathContainer implements
041: IClasspathContainer {
042: /** Description of the Field */
043: protected IClasspathEntry[] entries;
044:
045: /** Description of the Field */
046: protected IPath path;
047:
048: /**
049: *Constructor for the AbstractClasspathContainer object
050: *
051: * @param path Description of the Parameter
052: */
053: public AbstractClasspathContainer(IPath path) {
054: this .path = path;
055: }
056:
057: /**
058: * Gets the classpathEntries attribute of the AbstractClasspathContainer object
059: *
060: * @return The classpathEntries value
061: */
062: public IClasspathEntry[] getClasspathEntries() {
063: if (entries == null) {
064: entries = computeEntries();
065: }
066: return entries;
067: }
068:
069: /**
070: * Gets the description attribute of the AbstractClasspathContainer object
071: *
072: * @return The description value
073: */
074: public abstract String getDescription();
075:
076: /**
077: * Gets the kind attribute of the AbstractClasspathContainer object
078: *
079: * @return The kind value
080: */
081: public int getKind() {
082: return IClasspathContainer.K_APPLICATION;
083: }
084:
085: /**
086: * Gets the path attribute of the AbstractClasspathContainer object
087: *
088: * @return The path value
089: */
090: public IPath getPath() {
091: return this .path;
092: }
093:
094: /**
095: * Description of the Method
096: *
097: * @return Description of the Return Value
098: */
099: protected IClasspathEntry[] computeEntries() {
100: ArrayList entries = new ArrayList();
101:
102: String libPath = "";
103: String libSrcPath = "";
104:
105: String home = EsbPathHelper.getCbesbHomeDir();
106: if (home != null) {
107: libPath = home + "/" + ClassPathConstants.LIB_FOLDER + "/"
108: + getLibFolder();
109: libSrcPath = home + "/"
110: + ClassPathConstants.LIB_SOURCE_FOLDER + "/"
111: + getLibFolder();
112:
113: } else {
114: String baseDir = Activator.getDefault().getBaseDir();
115: libPath = baseDir + "/lib/" + getLibFolder();
116: libSrcPath = home + "/libsrc/" + getLibFolder();
117:
118: }
119:
120: File libDir = new File(libPath);//$NON-NLS-1$ //$NON-NLS-2$
121: File libSrcDir = new File(libSrcPath);//$NON-NLS-1$ //$NON-NLS-2$
122:
123: // Lists every modules in the lib dir
124: File[] jars = libDir.listFiles(new FileFilter() {
125: public boolean accept(File file) {
126: return (file.toString().endsWith(".jar"));//$NON-NLS-1$
127: }
128: });
129:
130: if (jars != null) {
131: for (int i = 0; i < jars.length; i++) {
132: File jarFile = jars[i];
133: String jarFileName = jarFile.getName();
134: File jarSrcFile = new File(libSrcDir, jarFileName);
135:
136: IPath entryPath = new Path(jarFile.toString());
137:
138: IPath sourceAttachementPath = null;
139: IPath sourceAttachementRootPath = null;
140:
141: if (jarSrcFile.exists()) {
142: sourceAttachementPath = new Path(jarSrcFile
143: .toString());
144: sourceAttachementRootPath = new Path("/");//$NON-NLS-1$
145: }
146:
147: IClasspathEntry entry = JavaCore.newLibraryEntry(
148: entryPath, sourceAttachementPath,
149: sourceAttachementRootPath, true);
150: entries.add(entry);
151: }
152: }
153:
154: return (IClasspathEntry[]) entries
155: .toArray(new IClasspathEntry[entries.size()]);
156: }
157:
158: /**
159: * Gets the libFolder attribute of the AbstractClasspathContainer object
160: *
161: * @return The libFolder value
162: */
163: protected abstract String getLibFolder();
164:
165: /**
166: * Gets the plugin attribute of the AbstractClasspathContainer object
167: *
168: * @return The plugin value
169: */
170: protected abstract AbstractUIPlugin getPlugin();
171: }
|