You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ge...@apache.org on 2002/08/05 07:06:21 UTC

cvs commit: jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util AbstractExecutor.java ArrayIterator.java BooleanPropertyExecutor.java EnumerationIterator.java GetExecutor.java PropertyExecutor.java Introspector.java LogAdapter.java

geirm       2002/08/04 22:06:21

  Modified:    jexl/src/java/org/apache/commons/jexl/util Introspector.java
                        LogAdapter.java
  Added:       jexl/src/java/org/apache/commons/jexl/util
                        AbstractExecutor.java ArrayIterator.java
                        BooleanPropertyExecutor.java
                        EnumerationIterator.java GetExecutor.java
                        PropertyExecutor.java
  Log:
  more porting of velocity's core introspection stuff so Jexl is free to
  do what it needs and removes dependency on velocity for functionality
  
  Revision  Changes    Path
  1.3       +5 -15     jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/Introspector.java
  
  Index: Introspector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/Introspector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Introspector.java	20 May 2002 12:07:59 -0000	1.2
  +++ Introspector.java	5 Aug 2002 05:06:21 -0000	1.3
  @@ -53,14 +53,11 @@
    */
   package org.apache.commons.jexl.util;
   
  -import org.apache.velocity.util.introspection.Uberspect;
  -import org.apache.velocity.util.introspection.UberspectImpl;
  -import org.apache.velocity.util.introspection.UberspectLoggable;
  -import org.apache.velocity.util.introspection.Info;
  -import org.apache.velocity.util.introspection.VelMethod;
  -import org.apache.velocity.runtime.RuntimeLogger;
   import org.apache.commons.logging.LogFactory;
   import org.apache.commons.logging.Log;
  +import org.apache.commons.jexl.util.introspection.Uberspect;
  +import org.apache.commons.jexl.util.introspection.UberspectImpl;
  +import org.apache.commons.jexl.util.introspection.UberspectLoggable;
   
   import java.lang.reflect.Method;
   
  @@ -78,19 +75,12 @@
        */
       private static Uberspect uberSpect;
   
  -    /**
  -     *  so we can convert between commons and Velocity logging
  -     */
  -    private static LogAdapter logAdapter;
  -
       static {
   
           Log logger = LogFactory.getLog(Introspector.class);
   
           uberSpect = new UberspectImpl();
  -        logAdapter = new LogAdapter(logger);
  -
  -        ((UberspectLoggable) uberSpect).setRuntimeLogger(logAdapter);
  +        ((UberspectLoggable) uberSpect).setRuntimeLogger(logger);
       }
   
       /**
  
  
  
  1.2       +1 -2      jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/LogAdapter.java
  
  Index: LogAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/LogAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogAdapter.java	26 Apr 2002 04:23:17 -0000	1.1
  +++ LogAdapter.java	5 Aug 2002 05:06:21 -0000	1.2
  @@ -1,13 +1,12 @@
   package org.apache.commons.jexl.util;
   
   import org.apache.commons.logging.Log;
  -import org.apache.velocity.runtime.RuntimeLogger;
   
   /**
    *
    *  @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
    */
  -public class LogAdapter implements RuntimeLogger
  +public class LogAdapter
   {
       Log logger;
   
  
  
  
  1.1                  jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/AbstractExecutor.java
  
  Index: AbstractExecutor.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 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", "Velocity", 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 Group.
   *
   * 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.jexl.util;
  
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  import org.apache.commons.logging.Log;
  
  /**
   * Abstract class that is used to execute an arbitrary
   * method that is in introspected. This is the superclass
   * for the GetExecutor and PropertyExecutor.
   *
   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
   * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
   * @version $Id: AbstractExecutor.java,v 1.1 2002/08/05 05:06:21 geirm Exp $
   */
  public abstract class AbstractExecutor
  {
      protected Log rlog = null;
      
      /**
       * Method to be executed.
       */
      protected Method method = null;
      
      /**
       * Execute method against context.
       */
       public abstract Object execute(Object o)
           throws IllegalAccessException, InvocationTargetException;
  
      /**
       * Tell whether the executor is alive by looking
       * at the value of the method.
       */
      public boolean isAlive()
      {
          return (method != null);
      }
  
      public Method getMethod()
      {
          return method;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/ArrayIterator.java
  
  Index: ArrayIterator.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 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", "Velocity", 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 Group.
   *
   * 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.jexl.util;
  
  
  
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import java.lang.reflect.Array;
  
  
  /**
   *  <p>
   *  An Iterator wrapper for an Object[]. This will
   *  allow us to deal with all array like structures
   *  in a consistent manner.
   *  </p>
   *  <p>
   *  WARNING : this class's operations are NOT synchronized.
   *  It is meant to be used in a single thread, newly created
   *  for each use in the #foreach() directive.
   *  If this is used or shared, synchronize in the
   *  next() method.
   *  </p>
   *
   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
   * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
   * @version $Id: ArrayIterator.java,v 1.1 2002/08/05 05:06:21 geirm Exp $
   */
  public class ArrayIterator implements Iterator
  {
      /**
       * The objects to iterate.
       */
      private Object array;
  
      /**
       * The current position and size in the array.
       */
      private int pos;
      private int size;
  
      /**
       * Creates a new iterator instance for the specified array.
       *
       * @param array The array for which an iterator is desired.
       */
      public ArrayIterator(Object array)
      {
          /*
           * if this isn't an array, then throw.  Note that this is 
           * for internal use - so this should never happen - if it does
           *  we screwed up.
           */
           
          if ( !array.getClass().isArray() )
          {   
              throw new IllegalArgumentException( 
                  "Programmer error : internal ArrayIterator invoked w/o array");
          }
              
          this.array = array;
          pos = 0;
          size = Array.getLength( this.array );
      }
  
      /**
       * Move to next element in the array.
       *
       * @return The next object in the array.
       */
      public Object next()
      {
          if (pos < size )
              return Array.get( array, pos++);
                  
          /*
           *  we screwed up...
           */
           
          throw new NoSuchElementException("No more elements: " + pos +
                                           " / " + size);
      }
      
      /**
       * Check to see if there is another element in the array.
       *
       * @return Whether there is another element.
       */
      public boolean hasNext()
      {
          return (pos < size );
      }
  
      /**
       * No op--merely added to satify the <code>Iterator</code> interface.
       */
      public void remove()
      {
          throw new UnsupportedOperationException();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/BooleanPropertyExecutor.java
  
  Index: BooleanPropertyExecutor.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 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", "Velocity", 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 Group.
   *
   * 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.jexl.util;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  
  import org.apache.commons.logging.Log;
  /**
   *  Handles discovery and valuation of a
   *  boolean object property, of the
   *  form public boolean is<property> when executed.
   *
   *  We do this separately as to preserve the current
   *  quasi-broken semantics of get<as is property>
   *  get< flip 1st char> get("property") and now followed
   *  by is<Property>
   *
   *  @author <a href="geirm@apache.org">Geir Magnusson Jr.</a>
   *  @version $Id: BooleanPropertyExecutor.java,v 1.1 2002/08/05 05:06:21 geirm Exp $
   */
  public class BooleanPropertyExecutor extends PropertyExecutor
  {
      public BooleanPropertyExecutor(Log rlog, org.apache.commons.jexl.util.introspection.Introspector is, Class clazz, String property)
      {
          super(rlog, is, clazz, property);
      }
  
      protected void discover(Class clazz, String property)
      {
          try
          {
              char c;
              StringBuffer sb;
  
              Object[] params = {  };
  
              /*
               *  now look for a boolean isFoo
               */
  
              sb = new StringBuffer("is");
              sb.append(property);
  
              c = sb.charAt(2);
  
              if (Character.isLowerCase(c))
              {
                  sb.setCharAt(2, Character.toUpperCase(c));
              }
  
              methodUsed = sb.toString();
              method = introspector.getMethod(clazz, methodUsed, params);
  
              if (method != null)
              {
                  /*
                   *  now, this has to return a boolean
                   */
  
                  if (method.getReturnType() == Boolean.TYPE)
                      return;
  
                  method = null;
              }
          }
          catch(Exception e)
          {
              rlog.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e);
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/EnumerationIterator.java
  
  Index: EnumerationIterator.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 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", "Velocity", 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 Group.
   *
   * 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.jexl.util;
  
  
  import java.util.Iterator;
  import java.util.Enumeration;
  
  /**
   * An Iterator wrapper for an Enumeration.
   *
   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
   * @version $Id: EnumerationIterator.java,v 1.1 2002/08/05 05:06:21 geirm Exp $
   */
  public class EnumerationIterator implements Iterator
  {
      /**
       * The enumeration to iterate.
       */
      private Enumeration enum = null;
  
      /**
       * Creates a new iteratorwrapper instance for the specified 
       * Enumeration.
       *
       * @param enum  The Enumeration to wrap.
       */
      public EnumerationIterator( Enumeration enum)
      {
          this.enum = enum;
      }
  
      /**
       * Move to next element in the array.
       *
       * @return The next object in the array.
       */
      public Object next()
      {
          return enum.nextElement();
      }
      
      /**
       * Check to see if there is another element in the array.
       *
       * @return Whether there is another element.
       */
      public boolean hasNext()
      {
          return enum.hasMoreElements();
      }
  
      /**
       *  Unimplemented.  No analogy in Enumeration
       */
      public void remove()
      {
          // not implemented
      }
     
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/GetExecutor.java
  
  Index: GetExecutor.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 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", "Velocity", 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 Group.
   *
   * 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.jexl.util;
  
  import org.apache.commons.logging.Log;
  
  import java.lang.reflect.Method;
  
  import java.lang.reflect.InvocationTargetException;
  
  
  /**
   * Executor that simply tries to execute a get(key)
   * operation. This will try to find a get(key) method
   * for any type of object, not just objects that
   * implement the Map interface as was previously
   * the case.
   *
   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
   * @version $Id: GetExecutor.java,v 1.1 2002/08/05 05:06:21 geirm Exp $
   */
  public class GetExecutor extends AbstractExecutor
  {
      /**
       * Container to hold the 'key' part of 
       * get(key).
       */
      private Object[] args = new Object[1];
      
      /**
       * Default constructor.
       */
      public GetExecutor(Log r, org.apache.commons.jexl.util.introspection.Introspector ispect, Class c, String key)
          throws Exception
      {
          rlog = r;
          args[0] = key;
          method = ispect.getMethod(c, "get", args);
      }
  
      /**
       * Execute method against context.
       */
      public Object execute(Object o)
          throws IllegalAccessException, InvocationTargetException
      {
          if (method == null)
              return null;
  
          return method.invoke(o, args);
      }
  
  }
  
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/jexl/src/java/org/apache/commons/jexl/util/PropertyExecutor.java
  
  Index: PropertyExecutor.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-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", "Velocity", 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 Group.
   *
   * 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.jexl.util;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  
  import org.apache.commons.jexl.util.introspection.Introspector;
  import org.apache.commons.logging.Log;
  
  /**
   * Returned the value of object property when executed.
   */
  public class PropertyExecutor extends AbstractExecutor
  {
      protected Introspector introspector = null;
  
      protected String methodUsed = null;
  
      public PropertyExecutor(Log r, Introspector ispctr,
                              Class clazz, String property)
      {
          rlog = r;
          introspector = ispctr;
  
          discover(clazz, property);
      }
  
      protected void discover(Class clazz, String property)
      {
          /*
           *  this is gross and linear, but it keeps it straightforward.
           */
  
          try
          {
              char c;
              StringBuffer sb;
  
              Object[] params = {  };
  
              /*
               *  start with get<property>
               *  this leaves the property name 
               *  as is...
               */
              sb = new StringBuffer("get");
              sb.append(property);
  
              methodUsed = sb.toString();
  
              method = introspector.getMethod(clazz, methodUsed, params);
               
              if (method != null)
                  return;
          
              /*
               *  now the convenience, flip the 1st character
               */
           
              sb = new StringBuffer("get");
              sb.append(property);
  
              c = sb.charAt(3);
  
              if (Character.isLowerCase(c))
              {
                  sb.setCharAt(3, Character.toUpperCase(c));
              }
              else
              {
                  sb.setCharAt(3, Character.toLowerCase(c));
              }
  
              methodUsed = sb.toString();
              method = introspector.getMethod(clazz, methodUsed, params);
  
              if (method != null)
                  return; 
              
          }
          catch(Exception e)
          {
              rlog.error("PROGRAMMER ERROR : PropertyExector() : " + e );
          }
      }
  
  
      /**
       * Execute method against context.
       */
      public Object execute(Object o)
          throws IllegalAccessException,  InvocationTargetException
      {
          if (method == null)
              return null;
  
          return method.invoke(o, null);
      }
  }
  
  
  
  
  

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