View Javadoc

1   /*
2    * $Id: KazukiPlugin.java,v 1.14 2004/09/20 03:51:50 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8   package com.bbn.swede.library.kazuki;
9   
10  import java.io.IOException;
11  import java.net.URL;
12  
13  import org.eclipse.core.runtime.Path;
14  import org.eclipse.core.runtime.Platform;
15  import org.eclipse.core.runtime.Plugin;
16  import org.eclipse.jdt.core.IClasspathEntry;
17  import org.eclipse.jdt.core.IJavaProject;
18  import org.eclipse.jdt.core.JavaCore;
19  import org.eclipse.jdt.core.JavaModelException;
20  
21  import com.bbn.swede.core.OWLCore;
22  
23  /***
24   * Plugin class for com.bbn.swede.library.kazuki.  Contains convenience
25   * methods for working with the Kazuki classpath container.
26   */
27  public class KazukiPlugin extends Plugin
28  {
29     //The shared instance.
30     private static KazukiPlugin _plugin;
31  
32     /***
33      * Creates a new KazukiPlugin and sets it as the singleton instance.
34      */
35     public KazukiPlugin()
36     {
37        super();
38        _plugin = this;
39     }
40  
41     /***
42      * Provides access to the one and only instance of KazukiPlugin.
43      * @return The singleton instance
44      */
45     public static KazukiPlugin getKazukiPlugin()
46     {
47        return _plugin;
48     }
49  
50     private static String[] _asJarLocations;
51     /***
52      * Compiles a list of .jar file locations for the Kazuki library.
53      * @return An array of strings specifying filesystem paths for each .jar file
54      *         to be included in the Kazuki container
55      */
56     public String[] getKazukiLibraryLocations()
57     {
58        if (_asJarLocations == null)
59        {
60           try
61           {
62              _asJarLocations = new String[1];
63              String sJar = "kazuki.jar";
64              URL url = find(new Path(sJar));
65              url = Platform.asLocalURL(url);
66              _asJarLocations[0] = url.getFile();
67           }
68           catch (IOException e)
69           {
70              OWLCore.logError(getID(), "Unable to locate Kazuki jars on the filesystem", e);
71           }
72        }
73        return _asJarLocations;
74     }
75  
76     /***
77      * Adds the Kazuki container to a Java project's classpath.  If Kazuki
78      * is already there, nothing happens.
79      * @param project The project to receive the Kazuki classpath container
80      * @throws JavaModelException if an error occurs modifying the classpath
81      */
82     public static void addKazukiToClasspath(IJavaProject project)
83        throws JavaModelException
84     {
85        IClasspathEntry entry =
86           JavaCore.newContainerEntry(
87              new Path("com.bbn.swede.library.kazuki.kazukiContainer"));
88        IClasspathEntry[] entries = project.getRawClasspath();
89        for (int i = 0; i < entries.length; i++)
90        {
91           if (entries[i].equals(entry))
92           {
93              return;
94           }
95        }
96        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
97        System.arraycopy(entries, 0, newEntries, 0, entries.length);
98        newEntries[entries.length] = entry;
99        project.setRawClasspath(newEntries, null);
100    }
101 
102    /***
103     * Retrieves the plugin's ID from the resource bundle.
104     * @return The plugin ID
105     */
106    public static String getID()
107    {
108       return KazukiPlugin.getKazukiPlugin().getBundle().getSymbolicName();
109    }
110 
111 }