javasci::ClassPath Class Reference

Collaboration diagram for javasci::ClassPath:

Collaboration graph
[legend]

Static Public Member Functions

static void addFile (final String s, int i) throws IOException
static void addFile (final File f, int i) throws IOException
static void addURL (final URL u, int i)
static String[] getClassPath ()
static void loadBackGroundClassPath ()

Static Private Attributes

static final Class[] parameters = new Class[]{URL.class}
static Vector< URL > queued = new Vector<URL>()

Detailed Description

ClassPath to overload java classpath.

Definition at line 31 of file ClassPath.java.


Member Function Documentation

static void javasci::ClassPath::addFile ( final String  s,
int  i 
) throws IOException [inline, static]

add a filename to java classpath.

Parameters:
s a filename
Exceptions:
IOException if an error occurs

Definition at line 42 of file ClassPath.java.

References i, and s.

00042                                                                             {
00043                 addFile(new File(s), i);
00044         }

static void javasci::ClassPath::addFile ( final File  f,
int  i 
) throws IOException [inline, static]

add a file to java classpath.

Parameters:
f a file
Exceptions:
IOException if an error occurs

Definition at line 51 of file ClassPath.java.

References addURL(), f, and i.

00051                                                                            {
00052                 addURL(f.toURI().toURL(), i);
00053         }

Here is the call graph for this function:

static void javasci::ClassPath::addURL ( final URL  u,
int  i 
) [inline, static]

Add a URL to classpath.

Parameters:
u URL of the classes (jar or path)
i the type of load: i=0 startup / i=1 background / i=2 onUse

Definition at line 61 of file ClassPath.java.

References Method, parameters, and queued.

Referenced by addFile().

00061                                                       {
00062 
00063                 final URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
00064                 Class sysclass = URLClassLoader.class;
00065 
00066                 try {
00067 
00068                         final Method method = sysclass.getDeclaredMethod("addURL", parameters);
00069                         method.setAccessible(true);
00070                         switch (i) {
00071                                 case 0: /* Load now */
00072                                         method.invoke(sysloader , new Object[] { u });
00073                                         break;
00074                                 case 1: /* Load later (background) */
00075                                         queued.add(u);
00076                                         break;
00077                         }
00078 
00079                 } catch (NoSuchMethodException e) {
00080                         System.err.println("Error: Cannot find the declared method: " + e.getLocalizedMessage());
00081                 } catch (IllegalAccessException e) {
00082                         System.err.println("Error: Illegal access: " + e.getLocalizedMessage());
00083                 } catch (InvocationTargetException e) {
00084                         System.err.println("Error: Could not invocate target: " + e.getLocalizedMessage());
00085                 }
00086 
00087         }

Here is the caller graph for this function:

static String [] javasci::ClassPath::getClassPath (  )  [inline, static]

Get the classpath loaded

Returns:
classpath The list of the classpath

Definition at line 93 of file ClassPath.java.

References i.

00093                                               {
00094         
00095                 URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
00096                 URL[] path = sysloader.getURLs();
00097                 String[] paths = new String[path.length];
00098                 for (int i = 0; i < path.length; i++) {
00099                         paths[i] = path[i].getFile();
00100                 }
00101                 return paths;
00102         }

static void javasci::ClassPath::loadBackGroundClassPath (  )  [inline, static]

Load all the classpath in dedicated threads in background

Definition at line 108 of file ClassPath.java.

References queued, and run().

00108                                                     {
00109                 Thread backgroundLoader = new Thread() {
00110                                 public void run() { 
00111                                         try {
00112 
00113                                                 Iterator<URL> urlIt = queued.iterator();
00114 
00115                                                 while (urlIt.hasNext()) {
00116                                                         ClassPath.addURL(urlIt.next(),0);
00117                                                 }
00118 
00119                                         }catch (Exception e){
00120                                                 System.err.println("Error : "+e.getLocalizedMessage());
00121                                         }
00122                                 }
00123                         };
00124                 backgroundLoader.start();
00125         }

Here is the call graph for this function:


Field Documentation

final Class [] javasci::ClassPath::parameters = new Class[]{URL.class} [static, private]

Definition at line 33 of file ClassPath.java.

Referenced by addURL().

Vector<URL> javasci::ClassPath::queued = new Vector<URL>() [static, private]

Definition at line 35 of file ClassPath.java.

Referenced by addURL(), and loadBackGroundClassPath().


The documentation for this class was generated from the following file:

Generated on Tue Sep 9 18:23:59 2008 for Scilab [trunk] by  doxygen 1.5.5