You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/12/03 05:43:54 UTC

cvs commit: avalon/util/factory/impl/src/java/org/apache/avalon/util/factory/impl Criteria.java

mcconnell    2003/12/02 20:43:54

  Modified:    util/factory/impl/src/java/org/apache/avalon/util/factory/impl
                        Criteria.java
  Log:
  Add validation of supplied type from derived classes.
  
  Revision  Changes    Path
  1.2       +42 -7     avalon/util/factory/impl/src/java/org/apache/avalon/util/factory/impl/Criteria.java
  
  Index: Criteria.java
  ===================================================================
  RCS file: /home/cvs/avalon/util/factory/impl/src/java/org/apache/avalon/util/factory/impl/Criteria.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Criteria.java	2 Dec 2003 23:05:30 -0000	1.1
  +++ Criteria.java	3 Dec 2003 04:43:54 -0000	1.2
  @@ -101,16 +101,45 @@
       * Set a named parameter of the criteria to a value.
       * @param key the parameter key
       * @param value the value to assign to the key
  -    * @exception ValidationException if the supplied value fails
  +    * @return the original value
  +    * @exception FactoryRuntimeException if the supplied value fails
       *    the validation test for its associated parameter
       */
  -    public void put( final String key, final Object value ) 
  +    public Object put( final Object key, final Object value ) 
       {
  -        final Parameter p = getParameter( key );
  +        if( !(key instanceof String ))
  +        {
  +            final String error = 
  +              "Invalid key: " + key;
  +            throw new IllegalArgumentException( error );
  +        }
  +
  +        Object current = super.get( key );
  +
  +        if( null == value )
  +        {
  +            super.put( key, null );
  +            return current;
  +        }
  +
  +        final Parameter p = getParameter( (String) key );
  +
           try
           {
               final Object v = p.resolve( value );
  -            super.put( key, v );
  +            if( p.getParameterClass().isInstance( v ) )
  +            {
  +                super.put( key, v );
  +                return current;
  +            }
  +            else
  +            {
  +                final String error = 
  +                  "Resolved value: " + v 
  +                  + " does not implement the parameter type: "
  +                  + p.getParameterClass();
  +                throw new IllegalArgumentException( error );
  +            }
           }
           catch( Throwable e )
           {
  @@ -128,8 +157,14 @@
       {
           Parameter param = getParameterFromObject( key );
           Object value = super.get( param.getKey() );
  -        if( null != value ) return value;
  -        return param.getDefault();
  +        if( null != value )
  +        {
  +            return value;
  +        }
  +        else
  +        {
  +            return param.getDefault();
  +        }
       }
   
       //--------------------------------------------------------------
  
  
  

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