1
2
3
4
5
6
7
8
9 package com.bbn.jena;
10
11 import org.eclipse.core.runtime.Path;
12 import org.eclipse.core.runtime.Platform;
13 import org.eclipse.core.runtime.Plugin;
14 import org.eclipse.jdt.core.IClasspathEntry;
15 import org.eclipse.jdt.core.IJavaProject;
16 import org.eclipse.jdt.core.JavaCore;
17 import org.eclipse.jdt.core.JavaModelException;
18
19 import java.io.IOException;
20 import java.net.URL;
21
22 /***
23 * Plugin class for com.bbn.jena. Contains convenience methods for working with
24 * the Jena classpath container.
25 * @author jlerner
26 */
27 public class JenaPlugin extends Plugin
28 {
29 private static JenaPlugin _plugin;
30
31 /***
32 * Constructs a new JenaPlugin and sets it as the one and only instance.
33 */
34 public JenaPlugin()
35 {
36 super();
37 _plugin = this;
38 }
39
40 /***
41 * Provides access to the one and only instance of JenaPlugin.
42 * @return The singleton instance
43 */
44 public static JenaPlugin getJenaPlugin()
45 {
46 return _plugin;
47 }
48
49 private static final String[] AS_JARS =
50 {
51 "antlr.jar",
52 "concurrent.jar",
53 "icu4j.jar",
54 "jakarta-oro-2.0.5.jar",
55 "jena.jar",
56 "junit.jar",
57 "log4j-1.2.7.jar",
58 "rdf-api-2001-01-19.jar",
59 "xercesImpl.jar",
60 "xmlParserAPIs.jar",
61 "commons-logging.jar",
62 "xml-apis.jar",
63 };
64 private static String[] _asJarLocations;
65 /***
66 * Compiles a list of .jar file locations for the Jena library.
67 * @return An array of strings specifying filesystem paths for each .jar file
68 * to be included in the Jena container
69 */
70 public String[] getJenaLibraryLocations()
71 {
72 if (_asJarLocations == null)
73 {
74 _asJarLocations = new String[AS_JARS.length];
75 for (int i = 0; i < AS_JARS.length; i++)
76 {
77 String sJar = AS_JARS[i];
78 URL url = find(new Path(sJar));
79 try
80 {
81 url = Platform.asLocalURL(url);
82 _asJarLocations[i] = url.getFile();
83 }
84 catch (IOException e)
85 {
86
87 e.printStackTrace();
88 }
89 }
90 }
91 return _asJarLocations;
92 }
93
94 /***
95 * Adds the Jena container to a Java project's classpath. If Jena
96 * is already there, nothing happens.
97 * @param project The project to receive the Jena classpath container
98 * @throws JavaModelException if the classpath cannot be updated
99 */
100 public static void addJenaToClasspath(IJavaProject project)
101 throws JavaModelException
102 {
103 IClasspathEntry entry =
104 JavaCore.newContainerEntry(new Path("com.bbn.jena.jenaContainer"));
105 IClasspathEntry[] entries = project.getRawClasspath();
106 for (int i = 0; i < entries.length; i++)
107 {
108 if (entries[i].equals(entry))
109 {
110
111 return;
112 }
113 }
114 IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
115 System.arraycopy(entries, 0, newEntries, 0, entries.length);
116 newEntries[entries.length] = entry;
117 project.setRawClasspath(newEntries, null);
118 }
119 }