commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsi...@apache.org
Subject cvs commit: jakarta-commons/discovery/src/java/org/apache/commons/discovery DiscoverSystemProperties.java DiscoverManagedProperties.java DiscoverDictionaryResources.java DiscoverFiledResources.java DiscoverClasses.java DiscoverClassLoaderResources.java DiscoverResources.java DiscoverPropertyResources.java
Date Thu, 29 Aug 2002 16:02:39 GMT
rsitze      2002/08/29 09:02:39

  Modified:    discovery/src/java/org/apache/commons/discovery
                        DiscoverFiledResources.java DiscoverClasses.java
                        DiscoverClassLoaderResources.java
                        DiscoverResources.java
  Added:       discovery/src/java/org/apache/commons/discovery
                        DiscoverSystemProperties.java
                        DiscoverManagedProperties.java
                        DiscoverDictionaryResources.java
  Removed:     discovery/src/java/org/apache/commons/discovery
                        DiscoverPropertyResources.java
  Log:
  Updates/corrections..  a few new classes.
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverFiledResources.java
  
  Index: DiscoverFiledResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverFiledResources.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DiscoverFiledResources.java	29 Aug 2002 05:36:36 -0000	1.1
  +++ DiscoverFiledResources.java	29 Aug 2002 16:02:39 -0000	1.2
  @@ -117,7 +117,7 @@
        */
       public ResourceIterator find(final String fileName) {
           if (log.isDebugEnabled())
  -            log.debug("findResources: fileName='" + fileName + "'");
  +            log.debug("find: fileName='" + fileName + "'");
   
           return new ResourceIterator() {
               private ResourceIterator files = getDiscoverer().find(fileName);
  @@ -142,7 +142,7 @@
                   if (classNames == null || idx >= classNames.size()) {
                       classNames = getNextClassNames();
                       idx = 0;
  -                    if (classNames != null) {
  +                    if (classNames == null) {
                           return null;
                       }
                   }
  
  
  
  1.2       +1 -1      jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverClasses.java
  
  Index: DiscoverClasses.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverClasses.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DiscoverClasses.java	29 Aug 2002 05:36:36 -0000	1.1
  +++ DiscoverClasses.java	29 Aug 2002 16:02:39 -0000	1.2
  @@ -123,7 +123,7 @@
           final String resourceName = className.replace('.','/') + ".class";
           
           if (log.isDebugEnabled())
  -            log.debug("findClasses: className='" + className + "'");
  +            log.debug("find: className='" + className + "'");
   
           return new ResourceIterator() {
               private Vector history = new Vector();
  
  
  
  1.2       +1 -1      jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverClassLoaderResources.java
  
  Index: DiscoverClassLoaderResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverClassLoaderResources.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DiscoverClassLoaderResources.java	29 Aug 2002 05:36:36 -0000	1.1
  +++ DiscoverClassLoaderResources.java	29 Aug 2002 16:02:39 -0000	1.2
  @@ -120,7 +120,7 @@
        */
       public ResourceIterator find(final String resourceName) {
           if (log.isDebugEnabled())
  -            log.debug("findResources: resourceName='" + resourceName + "'");
  +            log.debug("find: resourceName='" + resourceName + "'");
   
           return new ResourceIterator() {
               private int idx = 0;
  
  
  
  1.2       +37 -2     jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverResources.java
  
  Index: DiscoverResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverResources.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DiscoverResources.java	29 Aug 2002 05:36:36 -0000	1.1
  +++ DiscoverResources.java	29 Aug 2002 16:02:39 -0000	1.2
  @@ -57,8 +57,12 @@
   
   package org.apache.commons.discovery;
   
  +import java.io.IOException;
  +import java.net.URL;
  +import java.util.Enumeration;
   import java.util.Vector;
   
  +import org.apache.commons.discovery.jdk.JDKHooks;
   import org.apache.commons.discovery.log.DiscoveryLogFactory;
   import org.apache.commons.logging.Log;
   
  @@ -89,7 +93,7 @@
       }
       
       public Discover get(int idx) {
  -        return (Discover)discoverers.elementAt(idx);
  +        return (Discover)discoverers.get(idx);
       }
   
       /**
  @@ -109,6 +113,37 @@
        * 
        * @return ResourceIterator
        */
  -    public ResourceIterator find(String resourceName) {
  +    public ResourceIterator find(final String resourceName) {
  +        if (log.isDebugEnabled())
  +            log.debug("find: resourceName='" + resourceName + "'");
  +
  +        return new ResourceIterator() {
  +            private int idx = 0;
  +            private ResourceIterator iterator = null;
  +            
  +            public boolean hasNext() {
  +                if (iterator == null  ||  !iterator.hasNext()) {
  +                    iterator = getNextIterator();
  +                    if (iterator == null) {
  +                        return false;
  +                    }
  +                }
  +                return iterator.hasNext();
  +            }
  +            
  +            public ResourceInfo next() {
  +                return iterator.next();
  +            }
  +            
  +            private ResourceIterator getNextIterator() {
  +                while (idx < size()) {
  +                    ResourceIterator iter = get(idx++).find(resourceName);
  +                    if (iter.hasNext()) {
  +                        return iter;
  +                    }
  +                }
  +                return null;
  +            }
  +        };
       }
   }
  
  
  
  1.1                  jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverSystemProperties.java
  
  Index: DiscoverSystemProperties.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.discovery;
  
  import java.util.Dictionary;
  import java.util.Hashtable;
  
  import org.apache.commons.discovery.log.DiscoveryLogFactory;
  import org.apache.commons.logging.Log;
  
  
  /**
   * Recover resource name from System Properties.
   * 
   * @author Richard A. Sitze
   */
  public class DiscoverSystemProperties implements Discover
  {
      private static Log log = DiscoveryLogFactory.newLog(DiscoverSystemProperties.class);
      public static void setLog(Log _log) {
          log = _log;
      }
      
      /** Construct a new resource discoverer
       */
      public DiscoverSystemProperties() {
      }
  
      /**
       * @return Enumeration of ResourceInfo
       */
      public ResourceIterator find(final String resourceName) {
          if (log.isDebugEnabled())
              log.debug("find: resourceName='" + resourceName + "'");
  
          return new ResourceIterator() {
              private String resource = System.getProperty(resourceName);
              
              public boolean hasNext() {
                  return resource != null;
              }
              
              public ResourceInfo next() {
                  ResourceInfo element = new ResourceInfo(resource);
                  resource = null;
                  return element;
              }
          };
      }
  }
  
  
  
  1.1                  jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverManagedProperties.java
  
  Index: DiscoverManagedProperties.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.discovery;
  
  import org.apache.commons.discovery.log.DiscoveryLogFactory;
  import org.apache.commons.discovery.tools.ManagedProperties;
  import org.apache.commons.logging.Log;
  
  
  /**
   * Recover resource name from Managed Properties.
   * @see org.apache.commons.discovery.tools.ManagedProperties
   * 
   * @author Richard A. Sitze
   */
  public class DiscoverManagedProperties implements Discover
  {
      private static Log log = DiscoveryLogFactory.newLog(DiscoverManagedProperties.class);
      public static void setLog(Log _log) {
          log = _log;
      }
      
      /** Construct a new resource discoverer
       */
      public DiscoverManagedProperties() {
      }
  
      /**
       * @return Enumeration of ResourceInfo
       */
      public ResourceIterator find(final String resourceName) {
          if (log.isDebugEnabled())
              log.debug("find: resourceName='" + resourceName + "'");
  
          return new ResourceIterator() {
              private String resource = ManagedProperties.getProperty(resourceName);
              
              public boolean hasNext() {
                  return resource != null;
              }
              
              public ResourceInfo next() {
                  ResourceInfo element = new ResourceInfo(resource);
                  resource = null;
                  return element;
              }
          };
      }
  }
  
  
  
  1.1                  jakarta-commons/discovery/src/java/org/apache/commons/discovery/DiscoverDictionaryResources.java
  
  Index: DiscoverDictionaryResources.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.discovery;
  
  import java.util.Dictionary;
  import java.util.Hashtable;
  
  import org.apache.commons.discovery.log.DiscoveryLogFactory;
  import org.apache.commons.logging.Log;
  
  
  /**
   * Recover resources from a Dictionary.  This covers Properties as well,
   * since <code>Properties extends Hashtable extends Dictionary</code>.
   * 
   * The recovered value is expected to be either a <code>String</code>
   * or a <code>String[]</code>.
   * 
   * @author Richard A. Sitze
   */
  public class DiscoverDictionaryResources implements Discover
  {
      private static Log log = DiscoveryLogFactory.newLog(DiscoverDictionaryResources.class);
      public static void setLog(Log _log) {
          log = _log;
      }
  
      private Dictionary dictionary;
      
      /** Construct a new resource discoverer
       */
      public DiscoverDictionaryResources() {
          setDictionary(new Hashtable());
      }
      
      /** Construct a new resource discoverer
       */
      public DiscoverDictionaryResources(Dictionary dictionary) {
          setDictionary(dictionary);
      }
  
      protected Dictionary getDictionary() {
          return dictionary;
      }
  
      /**
       * Specify set of class loaders to be used in searching.
       */
      public void setDictionary(Dictionary table) {
          this.dictionary = dictionary;
      }
      
      public void addResource(String resourceName, String resource) {
          dictionary.put(resourceName, resource);
      }
      
      public void addResource(String resourceName, String[] resources) {
          dictionary.put(resourceName, resources);
      }
  
      /**
       * @return Enumeration of ResourceInfo
       */
      public ResourceIterator find(final String resourceName) {
          if (log.isDebugEnabled())
              log.debug("find: resourceName='" + resourceName + "'");
  
          Object baseResource = dictionary.get(resourceName);
  
          final String[] resources;
          if (baseResource instanceof String) {
              resources = new String[] { (String)baseResource };
          } else if (baseResource instanceof String[]) {
              resources = (String[])baseResource;
          } else {
              resources = null;
          }
  
          return new ResourceIterator() {
              private int idx = 0;
              
              public boolean hasNext() {
                  return (resources != null && idx < resources.length);
              }
              
              public ResourceInfo next() {
                  return new ResourceInfo(resources[idx++]);
              }
          };
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message