donaldp     02/03/12 02:20:22

  Modified:    
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace
                        DefaultTaskContext.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components
                        AbstractComponentTest.java
               
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/workspace
                        ClassicPropertyResolverTest.java
                        DefaultPropertyResolverTest.java
               
proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java
  Added:       
proposal/myrmidon/src/java/org/apache/myrmidon/components/property
                        ClassicPropertyResolver.java
                        DefaultPropertyResolver.java
               
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property
                        PropertyResolver.java
  Removed:     
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace
                        ClassicPropertyResolver.java
                        DefaultPropertyResolver.java
               
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/workspace
                        PropertyResolver.java
  Log:
  Move PropertyResolver and friends into own package hierarchy
  
  Revision  Changes    Path
  1.25      +2 -2      
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
  
  Index: DefaultTaskContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DefaultTaskContext.java   12 Mar 2002 09:45:10 -0000      1.24
  +++ DefaultTaskContext.java   12 Mar 2002 10:20:21 -0000      1.25
  @@ -21,13 +21,13 @@
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.interfaces.model.DefaultNameValidator;
  -import org.apache.myrmidon.interfaces.workspace.PropertyResolver;
  +import org.apache.myrmidon.interfaces.property.PropertyResolver;
   
   /**
    * Default implementation of TaskContext.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @version $Revision: 1.24 $ $Date: 2002/03/12 09:45:10 $
  + * @version $Revision: 1.25 $ $Date: 2002/03/12 10:20:21 $
    */
   public class DefaultTaskContext
       implements TaskContext, Context
  
  
  
  1.14      +2 -2      
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractComponentTest.java        11 Mar 2002 06:02:22 -0000      1.13
  +++ AbstractComponentTest.java        12 Mar 2002 10:20:22 -0000      1.14
  @@ -26,7 +26,7 @@
   import org.apache.myrmidon.components.extensions.DefaultExtensionManager;
   import org.apache.myrmidon.components.role.DefaultRoleManager;
   import org.apache.myrmidon.components.type.DefaultTypeManager;
  -import org.apache.myrmidon.components.workspace.DefaultPropertyResolver;
  +import org.apache.myrmidon.components.property.DefaultPropertyResolver;
   import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
  @@ -37,7 +37,7 @@
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeException;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  -import org.apache.myrmidon.interfaces.workspace.PropertyResolver;
  +import org.apache.myrmidon.interfaces.property.PropertyResolver;
   
   /**
    * A base class for tests for the default components.
  
  
  
  1.1                  
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/ClassicPropertyResolver.java
  
  Index: ClassicPropertyResolver.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.components.property;
  
  import org.apache.myrmidon.interfaces.property.PropertyResolver;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  
  /**
   * A [EMAIL PROTECTED] PropertyResolver} implementation which resolves 
properties
   * as per Ant1, ignoring undefined properties.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/12 10:20:22 $
   */
  public class ClassicPropertyResolver
      extends DefaultPropertyResolver
      implements PropertyResolver
  {
      /**
       * Retrieve a value from the specified context using the specified key.
       * If there is no such value, returns the original property reference.
       *
       * @param propertyName the name of the property to retrieve
       * @param context the set of known properties
       */
      protected Object getPropertyValue( final String propertyName,
                                         final Context context )
      {
          try
          {
              return context.get( propertyName );
          }
          catch( ContextException e )
          {
              return "${" + propertyName + "}";
          }
      }
  }
  
  
  
  1.1                  
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/DefaultPropertyResolver.java
  
  Index: DefaultPropertyResolver.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.components.property;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.interfaces.property.PropertyResolver;
  
  /**
   * Base class for PropertyResolver implementations.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/12 10:20:22 $
   */
  public class DefaultPropertyResolver
      implements PropertyResolver
  {
      private final static Resources REZ =
          ResourceManager.getPackageResources( DefaultPropertyResolver.class );
  
      /**
       * Resolve a string property. This evaluates all property
       * substitutions based on specified context.
       *
       * If the content contains a single property reference, then the property 
value
       * <code>Object</code> itself is returned.
       * Otherwise, a <code>String</code> is returned, comprising the supplied
       * content, with all property references replaced with the result of
       * <code>toString()</code> called on the property value.
       *
       * @param content the property to resolve
       * @param context the context in which to resolve property
       * @return the reolved property
       * @exception TaskException if an error occurs
       */
      public Object resolveProperties( final String content,
                                       final Context context )
          throws TaskException
      {
          int start = findNextProperty( content, 0 );
          if( -1 == start )
          {
              return content;
          }
  
          int end = findEnding( content, start );
  
          final int length = content.length();
  
          if( 0 == start && end == ( length - 1 ) )
          {
              return getPropertyValue( content.substring( start + 2, end ),
                                       context );
          }
  
          final StringBuffer sb = new StringBuffer( length * 2 );
          int lastPlace = 0;
  
          while( true )
          {
              final Object propertyValue =
                  getPropertyValue( content.substring( start + 2, end ),
                                    context );
  
              sb.append( content.substring( lastPlace, start ) );
              sb.append( propertyValue );
  
              lastPlace = end + 1;
  
              start = findNextProperty( content, lastPlace );
              if( -1 == start )
              {
                  break;
              }
  
              end = findEnding( content, start );
          }
  
          sb.append( content.substring( lastPlace, length ) );
  
          return sb.toString();
      }
  
      /**
       * Resolve a string property. This recursively evaluates all property
       * substitutions based on specified context.
       *
       * @param content the property to resolve
       * @param context the context in which to resolve property
       * @return the reolved property
       * @exception TaskException if an error occurs
       */
      protected Object recursiveResolveProperty( final String content,
                                                 final Context context )
          throws TaskException
      {
          int start = findNextProperty( content, 0 );
          if( -1 == start )
          {
              return content;
          }
  
          int end = findNestedEnding( content, start );
  
          final int length = content.length();
  
          if( 0 == start && end == ( length - 1 ) )
          {
              final String propertyName = content.substring( start + 2, end );
              final Object key = recursiveResolveProperty( propertyName, 
context );
              return getPropertyValue( key.toString(), context );
          }
  
          final StringBuffer sb = new StringBuffer( length * 2 );
  
          int lastPlace = 0;
  
          while( true )
          {
              final String propertyName = content.substring( start + 2, end );
              final Object key = recursiveResolveProperty( propertyName, 
context );
              final Object value = getPropertyValue( key.toString(), context );
  
              sb.append( content.substring( lastPlace, start ) );
              sb.append( value );
  
              lastPlace = end + 1;
  
              start = findNextProperty( content, lastPlace );
              if( -1 == start )
              {
                  break;
              }
  
              end = findNestedEnding( content, start );
          }
  
          sb.append( content.substring( lastPlace, length ) );
  
          return sb.toString();
      }
  
      /**
       * Finds the next occurrance of the start of a Property identifier.
       * @param content the String to search
       * @param currentPosition start location of the search
       * @return the position of the next occurrence, or <code>-1</code> if none
       *          was found.
       */
      private int findNextProperty( final String content, final int 
currentPosition )
      {
          //TODO: Check if it is commented out
          return content.indexOf( "${", currentPosition );
      }
  
      /**
       * Finds the next occurrence of the end of a Property identifier.
       * @param property the String to search
       * @param currentPosition start location of the search
       * @return the position of the next occurrence
       * @throws TaskException if no end was found
       */
      private int findEnding( final String property, final int currentPosition )
          throws TaskException
      {
          //TODO: Check if it is commented out
          final int index = property.indexOf( '}', currentPosition );
          if( -1 == index )
          {
              final String message = REZ.getString( 
"prop.mismatched-braces.error" );
              throw new TaskException( message );
          }
  
          return index;
      }
  
      /**
       * Finds the end of the property identifier at the currentPosition,
       * taking into account nested property identifiers.
       * @param property the String to search
       * @param currentPosition location of the property
       * @return the position of the propery ending.
       * @throws TaskException if the property is not properly ended.
       */
      private int findNestedEnding( final String property, final int 
currentPosition )
          throws TaskException
      {
          final int length = property.length();
          final int start = currentPosition + 2;
  
          int weight = 1;
          for( int i = start; ( weight > 0 ) && ( i < length ); i++ )
          {
              final char ch = property.charAt( i );
              switch( ch )
              {
                  case '}':
                      //TODO: Check if it is commented out
                      weight--;
                      if( weight == 0 )
                      {
                          return i;
                      }
                      break;
  
                  case '$':
                      {
                          //TODO: Check if it is commented out
                          final int next = i + 1;
                          if( next < length && '{' == property.charAt( next ) )
                          {
                              weight++;
                          }
                      }
                      break;
              }
          }
  
          final String message = REZ.getString( "prop.mismatched-braces.error" 
);
          throw new TaskException( message );
      }
  
      /**
       * Retrieve a value from the specified context using the specified key.
       *
       * @param propertyName the key of value in context
       * @param context the set of known properties
       * @return the object retrieved from context
       * @exception TaskException if the property is undefined
       */
      protected Object getPropertyValue( final String propertyName,
                                         final Context context )
          throws TaskException
      {
          try
          {
              return context.get( propertyName );
          }
          catch( ContextException e )
          {
              final String message = REZ.getString( "prop.missing-value.error", 
propertyName );
              throw new TaskException( message );
          }
      }
  }
  
  
  
  
  1.2       +3 -2      
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/workspace/ClassicPropertyResolverTest.java
  
  Index: ClassicPropertyResolverTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/workspace/ClassicPropertyResolverTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassicPropertyResolverTest.java  9 Mar 2002 02:04:25 -0000       1.1
  +++ ClassicPropertyResolverTest.java  12 Mar 2002 10:20:22 -0000      1.2
  @@ -7,13 +7,14 @@
    */
   package org.apache.myrmidon.components.workspace;
   
  -import org.apache.myrmidon.interfaces.workspace.PropertyResolver;
  +import org.apache.myrmidon.interfaces.property.PropertyResolver;
  +import org.apache.myrmidon.components.property.ClassicPropertyResolver;
   
   /**
    * A test for [EMAIL PROTECTED] ClassicPropertyResolver}
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
  - * @version $Revision: 1.1 $ $Date: 2002/03/09 02:04:25 $
  + * @version $Revision: 1.2 $ $Date: 2002/03/12 10:20:22 $
    */
   public class ClassicPropertyResolverTest
       extends DefaultPropertyResolverTest
  
  
  
  1.2       +3 -2      
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/workspace/DefaultPropertyResolverTest.java
  
  Index: DefaultPropertyResolverTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/workspace/DefaultPropertyResolverTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultPropertyResolverTest.java  9 Mar 2002 02:04:25 -0000       1.1
  +++ DefaultPropertyResolverTest.java  12 Mar 2002 10:20:22 -0000      1.2
  @@ -14,13 +14,14 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.components.AbstractComponentTest;
  -import org.apache.myrmidon.interfaces.workspace.PropertyResolver;
  +import org.apache.myrmidon.components.property.DefaultPropertyResolver;
  +import org.apache.myrmidon.interfaces.property.PropertyResolver;
   
   /**
    * Functional tests for [EMAIL PROTECTED] DefaultPropertyResolver}.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
  - * @version $Revision: 1.1 $ $Date: 2002/03/09 02:04:25 $
  + * @version $Revision: 1.2 $ $Date: 2002/03/12 10:20:22 $
    */
   public class DefaultPropertyResolverTest
       extends AbstractComponentTest
  
  
  
  1.33      +3 -3      
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- DefaultEmbeddor.java      11 Mar 2002 06:02:22 -0000      1.32
  +++ DefaultEmbeddor.java      12 Mar 2002 10:20:22 -0000      1.33
  @@ -42,7 +42,7 @@
   import org.apache.myrmidon.interfaces.service.MultiSourceServiceManager;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  -import org.apache.myrmidon.interfaces.workspace.PropertyResolver;
  +import org.apache.myrmidon.interfaces.property.PropertyResolver;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
   import org.apache.myrmidon.listeners.ProjectListener;
   
  @@ -51,7 +51,7 @@
    * Instantiate this to embed inside other applications.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @version $Revision: 1.32 $ $Date: 2002/03/11 06:02:22 $
  + * @version $Revision: 1.33 $ $Date: 2002/03/12 10:20:22 $
    */
   public class DefaultEmbeddor
       extends AbstractLogEnabled
  @@ -263,7 +263,7 @@
           createComponent( Deployer.class, PREFIX + "deployer.DefaultDeployer" 
);
           createComponent( ClassLoaderManager.class, PREFIX + 
"classloader.DefaultClassLoaderManager" );
           createComponent( Executor.class, PREFIX + 
"executor.AspectAwareExecutor" );
  -        createComponent( PropertyResolver.class, PREFIX + 
"workspace.DefaultPropertyResolver" );
  +        createComponent( PropertyResolver.class, PREFIX + 
"property.DefaultPropertyResolver" );
   
           // Setup the components
           for( Iterator iterator = m_components.iterator(); 
iterator.hasNext(); )
  
  
  
  1.1                  
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/property/PropertyResolver.java
  
  Index: PropertyResolver.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.property;
  
  import org.apache.myrmidon.api.TaskException;
  import org.apache.avalon.framework.context.Context;
  
  /**
   *
   * Provides a service for the resolution of property identifiers within
   * String content.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/12 10:20:22 $
   */
  public interface PropertyResolver
  {
      String ROLE = PropertyResolver.class.getName();
  
      /**
       * Resolve a string property. This evaluates all property
       * substitutions based on specified contex.
       * Rules used for property resolution are implementation dependent.
       *
       * @param value the value to resolve, which may contain property 
identifiers
       * @param context the set of properties to resolve against.
       * @return the resolved content
       * @exception TaskException if an error occurs
       */
      Object resolveProperties( final String value,
                                final Context context )
          throws TaskException;
  }
  
  
  

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

Reply via email to