avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance DefaultApplianceRepository.java
Date Thu, 24 Apr 2003 12:16:28 GMT
mcconnell    2003/04/24 05:16:28

  Modified:    merlin/assembly/src/java/org/apache/avalon/assembly/appliance
                        DefaultApplianceRepository.java
  Log:
  Updated terminology from XxxxManager to XxxxRepository to avoid confusing with class ServiceManager
terminology used within the framework.
  
  Revision  Changes    Path
  1.11      +64 -45    avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceRepository.java
  
  Index: DefaultApplianceRepository.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceRepository.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DefaultApplianceRepository.java	17 Apr 2003 03:37:22 -0000	1.10
  +++ DefaultApplianceRepository.java	24 Apr 2003 12:16:28 -0000	1.11
  @@ -222,7 +222,7 @@
           while( iterator.hasNext() )
           {
               Appliance appliance = (Appliance) iterator.next();
  -            Object service = appliance.getType().getService( reference );
  +            Object service = appliance.getService( reference );
               if( service != null )
               {
                   list.add( appliance );
  @@ -354,74 +354,93 @@
               throw new NullPointerException( "appliance" );
           }
   
  -        if( m_appliances.values().contains( appliance ) )
  -        {
  -            throw new DuplicateApplianceException( appliance.toString() );
  -        }
  -
           final String local = getURL().getPath();
           if( appliance.getURL().getPath().startsWith( local ) )
           {
  -            final String key = appliance.getURL().getPath().substring( local.length() );
  +            final String key = getKey( appliance );
  +            if( m_appliances.get( key ) != null )
  +            {
  +                final String error = 
  +                  "Illegal attempt to register a duplicate key: " + key;
  +                throw new DuplicateApplianceException( error );
  +            }
               m_appliances.put( key, appliance );
  -        } else
  +        } 
  +        else
           {
               final String error =
  -                    "Appliance URL " + appliance.getURL()
  -                    + " does not match repository URL " + getURL();
  +              "Appliance URL " + appliance.getURL()
  +              + " does not match repository URL " + getURL();
               throw new ApplianceRuntimeException( error );
           }
       }
   
  +    private String getKey( Appliance appliance )
  +    {
  +        final String local = getURL().getPath();
  +        final String path = appliance.getURL().getPath();
  +        final String key = path.substring( local.length() );
  +        return getKey( key );
  +    }
  +
  +    private String getKey( String key )
  +    {
  +        int n = key.indexOf( "/" );
  +        if( n > -1 )
  +        {
  +            return key.substring( 0, n );
  +        }
  +        else
  +        {
  +            return key;
  +        }
  +    }
  +
  +
       /**
        * Return an appliance relative to the supplied path.
        * @param uri the appliance path
        */
       public Appliance resolve( String uri )
       {
  -        if( uri.startsWith( m_url.getPath() ) )
  +        if( !uri.startsWith( m_url.getPath() ) )
           {
  -            // its in scope so substract the path of this repository
  -            // from the supplied uri then get the name of the child
  +            final String error = 
  +              "Invalid path: " + uri;
  +            throw new IllegalArgumentException( error );
  +        }
   
  -            String path = uri.substring( m_url.getPath().length() );
  +        String relative = uri.substring( m_url.getPath().length() );
  +        String key = getKey( relative );
  +        Appliance appliance = (Appliance) m_appliances.get( key );
  +        if( appliance == null )
  +        {
  +            final String error = 
  +              "Unresolvable path: " + uri;
  +            throw new IllegalArgumentException( error );
  +        }
   
  -            if( path.indexOf( "/" ) > -1 )
  +        if( relative.indexOf( "/" ) > -1 )
  +        {
  +            if( appliance instanceof ApplianceResolver )
               {
  -                //
  -                // looking for a child
  -                //
  -
  -                String name = path.substring( 0, path.indexOf( "/" ) + 1 );
  -                ApplianceRepository child = (ApplianceRepository) m_children.get( name
);
  -                if( child != null )
  -                {
  -                    return child.resolve( uri );
  -                }
  -
  -                final String error = 
  -                  "Unresolvable path: " + uri;
  -                throw new IllegalArgumentException( error );
  -            } else
  +                return ((ApplianceResolver)appliance).resolve( uri );
  +            }
  +            else
               {
  -                //
  -                // looking for a local appliance
  -                //
  -
  -                Appliance appliance = (Appliance) m_appliances.get( path );
  -                if( appliance != null )
  -                {
  -                    return appliance;
  -                }
                   final String error = 
  -                  "Unresolvable uri: " + uri + " path: '" + path + "'. in: " + this;
  +                  "Unresolvable path: " + uri;
                   throw new IllegalArgumentException( error );
               }
  -        } else
  +        }
  +        else
           {
  -            final String error = 
  -              "Invalid path: " + uri;
  -            throw new IllegalArgumentException( error );
  +            return appliance;
           }
  +    }
  +
  +    public String toString()
  +    {
  +        return "[repository:" + m_url.getPath() + "]";
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message