Package gnu.java.net.loader

Examples of gnu.java.net.loader.URLLoader


        // Reset the toString() value.
        thisString = null;

        // Create a loader for this URL.
        URLLoader loader = null;
        String file = newUrl.getFile();
        try
          {
            file = gnu.java.net.protocol.file.Connection.unquote(file);
          }
        catch (MalformedURLException e)
          {
            // ignore
          }
        String protocol = newUrl.getProtocol();

        // If we have a file: URL, we want to make it absolute
        // here, before we decide whether it is really a jar.
        URL absoluteURL;
        if ("file".equals (protocol))
          {
            File dir = new File(file);
            try
              {
                absoluteURL = dir.getCanonicalFile().toURL();
              }
            catch (IOException ignore)
              {
                try
                  {
                    absoluteURL = dir.getAbsoluteFile().toURL();
                  }
                catch (MalformedURLException _)
                  {
                    // This really should not happen.
                    absoluteURL = newUrl;
                  }
              }
          }
        else
          {
            // This doesn't hurt, and it simplifies the logic a
            // little.
            absoluteURL = newUrl;
          }

        // First see if we can find a handler with the correct name.
        try
          {
            Class handler = Class.forName(URL_LOADER_PREFIX + protocol);
            Class[] argTypes = new Class[] { URLClassLoader.class,
                                             URLStreamHandlerCache.class,
                                             URLStreamHandlerFactory.class,
                                             URL.class,
                                             URL.class };
            Constructor k = handler.getDeclaredConstructor(argTypes);
            loader
              = (URLLoader) k.newInstance(new Object[] { this,
                                                         factoryCache,
                                                         factory,
                                                         newUrl,
                                                         absoluteURL });
          }
        catch (ClassNotFoundException ignore)
          {
            // Fall through.
          }
        catch (NoSuchMethodException nsme)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("couldn't find URLLoader constructor");
            vme.initCause(nsme);
            throw vme;
          }
        catch (InstantiationException inste)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("couldn't instantiate URLLoader");
            vme.initCause(inste);
            throw vme;
          }
        catch (InvocationTargetException ite)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("error instantiating URLLoader");
            vme.initCause(ite);
            throw vme;
          }
        catch (IllegalAccessException illae)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("invalid access to URLLoader");
            vme.initCause(illae);
            throw vme;
          }

        if (loader == null)
          {
            // If it is not a directory, use the jar loader.
            if (! (file.endsWith("/") || file.endsWith(File.separator)))
              loader = new JarURLLoader(this, factoryCache, factory,
                                        newUrl, absoluteURL);
            else if ("file".equals(protocol))
              loader = new FileURLLoader(this, factoryCache, factory,
                                         newUrl, absoluteURL);
            else
              loader = new RemoteURLLoader(this, factoryCache, factory,
                                           newUrl);
          }

        urlinfos.add(loader);
        ArrayList extra = loader.getClassPath();
        if (extra != null)
          urlinfos.addAll(extra);
      }
  }
View Full Code Here


    String resourceName = className.replace('.', '/') + ".class";
    int max = urlinfos.size();
    Resource resource = null;
    for (int i = 0; i < max && resource == null; i++)
      {
        URLLoader loader = (URLLoader)urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Class k = loader.getClass(className);
        if (k != null)
          return k;

        resource = loader.getResource(resourceName);
      }
    if (resource == null)
      throw new ClassNotFoundException(className + " not found in " + this);

    // Try to read the class data, create the CodeSource, Package and
View Full Code Here

  private Resource findURLResource(String resourceName)
  {
    int max = urlinfos.size();
    for (int i = 0; i < max; i++)
      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          return resource;
      }
    return null;
  }
View Full Code Here

  {
    Vector resources = new Vector();
    int max = urlinfos.size();
    for (int i = 0; i < max; i++)
      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          resources.add(resource.getURL());
      }
    return resources.elements();
  }
View Full Code Here

  // Reset the toString() value.
  thisString = null;

        // Create a loader for this URL.
        URLLoader loader = null;
        String file = newUrl.getFile();
        String protocol = newUrl.getProtocol();

        // If we have a file: URL, we want to make it absolute
        // here, before we decide whether it is really a jar.
        URL absoluteURL;
        if ("file".equals (protocol))
          {
            File dir = new File(file);
            try
              {
                absoluteURL = dir.getCanonicalFile().toURL();
              }
            catch (IOException ignore)
              {
                try
                  {
                    absoluteURL = dir.getAbsoluteFile().toURL();
                  }
                catch (MalformedURLException _)
                  {
                    // This really should not happen.
                    absoluteURL = newUrl;
                  }
              }
          }
        else
          {
            // This doesn't hurt, and it simplifies the logic a
            // little.
            absoluteURL = newUrl;
          }

        // First see if we can find a handler with the correct name.
        try
          {
            Class<?> handler = Class.forName(URL_LOADER_PREFIX + protocol);
            Class<?>[] argTypes = new Class<?>[] { URLClassLoader.class,
                                                   URLStreamHandlerCache.class,
                                                   URLStreamHandlerFactory.class,
                                                   URL.class,
                                                   URL.class };
            Constructor k = handler.getDeclaredConstructor(argTypes);
            loader
              = (URLLoader) k.newInstance(new Object[] { this,
                                                         factoryCache,
                                                         factory,
                                                         newUrl,
                                                         absoluteURL });
          }
        catch (ClassNotFoundException ignore)
          {
            // Fall through.
          }
        catch (NoSuchMethodException nsme)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("couldn't find URLLoader constructor");
            vme.initCause(nsme);
            throw vme;
          }
        catch (InstantiationException inste)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("couldn't instantiate URLLoader");
            vme.initCause(inste);
            throw vme;
          }
        catch (InvocationTargetException ite)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("error instantiating URLLoader");
            vme.initCause(ite);
            throw vme;
          }
        catch (IllegalAccessException illae)
          {
            // Programming error in the class library.
            InternalError vme
              = new InternalError("invalid access to URLLoader");
            vme.initCause(illae);
            throw vme;
          }

        if (loader == null)
          {
            // If it is not a directory, use the jar loader.
            if (! (file.endsWith("/") || file.endsWith(File.separator)))
              loader = new JarURLLoader(this, factoryCache, factory,
                                        newUrl, absoluteURL);
            else if ("file".equals(protocol))
              loader = new FileURLLoader(this, factoryCache, factory,
                                         newUrl, absoluteURL);
            else
              loader = new RemoteURLLoader(this, factoryCache, factory,
                                           newUrl);
          }

  urlinfos.add(loader);
  ArrayList<URLLoader> extra = loader.getClassPath();
        if (extra != null)
          urlinfos.addAll(extra);
      }
  }
View Full Code Here

    String resourceName = className.replace('.', '/') + ".class";
    int max = urlinfos.size();
    Resource resource = null;
    for (int i = 0; i < max && resource == null; i++)
      {
        URLLoader loader = (URLLoader)urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Class k = loader.getClass(className);
        if (k != null)
          return k;

        resource = loader.getResource(resourceName);
      }
    if (resource == null)
      throw new ClassNotFoundException(className + " not found in " + this);

    // Try to read the class data, create the CodeSource, Package and
View Full Code Here

  private Resource findURLResource(String resourceName)
  {
    int max = urlinfos.size();
    for (int i = 0; i < max; i++)
      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          return resource;
      }
    return null;
  }
View Full Code Here

  {
    Vector<URL> resources = new Vector<URL>();
    int max = urlinfos.size();
    for (int i = 0; i < max; i++)
      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          resources.add(resource.getURL());
      }
    return resources.elements();
  }
View Full Code Here

TOP

Related Classes of gnu.java.net.loader.URLLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.