bloritsch    2003/05/29 13:53:24

  Modified:    fortress/src/tools/org/apache/avalon/fortress/tools
                        Component.java
  Log:
  Refactoring to increase readability and reliability.  Ensures first match is used.
  
  Revision  Changes    Path
  1.12      +27 -20    
avalon-excalibur/fortress/src/tools/org/apache/avalon/fortress/tools/Component.java
  
  Index: Component.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-excalibur/fortress/src/tools/org/apache/avalon/fortress/tools/Component.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Component.java    29 May 2003 20:23:00 -0000      1.11
  +++ Component.java    29 May 2003 20:53:24 -0000      1.12
  @@ -367,34 +367,41 @@
           if ( null == sourceCode ) return null;
           if ( null == serviceName ) throw new BuildException( "You must specify the 
service name with the \"type\" parameter" );
   
  -        String className = stripQuotes( serviceName );
  +        final String className = stripQuotes( serviceName );
   
           if ( className != null || className.length() > 0 )
           {
               if ( className.indexOf( '.' ) < 0 )
               {
  -                className = checkPackage(sourceCode, sourceCode.getPackage(), 
serviceName);
  +                String checkName = checkPackage(sourceCode, 
sourceCode.getPackage(), className);
  +                if ( ! checkName.equals(className) ) return checkName;
   
  -                if ( className.equals(serviceName) )
  +                String[] imports = sourceCode.getImports();
  +                for ( int t = 0; t < imports.length; t++ )
                   {
  -                    String[] imports = sourceCode.getImports();
  -                    for ( int t = 0; t < imports.length; t++ )
  -                    {
  -                        final String type = imports[t];
  -                        final String tail = type.substring( type.lastIndexOf( '.' ) 
+ 1 );
  -
  -                        if ( tail.equals( className ) )
  -                        {
  -                            className = type;
  -                        }
  -                        else if ( tail.equals( "*" ) )
  -                        {
  -                            final String pack = type.substring( 0, 
type.lastIndexOf( '.' ) );
  -                            className = checkPackage( sourceCode, pack, serviceName 
);
  -                        }
  -                    }
  +                    checkName = checkImport( sourceCode, imports[t], className);
  +                    if ( ! checkName.equals( className ) ) return checkName;
                   }
               }
  +        }
  +
  +        return className;
  +    }
  +
  +    private String checkImport ( final JavaSource sourceCode, final String type, 
final String className)
  +    {
  +        final String tail = type.substring( type.lastIndexOf( '.' ) + 1 );
  +
  +        if ( tail.equals( className ) )
  +        {
  +            return type;
  +        }
  +        else if ( tail.equals( "*" ) )
  +        {
  +            final String pack = type.substring( 0, type.lastIndexOf( '.' ) );
  +
  +            String checkName = checkPackage( sourceCode, pack, className );
  +            if ( !checkName.equals( className ) ) return checkName;
           }
   
           return className;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to