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/resource/names DiscoverServiceNames.java DiscoverNamesInManagedProperties.java DiscoverNamesInFile.java
Date Mon, 05 May 2003 14:22:45 GMT
rsitze      2003/05/05 07:22:45

  Modified:    discovery/src/java/org/apache/commons/discovery/resource/names
                        DiscoverServiceNames.java
                        DiscoverNamesInManagedProperties.java
                        DiscoverNamesInFile.java
  Log:
  Generalize qualification of resource/file-names by prefix/suffix.
  
  Revision  Changes    Path
  1.2       +20 -7     jakarta-commons/discovery/src/java/org/apache/commons/discovery/resource/names/DiscoverServiceNames.java
  
  Index: DiscoverServiceNames.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/resource/names/DiscoverServiceNames.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DiscoverServiceNames.java	30 Aug 2002 00:15:20 -0000	1.1
  +++ DiscoverServiceNames.java	5 May 2003 14:22:45 -0000	1.2
  @@ -83,26 +83,39 @@
       /** Construct a new service discoverer
        */
       public DiscoverServiceNames() {
  -        super();
  +        super(SERVICE_HOME, null);
  +    }
  +        
  +    /**
  +     *  Construct a new resource discoverer
  +     */
  +    public DiscoverServiceNames(String prefix, String suffix) {
  +        super((prefix == null) ? SERVICE_HOME : SERVICE_HOME + prefix, suffix);
       }
       
       /**
        *  Construct a new resource discoverer
        */
       public DiscoverServiceNames(ClassLoaders loaders) {
  -        super(loaders);
  +        super(loaders, SERVICE_HOME, null);
  +    }
  +    
  +    /**
  +     *  Construct a new resource discoverer
  +     */
  +    public DiscoverServiceNames(ClassLoaders loaders, String prefix, String suffix) {
  +        super(loaders, (prefix == null) ? SERVICE_HOME : SERVICE_HOME + prefix, suffix);
       }
       
       /** Construct a new service discoverer
        */
       public DiscoverServiceNames(ResourceDiscover discoverer) {
  -        super(discoverer);
  +        super(discoverer, SERVICE_HOME, null);
       }
       
  -    /**
  -     * @return Enumeration of ServiceInfo
  +    /** Construct a new service discoverer
        */
  -    public ResourceNameIterator findResourceNames(String serviceName) {
  -        return super.findResourceNames(SERVICE_HOME + serviceName);
  +    public DiscoverServiceNames(ResourceDiscover discoverer, String prefix, String suffix)
{
  +        super(discoverer, (prefix == null) ? SERVICE_HOME : SERVICE_HOME + prefix, suffix);
       }
   }
  
  
  
  1.3       +33 -4     jakarta-commons/discovery/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInManagedProperties.java
  
  Index: DiscoverNamesInManagedProperties.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInManagedProperties.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DiscoverNamesInManagedProperties.java	30 Aug 2002 22:19:33 -0000	1.2
  +++ DiscoverNamesInManagedProperties.java	5 May 2003 14:22:45 -0000	1.3
  @@ -78,22 +78,51 @@
       public static void setLog(Log _log) {
           log = _log;
       }
  +
  +    
  +    private final String _prefix;
  +    private final String _suffix;
       
       /** Construct a new resource discoverer
        */
       public DiscoverNamesInManagedProperties() {
  +        _prefix = null;
  +        _suffix = null;
  +    }
  +    
  +    /** Construct a new resource discoverer
  +     */
  +    public DiscoverNamesInManagedProperties(String prefix, String suffix) {
  +        _prefix = prefix;
  +        _suffix = suffix;
       }
   
       /**
        * @return Enumeration of ResourceInfo
        */
       public ResourceNameIterator findResourceNames(final String resourceName) {
  -        if (log.isDebugEnabled())
  -            log.debug("find: resourceName='" + resourceName + "'");
  +        String name;
  +        if (_prefix != null && _prefix.length() > 0) {
  +            name = _prefix + resourceName;
  +        } else {
  +            name = resourceName;
  +        }
  +
  +        if (_suffix != null && _suffix.length() > 0) {
  +            name = name + _suffix;
  +        }
  +
  +        if (log.isDebugEnabled()) {
  +            if (_prefix != null  &&  _suffix != null) {
  +                log.debug("find: resourceName='" + resourceName + "' as '" + name + "'");
  +            } else {
  +                log.debug("find: resourceName = '" + name + "'");
  +            }
  +        }
   
  +        final String newResourcName = name;
           return new ResourceNameIterator() {
  -            private String resource = ManagedProperties.getProperty(resourceName);
  -            
  +            private String resource = ManagedProperties.getProperty(newResourcName);
               public boolean hasNext() {
                   return resource != null;
               }
  
  
  
  1.3       +65 -12    jakarta-commons/discovery/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInFile.java
  
  Index: DiscoverNamesInFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInFile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DiscoverNamesInFile.java	30 Aug 2002 22:19:33 -0000	1.2
  +++ DiscoverNamesInFile.java	5 May 2003 14:22:45 -0000	1.3
  @@ -100,54 +100,107 @@
           log = _log;
       }
       
  -    private ResourceDiscover discoverResources;
  +    private ResourceDiscover _discoverResources;
       
  +    private final String _prefix;
  +    private final String _suffix;
  +        
       /**
        *  Construct a new resource discoverer
        */
       public DiscoverNamesInFile() {
  -        discoverResources = new DiscoverResources();
  +        _discoverResources = new DiscoverResources();
  +        _prefix = null;
  +        _suffix = null;
  +    }
  +        
  +    /**
  +     *  Construct a new resource discoverer
  +     */
  +    public DiscoverNamesInFile(String prefix, String suffix) {
  +        _discoverResources = new DiscoverResources();
  +        _prefix = prefix;
  +        _suffix = suffix;
       }
       
       /**
        *  Construct a new resource discoverer
        */
       public DiscoverNamesInFile(ClassLoaders loaders) {
  -        discoverResources = new DiscoverResources(loaders);
  +        _discoverResources = new DiscoverResources(loaders);
  +        _prefix = null;
  +        _suffix = null;
  +    }
  +    
  +    /**
  +     *  Construct a new resource discoverer
  +     */
  +    public DiscoverNamesInFile(ClassLoaders loaders, String prefix, String suffix) {
  +        _discoverResources = new DiscoverResources(loaders);
  +        _prefix = prefix;
  +        _suffix = suffix;
       }
       
       /**
        *  Construct a new resource discoverer
        */
       public DiscoverNamesInFile(ResourceDiscover discoverer) {
  -        this.discoverResources = discoverer;
  +        _discoverResources = discoverer;
  +        _prefix = null;
  +        _suffix = null;
  +    }
  +    
  +    /**
  +     *  Construct a new resource discoverer
  +     */
  +    public DiscoverNamesInFile(ResourceDiscover discoverer, String prefix, String suffix)
{
  +        _discoverResources = discoverer;
  +        _prefix = prefix;
  +        _suffix = suffix;
       }
   
       /**
        * Specify set of class loaders to be used in searching.
        */
       public void setDiscoverer(ResourceDiscover discover) {
  -        this.discoverResources = discover;
  +        _discoverResources = discover;
       }
   
       /**
        * To be used by downstream elements..
        */
       public ResourceDiscover getDiscover() {
  -        return discoverResources;
  +        return _discoverResources;
       }
   
       /**
        * @return Enumeration of ServiceInfo
        */
  -    public ResourceNameIterator findResourceNames(final String fileName) {
  -        if (log.isDebugEnabled())
  -            log.debug("find: fileName='" + fileName + "'");
  +    public ResourceNameIterator findResourceNames(final String serviceName) {
  +        String fileName;
  +        if (_prefix != null && _prefix.length() > 0) {
  +            fileName = _prefix + serviceName;
  +        } else {
  +            fileName = serviceName;
  +        }
   
  -        return new ResourceNameIterator() {
  -            private ResourceIterator files =
  -                getDiscover().findResources(fileName);
  +        if (_suffix != null && _suffix.length() > 0) {
  +            fileName = fileName + _suffix;
  +        }
   
  +        if (log.isDebugEnabled()) {
  +            if (_prefix != null  &&  _suffix != null) {
  +                log.debug("find: serviceName='" + serviceName + "' as '" + fileName + "'");
  +            } else {
  +                log.debug("find: serviceName = '" + fileName + "'");
  +            }
  +        }
  +
  +
  +        final ResourceIterator files =
  +            getDiscover().findResources(fileName);
  +
  +        return new ResourceNameIterator() {
               private int idx = 0;
               private Vector classNames = null;
               private String resource = null;
  
  
  

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


Mime
View raw message