commons-discovery

16:34:44.397 INFO  jd.cli.Main - Decompiling commons-discovery.jar
package org.apache.commons.discovery.ant;

import java.io.PrintStream;
import java.util.Vector;
import org.apache.commons.discovery.ResourceNameIterator;
import org.apache.commons.discovery.jdk.JDKHooks;
import org.apache.commons.discovery.resource.DiscoverResources;
import org.apache.commons.discovery.resource.ResourceDiscoverImpl;

public class ServiceDiscoveryTask
{
  String name;
  int debug = 0;
  String[] drivers = null;
  
  public void setServiceName(String name)
  {
    this.name = name;
  }
  
  public void setDebug(int i)
  {
    debug = debug;
  }
  
  public String[] getServiceInfo()
  {
    return drivers;
  }
  
  public void execute()
    throws Exception
  {
    System.out.println("XXX ");
    
    DiscoverResources disc = new DiscoverResources();
    disc.addClassLoader(JDKHooks.getJDKHooks().getThreadContextClassLoader());
    disc.addClassLoader(getClass().getClassLoader());
    
    ResourceNameIterator iterator = disc.findResources(name);
    
    Vector vector = new Vector();
    while (iterator.hasNext())
    {
      String resourceInfo = iterator.nextResourceName();
      vector.add(resourceInfo);
      if (debug > 0) {
        System.out.println("Found " + resourceInfo);
      }
    }
    drivers = new String[vector.size()];
    vector.copyInto(drivers);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.ant.ServiceDiscoveryTask
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery;

import java.io.PrintWriter;
import java.io.StringWriter;

public class DiscoveryException
  extends RuntimeException
{
  public DiscoveryException() {}
  
  public DiscoveryException(String message)
  {
    super(message);
  }
  
  public DiscoveryException(Throwable cause)
  {
    this(cause == null ? null : cause.toString(), cause);
  }
  
  public DiscoveryException(String message, Throwable cause)
  {
    super(message);
    this.cause = cause;
  }
  
  protected Throwable cause = null;
  
  public Throwable getCause()
  {
    return cause;
  }
  
  public String toString()
  {
    String ls = System.getProperty("line.separator");
    String str = super.toString();
    if (cause != null) {
      str = str + ls + "*****" + ls + stackToString(cause);
    }
    return str;
  }
  
  private static String stackToString(Throwable e)
  {
    StringWriter sw = new StringWriter(1024);
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    pw.close();
    return sw.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.DiscoveryException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.jdk;

import java.io.IOException;
import java.util.Enumeration;

class JDK11Hooks
  extends JDKHooks
{
  private static final ClassLoader systemClassLoader = new PsuedoSystemClassLoader();
  
  public ClassLoader getThreadContextClassLoader()
  {
    return null;
  }
  
  public ClassLoader getSystemClassLoader()
  {
    return systemClassLoader;
  }
  
  public Enumeration getResources(ClassLoader loader, String resourceName)
    throws IOException
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.jdk.JDK11Hooks
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.jdk;

import java.io.IOException;
import java.util.Enumeration;

class JDK12Hooks
  extends JDKHooks
{
  public ClassLoader getThreadContextClassLoader()
  {
    ClassLoader classLoader;
    try
    {
      classLoader = Thread.currentThread().getContextClassLoader();
    }
    catch (SecurityException e)
    {
      classLoader = null;
    }
    return classLoader;
  }
  
  public ClassLoader getSystemClassLoader()
  {
    ClassLoader classLoader;
    try
    {
      classLoader = ClassLoader.getSystemClassLoader();
    }
    catch (SecurityException e)
    {
      classLoader = null;
    }
    return classLoader;
  }
  
  public Enumeration getResources(ClassLoader loader, String resourceName)
    throws IOException
  {
    return loader.getResources(resourceName);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.jdk.JDK12Hooks
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.jdk;

import java.io.IOException;
import java.util.Enumeration;

public abstract class JDKHooks
{
  private static final JDKHooks jdkHooks = new JDK12Hooks();
  
  public static final JDKHooks getJDKHooks()
  {
    return jdkHooks;
  }
  
  public abstract ClassLoader getThreadContextClassLoader();
  
  public abstract ClassLoader getSystemClassLoader();
  
  public abstract Enumeration getResources(ClassLoader paramClassLoader, String paramString)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.jdk.JDKHooks
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.jdk;

import java.io.InputStream;
import java.net.URL;

class PsuedoSystemClassLoader
  extends ClassLoader
{
  protected Class loadClass(String className, boolean resolve)
    throws ClassNotFoundException
  {
    return findSystemClass(className);
  }
  
  public URL getResource(String resName)
  {
    return ClassLoader.getSystemResource(resName);
  }
  
  public InputStream getResourceAsStream(String resName)
  {
    return ClassLoader.getSystemResourceAsStream(resName);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.jdk.PsuedoSystemClassLoader
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.log;

import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.commons.discovery.DiscoveryException;
import org.apache.commons.discovery.tools.ClassUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DiscoveryLogFactory
{
  private static LogFactory logFactory = null;
  private static final Hashtable classRegistry = new Hashtable();
  private static final Class[] setLogParamClasses = { Log.class };
  private static Log log = _newLog(DiscoveryLogFactory.class);
  
  public static Log newLog(Class clazz)
  {
    try
    {
      Method setLog = ClassUtils.findPublicStaticMethod(clazz, Void.TYPE, "setLog", setLogParamClasses);
      if (setLog == null)
      {
        String msg = "Internal Error: " + clazz.getName() + " required to implement 'public static void setLog(Log)'";
        log.fatal(msg);
        throw new DiscoveryException(msg);
      }
    }
    catch (SecurityException se)
    {
      String msg = "Required Security Permissions not present";
      log.fatal(msg, se);
      throw new DiscoveryException(msg, se);
    }
    if (log.isDebugEnabled()) {
      log.debug("Class meets requirements: " + clazz.getName());
    }
    return _newLog(clazz);
  }
  
  public static Log _newLog(Class clazz)
  {
    classRegistry.put(clazz, clazz);
    
    return logFactory == null ? new SimpleLog(clazz.getName()) : logFactory.getInstance(clazz.getName());
  }
  
  public static void setLog(Log _log)
  {
    log = _log;
  }
  
  public static void setFactory(LogFactory factory)
  {
    if (logFactory == null)
    {
      logFactory = factory;
      
      Enumeration elements = classRegistry.elements();
      while (elements.hasMoreElements())
      {
        Class clazz = (Class)elements.nextElement();
        if (log.isDebugEnabled()) {
          log.debug("Reset Log for: " + clazz.getName());
        }
        Method setLog = null;
        try
        {
          setLog = clazz.getMethod("setLog", setLogParamClasses);
        }
        catch (Exception e)
        {
          String msg = "Internal Error: pre-check for " + clazz.getName() + " failed?!";
          log.fatal(msg, e);
          throw new DiscoveryException(msg, e);
        }
        Object[] setLogParam = { factory.getInstance(clazz.getName()) };
        try
        {
          setLog.invoke(null, setLogParam);
        }
        catch (Exception e)
        {
          String msg = "Internal Error: setLog failed for " + clazz.getName();
          log.fatal(msg, e);
          throw new DiscoveryException(msg, e);
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.log.DiscoveryLogFactory
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.log;

import java.io.PrintStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.logging.Log;

public class SimpleLog
  implements Log
{
  public static final int LOG_LEVEL_TRACE = 1;
  public static final int LOG_LEVEL_DEBUG = 2;
  public static final int LOG_LEVEL_INFO = 3;
  public static final int LOG_LEVEL_WARN = 4;
  public static final int LOG_LEVEL_ERROR = 5;
  public static final int LOG_LEVEL_FATAL = 6;
  public static final int LOG_LEVEL_ALL = 0;
  public static final int LOG_LEVEL_OFF = 7;
  protected static final String PROP_LEVEL = "org.apache.commons.discovery.log.level";
  protected static boolean showLogName = false;
  protected static boolean showShortName = true;
  protected static boolean showDateTime = false;
  protected static DateFormat dateFormatter = null;
  protected static int logLevel = 3;
  private static PrintStream out = System.out;
  
  static
  {
    if (showDateTime) {
      dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS zzz");
    }
    String lvl = System.getProperty("org.apache.commons.discovery.log.level");
    if ("all".equalsIgnoreCase(lvl)) {
      setLevel(0);
    } else if ("trace".equalsIgnoreCase(lvl)) {
      setLevel(1);
    } else if ("debug".equalsIgnoreCase(lvl)) {
      setLevel(2);
    } else if ("info".equalsIgnoreCase(lvl)) {
      setLevel(3);
    } else if ("warn".equalsIgnoreCase(lvl)) {
      setLevel(4);
    } else if ("error".equalsIgnoreCase(lvl)) {
      setLevel(5);
    } else if ("fatal".equalsIgnoreCase(lvl)) {
      setLevel(6);
    } else if ("off".equalsIgnoreCase(lvl)) {
      setLevel(7);
    }
  }
  
  public static void setLevel(int currentLogLevel)
  {
    logLevel = currentLogLevel;
  }
  
  public static int getLevel()
  {
    return logLevel;
  }
  
  protected static boolean isLevelEnabled(int level)
  {
    return level >= getLevel();
  }
  
  protected String logName = null;
  private String prefix = null;
  
  public SimpleLog(String name)
  {
    logName = name;
  }
  
  protected void log(int type, Object message, Throwable t)
  {
    StringBuffer buf = new StringBuffer();
    if (showDateTime)
    {
      buf.append(dateFormatter.format(new Date()));
      buf.append(" ");
    }
    switch (type)
    {
    case 1: 
      buf.append("[TRACE] "); break;
    case 2: 
      buf.append("[DEBUG] "); break;
    case 3: 
      buf.append("[INFO ] "); break;
    case 4: 
      buf.append("[WARN ] "); break;
    case 5: 
      buf.append("[ERROR] "); break;
    case 6: 
      buf.append("[FATAL] ");
    }
    if (showShortName)
    {
      if (prefix == null)
      {
        prefix = (logName.substring(logName.lastIndexOf(".") + 1) + " - ");
        prefix = (prefix.substring(prefix.lastIndexOf("/") + 1) + "-");
      }
      buf.append(prefix);
    }
    else if (showLogName)
    {
      buf.append(String.valueOf(logName)).append(" - ");
    }
    buf.append(String.valueOf(message));
    if (t != null)
    {
      buf.append(" <");
      buf.append(t.toString());
      buf.append(">");
    }
    out.println(buf.toString());
    if (t != null) {
      t.printStackTrace(System.err);
    }
  }
  
  public final void debug(Object message)
  {
    if (isLevelEnabled(2)) {
      log(2, message, null);
    }
  }
  
  public final void debug(Object message, Throwable t)
  {
    if (isLevelEnabled(2)) {
      log(2, message, t);
    }
  }
  
  public final void trace(Object message)
  {
    if (isLevelEnabled(1)) {
      log(1, message, null);
    }
  }
  
  public final void trace(Object message, Throwable t)
  {
    if (isLevelEnabled(1)) {
      log(1, message, t);
    }
  }
  
  public final void info(Object message)
  {
    if (isLevelEnabled(3)) {
      log(3, message, null);
    }
  }
  
  public final void info(Object message, Throwable t)
  {
    if (isLevelEnabled(3)) {
      log(3, message, t);
    }
  }
  
  public final void warn(Object message)
  {
    if (isLevelEnabled(4)) {
      log(4, message, null);
    }
  }
  
  public final void warn(Object message, Throwable t)
  {
    if (isLevelEnabled(4)) {
      log(4, message, t);
    }
  }
  
  public final void error(Object message)
  {
    if (isLevelEnabled(5)) {
      log(5, message, null);
    }
  }
  
  public final void error(Object message, Throwable t)
  {
    if (isLevelEnabled(5)) {
      log(5, message, t);
    }
  }
  
  public final void fatal(Object message)
  {
    if (isLevelEnabled(6)) {
      log(6, message, null);
    }
  }
  
  public final void fatal(Object message, Throwable t)
  {
    if (isLevelEnabled(6)) {
      log(6, message, t);
    }
  }
  
  public final boolean isDebugEnabled()
  {
    return isLevelEnabled(2);
  }
  
  public final boolean isErrorEnabled()
  {
    return isLevelEnabled(5);
  }
  
  public final boolean isFatalEnabled()
  {
    return isLevelEnabled(6);
  }
  
  public final boolean isInfoEnabled()
  {
    return isLevelEnabled(3);
  }
  
  public final boolean isTraceEnabled()
  {
    return isLevelEnabled(1);
  }
  
  public final boolean isWarnEnabled()
  {
    return isLevelEnabled(4);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.log.SimpleLog
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.classes;

import java.net.URL;
import java.util.Vector;
import org.apache.commons.discovery.ResourceClass;
import org.apache.commons.discovery.ResourceClassIterator;
import org.apache.commons.discovery.resource.ClassLoaders;
import org.apache.commons.logging.Log;

class DiscoverClasses$1
  extends ResourceClassIterator
{
  private Vector history;
  private int idx;
  private ResourceClass resource;
  private final String val$resourceName;
  private final String val$className;
  private final DiscoverClasses this$0;
  
  public boolean hasNext()
  {
    if (resource == null) {
      resource = getNextClass();
    }
    return resource != null;
  }
  
  public ResourceClass nextResourceClass()
  {
    ResourceClass element = resource;
    resource = null;
    return element;
  }
  
  DiscoverClasses$1(DiscoverClasses this$0, String val$resourceName, String val$className)
  {
    this.this$0 = this$0;this.val$resourceName = val$resourceName;this.val$className = val$className;history = new Vector();idx = 0;resource = null;
  }
  
  private ResourceClass getNextClass()
  {
    while (idx < DiscoverClasses.access$001(this$0).size())
    {
      ClassLoader loader = DiscoverClasses.access$101(this$0).get(idx++);
      URL url = loader.getResource(val$resourceName);
      if (url != null)
      {
        if (!history.contains(url))
        {
          history.addElement(url);
          if (DiscoverClasses.access$200().isDebugEnabled()) {
            DiscoverClasses.access$200().debug("getNextClass: next URL='" + url + "'");
          }
          return new ResourceClass(val$className, url, loader);
        }
        if (DiscoverClasses.access$200().isDebugEnabled()) {
          DiscoverClasses.access$200().debug("getNextClass: duplicate URL='" + url + "'");
        }
      }
      else if (DiscoverClasses.access$200().isDebugEnabled())
      {
        DiscoverClasses.access$200().debug("getNextClass: loader " + loader + ": '" + val$resourceName + "' not found");
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.classes.DiscoverClasses.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.classes;

import java.net.URL;
import java.util.Vector;
import org.apache.commons.discovery.ResourceClass;
import org.apache.commons.discovery.ResourceClassDiscover;
import org.apache.commons.discovery.ResourceClassIterator;
import org.apache.commons.discovery.log.DiscoveryLogFactory;
import org.apache.commons.discovery.resource.ClassLoaders;
import org.apache.commons.logging.Log;

public class DiscoverClasses
  extends ResourceClassDiscoverImpl
  implements ResourceClassDiscover
{
  private static Log log = DiscoveryLogFactory.newLog(DiscoverClasses.class);
  
  public static void setLog(Log _log)
  {
    log = _log;
  }
  
  public DiscoverClasses() {}
  
  public DiscoverClasses(ClassLoaders classLoaders)
  {
    super(classLoaders);
  }
  
  public ResourceClassIterator findResourceClasses(String className)
  {
    String resourceName = className.replace('.', '/') + ".class";
    if (log.isDebugEnabled()) {
      log.debug("find: className='" + className + "'");
    }
    new ResourceClassIterator()
    {
      private Vector history;
      private int idx;
      private ResourceClass resource;
      private final String val$resourceName;
      private final String val$className;
      
      public boolean hasNext()
      {
        if (resource == null) {
          resource = getNextClass();
        }
        return resource != null;
      }
      
      public ResourceClass nextResourceClass()
      {
        ResourceClass element = resource;
        resource = null;
        return element;
      }
      
      private ResourceClass getNextClass()
      {
        while (idx < DiscoverClasses.this.getClassLoaders().size())
        {
          ClassLoader loader = DiscoverClasses.this.getClassLoaders().get(idx++);
          URL url = loader.getResource(val$resourceName);
          if (url != null)
          {
            if (!history.contains(url))
            {
              history.addElement(url);
              if (DiscoverClasses.log.isDebugEnabled()) {
                DiscoverClasses.log.debug("getNextClass: next URL='" + url + "'");
              }
              return new ResourceClass(val$className, url, loader);
            }
            if (DiscoverClasses.log.isDebugEnabled()) {
              DiscoverClasses.log.debug("getNextClass: duplicate URL='" + url + "'");
            }
          }
          else if (DiscoverClasses.log.isDebugEnabled())
          {
            DiscoverClasses.log.debug("getNextClass: loader " + loader + ": '" + val$resourceName + "' not found");
          }
        }
        return null;
      }
    };
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.classes.DiscoverClasses
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.classes;

import org.apache.commons.discovery.ResourceClass;
import org.apache.commons.discovery.ResourceClassIterator;
import org.apache.commons.discovery.ResourceIterator;
import org.apache.commons.discovery.ResourceNameIterator;

class ResourceClassDiscoverImpl$1
  extends ResourceClassIterator
{
  private ResourceClassIterator classes;
  private ResourceClass resource;
  private final ResourceNameIterator val$inputNames;
  private final ResourceClassDiscoverImpl this$0;
  
  public boolean hasNext()
  {
    if (resource == null) {
      resource = getNextResource();
    }
    return resource != null;
  }
  
  public ResourceClass nextResourceClass()
  {
    ResourceClass rsrc = resource;
    resource = null;
    return rsrc;
  }
  
  ResourceClassDiscoverImpl$1(ResourceClassDiscoverImpl this$0, ResourceNameIterator val$inputNames)
  {
    this.this$0 = this$0;this.val$inputNames = val$inputNames;classes = null;resource = null;
  }
  
  private ResourceClass getNextResource()
  {
    while ((val$inputNames.hasNext()) && ((classes == null) || (!classes.hasNext()))) {
      classes = this$0.findResourceClasses(val$inputNames.nextResourceName());
    }
    return (classes != null) && (classes.hasNext()) ? classes.nextResourceClass() : null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.classes.ResourceClassDiscoverImpl.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.classes;

import org.apache.commons.discovery.ResourceClass;
import org.apache.commons.discovery.ResourceClassDiscover;
import org.apache.commons.discovery.ResourceClassIterator;
import org.apache.commons.discovery.ResourceIterator;
import org.apache.commons.discovery.ResourceNameIterator;
import org.apache.commons.discovery.resource.ClassLoaders;
import org.apache.commons.discovery.resource.ResourceDiscoverImpl;

public abstract class ResourceClassDiscoverImpl
  extends ResourceDiscoverImpl
  implements ResourceClassDiscover
{
  public ResourceClassDiscoverImpl() {}
  
  public ResourceClassDiscoverImpl(ClassLoaders classLoaders)
  {
    super(classLoaders);
  }
  
  public ResourceNameIterator findResourceNames(String resourceName)
  {
    return findResourceClasses(resourceName);
  }
  
  public ResourceNameIterator findResourceNames(ResourceNameIterator resourceNames)
  {
    return findResourceClasses(resourceNames);
  }
  
  public ResourceIterator findResources(String resourceName)
  {
    return findResourceClasses(resourceName);
  }
  
  public ResourceIterator findResources(ResourceNameIterator resourceNames)
  {
    return findResourceClasses(resourceNames);
  }
  
  public abstract ResourceClassIterator findResourceClasses(String paramString);
  
  public ResourceClassIterator findResourceClasses(ResourceNameIterator inputNames)
  {
    new ResourceClassIterator()
    {
      private ResourceClassIterator classes;
      private ResourceClass resource;
      private final ResourceNameIterator val$inputNames;
      
      public boolean hasNext()
      {
        if (resource == null) {
          resource = getNextResource();
        }
        return resource != null;
      }
      
      public ResourceClass nextResourceClass()
      {
        ResourceClass rsrc = resource;
        resource = null;
        return rsrc;
      }
      
      private ResourceClass getNextResource()
      {
        while ((val$inputNames.hasNext()) && ((classes == null) || (!classes.hasNext()))) {
          classes = findResourceClasses(val$inputNames.nextResourceName());
        }
        return (classes != null) && (classes.hasNext()) ? classes.nextResourceClass() : null;
      }
    };
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.classes.ResourceClassDiscoverImpl
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource;

import java.util.Vector;
import org.apache.commons.discovery.jdk.JDKHooks;

public class ClassLoaders
{
  protected Vector classLoaders = new Vector();
  
  public int size()
  {
    return classLoaders.size();
  }
  
  public ClassLoader get(int idx)
  {
    return (ClassLoader)classLoaders.elementAt(idx);
  }
  
  public void put(ClassLoader classLoader)
  {
    if (classLoader != null) {
      classLoaders.addElement(classLoader);
    }
  }
  
  public void put(ClassLoader classLoader, boolean prune)
  {
    if ((classLoader != null) && ((!prune) || (!isAncestor(classLoader)))) {
      classLoaders.addElement(classLoader);
    }
  }
  
  public boolean isAncestor(ClassLoader classLoader)
  {
    if (classLoader == null) {
      return true;
    }
    for (int idx = 0; idx < size(); idx++) {
      for (ClassLoader walker = get(idx); walker != null; walker = walker.getParent()) {
        if (walker == classLoader) {
          return true;
        }
      }
    }
    return false;
  }
  
  public static ClassLoaders getLibLoaders(Class spi, Class factory, boolean prune)
  {
    ClassLoaders loaders = new ClassLoaders();
    if (spi != null) {
      loaders.put(spi.getClassLoader());
    }
    if (factory != null) {
      loaders.put(factory.getClassLoader(), prune);
    }
    loaders.put(JDKHooks.getJDKHooks().getSystemClassLoader(), prune);
    
    return loaders;
  }
  
  public static ClassLoaders getAppLoaders(Class spi, Class factory, boolean prune)
  {
    ClassLoaders loaders = new ClassLoaders();
    
    loaders.put(JDKHooks.getJDKHooks().getThreadContextClassLoader());
    if (spi != null) {
      loaders.put(spi.getClassLoader(), prune);
    }
    if (factory != null) {
      loaders.put(factory.getClassLoader(), prune);
    }
    loaders.put(JDKHooks.getJDKHooks().getSystemClassLoader(), prune);
    
    return loaders;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.ClassLoaders
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import org.apache.commons.discovery.Resource;
import org.apache.commons.discovery.ResourceIterator;
import org.apache.commons.discovery.jdk.JDKHooks;
import org.apache.commons.logging.Log;

class DiscoverResources$1
  extends ResourceIterator
{
  private int idx;
  private ClassLoader loader;
  private Enumeration resources;
  private Resource resource;
  private final String val$resourceName;
  private final DiscoverResources this$0;
  
  public boolean hasNext()
  {
    if (resource == null) {
      resource = getNextResource();
    }
    return resource != null;
  }
  
  public Resource nextResource()
  {
    Resource element = resource;
    resource = null;
    return element;
  }
  
  private Resource getNextResource()
  {
    if ((resources == null) || (!resources.hasMoreElements())) {
      resources = getNextResources();
    }
    Resource resourceInfo;
    if (resources != null)
    {
      URL url = (URL)resources.nextElement();
      if (DiscoverResources.access$000().isDebugEnabled()) {
        DiscoverResources.access$000().debug("getNextResource: next URL='" + url + "'");
      }
      resourceInfo = new Resource(val$resourceName, url, loader);
    }
    else
    {
      resourceInfo = null;
    }
    return resourceInfo;
  }
  
  DiscoverResources$1(DiscoverResources this$0, String val$resourceName)
  {
    this.this$0 = this$0;this.val$resourceName = val$resourceName;idx = 0;loader = null;resources = null;resource = null;
  }
  
  private Enumeration getNextResources()
  {
    while (idx < this$0.getClassLoaders().size())
    {
      loader = this$0.getClassLoaders().get(idx++);
      if (DiscoverResources.access$000().isDebugEnabled()) {
        DiscoverResources.access$000().debug("getNextResources: search using ClassLoader '" + loader + "'");
      }
      try
      {
        Enumeration enum = JDKHooks.getJDKHooks().getResources(loader, val$resourceName);
        if ((enum != null) && (enum.hasMoreElements())) {
          return enum;
        }
      }
      catch (IOException ex)
      {
        DiscoverResources.access$000().warn("getNextResources: Ignoring Exception", ex);
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.DiscoverResources.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import org.apache.commons.discovery.Resource;
import org.apache.commons.discovery.ResourceDiscover;
import org.apache.commons.discovery.ResourceIterator;
import org.apache.commons.discovery.jdk.JDKHooks;
import org.apache.commons.discovery.log.DiscoveryLogFactory;
import org.apache.commons.logging.Log;

public class DiscoverResources
  extends ResourceDiscoverImpl
  implements ResourceDiscover
{
  private static Log log = DiscoveryLogFactory.newLog(DiscoverResources.class);
  
  public static void setLog(Log _log)
  {
    log = _log;
  }
  
  public DiscoverResources() {}
  
  public DiscoverResources(ClassLoaders classLoaders)
  {
    super(classLoaders);
  }
  
  public ResourceIterator findResources(String resourceName)
  {
    if (log.isDebugEnabled()) {
      log.debug("find: resourceName='" + resourceName + "'");
    }
    new ResourceIterator()
    {
      private int idx;
      private ClassLoader loader;
      private Enumeration resources;
      private Resource resource;
      private final String val$resourceName;
      
      public boolean hasNext()
      {
        if (resource == null) {
          resource = getNextResource();
        }
        return resource != null;
      }
      
      public Resource nextResource()
      {
        Resource element = resource;
        resource = null;
        return element;
      }
      
      private Resource getNextResource()
      {
        if ((resources == null) || (!resources.hasMoreElements())) {
          resources = getNextResources();
        }
        Resource resourceInfo;
        if (resources != null)
        {
          URL url = (URL)resources.nextElement();
          if (DiscoverResources.log.isDebugEnabled()) {
            DiscoverResources.log.debug("getNextResource: next URL='" + url + "'");
          }
          resourceInfo = new Resource(val$resourceName, url, loader);
        }
        else
        {
          resourceInfo = null;
        }
        return resourceInfo;
      }
      
      private Enumeration getNextResources()
      {
        while (idx < getClassLoaders().size())
        {
          loader = getClassLoaders().get(idx++);
          if (DiscoverResources.log.isDebugEnabled()) {
            DiscoverResources.log.debug("getNextResources: search using ClassLoader '" + loader + "'");
          }
          try
          {
            Enumeration enum = JDKHooks.getJDKHooks().getResources(loader, val$resourceName);
            if ((enum != null) && (enum.hasMoreElements())) {
              return enum;
            }
          }
          catch (IOException ex)
          {
            DiscoverResources.log.warn("getNextResources: Ignoring Exception", ex);
          }
        }
        return null;
      }
    };
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.DiscoverResources
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.names;

import org.apache.commons.discovery.ResourceNameIterator;

class DiscoverMappedNames$1
  implements ResourceNameIterator
{
  String[] names;
  private int idx;
  private final Object val$obj;
  private final DiscoverMappedNames this$0;
  
  public boolean hasNext()
  {
    return idx < names.length;
  }
  
  DiscoverMappedNames$1(DiscoverMappedNames this$0, Object val$obj)
  {
    this.this$0 = this$0;this.val$obj = val$obj;names = ((this.val$obj == null) || ((this.val$obj instanceof String)) ? new String[] { (String)this.val$obj } : (String[])this.val$obj);idx = 0;
  }
  
  public String nextResourceName()
  {
    return hasNext() ? names[(idx++)] : null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.names.DiscoverMappedNames.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.names;

import java.util.Hashtable;
import org.apache.commons.discovery.ResourceNameDiscover;
import org.apache.commons.discovery.ResourceNameIterator;
import org.apache.commons.discovery.log.DiscoveryLogFactory;
import org.apache.commons.logging.Log;

public class DiscoverMappedNames
  extends ResourceNameDiscoverImpl
  implements ResourceNameDiscover
{
  private static Log log = DiscoveryLogFactory.newLog(DiscoverMappedNames.class);
  
  public static void setLog(Log _log)
  {
    log = _log;
  }
  
  private Hashtable mapping = new Hashtable();
  
  public void map(String fromName, String toName)
  {
    mapping.put(fromName, toName);
  }
  
  public void map(String fromName, String[] toNames)
  {
    mapping.put(fromName, toNames);
  }
  
  public ResourceNameIterator findResourceNames(String resourceName)
  {
    if (log.isDebugEnabled()) {
      log.debug("find: resourceName='" + resourceName + "', mapping to constants");
    }
    Object obj = mapping.get(resourceName);
    
    new ResourceNameIterator()
    {
      String[] names;
      private int idx;
      private final Object val$obj;
      
      public boolean hasNext()
      {
        return idx < names.length;
      }
      
      public String nextResourceName()
      {
        return hasNext() ? names[(idx++)] : null;
      }
    };
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.names.DiscoverMappedNames
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.names;

import org.apache.commons.discovery.ResourceNameIterator;
import org.apache.commons.discovery.tools.ManagedProperties;

class DiscoverNamesInAlternateManagedProperties$1
  implements ResourceNameIterator
{
  private String resource;
  private final String val$mappedName;
  private final DiscoverNamesInAlternateManagedProperties this$0;
  
  public boolean hasNext()
  {
    return resource != null;
  }
  
  DiscoverNamesInAlternateManagedProperties$1(DiscoverNamesInAlternateManagedProperties this$0, String val$mappedName)
  {
    this.this$0 = this$0;this.val$mappedName = val$mappedName;resource = (this.val$mappedName == null ? null : ManagedProperties.getProperty(this.val$mappedName));
  }
  
  public String nextResourceName()
  {
    String element = resource;
    resource = null;
    return element;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.names.DiscoverNamesInAlternateManagedProperties.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.names;

import java.util.HashMap;
import org.apache.commons.discovery.ResourceNameDiscover;
import org.apache.commons.discovery.ResourceNameIterator;
import org.apache.commons.discovery.log.DiscoveryLogFactory;
import org.apache.commons.discovery.tools.ManagedProperties;
import org.apache.commons.logging.Log;

public class DiscoverNamesInAlternateManagedProperties
  extends ResourceNameDiscoverImpl
  implements ResourceNameDiscover
{
  private static Log log = DiscoveryLogFactory.newLog(DiscoverNamesInAlternateManagedProperties.class);
  
  public static void setLog(Log _log)
  {
    log = _log;
  }
  
  HashMap mapping = new HashMap();
  
  public void addClassToPropertyNameMapping(String className, String propertyName)
  {
    mapping.put(className, propertyName);
  }
  
  public ResourceNameIterator findResourceNames(String resourceName)
  {
    String mappedName = (String)mapping.get(resourceName);
    if (log.isDebugEnabled()) {
      if (mappedName == null) {
        log.debug("find: resourceName='" + resourceName + "', no mapping");
      } else {
        log.debug("find: resourceName='" + resourceName + "', lookup property '" + mappedName + "'");
      }
    }
    new ResourceNameIterator()
    {
      private String resource;
      private final String val$mappedName;
      
      public boolean hasNext()
      {
        return resource != null;
      }
      
      public String nextResourceName()
      {
        String element = resource;
        resource = null;
        return element;
      }
    };
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.names.DiscoverNamesInAlternateManagedProperties
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.names;

import org.apache.commons.discovery.ResourceNameIterator;

class DiscoverNamesInDictionary$1
  implements ResourceNameIterator
{
  private int idx;
  private final String[] val$resources;
  private final DiscoverNamesInDictionary this$0;
  
  public boolean hasNext()
  {
    return (val$resources != null) && (idx < val$resources.length);
  }
  
  DiscoverNamesInDictionary$1(DiscoverNamesInDictionary this$0, String[] val$resources)
  {
    this.this$0 = this$0;this.val$resources = val$resources;idx = 0;
  }
  
  public String nextResourceName()
  {
    return val$resources[(idx++)];
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.names.DiscoverNamesInDictionary.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.names;

import java.util.Dictionary;
import java.util.Hashtable;
import org.apache.commons.discovery.ResourceNameDiscover;
import org.apache.commons.discovery.ResourceNameIterator;
import org.apache.commons.discovery.log.DiscoveryLogFactory;
import org.apache.commons.logging.Log;

public class DiscoverNamesInDictionary
  extends ResourceNameDiscoverImpl
  implements ResourceNameDiscover
{
  private static Log log = DiscoveryLogFactory.newLog(DiscoverNamesInDictionary.class);
  private Dictionary dictionary;
  
  public static void setLog(Log _log)
  {
    log = _log;
  }
  
  public DiscoverNamesInDictionary()
  {
    setDictionary(new Hashtable());
  }
  
  public DiscoverNamesInDictionary(Dictionary dictionary)
  {
    setDictionary(dictionary);
  }
  
  protected Dictionary getDictionary()
  {
    return dictionary;
  }
  
  public void setDictionary(Dictionary table)
  {
    dictionary = dictionary;
  }
  
  public void addResource(String resourceName, String resource)
  {
    dictionary.put(resourceName, resource);
  }
  
  public void addResource(String resourceName, String[] resources)
  {
    dictionary.put(resourceName, resources);
  }
  
  public ResourceNameIterator findResourceNames(String resourceName)
  {
    if (log.isDebugEnabled()) {
      log.debug("find: resourceName='" + resourceName + "'");
    }
    Object baseResource = dictionary.get(resourceName);
    String[] resources;
    if ((baseResource instanceof String)) {
      resources = new String[] { (String)baseResource };
    } else if ((baseResource instanceof String[])) {
      resources = (String[])baseResource;
    } else {
      resources = null;
    }
    new ResourceNameIterator()
    {
      private int idx;
      private final String[] val$resources;
      
      public boolean hasNext()
      {
        return (val$resources != null) && (idx < val$resources.length);
      }
      
      public String nextResourceName()
      {
        return val$resources[(idx++)];
      }
    };
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.discovery.resource.names.DiscoverNamesInDictionary
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.discovery.resource.names;

import java.util.Vector;
import org.apache.commons.discovery.ResourceDiscover;
import org.apache.commons.discovery.ResourceIterator;
import org.apache.commons.discovery.ResourceNameIterator;
import org.apache.commons.logging.Log;

class DiscoverNamesInFile$1
  implements ResourceNameIterator
{
  private ResourceIterator files;
  private int idx;
  private Vector classNames;
  private String resource;
  private final String val$fileName;
  private final DiscoverNamesInFile this$0;
  
  public boolean hasNext()
  {
    if (resource == null) {
      resource = getNextClassName();
    }
    return resource != null;
  }
  
  public String nextResourceName()
  {
    String element = resource;
    resource = null;
    return element;
  }
  
  private String getNextClassName()
  {
    if ((classNames == null) || (idx >= classNames.size()))
    {
      classNames = getNextClassNames();
      idx = 0;
      if (classNames == null) {
        return null;
      }
    }
    String className = (String)classNames.get(idx++);
    if (DiscoverNamesInFile.access$000().isDebugEnabled()) {
      DiscoverNamesInFile.access$000().debug("getNextClas
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd