View Javadoc

1   /*
2    * $Id: JenaContainer.java,v 1.7 2005/06/01 14:36:05 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   
9   /***
10   * @author jlerner
11   */
12  package com.bbn.jena;
13  
14  import org.eclipse.core.runtime.IPath;
15  import org.eclipse.core.runtime.Path;
16  import org.eclipse.jdt.core.IClasspathContainer;
17  import org.eclipse.jdt.core.IClasspathEntry;
18  import org.eclipse.jdt.core.JavaCore;
19  
20  /***
21   * A JDT classpath container that allows projects to compile
22   * against the Jena libs without manually referencing the jars.
23   * @author jlerner
24   */
25  public class JenaContainer implements IClasspathContainer
26  {
27     private IPath _path;
28  
29     private static IClasspathEntry[] _classpathEntries;
30  
31     /***
32      * Creates a new instance of the Jena classpath container that returns a 
33      * specified IPath as the container path.
34      * @param path The IPath to use as the container path
35      */
36     public JenaContainer(IPath path)
37     {
38        _path = path;
39        computeClasspathEntries();
40     }
41     
42     /***
43      * Populates <code>_classpathEntries</code> with a list of all the jar
44      * files that are included in the Jena classpath container.
45      */
46     private void computeClasspathEntries()
47     {
48        if (_classpathEntries != null)
49        {
50           return;
51        }
52        String[] jars = JenaPlugin.getJenaPlugin().getJenaLibraryLocations();
53        _classpathEntries = new IClasspathEntry[jars.length];
54        for (int i = 0; i < jars.length; i++)
55        {
56           String sJarLoc = jars[i];
57           _classpathEntries[i] =
58              JavaCore.newLibraryEntry(new Path(sJarLoc), null, null);
59        }
60     }
61  
62     /*
63      *  (non-Javadoc)
64      * @see org.eclipse.jdt.core.IClasspathContainer#getClasspathEntries()
65      */
66     public IClasspathEntry[] getClasspathEntries()
67     {
68        return _classpathEntries;
69     }
70  
71     /*
72      *  (non-Javadoc)
73      * @see org.eclipse.jdt.core.IClasspathContainer#getDescription()
74      */
75     public String getDescription()
76     {
77        return "Jena Library [Jena 2.1]";
78     }
79  
80     /*
81      *  (non-Javadoc)
82      * @see org.eclipse.jdt.core.IClasspathContainer#getKind()
83      */
84     public int getKind()
85     {
86        return IClasspathContainer.K_APPLICATION;
87     }
88  
89     /*
90      *  (non-Javadoc)
91      * @see org.eclipse.jdt.core.IClasspathContainer#getPath()
92      */
93     public IPath getPath()
94     {
95        return _path;
96     }
97  
98  }