You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/11/05 17:44:29 UTC

cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang/functor Closure.java ClosureException.java ClosureUtils.java Factory.java FactoryException.java FactoryUtils.java Predicate.java PredicateException.java PredicateUtils.java Transformer.java TransformerException.java TransformerUtils.java

bayard      2002/11/05 08:44:29

  Added:       lang/src/java/org/apache/commons/lang/functor Closure.java
                        ClosureException.java ClosureUtils.java
                        Factory.java FactoryException.java
                        FactoryUtils.java Predicate.java
                        PredicateException.java PredicateUtils.java
                        Transformer.java TransformerException.java
                        TransformerUtils.java
  Log:
  Transfer of some of Patterns over to Lang.
  
  Revision  Changes    Path
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/Closure.java
  
  Index: Closure.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  /**
   * <code>Closure</code> defines an interface implemented by classes that
   * do something.
   *
   * @author <a href="mailto:nicolaken@apache.org">Nicola Ken Barozzi</a>
   * @version $Id: Closure.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public interface Closure {
      
      /**
       * Does what it has to.
       *
       * @param description  the extra information needed to execute the 
       *                     command
       *
       * @throws ClosureException (runtime) if the execution fails
       */
      public void execute(Object description);
      
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/ClosureException.java
  
  Index: ClosureException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import org.apache.commons.lang.exception.NestableRuntimeException;
  /**
   * Exception thrown when the Comand fails to execute.
   * If required, a root cause error can be wrapped within this one.
   *
   * @author <a href="mailto:nicolaken@apache.org">Nicola Ken Barozzi</a>
   * @version $Id: ClosureException.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class ClosureException extends NestableRuntimeException {
  
      /**
       * Constructs a new <code>ClosureException</code> without specified
       * detail message.
       */
      public ClosureException() {
          super();
      }
  
      /**
       * Constructs a new <code>ClosureException</code> with specified
       * detail message.
       *
       * @param msg  the error message.
       */
      public ClosureException(String msg) {
          super(msg);
      }
  
      /**
       * Constructs a new <code>ClosureException</code> with specified
       * nested <code>Throwable</code> root cause.
       *
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public ClosureException(Throwable rootCause) {
          super(rootCause);
      }
  
      /**
       * Constructs a new <code>ClosureException</code> with specified
       * detail message and nested <code>Throwable</code> root cause.
       *
       * @param msg        the error message.
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public ClosureException(String msg, Throwable rootCause) {
          super(msg, rootCause);
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/ClosureUtils.java
  
  Index: ClosureUtils.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import java.io.Serializable;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.commons.lang.functor.Predicate;
  import org.apache.commons.lang.functor.PredicateUtils;
  import org.apache.commons.lang.functor.Transformer;
  import org.apache.commons.lang.functor.TransformerException;
  import org.apache.commons.lang.functor.TransformerUtils;
  /**
   * <code>ClosureUtils</code> provides reference implementations and utilities
   * for the Closure pattern interface. The supplied commands are:
   * <ul>
   * <li>Invoker - invokes a method on the input object
   * <li>For - repeatedly calls a command for a fixed number of times
   * <li>While - repeatedly calls a command while a predicate is true
   * <li>DoWhile - repeatedly calls a command while a predicate is true
   * <li>Chained - chains two or more commands together
   * <li>Switch - calls one command based on one or more predicates
   * <li>SwitchMap - calls one command looked up from a Map
   * <li>Transformer - wraps a Transformer as a Predicate
   * <li>NOP - does nothing
   * <li>Exception - always throws an exception
   * </ul>
   * All the supplied commands are Serializable.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: ClosureUtils.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class ClosureUtils {
  
      /**
       * A Closure that always throws an exception
       */
      private static final Closure EXCEPTION_COMMAND = new ExceptionClosure();
      /**
       * A Closure that does nothing
       */
      private static final Closure NOP_COMMAND = new NOPClosure();
  
      /**
       * Restrictive constructor
       */
      protected ClosureUtils() {
          super();
      }
  
      /**
       * Gets a Closure that always throws an exception.
       * This could be useful during testing as a placeholder.
       *
       * @return the command
       */
      public static Closure exceptionClosure() {
          return EXCEPTION_COMMAND;
      }
  
      /**
       * Gets a Closure that will do nothing.
       * This could be useful during testing as a placeholder.
       *
       * @return the command
       */
      public static Closure nopClosure() {
          return NOP_COMMAND;
      }
  
      /**
       * Creates a Closure that calls a Factory each time the transformer is used.
       * The transformer will return the value returned by the factory.
       *
       * @param transformer  the transformer to run each time in the command
       * @return the command.
       */
      public static Closure asClosure(Transformer transformer) {
          if (transformer == null) {
              throw new IllegalArgumentException("TransformerClosure: The transformer must not be null");
          }
          return new TransformerClosure(transformer);
      }
  
      /**
       * Creates a Closure that will call the command <code>count</code> times.
       *
       * @param count  the number of times to loop
       * @param command  the command to call repeatedly
       * @return the command
       * @throws IllegalArgumentException if either argument is null
       */
      public static Closure forClosure(int count, Closure command) {
          if (count < 0) {
              throw new IllegalArgumentException("ForClosure: The loop count must not be less than zero, it was " + count);
          }
          if (command == null) {
              throw new IllegalArgumentException("ForClosure: The command must not be null");
          }
          return new ForClosure(count, command);
      }
  
      /**
       * Creates a Closure that will call the command repeatedly until the 
       * predicate returns false.
       *
       * @param predicate  the predicate to use as an end of loop test
       * @param command  the command to call repeatedly
       * @return the command
       * @throws IllegalArgumentException if either argument is null
       */
      public static Closure whileClosure(Predicate predicate, Closure command) {
          if (predicate == null) {
              throw new IllegalArgumentException("WhileClosure: The predicate must not be null");
          }
          if (command == null) {
              throw new IllegalArgumentException("WhileClosure: The command must not be null");
          }
          return new WhileClosure(predicate, command, false);
      }
  
      /**
       * Creates a Closure that will call the command once and then repeatedly
       * until the predicate returns false.
       *
       * @param command  the command to call repeatedly
       * @param predicate  the predicate to use as an end of loop test
       * @return the command
       * @throws IllegalArgumentException if either argument is null
       */
      public static Closure doWhileClosure(Closure command, Predicate predicate) {
          if (command == null) {
              throw new IllegalArgumentException("DoWhileClosure: The command must not be null");
          }
          if (predicate == null) {
              throw new IllegalArgumentException("DoWhileClosure: The predicate must not be null");
          }
          return new WhileClosure(predicate, command, true);
      }
  
      /**
       * Creates a Closure that will invoke a specific method on the command's
       * input object by reflection.
       *
       * @param methodName  the name of the method
       * @return the command
       * @throws IllegalArgumentException if the method name is null
       */
      public static Closure invokerClosure(String methodName) {
          return asClosure(TransformerUtils.invokerTransformer(methodName, null, null));
      }
  
      /**
       * Creates a Closure that will invoke a specific method on the command's
       * input object by reflection.
       *
       * @param methodName  the name of the method
       * @param paramTypes  the parameter types
       * @param args  the arguments
       * @return the command
       * @throws IllegalArgumentException if the method name is null
       * @throws IllegalArgumentException if the paramTypes and args don't match
       */
      public static Closure invokerClosure(String methodName, Class[] paramTypes, Object[] args) {
          return asClosure(TransformerUtils.invokerTransformer(methodName, paramTypes, args));
      }
  
      /**
       * Create a new Closure that calls two Closures, passing the result of
       * the first into the second.
       * 
       * @param command1  the first command
       * @param command2  the second command
       * @return the command
       * @throws IllegalArgumentException if either command is null
       */
      public static Closure chainedClosure(Closure command1, Closure command2) {
          Closure[] commands = new Closure[] { command1, command2 };
          validate(commands);
          return new ChainedClosure(commands);
      }
  
      /**
       * Create a new Closure that calls each command in turn, passing the 
       * result into the next command.
       * 
       * @param commands  an array of commands to chain
       * @return the command
       * @throws IllegalArgumentException if the commands array is null
       * @throws IllegalArgumentException if the commands array has 0 elements
       * @throws IllegalArgumentException if any command in the array is null
       */
      public static Closure chainedClosure(Closure[] commands) {
          commands = copy(commands);
          validate(commands);
          return new ChainedClosure(commands);
      }
  
      /**
       * Create a new Closure that calls each command in turn, passing the 
       * result into the next command. The ordering is that of the iterator()
       * method on the collection.
       * 
       * @param commands  a collection of commands to chain
       * @return the command
       * @throws IllegalArgumentException if the commands collection is null
       * @throws IllegalArgumentException if the commands collection is empty
       * @throws IllegalArgumentException if any command in the collection is null
       */
      public static Closure chainedClosure(Collection commands) {
          if (commands == null) {
              throw new IllegalArgumentException("ChainedClosure: The command collection must not be null");
          }
          // convert to array like this to guarantee iterator() ordering
          Closure[] cmds = new Closure[commands.size()];
          int i = 0;
          for (Iterator it = commands.iterator(); it.hasNext();) {
              cmds[i++] = (Closure) it.next();
          }
          validate(cmds);
          return new ChainedClosure(cmds);
      }
  
      /**
       * Create a new Closure that calls one of two commands depending 
       * on the specified predicate.
       * 
       * @param predicate  the predicate to switch on
       * @param trueClosure  the command called if the predicate is true
       * @param falseClosure  the command called if the predicate is false
       * @return the command
       * @throws IllegalArgumentException if the predicate is null
       * @throws IllegalArgumentException if either command is null
       */
      public static Closure switchClosure(Predicate predicate, Closure trueClosure, Closure falseClosure) {
          return switchClosureInternal(new Predicate[] { predicate }, new Closure[] { trueClosure }, falseClosure);
      }
  
      /**
       * Create a new Closure that calls one of the commands depending 
       * on the predicates. The command at array location 0 is called if the
       * predicate at array location 0 returned true. Each predicate is evaluated
       * until one returns true.
       * 
       * @param predicates  an array of predicates to check
       * @param commands  an array of commands to call
       * @return the command
       * @throws IllegalArgumentException if the either array is null
       * @throws IllegalArgumentException if the either array has 0 elements
       * @throws IllegalArgumentException if any element in the arrays is null
       * @throws IllegalArgumentException if the arrays are different sizes
       */
      public static Closure switchClosure(Predicate[] predicates, Closure[] commands) {
          return switchClosureInternal(copy(predicates), copy(commands), null);
      }
  
      /**
       * Create a new Closure that calls one of the commands depending 
       * on the predicates. The command at array location 0 is called if the
       * predicate at array location 0 returned true. Each predicate is evaluated
       * until one returns true. If no predicates evaluate to true, the default
       * command is called.
       * 
       * @param predicates  an array of predicates to check
       * @param commands  an array of commands to call
       * @param defaultClosure  the default to call if no predicate matches
       * @return the command
       * @throws IllegalArgumentException if the either array is null
       * @throws IllegalArgumentException if the either array has 0 elements
       * @throws IllegalArgumentException if any element in the arrays is null
       * @throws IllegalArgumentException if the arrays are different sizes
       */
      public static Closure switchClosure(Predicate[] predicates, Closure[] commands, Closure defaultClosure) {
          return switchClosureInternal(copy(predicates), copy(commands), defaultClosure);
      }
      
      /**
       * Create a new Closure that calls one of the commands depending 
       * on the predicates. 
       * <p>
       * The Map consists of Predicate keys and Closure values. A command 
       * is called if its matching predicate returns true. Each predicate is evaluated
       * until one returns true. If no predicates evaluate to true, the default
       * command is called. The default command is set in the map with a 
       * null key. The ordering is that of the iterator() method on the entryset 
       * collection of the map.
       * 
       * @param predicatesAndClosures  a map of predicates to commands
       * @return the command
       * @throws IllegalArgumentException if the map is null
       * @throws IllegalArgumentException if the map is empty
       * @throws IllegalArgumentException if any command in the map is null
       * @throws ClassCastException  if the map elements are of the wrong type
       */
      public static Closure switchClosure(Map predicatesAndClosures) {
          Closure[] trs = null;
          Predicate[] preds = null;
          if (predicatesAndClosures == null) {
              throw new IllegalArgumentException("SwitchClosure: The predicate and command map must not be null");
          }
          // convert to array like this to guarantee iterator() ordering
          Closure def = (Closure) predicatesAndClosures.remove(null);
          int size = predicatesAndClosures.size();
          trs = new Closure[size];
          preds = new Predicate[size];
          int i = 0;
          for (Iterator it = predicatesAndClosures.entrySet().iterator(); it.hasNext();) {
              Map.Entry entry = (Map.Entry) it.next();
              preds[i] = (Predicate) entry.getKey();
              trs[i] = (Closure) entry.getValue();
              i++;
          }
          return switchClosureInternal(preds, trs, def);
      }
  
      /**
       * Validate input and create command
       */
      private static Closure switchClosureInternal(Predicate[] predicates, Closure[] commands, Closure defaultClosure) {
          validate(predicates);
          validate(commands);
          if (predicates.length != commands.length) {
              throw new IllegalArgumentException("SwitchClosure: The predicate and command arrays must be the same size");
          }
          if (defaultClosure == null) {
              defaultClosure = nopClosure();
          }
          return new SwitchClosure(predicates, commands, defaultClosure);
      }
  
      /**
       * Create a new Closure that uses the input object as a key to find the
       * command to call. 
       * <p>
       * The Map consists of object keys and Closure values. A command 
       * is called if the input object equals the key. If there is no match, the
       * default command is called. The default command is set in the map
       * using a null key.
       * 
       * @param objectsAndClosures  a map of objects to commands
       * @return the command
       * @throws IllegalArgumentException if the map is null
       * @throws IllegalArgumentException if the map is empty
       * @throws IllegalArgumentException if any command in the map is null
       */
      public static Closure switchMapClosure(Map objectsAndClosures) {
          Closure[] trs = null;
          Predicate[] preds = null;
          if (objectsAndClosures == null) {
              throw new IllegalArgumentException("SwitchEqualsClosure: The obejct and command map must not be null");
          }
          Closure def = (Closure) objectsAndClosures.remove(null);
          int size = objectsAndClosures.size();
          trs = new Closure[size];
          preds = new Predicate[size];
          int i = 0;
          for (Iterator it = objectsAndClosures.entrySet().iterator(); it.hasNext();) {
              Map.Entry entry = (Map.Entry) it.next();
              preds[i] = PredicateUtils.equalPredicate(entry.getKey());
              trs[i] = (Closure) entry.getValue();
              i++;
          }
          return switchClosure(preds, trs, def);
      }
  
      /**
       * Copy method
       * 
       * @param predicates  the predicates to copy
       */
      private static Predicate[] copy(Predicate[] predicates) {
          if (predicates == null) {
              return null;
          }
          return (Predicate[]) predicates.clone();
      }
      
      /**
       * Validate method
       * 
       * @param predicates  the predicates to validate
       */
      private static void validate(Predicate[] predicates) {
          if (predicates == null) {
              throw new IllegalArgumentException("ClosureUtils: The predicate array must not be null");
          }
          if (predicates.length < 1) {
              throw new IllegalArgumentException(
                  "ClosureUtils: At least 1 predicate must be specified in the predicate array, size was " + predicates.length);
          }
          for (int i = 0; i < predicates.length; i++) {
              if (predicates[i] == null) {
                  throw new IllegalArgumentException("ClosureUtils: The predicate array must not contain a null predicate, index " + i + " was null");
              }
          }
      }
  
      /**
       * Copy method
       * 
       * @param commands  the commands to copy
       */
      private static Closure[] copy(Closure[] commands) {
          if (commands == null) {
              return null;
          }
          return (Closure[]) commands.clone();
      }
      
      /**
       * Validate method
       * 
       * @param commands  the commands to validate
       */
      private static void validate(Closure[] commands) {
          if (commands == null) {
              throw new IllegalArgumentException("ClosureUtils: The command array must not be null");
          }
          if (commands.length < 1) {
              throw new IllegalArgumentException(
                  "ClosureUtils: At least 1 command must be specified in the command array, size was " + commands.length);
          }
          for (int i = 0; i < commands.length; i++) {
              if (commands[i] == null) {
                  throw new IllegalArgumentException("ClosureUtils: The command array must not contain a null command, index " + i + " was null");
              }
          }
      }
  
      // ExceptionClosure
      //----------------------------------------------------------------------------------
  
      /**
       * ExceptionClosure always throws an exception
       */
      private static class ExceptionClosure implements Closure, Serializable {
  
          /**
           * Constructor
           */
          private ExceptionClosure() {
              super();
          }
  
          /**
           * Always throw an exception
           */
          public void execute(Object input) {
              throw new ClosureException("ExceptionClosure invoked");
          }
      }
  
      // NOPClosure
      //----------------------------------------------------------------------------------
  
      /**
       * NOPClosure does nothing
       */
      private static class NOPClosure implements Closure, Serializable {
  
          /**
           * Constructor
           */
          private NOPClosure() {
              super();
          }
  
          /**
           * Do nothing
           */
          public void execute(Object input) {
              // do nothing
          }
      }
  
      // TransformerClosure
      //----------------------------------------------------------------------------------
  
      /**
       * TransformerClosure returns the result of calling a Transformer.
       */
      private static class TransformerClosure implements Closure, Serializable {
  
          private final Transformer iTransformer;
  
          /**
           * Constructor to store factory
           */
          private TransformerClosure(Transformer transformer) {
              super();
              iTransformer = transformer;
          }
  
          /**
           * Return the result of calling the factory
           */
          public void execute(Object input) {
              try {
                  iTransformer.transform(input);
  
              } catch (TransformerException ex) {
                  throw new ClosureException("TransformerClosure: " + ex.getMessage(), ex);
              }
          }
      }
  
      // ChainedClosure
      //----------------------------------------------------------------------------------
  
      /**
       * ChainedClosure calls a list of commands.
       */
      private static class ChainedClosure implements Closure, Serializable {
  
          private final Closure[] iClosures;
  
          /**
           * Constructor to store params
           */
          private ChainedClosure(Closure[] commands) {
              super();
              iClosures = commands;
          }
  
          /**
           * Execute a list of commands
           */
          public void execute(Object input) {
              for (int i = 0; i < iClosures.length; i++) {
                  iClosures[i].execute(input);
              }
          }
      }
  
      // SwitchClosure
      //----------------------------------------------------------------------------------
  
      /**
       * SwitchClosure calls the command whose predicate returns true.
       */
      private static class SwitchClosure implements Closure, Serializable {
  
          private final Predicate[] iPredicates;
          private final Closure[] iClosures;
          private final Closure iDefault;
  
          /**
           * Constructor to store params
           */
          private SwitchClosure(Predicate[] predicates, Closure[] commands, Closure defaultClosure) {
              super();
              iPredicates = predicates;
              iClosures = commands;
              iDefault = defaultClosure;
          }
  
          /**
           * Execute the command whose predicate returns true
           */
          public void execute(Object input) {
              for (int i = 0; i < iPredicates.length; i++) {
                  if (iPredicates[i].evaluate(input) == true) {
                      iClosures[i].execute(input);
                      return;
                  }
              }
              iDefault.execute(input);
          }
      }
  
      // ForClosure
      //----------------------------------------------------------------------------------
  
      /**
       * ForClosure calls the command a fixed nunmber of times.
       */
      private static class ForClosure implements Closure, Serializable {
  
          private final int iCount;
          private final Closure iClosure;
  
          /**
           * Constructor to store params
           */
          private ForClosure(int count, Closure command) {
              super();
              iCount = count;
              iClosure = command;
          }
  
          /**
           * Execute the command count times
           */
          public void execute(Object input) {
              for (int i = 0; i < iCount; i++) {
                  iClosure.execute(input);
              }
          }
      }
  
      // WhileClosure
      //----------------------------------------------------------------------------------
  
      /**
       * WhileClosure calls the command until the predicate is false.
       */
      private static class WhileClosure implements Closure, Serializable {
  
          private final Predicate iPredicate;
          private final Closure iClosure;
          private final boolean iDoLoop;
  
          /**
           * Constructor to store params
           */
          private WhileClosure(Predicate predicate, Closure command, boolean doLoop) {
              super();
              iPredicate = predicate;
              iClosure = command;
              iDoLoop = doLoop;
          }
  
          /**
           * Execute the command until the predicate is false
           */
          public void execute(Object input) {
              if (iDoLoop) {
                  iClosure.execute(input);
              }
              while (iPredicate.evaluate(input)) {
                  iClosure.execute(input);
              }
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/Factory.java
  
  Index: Factory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  /**
   * <code>Factory</code> defines an interface implemented by classes that
   * create objects.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: Factory.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public interface Factory {
      
      /**
       * Create a new object.
       *
       * @return an new object
       * @throws FactoryException (runtime) if the factory cannot create an object
       */
      public Object create();
      
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/FactoryException.java
  
  Index: FactoryException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import org.apache.commons.lang.exception.NestableRuntimeException;
  /**
   * Exception thrown when the a Factory cannot create the object as requested.
   * If required, a root cause error can be wrapped within this one.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: FactoryException.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class FactoryException extends NestableRuntimeException {
  
      /**
       * Constructs a new <code>FactoryException</code> without specified
       * detail message.
       */
      public FactoryException() {
          super();
      }
  
      /**
       * Constructs a new <code>FactoryException</code> with specified
       * detail message.
       *
       * @param msg  the error message.
       */
      public FactoryException(String msg) {
          super(msg);
      }
  
      /**
       * Constructs a new <code>FactoryException</code> with specified
       * nested <code>Throwable</code> root cause.
       *
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public FactoryException(Throwable rootCause) {
          super(rootCause);
      }
  
      /**
       * Constructs a new <code>FactoryException</code> with specified
       * detail message and nested <code>Throwable</code> root cause.
       *
       * @param msg        the error message.
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public FactoryException(String msg, Throwable rootCause) {
          super(msg, rootCause);
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/FactoryUtils.java
  
  Index: FactoryUtils.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import java.io.Serializable;
  import java.lang.reflect.Constructor;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  import org.apache.commons.lang.SerializationException;
  import org.apache.commons.lang.SerializationUtils;
  /**
   * <code>FactoryUtils</code> provides reference implementations and utilities
   * for the Factory pattern interface. The supplied factories are:
   * <ul>
   * <li>Prototype - clones a specified object
   * <li>Reflection - creates objects using reflection
   * <li>Constant - always returns the same object
   * <li>Null - always returns null
   * <li>Exception - always throws an exception
   * </ul>
   * All the supplied factories are Serializable.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: FactoryUtils.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class FactoryUtils {
  
      /**
       * A factory that always throws an exception
       */
      private static final Factory EXCEPTION_FACTORY = new ExceptionFactory();
      /**
       * A factory that always returns null
       */
      private static final Factory NULL_FACTORY = new ConstantFactory(null);
  
      /**
       * Restrictive constructor
       */
      protected FactoryUtils() {
          super();
      }
  
      /**
       * Gets a Factory that always throws an exception.
       * This could be useful during testing as a placeholder.
       *
       * @return the factory
       */
      public static Factory exceptionFactory() {
          return EXCEPTION_FACTORY;
      }
  
      /**
       * Gets a Factory that will return null each time the factory is used.
       *
       * @return the factory
       */
      public static Factory nullFactory() {
          return NULL_FACTORY;
      }
  
      /**
       * Creates a Factory that will return the same object each time the factory
       * is used. No check is made that the object is immutable. In general, only
       * immutable objects should use the constant factory. Mutable objects should
       * use the prototype factory.
       *
       * @param constantToReturn  the constant object to return each time in the factory
       * @return the factory.
       */
      public static Factory constantFactory(Object constantToReturn) {
          return new ConstantFactory(constantToReturn);
      }
  
      /**
       * Creates a Factory that will return a clone of the same prototype object
       * each time the factory is used. The prototype will be cloned using one of these
       * techniques (in order):
       * <ul>
       * <li>public clone method
       * <li>public copy constructor
       * <li>serialization clone
       * <ul>
       *
       * @param prototype  the object to clone each time in the factory
       * @return the factory
       * @throws IllegalArgumentException if the prototype is null
       * @throws IllegalArgumentException if the prototype cannot be cloned
       */
      public static Factory prototypeFactory(Object prototype) {
          if (prototype == null) {
              throw new IllegalArgumentException("PrototypeFactory: The prototype must not be null");
          }
          // TODO: move to cloneable pattern
          try {
              prototype.getClass().getMethod("clone", null);
              return new PrototypeCloneFactory(prototype);
  
          } catch (NoSuchMethodException ex) {
              try {
                  prototype.getClass().getConstructor(new Class[] { prototype.getClass()});
                  return new ReflectionFactory(prototype.getClass(), new Class[] { prototype.getClass()}, new Object[] { prototype });
  
              } catch (NoSuchMethodException ex2) {
                  if (prototype instanceof Serializable) {
                      return new PrototypeSerializationFactory((Serializable) prototype);
                  }
              }
          }
          throw new IllegalArgumentException("PrototypeFactory: The prototype must be cloneable");
      }
  
      /**
       * Creates a Factory that can create objects of a specific type using
       * a no-args constructor.
       *
       * @param classToInstantiate  the Class to instantiate each time in the factory
       * @return the factory
       * @throws IllegalArgumentException if the classToInstantiate is null
       */
      public static Factory reflectionFactory(Class classToInstantiate) {
          return new ReflectionFactory(classToInstantiate);
      }
  
      /**
       * Creates a Factory that can create objects of a specific type using
       * the arguments specified to this method.
       *
       * @param classToInstantiate  the Class to instantiate each time in the factory
       * @param paramTypes  parameter types for the constructor, can be null
       * @param args  the arguments to pass to the constructor, can be null
       * @return the factory
       * @throws IllegalArgumentException if the classToInstantiate is null
       * @throws IllegalArgumentException if the paramTypes and args don't match
       * @throws IllegalArgumentException if the constructor doesn't exist
       */
      public static Factory reflectionFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) {
          return new ReflectionFactory(classToInstantiate, paramTypes, args);
      }
  
      // ExceptionFactory
      //----------------------------------------------------------------------------------
  
      /**
       * ExceptionFactory always throws an exception
       */
      private static class ExceptionFactory implements Factory, Serializable {
  
          /**
           * Constructor
           */
          private ExceptionFactory() {
              super();
          }
  
          /**
           * Always throw an exception
           */
          public Object create() {
              throw new FactoryException("ExceptionFactory invoked");
          }
      }
  
      // ConstantFactory
      //----------------------------------------------------------------------------------
  
      /**
       * ConstantFactory returns the same instance each time.
       */
      private static class ConstantFactory implements Factory, Serializable {
  
          private final Object iConstant;
  
          /**
           * Constructor to store constant
           */
          private ConstantFactory(Object constant) {
              super();
              iConstant = constant;
          }
  
          /**
           * Always return constant
           */
          public Object create() {
              return iConstant;
          }
      }
  
      // PrototypeCloneFactory
      //----------------------------------------------------------------------------------
  
      /**
       * PrototypeCloneFactory creates objects by copying a prototype using the clone method.
       */
      private static class PrototypeCloneFactory implements Factory, Serializable {
          private final Object iPrototype;
          private transient Method iCloneMethod;
  
          /**
           * Constructor to store prototype
           */
          private PrototypeCloneFactory(Object prototype) {
              super();
              if (prototype == null) {
                  throw new IllegalArgumentException("PrototypeCloneFactory: The prototype must not be null");
              }
              iPrototype = prototype;
  
              findCloneMethod();
          }
  
          /**
           * Find the Clone method for the class specified.
           */
          private void findCloneMethod() {
              try {
                  iCloneMethod = iPrototype.getClass().getMethod("clone", null);
  
              } catch (NoSuchMethodException ex) {
                  throw new IllegalArgumentException("PrototypeCloneFactory: The clone method must exist and be public ");
              }
          }
  
          /**
           * Return clone of prototype
           */
          public Object create() {
              // needed for post-serialization
              if (iCloneMethod == null) {
                  findCloneMethod();
              }
  
              try {
                  return iCloneMethod.invoke(iPrototype, null);
  
              } catch (IllegalAccessException ex) {
                  throw new FactoryException("ReflectionFactory: Clone method must be public", ex);
              } catch (InvocationTargetException ex) {
                  throw new FactoryException("ReflectionFactory: Clone method threw an exception", ex);
              }
          }
      }
  
      // PrototypeSerializationFactory
      //----------------------------------------------------------------------------------
  
      /**
       * PrototypeSerializationFactory creates objects by cloning a prototype using serialization.
       */
      private static class PrototypeSerializationFactory implements Factory, Serializable {
  
          private final Serializable iPrototype;
  
          /**
           * Constructor to store prototype
           */
          private PrototypeSerializationFactory(Serializable prototype) {
              super();
              if (prototype == null) {
                  throw new IllegalArgumentException("PrototypeSerializationFactory: The prototype must not be null");
              }
              iPrototype = prototype;
          }
  
          /**
           * Return clone of prototype by serialization
           */
          public Object create() {
              try {
                  return SerializationUtils.clone(iPrototype);
  
              } catch (SerializationException ex) {
                  throw new FactoryException("PrototypeSerializationFactory: Unable to clone by serialization", ex);
              }
          }
      }
  
      // ReflectionFactory
      //----------------------------------------------------------------------------------
  
      /**
       * ReflectionFactory creates objects using reflection.
       */
      private static class ReflectionFactory implements Factory, Serializable {
  
          private final Class iClassToInstantiate;
          private final Class[] iParamTypes;
          private final Object[] iArgs;
          private transient Constructor iConstructor = null;
  
          /**
           * Constructor
           */
          public ReflectionFactory(Class classToInstantiate) {
              this(classToInstantiate, null, null);
          }
  
          /* builds the object factory taking all the options needed to provide
           * arguments to a constructor.
           */
          public ReflectionFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) {
              super();
              if (classToInstantiate == null) {
                  throw new IllegalArgumentException("ReflectionFactory: The class to instantiate must not be null");
              }
              if (((paramTypes == null) && (args != null))
                  || ((paramTypes != null) && (args == null))
                  || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) {
                  throw new IllegalArgumentException("ReflectionFactory: The parameter types must match the arguments");
              }
  
              iClassToInstantiate = classToInstantiate;
              if ((paramTypes == null) && (args == null)) {
                  iParamTypes = null;
                  iArgs = null;
              } else {
                  iParamTypes = (Class[]) paramTypes.clone();
                  iArgs = (Object[]) args.clone();
              }
  
              findConstructor();
          }
  
          /**
           * Find the Constructor for the class specified.
           */
          private void findConstructor() {
              try {
                  iConstructor = iClassToInstantiate.getConstructor(iParamTypes);
  
              } catch (NoSuchMethodException ex) {
                  throw new IllegalArgumentException("ReflectionFactory: The constructor must exist and be public ");
              }
          }
  
          /**
           * Create the object using a constructor
           */
          public Object create() {
              // needed for post-serialization
              if (iConstructor == null) {
                  findConstructor();
              }
  
              try {
                  return iConstructor.newInstance(iArgs);
  
              } catch (InstantiationException ex) {
                  throw new FactoryException("ReflectionFactory: InstantiationException", ex);
              } catch (IllegalAccessException ex) {
                  throw new FactoryException("ReflectionFactory: Constructor must be public", ex);
              } catch (InvocationTargetException ex) {
                  throw new FactoryException("ReflectionFactory: Constructor threw an exception", ex);
              }
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/Predicate.java
  
  Index: Predicate.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  /**
   * <code>Predicate</code> defines an interface implemented by classes that
   * perform a predicate test on an object. Predicate instances can be used
   * to implement queries or to do filtering. 
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: Predicate.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public interface Predicate {
      
      /**
       * Use the specified parameter to perform a test that returns true or false.
       *
       * @param object  the object to evaluate
       * @return true or false
       * @throws PredicateException (runtime) if the predicate encounters a problem
       */
      public boolean evaluate(Object object);
      
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/PredicateException.java
  
  Index: PredicateException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import org.apache.commons.lang.exception.NestableRuntimeException;
  /**
   * Exception thrown when the a Predicate encounters a problem.
   * If required, a root cause error can be wrapped within this one.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: PredicateException.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class PredicateException extends NestableRuntimeException {
  
      /**
       * Constructs a new <code>PredicateException</code> without specified
       * detail message.
       */
      public PredicateException() {
          super();
      }
  
      /**
       * Constructs a new <code>PredicateException</code> with specified
       * detail message.
       *
       * @param msg  the error message.
       */
      public PredicateException(String msg) {
          super(msg);
      }
  
      /**
       * Constructs a new <code>PredicateException</code> with specified
       * nested <code>Throwable</code> root cause.
       *
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public PredicateException(Throwable rootCause) {
          super(rootCause);
      }
  
      /**
       * Constructs a new <code>PredicateException</code> with specified
       * detail message and nested <code>Throwable</code> root cause.
       *
       * @param msg        the error message.
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public PredicateException(String msg, Throwable rootCause) {
          super(msg, rootCause);
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/PredicateUtils.java
  
  Index: PredicateUtils.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import java.io.Serializable;
  import java.util.Collection;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  
  import org.apache.commons.lang.functor.Transformer;
  import org.apache.commons.lang.functor.TransformerException;
  import org.apache.commons.lang.functor.TransformerUtils;
  /**
   * <code>PredicateUtils</code> provides reference implementations and utilities
   * for the Predicate pattern interface. The supplied predicates are:
   * <ul>
   * <li>Invoker - returns the result of a method call on the input object
   * <li>InstanceOf - true if the object is an instanceof a class
   * <li>Equal - true if the object equals() a specified object
   * <li>Identity - true if the object == a specified object
   * <li>Null - true if the object is null
   * <li>NotNull - true if the object is not null
   * <li>Unique - true if the object has not already been evaluated
   * <li>And/All - true if all of the predicates are true
   * <li>Or/Any - true if any of the predicates is true
   * <li>Either/One - true if only one of the predicate is true
   * <li>Neither/None - true if none of the predicates are true
   * <li>Not - true if the predicate is false, and vice versa
   * <li>Transformer - wraps a Transformer as a Predicate
   * <li>True - always return true
   * <li>False - always return false
   * <li>Exception - always throws an exception
   * <li>NullIsException/NullIsFalse/NullIsTrue - check for null input
   * </ul>
   * All the supplied predicates are Serializable.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @author Ola Berg
   * @version $Id: PredicateUtils.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class PredicateUtils {
  
      /**
       * A predicate that always throws an exception
       */
      private static final Predicate EXCEPTION_PREDICATE = new ExceptionPredicate();
      /**
       * A predicate that always returns true
       */
      private static final Predicate TRUE_PREDICATE = new ConstantPredicate(true);
      /**
       * A predicate that always returns false
       */
      private static final Predicate FALSE_PREDICATE = new ConstantPredicate(false);
      /**
       * A predicate that returns true if the object is null
       */
      private static final Predicate NULL_PREDICATE = new IdentityPredicate(null);
      /**
       * A predicate that returns true if the object is not null
       */
      private static final Predicate NOT_NULL_PREDICATE = new NotPredicate(NULL_PREDICATE);
  
      /**
       * Restrictive constructor
       */
      protected PredicateUtils() {
          super();
      }
  
      // Simple predicates
      //-----------------------------------------------------------------------------
  
      /** 
       * Gets a Predicate that always throws an exception.
       * This could be useful during testing as a placeholder.
       *
       * @return the factory
       */
      public static Predicate exceptionPredicate() {
          return EXCEPTION_PREDICATE;
      }
  
      /**
       * Gets a Predicate that always returns true.
       * 
       * @return the predicate
       */
      public static Predicate truePredicate() {
          return TRUE_PREDICATE;
      }
  
      /**
       * Gets a Predicate that always returns false.
       * 
       * @return the predicate
       */
      public static Predicate falsePredicate() {
          return FALSE_PREDICATE;
      }
  
      /**
       * Gets a Predicate that checks if the input object passed in is null.
       * 
       * @return the predicate
       */
      public static Predicate nullPredicate() {
          return NULL_PREDICATE;
      }
  
      /**
       * Gets a Predicate that checks if the input object passed in is not null.
       * 
       * @return the predicate
       */
      public static Predicate notNullPredicate() {
          return NOT_NULL_PREDICATE;
      }
  
      /**
       * Creates a Predicate that checks if the input object is equal to the
       * specified object using equals().
       * 
       * @param value  the value to compare against
       * @return the predicate
       */
      public static Predicate equalPredicate(Object value) {
          if (value == null) {
              return NULL_PREDICATE;
          }
          return new EqualPredicate(value);
      }
  
      /**
       * Creates a Predicate that checks if the input object is equal to the
       * specified object by identity.
       * 
       * @param value  the value to compare against
       * @return the predicate
       */
      public static Predicate identityPredicate(Object value) {
          if (value == null) {
              return NULL_PREDICATE;
          }
          return new IdentityPredicate(value);
      }
      
      /**
       * Creates a Predicate that checks if the object passed in is of
       * a particular type, using instanceof.
       * 
       * @param type  the type to check for, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the class is null
       */
      public static Predicate instanceofPredicate(Class type) {
          if (type == null) {
              throw new IllegalArgumentException("InstanceofPredicate: The type to check instanceof must not be null");
          }
          return new InstanceofPredicate(type);
      }
  
      /**
       * Creates a Predicate that returns true the first time an object is
       * encoutered, and false if the same object is received 
       * again. The comparison is by equals().
       * 
       * @return the predicate
       */
      public static Predicate uniquePredicate() {
          // must return new instance each time
          return new UniquePredicate();
      }
  
      /**
       * Creates a Predicate that invokes a method on the input object.
       * The method must return either a boolean or a non-null Boolean,
       * and have no parameters. If the input object is null, a 
       * PredicateException is thrown.
       * <p>
       * For example, <code>PredicateUtils.invokerPredicate("isEmpty");</code>
       * will call the <code>isEmpty</code> method on the input object to 
       * determine the predicate result.
       * 
       * @param methodName  the method name to call on the input object, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the methodName is null.
       */
      public static Predicate invokerPredicate(String methodName){
          return asPredicate(TransformerUtils.invokerTransformer(methodName));
      }
  
      /**
       * Creates a Predicate that invokes a method on the input object.
       * The method must return either a boolean or a non-null Boolean,
       * and have no parameters. If the input object is null, a 
       * PredicateException is thrown.
       * <p>
       * For example, <code>PredicateUtils.invokerPredicate("isEmpty");</code>
       * will call the <code>isEmpty</code> method on the input object to 
       * determine the predicate result.
       * 
       * @param methodName  the method name to call on the input object, may not be null
       * @param paramTypes  the parameter types
       * @param args  the arguments
       * @return the predicate
       * @throws IllegalArgumentException if the method name is null
       * @throws IllegalArgumentException if the paramTypes and args don't match
       */
      public static Predicate invokerPredicate(String methodName, Class[] paramTypes, Object[] args){
          return asPredicate(TransformerUtils.invokerTransformer(methodName, paramTypes, args));
      }
  
      // Boolean combinations
      //-----------------------------------------------------------------------------
  
      /**
       * Create a new Predicate that returns true only if both of the specified
       * predicates are true.
       * 
       * @param predicate1  the first predicate, may not be null
       * @param predicate2  the second predicate, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if either predicate is null
       */
      public static Predicate andPredicate(Predicate predicate1, Predicate predicate2) {
          return allPredicate(new Predicate[] { predicate1, predicate2 });
      }
  
      /**
       * Create a new Predicate that returns true only if all of the specified
       * predicates are true.
       * 
       * @param predicates  an array of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates array is null
       * @throws IllegalArgumentException if the predicates array has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the array is null
       */
      public static Predicate allPredicate(Predicate[] predicates) {
          return new AllPredicate(validate(predicates));
      }
  
      /**
       * Create a new Predicate that returns true only if all of the specified
       * predicates are true. The predicates are checked in iterator order.
       * 
       * @param predicates  a collection of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates collection is null
       * @throws IllegalArgumentException if the predicates collection has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the collection is null
       */
      public static Predicate allPredicate(Collection predicates) {
          return new AllPredicate(validate(predicates));
      }
  
      /**
       * Create a new Predicate that returns true if either of the specified
       * predicates are true.
       * 
       * @param predicate1  the first predicate, may not be null
       * @param predicate2  the second predicate, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if either predicate is null
       */
      public static Predicate orPredicate(Predicate predicate1, Predicate predicate2) {
          return anyPredicate(new Predicate[] { predicate1, predicate2 });
      }
  
      /**
       * Create a new Predicate that returns true if any of the specified
       * predicates are true.
       * 
       * @param predicates  an array of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates array is null
       * @throws IllegalArgumentException if the predicates array has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the array is null
       */
      public static Predicate anyPredicate(Predicate[] predicates) {
          return new AnyPredicate(validate(predicates));
      }
  
      /**
       * Create a new Predicate that returns true if any of the specified
       * predicates are true. The predicates are checked in iterator order.
       * 
       * @param predicates  a collection of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates collection is null
       * @throws IllegalArgumentException if the predicates collection has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the collection is null
       */
      public static Predicate anyPredicate(Collection predicates) {
          return new AnyPredicate(validate(predicates));
      }
  
      /**
       * Create a new Predicate that returns true if one, but not both, of the
       * specified predicates are true.
       * 
       * @param predicate1  the first predicate, may not be null
       * @param predicate2  the second predicate, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if either predicate is null
       */
      public static Predicate eitherPredicate(Predicate predicate1, Predicate predicate2) {
          return onePredicate(new Predicate[] { predicate1, predicate2 });
      }
  
      /**
       * Create a new Predicate that returns true if only one of the specified
       * predicates are true.
       * 
       * @param predicates  an array of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates array is null
       * @throws IllegalArgumentException if the predicates array has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the array is null
       */
      public static Predicate onePredicate(Predicate[] predicates) {
          return new OnePredicate(validate(predicates));
      }
  
      /**
       * Create a new Predicate that returns true if only one of the specified
       * predicates are true. The predicates are checked in iterator order.
       * 
       * @param predicates  a collection of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates collection is null
       * @throws IllegalArgumentException if the predicates collection has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the collection is null
       */
      public static Predicate onePredicate(Collection predicates) {
          return new OnePredicate(validate(predicates));
      }
  
      /**
       * Create a new Predicate that returns true if neither of the specified 
       * predicates are true.
       * 
       * @param predicate1  the first predicate, may not be null
       * @param predicate2  the second predicate, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if either predicate is null
       */
      public static Predicate neitherPredicate(Predicate predicate1, Predicate predicate2) {
          return nonePredicate(new Predicate[] { predicate1, predicate2 });
      }
  
      /**
       * Create a new Predicate that returns true if none of the specified
       * predicates are true.
       * 
       * @param predicates  an array of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates array is null
       * @throws IllegalArgumentException if the predicates array has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the array is null
       */
      public static Predicate nonePredicate(Predicate[] predicates) {
          Predicate[] preds = validate(predicates);
          for (int i = 0; i < preds.length; i++) {
              preds[i] = notPredicate(preds[i]);
          }
          return new AllPredicate(preds);
      }
  
      /**
       * Create a new Predicate that returns true if none of the specified
       * predicates are true. The predicates are checked in iterator order.
       * 
       * @param predicates  a collection of predicates to check, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicates collection is null
       * @throws IllegalArgumentException if the predicates collection has less than 2 elements
       * @throws IllegalArgumentException if any predicate in the collection is null
       */
      public static Predicate nonePredicate(Collection predicates) {
          Predicate[] preds = validate(predicates);
          for (int i = 0; i < preds.length; i++) {
              preds[i] = notPredicate(preds[i]);
          }
          return new AllPredicate(preds);
      }
  
      /**
       * Create a new Predicate that returns true if the specified predicate
       * returns false and vice versa.
       * 
       * @param predicate  the predicate to not
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null
       */
      public static Predicate notPredicate(Predicate predicate) {
          if (predicate == null) {
              throw new IllegalArgumentException("NotPredicate: The predicate must not be null");
          }
          return new NotPredicate(predicate);
      }
  
      // Adaptors
      //-----------------------------------------------------------------------------
  
      /**
       * Create a new Predicate that wraps a Transformer. The Transformer must
       * return either Boolean.TRUE or Boolean.FALSE otherwise a PredicateException
       * will be thrown.
       * 
       * @param transformer  the transformer to wrap, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the transformer is null
       */
      public static Predicate asPredicate(Transformer transformer) {
          if (transformer == null) {
              throw new IllegalArgumentException("TransformerPredicate: The transformer to call must not be null");
          }
          return new TransformerPredicate(transformer);
      }
  
      // Null handlers
      //-----------------------------------------------------------------------------
  
      /**
       * Gets a Predicate that throws an exception if the input object is null, 
       * otherwise it calls the specified Predicate. This allows null handling 
       * behaviour to be added to Predicates that don't support nulls.
       * 
       * @param predicate  the predicate to wrap, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null.
       */
      public static Predicate nullIsExceptionPredicate(Predicate predicate){
          if (predicate == null) {
              throw new IllegalArgumentException("The predicate must not be null");
          }
          return new NullIsExceptionPredicate( predicate);
      }
  
      /**
       * Gets a Predicate that returns false if the input object is null, otherwise
       * it calls the specified Predicate. This allows null handling behaviour to
       * be added to Predicates that don't support nulls.
       * 
       * @param predicate  the predicate to wrap, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null.
       */
      public static Predicate nullIsFalsePredicate(Predicate predicate){
          if (predicate == null) {
              throw new IllegalArgumentException("The predicate must not be null");
          }
          return new NullIsFalsePredicate(predicate);
      }
  
      /**
       * Gets a Predicate that returns true if the input object is null, otherwise
       * it calls the specified Predicate. This allows null handling behaviour to
       * be added to Predicates that don't support nulls.
       * 
       * @param predicate  the predicate to wrap, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null.
       */
      public static Predicate nullIsTruePredicate(Predicate predicate){
          if (predicate == null) {
              throw new IllegalArgumentException("The predicate must not be null");
          }
          return new NullIsTruePredicate(predicate);
      }
  
      /**
       * Convert a collection to an array using the iterator.
       * 
       * @param predicates  the predicates to validate
       * @return predicate array
       */
      private static Predicate[] validate(Collection predicates) {
          if (predicates == null) {
              throw new IllegalArgumentException("PredicateUtils: The predicate collection must not be null");
          }
          if (predicates.size() < 2) {
              throw new IllegalArgumentException(
                  "PredicateUtils: At least 2 predicates must be specified in the predicate collection, size was " + predicates.size());
          }
          // convert to array like this to guarantee iterator() ordering
          Predicate[] preds = new Predicate[predicates.size()];
          int i = 0;
          for (Iterator it = predicates.iterator(); it.hasNext();) {
              preds[i] = (Predicate) it.next();
              if (preds[i] == null) {
                  throw new IllegalArgumentException("PredicateUtils: The predicate collection must not contain a null predicate, index " + i + " was null");
              }
              i++;
          }
          return preds;
      }
      
      /**
       * Validate method shared amongst predicate implementations.
       * 
       * @param predicates  the predicates to validate
       * @return predicate array (copy)
       */
      private static Predicate[] validate(Predicate[] predicates) {
          if (predicates == null) {
              throw new IllegalArgumentException("PredicateUtils: The predicate array must not be null");
          }
          if (predicates.length < 2) {
              throw new IllegalArgumentException(
                  "PredicateUtils: At least 2 predicates must be specified in the predicate array, size was " + predicates.length);
          }
          Predicate[] preds = new Predicate[predicates.length];
          for (int i = 0; i < predicates.length; i++) {
              if (predicates[i] == null) {
                  throw new IllegalArgumentException("PredicateUtils: The predicate array must not contain a null predicate, index " + i + " was null");
              }
              preds[i] = predicates[i];
          }
          return preds;
      }
  
      // ExceptionPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * ExceptionPredicate always throws an exception
       */
      private static class ExceptionPredicate implements Predicate, Serializable {
  
          /**
           * Constructor
           */
          private ExceptionPredicate() {
              super();
          }
  
          /**
           * Always throw an exception
           */
          public boolean evaluate(Object object) {
              throw new PredicateException("ExceptionPredicate invoked");
          }
      }
  
      // ConstantPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * ConstantPredicate returns the same instance each time.
       */
      private static class ConstantPredicate implements Predicate, Serializable {
  
          private final boolean iConstant;
  
          /**
           * Constructor to store constant
           */
          private ConstantPredicate(boolean constant) {
              super();
              iConstant = constant;
          }
  
          /**
           * Always return constant
           */
          public boolean evaluate(Object object) {
              return iConstant;
          }
      }
  
      // AllPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * AllPredicate returns true if all predicates return true
       */
      private static class AllPredicate implements Predicate, Serializable {
          private final Predicate[] iPredicates;
  
          /**
           * Constructor
           */
          private AllPredicate(Predicate[] predicates) {
              super();
              iPredicates = predicates;
          }
  
          /**
           * Return true if all predicates return true
           */
          public boolean evaluate(Object object) {
              for (int i = 0; i < iPredicates.length; i++) {
                  if (iPredicates[i].evaluate(object) == false) {
                      return false;
                  }
              }
              return true;
          }
      }
  
      // AnyPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * AnyPredicate returns true if one of the predicates return true
       */
      private static class AnyPredicate implements Predicate, Serializable {
          private final Predicate[] iPredicates;
  
          /**
           * Constructor
           */
          private AnyPredicate(Predicate[] predicates) {
              super();
              iPredicates = predicates;
          }
  
          /**
           * Return true if one of the predicates returns true
           */
          public boolean evaluate(Object object) {
              for (int i = 0; i < iPredicates.length; i++) {
                  if (iPredicates[i].evaluate(object)) {
                      return true;
                  }
              }
              return false;
          }
      }
  
      // OnePredicate
      //----------------------------------------------------------------------------------
  
      /**
       * OnePredicate returns true if only one of the predicates return true
       */
      private static class OnePredicate implements Predicate, Serializable {
          private final Predicate[] iPredicates;
  
          /**
           * Constructor
           */
          private OnePredicate(Predicate[] predicates) {
              super();
              iPredicates = predicates;
          }
  
          /**
           * Return true if only one of the predicates returns true
           */
          public boolean evaluate(Object object) {
              boolean match = false;
              for (int i = 0; i < iPredicates.length; i++) {
                  if (iPredicates[i].evaluate(object)) {
                      if (match) {
                          return false;
                      }
                      match = true;
                  }
              }
              return match;
          }
      }
  
      // NotPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * NotPredicate returns the opposite of the wrapped predicate
       */
      private static class NotPredicate implements Predicate, Serializable {
          private final Predicate iPredicate;
  
          /**
           * Constructor
           */
          private NotPredicate(Predicate predicate) {
              super();
              iPredicate = predicate;
          }
  
          /**
           * Return true if the wrapped predicate returns false, and vice versa
           */
          public boolean evaluate(Object object) {
              return !iPredicate.evaluate(object);
          }
      }
  
      // InstanceofPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * InstanceofPredicate checks the type of an object
       */
      private static class InstanceofPredicate implements Predicate, Serializable {
          private final Class iType;
  
          /**
           * Constructor
           */
          public InstanceofPredicate(Class type) {
              super();
              iType = type;
          }
  
          /**
           * Return true if the object is an instanceof the type of the predicate.
           */
          public boolean evaluate(Object object) {
              return iType.isInstance(object);
          }
      }
  
      // EqualPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * EqualPredicate that checks if the object is a particular value by equals().
       */
      private static class EqualPredicate implements Predicate, Serializable {
          private final Object iValue;
  
          /**
           * Constructor
           */
          public EqualPredicate(Object value) {
              super();
              iValue = value;
          }
  
          /**
           * Return true if the object is equals() to the value stored in the predicate.
           */
          public boolean evaluate(Object object) {
              return iValue.equals(object);
          }
      }
  
      // IdentityPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * IdentityPredicate that checks if the object is a particular value by identity.
       */
      private static class IdentityPredicate implements Predicate, Serializable {
          private final Object iValue;
  
          /**
           * Constructor
           */
          public IdentityPredicate(Object value) {
              super();
              iValue = value;
          }
  
          /**
           * Return true if the object is equals() to the value stored in the predicate.
           */
          public boolean evaluate(Object object) {
              return iValue == object;
          }
      }
  
      // UniquePredicate
      //----------------------------------------------------------------------------------
  
      /**
       * UniquePredicate returns true the first time an object is
       * encoutered, and false if the same object is received 
       * again using equals().
       */
      private static class UniquePredicate implements Predicate, Serializable {
          private final Set iSet = new HashSet();
  
          /**
           * Constructor
           */
          public UniquePredicate() {
              super();
          }
  
          /**
           * Return true the first time, and false subsequant times
           * that an object is encountered, using equals().
           */
          public boolean evaluate(Object object) {
              return iSet.add(object);
          }
      }
  
      // TransformerPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * TransformerPredicate returns the result of the Transformer as a boolean.
       */
      private static class TransformerPredicate implements Predicate, Serializable {
  
          private final Transformer iTransformer;
  
          /**
           * Constructor
           */
          public TransformerPredicate(Transformer transformer) {
              super();
              iTransformer = transformer;
          }
  
          /**
           * Return the boolean result of a Transformer
           */
          public boolean evaluate(Object object) {
              Object result = null;
              try {
                  result = iTransformer.transform(object);
  
              } catch (TransformerException ex) {
                  throw new PredicateException("TransformerPredicate: " + ex.getMessage(), ex);
              }
              if (result instanceof Boolean == false) {
                  throw new PredicateException(
                      "TransformerPredicate: Transformer must return an instanceof Boolean, it was a "
                          + (result == null ? "null object" : result.getClass().getName()));
              }
              return ((Boolean) result).booleanValue();
          }
      }
  
      // NullIsExceptionPredicate
      //----------------------------------------------------------------------------------
  
      /**
       * NullIsExceptionPredicate returns an exception if null is passed in.
       */
      private static class NullIsExceptionPredicate implements Predicate, Serializable {
          private final Predicate iPredicate;
          
          /**
           * Constructor
           */
          private NullIsExceptionPredicate(Predicate predicate){
              super();
              iPredicate = predicate;
          }
          
          /**
           * Return an exception if null
           */
          public boolean evaluate(Object object){
              if (object == null) {
                  throw new PredicateException("NullIsExceptionPredicate: Input Object must not be null");
              }
              return iPredicate.evaluate(object);
          }
      };
  
      // NullIsFalsePredicate
      //----------------------------------------------------------------------------------
  
      /**
       * NullIsFalsePredicate returns false if null is passed in.
       */
      private static class NullIsFalsePredicate implements Predicate, Serializable {
          private final Predicate iPredicate;
          
          /**
           * Constructor
           */
          private NullIsFalsePredicate(Predicate predicate){
              super();
              iPredicate = predicate;
          }
          
          /**
           * Return false if null
           */
          public boolean evaluate(Object object){
              if (object == null) {
                  return false;
              }
              return iPredicate.evaluate(object);
          }
      };
  
      // NullIsTruePredicate
      //----------------------------------------------------------------------------------
  
      /**
       * NullIsTruePredicate returns true if null is passed in.
       */
      private static class NullIsTruePredicate implements Predicate, Serializable {
          private final Predicate iPredicate;
          
          /**
           * Constructor
           */
          private NullIsTruePredicate(Predicate predicate){
              super();
              iPredicate = predicate;
          }
          
          /**
           * Return true if null
           */
          public boolean evaluate(Object object){
              if (object == null) {
                  return true;
              }
              return iPredicate.evaluate(object);
          }
      };
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/Transformer.java
  
  Index: Transformer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  /**
   * <code>Transformer</code> defines an interface implemented by classes that
   * transform one object into another. The original object is left unchanged.
   * Transformers are typically used for type conversions, or extracting data
   * from an object.
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: Transformer.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public interface Transformer {
  
      /**
       * Transforms the input object (leaving it unchanged) into some output object.
       *
       * @param input  the object to be transformed
       * @return a transformed object
       * @throws TransformException (runtime) if the transform cannot be completed
       */
      public Object transform(Object input);
      
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/TransformerException.java
  
  Index: TransformerException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import org.apache.commons.lang.exception.NestableRuntimeException;
  /**
   * Exception thrown when the a Transformer encounters a problem.
   * If required, a root cause error can be wrapped within this one.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: TransformerException.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class TransformerException extends NestableRuntimeException {
  
      /**
       * Constructs a new <code>TransformerException</code> without specified
       * detail message.
       */
      public TransformerException() {
          super();
      }
  
      /**
       * Constructs a new <code>TransformerException</code> with specified
       * detail message.
       *
       * @param msg  the error message.
       */
      public TransformerException(String msg) {
          super(msg);
      }
  
      /**
       * Constructs a new <code>TransformerException</code> with specified
       * nested <code>Throwable</code> root cause.
       *
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public TransformerException(Throwable rootCause) {
          super(rootCause);
      }
  
      /**
       * Constructs a new <code>TransformerException</code> with specified
       * detail message and nested <code>Throwable</code> root cause.
       *
       * @param msg        the error message.
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public TransformerException(String msg, Throwable rootCause) {
          super(msg, rootCause);
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/functor/TransformerUtils.java
  
  Index: TransformerUtils.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang.functor;
  
  import java.io.Serializable;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Map;
  
  /**
   * <code>TransformerUtils</code> provides reference implementations and 
   * utilities for the Transformer pattern interface. The supplied transformers are:
   * <ul>
   * <li>Invoker - returns the result of a method call on the input object
   * <li>Clone - returns a clone of the input object
   * <li>Constant - always returns the same object
   * <li>Closure - performs a Closure and returns the input object
   * <li>Predicate - returns the result of the predicate as a Boolean
   * <li>Factory - returns a new object from a factory
   * <li>Chained - chains two or more transformers together
   * <li>Switch - calls one transformer based on one or more predicates
   * <li>SwitchMap - calls one transformer looked up from a Map
   * <li>Instantiate - the Class input object is instantiated
   * <li>Map - returns an object from a supplied Map
   * <li>Null - always returns null
   * <li>NOP - returns the input object, which should be immutable
   * <li>Exception - always throws an exception
   * </ul>
   * All the supplied transformers are Serializable.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: TransformerUtils.java,v 1.1 2002/11/05 16:44:28 bayard Exp $
   */
  public class TransformerUtils {
  
      /**
       * A transformer that always throws an exception
       */
      private static final Transformer EXCEPTION_TRANSFORMER = new ExceptionTransformer();
      /**
       * A transformer that always returns null
       */
      private static final Transformer NULL_TRANSFORMER = new ConstantTransformer(null);
      /**
       * A transformer that returns the input object
       */
      private static final Transformer NOP_TRANSFORMER = new NOPTransformer();
      /**
       * A transformer that clones the input object
       */
      private static final Transformer CLONE_TRANSFORMER = new CloneTransformer();
      /**
       * A transformer that creates an object from a Class
       */
      private static final Transformer INSTANTIATE_TRANSFORMER = new InstantiateTransformer(null, null);
  
      /**
       * Restrictive constructor
       */
      protected TransformerUtils() {
          super();
      }
  
      /**
       * Gets a transformer that always throws an exception.
       * This could be useful during testing as a placeholder.
       * 
       * @return the transformer
       */
      public static Transformer exceptionTransformer() {
          return EXCEPTION_TRANSFORMER;
      }
  
      /**
       * Gets a transformer that always returns null.
       * 
       * @return the transformer
       */
      public static Transformer nullTransformer() {
          return NULL_TRANSFORMER;
      }
  
      /**
       * Gets a transformer that returns the input object.
       * The input object should be immutable to maintain the
       * contract of Transformer (although this is not checked).
       * 
       * @return the transformer
       */
      public static Transformer nopTransformer() {
          return NOP_TRANSFORMER;
      }
  
      /**
       * Gets a transformer that returns a clone of the input
       * object. The input object will be cloned using one of these
       * techniques (in order):
       * <ul>
       * <li>public clone method
       * <li>public copy constructor
       * <li>serialization clone
       * <ul>
       * 
       * @return the transformer
       */
      public static Transformer cloneTransformer() {
          return CLONE_TRANSFORMER;
      }
  
      /**
       * Creates a Transformer that will return the same object each time the 
       * transformer is used.
       *
       * @param constantToReturn  the constant object to return each time in the transformer
       * @return the transformer.
       */
      public static Transformer constantTransformer(Object constantToReturn) {
          return new ConstantTransformer(constantToReturn);
      }
  
      /**
       * Creates a Transformer that calls a Closure each time the transformer is used.
       * The transformer returns the input object.
       *
       * @param command  the command to run each time in the transformer
       * @return the transformer.
       */
      public static Transformer asTransformer(Closure command) {
          if (command == null) {
              throw new IllegalArgumentException("ClosureTransformer: The command must not be null");
          }
          return new ClosureTransformer(command);
      }
  
      /**
       * Creates a Transformer that calls a Predicate each time the transformer is used.
       * The transformer will return either Boolean.TRUE or Boolean.FALSE.
       *
       * @param predicate  the predicate to run each time in the transformer
       * @return the transformer.
       */
      public static Transformer asTransformer(Predicate predicate) {
          if (predicate == null) {
              throw new IllegalArgumentException("PredicateTransformer: The predicate must not be null");
          }
          return new PredicateTransformer(predicate);
      }
  
      /**
       * Creates a Transformer that calls a Factory each time the transformer is used.
       * The transformer will return the value returned by the factory.
       *
       * @param factory  the factory to run each time in the transformer
       * @return the transformer.
       */
      public static Transformer asTransformer(Factory factory) {
          if (factory == null) {
              throw new IllegalArgumentException("FactoryTransformer: The factory must not be null");
          }
          return new FactoryTransformer(factory);
      }
  
      /**
       * Create a new Transformer that calls two transformers, passing the result of
       * the first into the second.
       * 
       * @param transformer1  the first transformer
       * @param transformer2  the second transformer
       * @return the transformer
       * @throws IllegalArgumentException if either transformer is null
       */
      public static Transformer chainedTransformer(Transformer transformer1, Transformer transformer2) {
          Transformer[] trs = new Transformer[] {transformer1, transformer2};
          validate(trs);
          return new ChainedTransformer(trs);
      }
  
      /**
       * Create a new Transformer that calls each transformer in turn, passing the 
       * result into the next transformer.
       * 
       * @param transformers  an array of transformers to chain
       * @return the transformer
       * @throws IllegalArgumentException if the transformers array is null
       * @throws IllegalArgumentException if the transformers array has 0 elements
       * @throws IllegalArgumentException if any transformer in the array is null
       */
      public static Transformer chainedTransformer(Transformer[] transformers) {
          Transformer[] trs = copy(transformers);
          validate(trs);
          return new ChainedTransformer(trs);
      }
  
      /**
       * Create a new Transformer that calls each transformer in turn, passing the 
       * result into the next transformer. The ordering is that of the iterator()
       * method on the collection.
       * 
       * @param transformers  a collection of transformers to chain
       * @return the transformer
       * @throws IllegalArgumentException if the transformers collection is null
       * @throws IllegalArgumentException if the transformers collection is empty
       * @throws IllegalArgumentException if any transformer in the collection is null
       */
      public static Transformer chainedTransformer(Collection transformers) {
          Transformer[] trs = null;
          if (transformers == null) {
              throw new IllegalArgumentException("ChainedTransformer: The transformer collection must not be null");
          }
          // convert to array like this to guarantee iterator() ordering
          trs = new Transformer[transformers.size()];
          int i = 0;
          for (Iterator it = transformers.iterator(); it.hasNext();) {
              trs[i++] = (Transformer) it.next();
          }
          validate(trs);
          return new ChainedTransformer(trs);
      }
  
      /**
       * Create a new Transformer that calls one of two transformers depending 
       * on the specified predicate.
       * 
       * @param predicate  the predicate to switch on
       * @param trueTransformer  the transformer called if the predicate is true
       * @param falseTransformer  the transformer called if the predicate is false
       * @return the transformer
       * @throws IllegalArgumentException if the predicate is null
       * @throws IllegalArgumentException if either transformer is null
       */
      public static Transformer switchTransformer(Predicate predicate, Transformer trueTransformer, Transformer falseTransformer) {
          return switchTransformerInternal(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer);
      }
  
      /**
       * Create a new Transformer that calls one of the transformers depending 
       * on the predicates. The transformer at array location 0 is called if the
       * predicate at array location 0 returned true. Each predicate is evaluated
       * until one returns true. If no predicates evaluate to true, null is returned.
       * 
       * @param predicates  an array of predicates to check
       * @param transformers  an array of transformers to call
       * @return the transformer
       * @throws IllegalArgumentException if the either array is null
       * @throws IllegalArgumentException if the either array has 0 elements
       * @throws IllegalArgumentException if any element in the arrays is null
       * @throws IllegalArgumentException if the arrays are different sizes
       */
      public static Transformer switchTransformer(Predicate[] predicates, Transformer[] transformers) {
          return switchTransformerInternal(copy(predicates), copy(transformers), null);
      }
  
      /**
       * Create a new Transformer that calls one of the transformers depending 
       * on the predicates. The transformer at array location 0 is called if the
       * predicate at array location 0 returned true. Each predicate is evaluated
       * until one returns true. If no predicates evaluate to true, the default
       * transformer is called.
       * 
       * @param predicates  an array of predicates to check
       * @param transformers  an array of transformers to call
       * @param defaultTransformer  the default to call if no predicate matches
       * @return the transformer
       * @throws IllegalArgumentException if the either array is null
       * @throws IllegalArgumentException if the either array has 0 elements
       * @throws IllegalArgumentException if any element in the arrays is null
       * @throws IllegalArgumentException if the arrays are different sizes
       */
      public static Transformer switchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) {
          return switchTransformerInternal(copy(predicates), copy(transformers), defaultTransformer);
      }
  
      /**
       * Create a new Transformer that calls one of the transformers depending 
       * on the predicates. 
       * <p>
       * The Map consists of Predicate keys and Transformer values. A transformer 
       * is called if its matching predicate returns true. Each predicate is evaluated
       * until one returns true. If no predicates evaluate to true, the default
       * transformer is called. The default transformer is set in the map with a 
       * null key. If no default transformer is set, null will be returned in a default
       * case. The ordering is that of the iterator() method on the entryset collection 
       * of the map.
       * 
       * @param predicatesAndTransformers  a map of predicates to transformers
       * @return the transformer
       * @throws IllegalArgumentException if the map is null
       * @throws IllegalArgumentException if the map is empty
       * @throws IllegalArgumentException if any transformer in the map is null
       * @throws ClassCastException  if the map elements are of the wrong type
       */
      public static Transformer switchTransformer(Map predicatesAndTransformers) {
          Transformer[] trs = null;
          Predicate[] preds = null;
          if (predicatesAndTransformers == null) {
              throw new IllegalArgumentException("SwitchTransformer: The predicate and transformer map must not be null");
          }
          // convert to array like this to guarantee iterator() ordering
          Transformer def = (Transformer) predicatesAndTransformers.remove(null);
          int size = predicatesAndTransformers.size();
          trs = new Transformer[size];
          preds = new Predicate[size];
          int i = 0;
          for (Iterator it = predicatesAndTransformers.entrySet().iterator(); it.hasNext();) {
              Map.Entry entry = (Map.Entry) it.next();
              preds[i] = (Predicate) entry.getKey();
              trs[i] = (Transformer) entry.getValue();
              i++;
          }
          return switchTransformerInternal(preds, trs, def);
      }
  
      /**
       * Validate input and create transformer
       */
      private static Transformer switchTransformerInternal(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) {
          validate(predicates);
          validate(transformers);
          if (predicates.length != transformers.length) {
              throw new IllegalArgumentException("SwitchTransformer: The predicate and transformer arrays must be the same size");
          }
          if (defaultTransformer == null) {
              defaultTransformer = nullTransformer();
          }
          return new SwitchTransformer(predicates, transformers, defaultTransformer);
      }
      
      /**
       * Create a new Transformer that uses the input object as a key to find the
       * transformer to call. 
       * <p>
       * The Map consists of object keys and Transformer values. A transformer 
       * is called if the input object equals the key. If there is no match, the
       * default transformer is called. The default transformer is set in the map
       * using a null key. If no default is set, null will be returned in a default case.
       * 
       * @param objectsAndTransformers  a map of objects to transformers
       * @return the transformer
       * @throws IllegalArgumentException if the map is null
       * @throws IllegalArgumentException if the map is empty
       * @throws IllegalArgumentException if any transformer in the map is null
       */
      public static Transformer switchMapTransformer(Map objectsAndTransformers) {
          Transformer[] trs = null;
          Predicate[] preds = null;
          if (objectsAndTransformers == null) {
              throw new IllegalArgumentException("SwitchEqualsTransformer: The obejct and transformer map must not be null");
          }
          Transformer def = (Transformer) objectsAndTransformers.remove(null);
          int size = objectsAndTransformers.size();
          trs = new Transformer[size];
          preds = new Predicate[size];
          int i = 0;
          for (Iterator it = objectsAndTransformers.entrySet().iterator(); it.hasNext();) {
              Map.Entry entry = (Map.Entry) it.next();
              preds[i] = PredicateUtils.equalPredicate(entry.getKey());
              trs[i] = (Transformer) entry.getValue();
              i++;
          }
          return switchTransformer(preds, trs, def);
      }
  
      /**
       * Gets a Transformer that expects an input Class object that it will instantiate.
       * 
       * @return the transformer
       */
      public static Transformer instantiateTransformer() {
          return INSTANTIATE_TRANSFORMER;
      }
  
      /** 
       * Creates a Transformer that expects an input Class object that it will 
       * instantiate. The constructor used is determined by the arguments specified
       * to this method.
       *
       * @param paramTypes  parameter types for the constructor, can be null
       * @param args  the arguments to pass to the constructor, can be null
       * @return the transformer
       * @throws IllegalArgumentException if the paramTypes and args don't match
       */
      public static Transformer instantiateTransformer(Class[] paramTypes, Object[] args) {
          return new InstantiateTransformer(paramTypes, args);
      }
  
      /** 
       * Creates a Transformer that uses the passed in Map to transform the input 
       * object (as a simple lookup).
       *
       * @param map  the map to use to transform the objects
       * @return the transformer
       * @throws IllegalArgumentException if the map is null
       */
      public static Transformer mapTransformer(Map map) {
          if (map == null) {
              throw new IllegalArgumentException("MapTransformer: The map must not be null");
          }
          return new MapTransformer(map);
      }
  
      /**
       * Gets a Transformer that invokes a method on the input object.
       * The method must have no parameters. If the input object is null, 
       * null is returned.
       * <p>
       * For example, <code>TransformerUtils.invokerTransformer("getName");</code>
       * will call the <code>getName/code> method on the input object to 
       * determine the transformer result.
       * 
       * @param methodName  the method name to call on the input object, may not be null
       * @return the transformer
       * @throws IllegalArgumentException if the methodName is null.
       */
      public static Transformer invokerTransformer(String methodName){
          return new InvokerTransformer(methodName, null, null);
      }
  
      /**
       * Gets a Transformer that invokes a method on the input object.
       * The method parameters are specified. If the input object is null, 
       * null is returned.
       * 
       * @param methodName  the name of the method
       * @param paramTypes  the parameter types
       * @param args  the arguments
       * @return the transformer
       * @throws IllegalArgumentException if the method name is null
       * @throws IllegalArgumentException if the paramTypes and args don't match
       */
      public static Transformer invokerTransformer(String methodName, Class[] paramTypes, Object[] args){
          return new InvokerTransformer(methodName, paramTypes, args);
      }
  
      /**
       * Copy method
       * 
       * @param predicates  the predicates to copy
       */
      private static Predicate[] copy(Predicate[] predicates) {
          if (predicates == null) {
              return null;
          }
          return (Predicate[]) predicates.clone();
      }
      
      /**
       * Validate method
       * 
       * @param predicates  the predicates to validate
       */
      private static void validate(Predicate[] predicates) {
          if (predicates == null) {
              throw new IllegalArgumentException("TransformerUtils: The predicate array must not be null");
          }
          if (predicates.length < 1) {
              throw new IllegalArgumentException(
                  "TransformerUtils: At least 1 predicate must be specified in the predicate array, size was " + predicates.length);
          }
          for (int i = 0; i < predicates.length; i++) {
              if (predicates[i] == null) {
                  throw new IllegalArgumentException(
                      "TransformerUtils: The predicate array must not contain a null predicate, index " + i + " was null");
              }
          }
      }
  
      /**
       * Copy method
       * 
       * @param transformers  the transformers to copy
       */
      private static Transformer[] copy(Transformer[] transformers) {
          if (transformers == null) {
              return null;
          }
          return (Transformer[]) transformers.clone();
      }
      
      /**
       * Validate method
       * 
       * @param transformers  the transformers to validate
       */
      private static void validate(Transformer[] transformers) {
          if (transformers == null) {
              throw new IllegalArgumentException("TransformerUtils: The transformer array must not be null");
          }
          if (transformers.length < 1) {
              throw new IllegalArgumentException(
                  "TransformerUtils: At least 1 transformer must be specified in the transformer array, size was " + transformers.length);
          }
          for (int i = 0; i < transformers.length; i++) {
              if (transformers[i] == null) {
                  throw new IllegalArgumentException(
                      "TransformerUtils: The transformer array must not contain a null transformer, index " + i + " was null");
              }
          }
      }
  
      // ExceptionTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * ExceptionTransformer always throws an exception.
       */
      private static class ExceptionTransformer implements Transformer, Serializable {
  
          /**
           * Constructor
           */
          private ExceptionTransformer() {
              super();
          }
  
          /**
           * Always throw exception
           */
          public Object transform(Object input) {
              throw new TransformerException("ExceptionTransformer invoked");
          }
      }
  
      // NOPTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * NOPTransformer returns the input object.
       */
      private static class NOPTransformer implements Transformer, Serializable {
  
          /**
           * Constructor
           */
          private NOPTransformer() {
              super();
          }
  
          /**
           * Return the input object
           */
          public Object transform(Object input) {
              return input;
          }
      }
  
      // CloneTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * CloneTransformer returns a clone of the input object.
       */
      private static class CloneTransformer implements Transformer, Serializable {
  
          /**
           * Constructor
           */
          private CloneTransformer() {
              super();
          }
  
          /**
           * Returns a clone of the input object
           */
          public Object transform(Object input) {
              if (input == null) {
                  return null;
              }
              try {
                  return FactoryUtils.prototypeFactory(input).create();
  
              } catch (IllegalArgumentException ex) {
                  throw new TransformerException("CloneTransformer", ex);
              } catch (FactoryException ex) {
                  throw new TransformerException("CloneTransformer", ex);
              }
          }
      }
  
      // ConstantTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * ConstantTransformer returns the same instance each time.
       */
      private static class ConstantTransformer implements Transformer, Serializable {
  
          private final Object iConstant;
  
          /**
           * Constructor to store constant
           */
          private ConstantTransformer(Object constant) {
              super();
              iConstant = constant;
          }
  
          /**
           * Always return constant
           */
          public Object transform(Object input) {
              return iConstant;
          }
      }
  
      // ClosureTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * ClosureTransformer executes a Closure object.
       */
      private static class ClosureTransformer implements Transformer, Serializable {
  
          private final Closure iClosure;
  
          /**
           * Constructor to store command
           */
          private ClosureTransformer(Closure command) {
              super();
              iClosure = command;
          }
  
          /**
           * Exceute the command and return the input
           */
          public Object transform(Object input) {
              try {
                  iClosure.execute(input);
                  return input;
  
              } catch (ClosureException ex) {
                  throw new TransformerException("ClosureTransformer: " + ex.getMessage(), ex);
              }
          }
      }
  
      // PredicateTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * PredicateTransformer evaluates a Predicate object.
       */
      private static class PredicateTransformer implements Transformer, Serializable {
  
          private final Predicate iPredicate;
  
          /**
           * Constructor to store predicate
           */
          private PredicateTransformer(Predicate predicate) {
              super();
              iPredicate = predicate;
          }
  
          /**
           * Evaluate the predicate and return the result as a Boolean
           */
          public Object transform(Object input) {
              try {
                  return new Boolean(iPredicate.evaluate(input));
  
              } catch (PredicateException ex) {
                  throw new TransformerException("PredicateTransformer: " + ex.getMessage(), ex);
              }
          }
      }
  
      // FactoryTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * FactoryTransformer returns the result of calling a Factory.
       */
      private static class FactoryTransformer implements Transformer, Serializable {
  
          private final Factory iFactory;
  
          /**
           * Constructor to store factory
           */
          private FactoryTransformer(Factory factory) {
              super();
              iFactory = factory;
          }
  
          /**
           * Return the result of calling the factory
           */
          public Object transform(Object input) {
              try {
                  return iFactory.create();
  
              } catch (FactoryException ex) {
                  throw new TransformerException("FactoryTransformer: " + ex.getMessage(), ex);
              }
          }
      }
  
      // ChainedTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * ChainedTransformer returns the result of calling a list of transformers.
       */
      private static class ChainedTransformer implements Transformer, Serializable {
  
          private final Transformer[] iTransformers;
  
          /**
           * Constructor to store params
           */
          private ChainedTransformer(Transformer[] transformers) {
              super();
              iTransformers = transformers;
          }
  
          /**
           * Returns the result of calling a list of transformers
           */
          public Object transform(Object object) {
              for (int i = 0; i < iTransformers.length; i++) {
                  object = iTransformers[i].transform(object);
              }
              return object;
          }
      }
  
      // SwitchTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * SwitchTransformer returns the result of the transformer whose predicate returns true.
       */
      private static class SwitchTransformer implements Transformer, Serializable {
  
          private final Predicate[] iPredicates;
          private final Transformer[] iTransformers;
          private final Transformer iDefault;
  
          /**
           * Constructor to store params
           */
          private SwitchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) {
              super();
              iPredicates = predicates;
              iTransformers = transformers;
              iDefault = defaultTransformer;
          }
  
          /**
           * Returns the result of the transformer whose predicate returns true
           */
          public Object transform(Object input) {
              for (int i = 0; i < iPredicates.length; i++) {
                  if (iPredicates[i].evaluate(input) == true) {
                      return iTransformers[i].transform(input);
                  }
              }
              return iDefault.transform(input);
          }
      }
  
      // InstantiateTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * InstantiateTransformer returns the result of calling a Factory.
       */
      private static class InstantiateTransformer implements Transformer, Serializable {
  
          private final Class[] iParamTypes;
          private final Object[] iArgs;
  
          /**
           * Constructor to store params
           */
          private InstantiateTransformer(Class[] paramTypes, Object[] args) {
              super();
              if (((paramTypes == null) && (args != null))
                  || ((paramTypes != null) && (args == null))
                  || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) {
                  throw new IllegalArgumentException("InstantiateTransformer: The parameter types must match the arguments");
              }
              if ((paramTypes == null) && (args == null)) {
                  iParamTypes = null;
                  iArgs = null;
              } else {
                  iParamTypes = (Class[]) paramTypes.clone();
                  iArgs = (Object[]) args.clone();
              }
          }
  
          /**
           * Return the result of calling the factory
           */
          public Object transform(Object input) {
              try {
                  if (input instanceof Class == false) {
                      throw new TransformerException(
                          "InstantiateTransformer: Input object was not an instanceof Class, it was a "
                              + (input == null ? "null object" : input.getClass().getName()));
                  }
                  return FactoryUtils.reflectionFactory((Class) input, iParamTypes, iArgs).create();
  
              } catch (IllegalArgumentException ex) {
                  throw new TransformerException("InstantiateTransformer", ex);
              } catch (FactoryException ex) {
                  throw new TransformerException("InstantiateTransformer", ex);
              }
          }
      }
  
      // MapTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * MapTransformer returns the result by looking up in the map.
       */
      private static class MapTransformer implements Transformer, Serializable {
  
          private final Map iMap;
  
          /**
           * Constructor to store map
           */
          private MapTransformer(Map map) {
              super();
              iMap = map;
          }
  
          /**
           * Returns the result by looking up in the map
           */
          public Object transform(Object input) {
              return iMap.get(input);
          }
      }
  
      // InvokerTransformer
      //----------------------------------------------------------------------------------
  
      /**
       * InvokerTransformer returns the result of invoking the specified method on 
       * the input object.
       */
      private static class InvokerTransformer implements Transformer, Serializable {
          private final String iMethodName;
          private final Class[] iParamTypes;
          private final Object[] iArgs;
  
          /**
           * Constructor
           */
          public InvokerTransformer(String methodName, Class[] paramTypes, Object[] args) {
              super();
              if (methodName == null) {
                  throw new IllegalArgumentException("InvokerTransformer: The method to invoke must not be null");
              }
              if (((paramTypes == null) && (args != null))
                  || ((paramTypes != null) && (args == null))
                  || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) {
                  throw new IllegalArgumentException("InvokerTransformer: The parameter types must match the arguments");
              }
  
              iMethodName = methodName;
              if ((paramTypes == null) && (args == null)) {
                  iParamTypes = null;
                  iArgs = null;
              } else {
                  iParamTypes = (Class[]) paramTypes.clone();
                  iArgs = (Object[]) args.clone();
              }
          }
  
          /**
           * Execute the command based on the input object.
           */
          public Object transform(Object input) {
              if (input == null) {
                  return null;
              }
              try {
                  Class cls = input.getClass();
                  Method method = cls.getMethod(iMethodName, iParamTypes);
                  return method.invoke(input, iArgs);
                  
              } catch (NoSuchMethodException ex) {
                  throw new TransformerException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' does not exist");
              } catch (IllegalAccessException ex) {
                  throw new TransformerException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' cannot be accessed");
              } catch (InvocationTargetException ex) {
                  throw new TransformerException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' threw an exception", ex);
              }
          }
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>