commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath ClassFunctions.java AbstractFactory.java JXPathContextFactoryConfigurationError.java MapDynamicPropertyHandler.java Pointer.java JXPathContextFactory.java BasicVariables.java PackageFunctions.java JXPathIntrospector.java
Date Wed, 24 Apr 2002 03:29:34 GMT
dmitri      02/04/23 20:29:34

  Modified:    jxpath/src/java/org/apache/commons/jxpath
                        ClassFunctions.java AbstractFactory.java
                        JXPathContextFactoryConfigurationError.java
                        MapDynamicPropertyHandler.java Pointer.java
                        JXPathContextFactory.java BasicVariables.java
                        PackageFunctions.java JXPathIntrospector.java
  Log:
  Improved formatting
  
  Revision  Changes    Path
  1.4       +33 -16    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ClassFunctions.java
  
  Index: ClassFunctions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ClassFunctions.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ClassFunctions.java	21 Apr 2002 21:52:31 -0000	1.3
  +++ ClassFunctions.java	24 Apr 2002 03:29:33 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ClassFunctions.java,v
1.3 2002/04/21 21:52:31 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/21 21:52:31 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ClassFunctions.java,v
1.4 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,10 +61,14 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  -import java.lang.reflect.*;
  -import org.apache.commons.jxpath.functions.*;
  -import org.apache.commons.jxpath.util.*;
  +import java.lang.reflect.Constructor;
  +import java.lang.reflect.Method;
  +import java.util.Collections;
  +import java.util.Set;
  +
  +import org.apache.commons.jxpath.functions.ConstructorFunction;
  +import org.apache.commons.jxpath.functions.MethodFunction;
  +import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
    * Extension functions provided by a Java class.
  @@ -90,7 +94,7 @@
    * the method.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/21 21:52:31 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/24 03:29:33 $
    */
   public class ClassFunctions implements Functions {
       private Class functionClass;
  @@ -102,6 +106,11 @@
           this.namespace = namespace;
       }
   
  +    /**
  +     * Returns a set of one namespace - the one specified in the constructor.
  +     * 
  +     * @returns a singleton
  +     */
       public Set getUsedNamespaces(){
           return Collections.singleton(namespace);
       }
  @@ -109,30 +118,38 @@
       /**
        * Returns a Function, if any, for the specified namespace,
        * name and parameter types.
  +     * 
  +     * @param namespace if it is not the namespace specified in the constructor,
  +     *     the method returns null
  +     * @param name is a function name or "new" for a constructor.
  +     * 
  +     * @return a MethodFunction, a ConstructorFunction or null if there is no
  +     *      such function.
        */
  -    public Function getFunction(String namespace, String name, Object[] parameters){
  -        if (!namespace.equals(this.namespace)){
  +    public Function getFunction(String namespace, String name, Object[] parameters) {
  +        if (!namespace.equals(this.namespace)) {
               return null;
           }
   
  -        if (parameters == null){
  +        if (parameters == null) {
               parameters = EMPTY_ARRAY;
           }
   
  -        if (name.equals("new")){
  -            Constructor constructor = TypeUtils.lookupConstructor(functionClass, parameters);
  -            if (constructor != null){
  +        if (name.equals("new")) {
  +            Constructor constructor =
  +                TypeUtils.lookupConstructor(functionClass, parameters);
  +            if (constructor != null) {
                   return new ConstructorFunction(constructor);
               }
           }
           else {
               Method method = TypeUtils.lookupStaticMethod(functionClass, name, parameters);
  -            if (method != null){
  +            if (method != null) {
                   return new MethodFunction(method);
               }
   
               method = TypeUtils.lookupMethod(functionClass, name, parameters);
  -            if (method != null){
  +            if (method != null) {
                   return new MethodFunction(method);
               }
           }
  
  
  
  1.3       +24 -14    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/AbstractFactory.java
  
  Index: AbstractFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/AbstractFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractFactory.java	21 Apr 2002 21:52:31 -0000	1.2
  +++ AbstractFactory.java	24 Apr 2002 03:29:33 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/AbstractFactory.java,v
1.2 2002/04/21 21:52:31 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/21 21:52:31 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/AbstractFactory.java,v
1.3 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,11 +61,9 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  -
   /**
  - * The {@link JXPathContext#createPath JXPathContext.createPath()} method of JXPathContext
can create
  - * missing objects as it traverses an XPath; it utilizes an AbstractFactory for that purpose.
  + * The {@link JXPathContext#createPath JXPathContext.createPath()} method of JXPathContext
can 
  + * create missing objects as it traverses an XPath; it utilizes an AbstractFactory for
that purpose.
    * Install a factory on JXPathContext by calling {@link JXPathContext#setFactory
    * JXPathContext.setFactory()}.
    * <p>
  @@ -73,7 +71,7 @@
    * return true to indicate that the factory has successfully created the described object.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2002/04/21 21:52:31 $
  + * @version $Revision: 1.3 $ $Date: 2002/04/24 03:29:33 $
    */
   public abstract class AbstractFactory {
   
  @@ -84,18 +82,30 @@
        * the collection. Then it should create the index'th element of the collection
        * and return true.
        * <p>
  -     * If the parameters describe an individual object, the factory should only
  -     * create an object if index == 0.
  -     * <p>
  -     * Return the created object or <b>null</b> if this factory cannot create
  -     * the requested object.
  +     * 
  +     * @param context can be used to evaluate other XPaths, get to variables etc.
  +     * @param pointer describes the location of the node to be created
  +     * @param parent is the object that will server as a parent of the new object
  +     * @param name is the name of the child of the parent that needs to be created. 
  +     *        In the case of DOM may be qualified.
  +     * @param index is used if the pointer represents a collection element. You may
  +     *        need to expand or even create the collection to accomodate the new element.
  +     * 
  +     * @return true if the object was successfully created
        */
  -    public boolean createObject(JXPathContext context, Pointer pointer, Object parent,
String name, int index){
  +    public boolean createObject(JXPathContext context, Pointer pointer, 
  +                                Object parent, String name, int index){
           return false;
       }
   
       /**
        * Create a new object and set it on the specified variable
  +     * 
  +     * @param context hosts variable pools. See {@link JXPathContext#getVariables() 
  +     *        JXPathContext.getVariables()}
  +     * @param name is the name of the variable without the "$" sign
  +     * 
  +     * @return true if the variable was successfully defined
        */
       public boolean declareVariable(JXPathContext context, String name){
           return false;
  
  
  
  1.2       +3 -6      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java
  
  Index: JXPathContextFactoryConfigurationError.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JXPathContextFactoryConfigurationError.java	23 Aug 2001 00:46:58 -0000	1.1
  +++ JXPathContextFactoryConfigurationError.java	24 Apr 2002 03:29:33 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java,v
1.1 2001/08/23 00:46:58 dmitri Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/23 00:46:58 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java,v
1.2 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,8 +61,6 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  -
   /**
    * Thrown when a problem with configuration with the JXPathContextFactories
    * exists. This error will typically be thrown when the class of a
  @@ -70,7 +68,7 @@
    * or instantiated.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.1 $ $Date: 2001/08/23 00:46:58 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/24 03:29:33 $
    */
   
   public class JXPathContextFactoryConfigurationError extends Error {
  @@ -121,7 +119,6 @@
        * @param e The exception to be encapsulated in a
        * JXPathContextFactoryConfigurationError
        * @param msg The detail message.
  -     * @param e The exception to be wrapped in a JXPathContextFactoryConfigurationError
        */
   
       public JXPathContextFactoryConfigurationError(Exception e, String msg) {
  
  
  
  1.2       +8 -7      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java
  
  Index: MapDynamicPropertyHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MapDynamicPropertyHandler.java	11 Sep 2001 23:34:26 -0000	1.1
  +++ MapDynamicPropertyHandler.java	24 Apr 2002 03:29:33 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java,v
1.1 2001/09/11 23:34:26 dmitri Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/09/11 23:34:26 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java,v
1.2 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,13 +61,14 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  +import java.util.Iterator;
  +import java.util.Map;
   
   /**
    * Implements the DynamicPropertyHandler interface for java.util.Map.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.1 $ $Date: 2001/09/11 23:34:26 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/24 03:29:33 $
    */
   public class MapDynamicPropertyHandler implements DynamicPropertyHandler {
   
  @@ -77,7 +78,7 @@
        * Returns string representations of all keys in the map.
        */
       public String[] getPropertyNames(Object object){
  -        Map map = (Map)object;
  +        Map map = (Map) object;
           String names[] = new String[map.size()];
           Iterator it = map.keySet().iterator();
           for (int i = 0; i < names.length; i++){
  @@ -89,8 +90,8 @@
       /**
        * Returns the value for the specified key.
        */
  -    public Object getProperty(Object object, String propertyName){
  -        return ((Map)object).get(propertyName);
  +    public Object getProperty(Object object, String propertyName) {
  +        return ((Map) object).get(propertyName);
       }
   
       /**
  
  
  
  1.2       +3 -5      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/Pointer.java
  
  Index: Pointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/Pointer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Pointer.java	23 Aug 2001 00:46:58 -0000	1.1
  +++ Pointer.java	24 Apr 2002 03:29:33 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/Pointer.java,v
1.1 2001/08/23 00:46:58 dmitri Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/23 00:46:58 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/Pointer.java,v
1.2 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,8 +61,6 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  -
   /**
    * Pointers represent locations of objects and their properties
    * in Java object graphs. JXPathContext has methods
  @@ -77,7 +75,7 @@
    * the map, which is the value of the property "aMap" of the root object.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.1 $ $Date: 2001/08/23 00:46:58 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/24 03:29:33 $
    */
   public interface Pointer {
   
  
  
  
  1.2       +69 -59    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactory.java
  
  Index: JXPathContextFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JXPathContextFactory.java	23 Aug 2001 00:46:58 -0000	1.1
  +++ JXPathContextFactory.java	24 Apr 2002 03:29:33 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactory.java,v
1.1 2001/08/23 00:46:58 dmitri Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/23 00:46:58 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactory.java,v
1.2 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -80,7 +80,7 @@
    * @see JXPathContext#newContext(JXPathContext,Object)
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.1 $ $Date: 2001/08/23 00:46:58 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/24 03:29:33 $
    */
   public abstract class JXPathContextFactory {
   
  @@ -173,106 +173,116 @@
           method is called the second time ( cache the result of
           finding the default impl )
       */
  -    private static String foundFactory=null;
  +    private static String foundFactory = null;
   
       /** Temp debug code - this will be removed after we test everything
        */
  -    private static boolean debug=false;
  +    private static boolean debug = false;
       static {
  -    try {
  -        debug=System.getProperty( "jxpath.debug" ) != null;
  -    } catch(SecurityException se ) {}
  +        try {
  +            debug = System.getProperty("jxpath.debug") != null;
  +        }
  +        catch (SecurityException se) {
  +        }
       }
   
       /** Private implementation method - will find the implementation
           class in the specified order.
           @param property    Property name
  -        @param factoryId   Qualified property name
           @param defaultFactory Default implementation, if nothing else is found
  +        
  +        @return class name of the JXPathContextFactory
       */
  -    private static String findFactory(String property, String defaultFactory)
  -    {
  +    private static String findFactory(String property, String defaultFactory) {
           // Use the system property first
           try {
  -            String systemProp = System.getProperty( property );
  -            if( systemProp!=null) {
  -                if( debug )
  -                    System.err.println("JXPath: found system property" +
  -                                       systemProp );
  +            String systemProp = System.getProperty(property);
  +            if (systemProp != null) {
  +                if (debug){
  +                    System.err.println("JXPath: found system property" + systemProp);
  +                }
                   return systemProp;
               }
   
  -        }catch (SecurityException se) {
  +        }
  +        catch (SecurityException se) {
           }
   
  -        if( foundFactory!=null)
  +        if (foundFactory != null){
               return foundFactory;
  +        }
   
           // Use the factory ID system property first
           try {
  -            String systemProp =
  -                System.getProperty( property );
  -            if( systemProp!=null) {
  -                if( debug )
  -                    System.err.println("JXPath: found system property" +
  -                                       systemProp );
  +            String systemProp = System.getProperty(property);
  +            if (systemProp != null) {
  +                if (debug){
  +                    System.err.println("JXPath: found system property" + systemProp);
  +                }
                   return systemProp;
               }
   
  -        }catch (SecurityException se) {
  +        }
  +        catch (SecurityException se) {
           }
   
           // try to read from $java.home/lib/xml.properties
           try {
  -            String javah=System.getProperty( "java.home" );
  -            String configFile = javah + File.separator +
  -                "lib" + File.separator + "jxpath.properties";
  -            File f=new File( configFile );
  -            if( f.exists()) {
  -                Properties props=new Properties();
  -                props.load( new FileInputStream(f));
  -                foundFactory=props.getProperty( property );
  -                if( debug )
  -                    System.err.println("JXPath: found java.home property " +
  -                                       foundFactory );
  -                if(foundFactory!=null )
  +            String javah = System.getProperty("java.home");
  +            String configFile =
  +                javah + File.separator + "lib" + File.separator + "jxpath.properties";
  +            File f = new File(configFile);
  +            if (f.exists()) {
  +                Properties props = new Properties();
  +                props.load(new FileInputStream(f));
  +                foundFactory = props.getProperty(property);
  +                if (debug){
  +                    System.err.println("JXPath: found java.home property " + foundFactory);
  +                }
  +                if (foundFactory != null){
                       return foundFactory;
  +                }
  +            }
  +        }
  +        catch (Exception ex) {
  +            if (debug){
  +                ex.printStackTrace();
               }
  -        } catch(Exception ex ) {
  -            if( debug ) ex.printStackTrace();
           }
   
           String serviceId = "META-INF/services/" + property;
           // try to find services in CLASSPATH
           try {
  -            ClassLoader cl=JXPathContextFactory.class.getClassLoader();
  -            InputStream is=null;
  -            if( cl == null ) {
  -                is=ClassLoader.getSystemResourceAsStream( serviceId );
  -            } else {
  -                is=cl.getResourceAsStream( serviceId );
  +            ClassLoader cl = JXPathContextFactory.class.getClassLoader();
  +            InputStream is = null;
  +            if (cl == null) {
  +                is = ClassLoader.getSystemResourceAsStream(serviceId);
  +            }
  +            else {
  +                is = cl.getResourceAsStream(serviceId);
               }
   
  -            if( is!=null ) {
  -                if( debug )
  -                    System.err.println("JXPath: found  " +
  -                                       serviceId);
  -                BufferedReader rd=new BufferedReader( new
  -                    InputStreamReader(is));
  +            if (is != null) {
  +                if (debug){
  +                    System.err.println("JXPath: found  " + serviceId);
  +                }
  +                BufferedReader rd = new BufferedReader(new InputStreamReader(is));
   
  -                foundFactory=rd.readLine();
  +                foundFactory = rd.readLine();
                   rd.close();
   
  -                if( debug )
  -                    System.err.println("JXPath: loaded from services: " +
  -                                       foundFactory );
  -                if( foundFactory != null &&
  -                    !  "".equals( foundFactory) ) {
  +                if (debug){
  +                    System.err.println("JXPath: loaded from services: " + foundFactory);
  +                }
  +                if (foundFactory != null && !"".equals(foundFactory)) {
                       return foundFactory;
                   }
               }
  -        } catch( Exception ex ) {
  -            if( debug ) ex.printStackTrace();
  +        }
  +        catch (Exception ex) {
  +            if (debug){
  +                ex.printStackTrace();
  +            }
           }
   
           return defaultFactory;
  
  
  
  1.2       +18 -4     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/BasicVariables.java
  
  Index: BasicVariables.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/BasicVariables.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicVariables.java	23 Aug 2001 00:46:58 -0000	1.1
  +++ BasicVariables.java	24 Apr 2002 03:29:33 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/BasicVariables.java,v
1.1 2001/08/23 00:46:58 dmitri Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/23 00:46:58 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/BasicVariables.java,v
1.2 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,21 +61,28 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  +import java.util.HashMap;
   
   /**
    * A basic implementation of the Variables interface that uses a HashMap.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.1 $ $Date: 2001/08/23 00:46:58 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/24 03:29:33 $
    */
   public class BasicVariables implements Variables {
   
  +    /**
  +     * Contains the values of declared variables
  +     */
       private HashMap vars = new HashMap();
   
       /**
        * Returns true if the variable has been defined, even if the
        * value of the variable is null.
  +     * 
  +     * @param varName is a variable name without the "$" sign
  +     * 
  +     * @return true if the variable is declared
        */
       public boolean isDeclaredVariable(String varName){
           return vars.containsKey(varName);
  @@ -84,6 +91,10 @@
       /**
        * Returns the value of the variable if it is defined,
        * otherwise, throws IllegalArgumentException
  +     * 
  +     * @param varName is a variable name without the "$" sign
  +     * 
  +     * @return the value of the variable
        */
       public Object getVariable(String varName){
           // Note that a variable may be defined with a null value
  @@ -98,6 +109,9 @@
       /**
        * Defines a new variable with the specified value or modifies
        * the value of an existing variable.
  +     * 
  +     * @param varName is a variable name without the "$" sign
  +     * @param value is the new value for the variable, which can be null
        */
       public void declareVariable(String varName, Object value){
           vars.put(varName, value);
  
  
  
  1.4       +52 -28    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java
  
  Index: PackageFunctions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PackageFunctions.java	21 Apr 2002 21:52:31 -0000	1.3
  +++ PackageFunctions.java	24 Apr 2002 03:29:33 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v
1.3 2002/04/21 21:52:31 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/21 21:52:31 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v
1.4 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,10 +61,14 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  -import java.lang.reflect.*;
  -import org.apache.commons.jxpath.functions.*;
  -import org.apache.commons.jxpath.util.*;
  +import java.lang.reflect.Constructor;
  +import java.lang.reflect.Method;
  +import java.util.Collections;
  +import java.util.Set;
  +
  +import org.apache.commons.jxpath.functions.ConstructorFunction;
  +import org.apache.commons.jxpath.functions.MethodFunction;
  +import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
    * Extension functions provided by Java classes.  The class prefix specified
  @@ -104,42 +108,60 @@
   
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/21 21:52:31 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/24 03:29:33 $
    */
   public class PackageFunctions implements Functions {
       private String classPrefix;
       private String namespace;
       private static final Object[] EMPTY_ARRAY = new Object[0];
   
  -    public PackageFunctions(String classPrefix, String namespace){
  +    public PackageFunctions(String classPrefix, String namespace) {
           this.classPrefix = classPrefix;
           this.namespace = namespace;
       }
   
  -    public Set getUsedNamespaces(){
  +    /**
  +     * Returns the namespace specified in the constructor
  +     */
  +    public Set getUsedNamespaces() {
           return Collections.singleton(namespace);
       }
   
       /**
        * Returns a Function, if any, for the specified namespace,
        * name and parameter types.
  +     * <p>
  +     * @param namespace - if it is not the same as specified in the construction,
  +     *      this method returns null
  +     * @param name - name of the method, which can one these forms:
  +     * <ul>
  +     * <li><b>methodname</b>, if invoking a method on an object passed
as the first parameter</li>
  +     * <li><b>Classname.new</b>, if looking for a constructor</li>
  +     * <li><b>subpackage.subpackage.Classname.new</b>, if looking for
a constructor in
  +     *      a subpackage</li>
  +     * <li><b>Classname.methodname</b>, if looking for a static method</li>
  +     * <li><b>subpackage.subpackage.Classname.methodname</b>, if looking
for a 
  +     *      static method of a class in a subpackage</li>
  +     * </ul>
  +     * 
  +     * @return a MethodFunction, a ConstructorFunction or null if no function is found
        */
  -    public Function getFunction(String namespace, String name, Object[] parameters){
  -        if ((namespace == null && this.namespace != null) ||
  -                (namespace != null && !namespace.equals(this.namespace))){
  +    public Function getFunction(String namespace, String name, Object[] parameters) {
  +        if ((namespace == null && this.namespace != null)
  +            || (namespace != null && !namespace.equals(this.namespace))) {
               return null;
           }
   
  -        if (parameters == null){
  +        if (parameters == null) {
               parameters = EMPTY_ARRAY;
           }
   
  -        if (parameters.length >= 1){
  +        if (parameters.length >= 1) {
               Object target = parameters[0];
  -            if (target != null){
  -                if (target instanceof ExpressionContext){
  -                    Pointer pointer = ((ExpressionContext)target).getContextNodePointer();
  -                    if (pointer != null){
  +            if (target != null) {
  +                if (target instanceof ExpressionContext) {
  +                    Pointer pointer = ((ExpressionContext) target).getContextNodePointer();
  +                    if (pointer != null) {
                           target = pointer.getValue();
                       }
                       else {
  @@ -147,9 +169,9 @@
                       }
                   }
               }
  -            if (target != null){
  +            if (target != null) {
                   Method method = TypeUtils.lookupMethod(target.getClass(), name, parameters);
  -                if (method != null){
  +                if (method != null) {
                       return new MethodFunction(method);
                   }
               }
  @@ -157,7 +179,7 @@
   
           String fullName = classPrefix + name;
           int inx = fullName.lastIndexOf('.');
  -        if (inx == -1){
  +        if (inx == -1) {
               return null;
           }
   
  @@ -168,19 +190,21 @@
           try {
               functionClass = Class.forName(className);
           }
  -        catch (ClassNotFoundException ex){
  +        catch (ClassNotFoundException ex) {
               throw new RuntimeException("Class not found: " + ex);
           }
   
  -        if (methodName.endsWith("new")){
  -            Constructor constructor = TypeUtils.lookupConstructor(functionClass, parameters);
  -            if (constructor != null){
  +        if (methodName.endsWith("new")) {
  +            Constructor constructor =
  +                TypeUtils.lookupConstructor(functionClass, parameters);
  +            if (constructor != null) {
                   return new ConstructorFunction(constructor);
               }
           }
           else {
  -            Method method = TypeUtils.lookupStaticMethod(functionClass, methodName, parameters);
  -            if (method != null){
  +            Method method =
  +                TypeUtils.lookupStaticMethod(functionClass, methodName, parameters);
  +            if (method != null) {
                   return new MethodFunction(method);
               }
           }
  
  
  
  1.3       +20 -15    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathIntrospector.java
  
  Index: JXPathIntrospector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathIntrospector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JXPathIntrospector.java	11 Sep 2001 23:34:26 -0000	1.2
  +++ JXPathIntrospector.java	24 Apr 2002 03:29:33 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathIntrospector.java,v
1.2 2001/09/11 23:34:26 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/09/11 23:34:26 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathIntrospector.java,v
1.3 2002/04/24 03:29:33 dmitri Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/24 03:29:33 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,15 +61,17 @@
    */
   package org.apache.commons.jxpath;
   
  -import java.util.*;
  -import org.apache.commons.jxpath.MapDynamicPropertyHandler;
  +import java.util.Date;
  +import java.util.HashMap;
  +import java.util.Properties;
  +import java.util.WeakHashMap;
   
   /**
    * JXPathIntrospector maintains a registry of {@link JXPathBeanInfo JXPathBeanInfo} objects
    * for Java classes.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2001/09/11 23:34:26 $
  + * @version $Revision: 1.3 $ $Date: 2002/04/24 03:29:33 $
    */
   public class JXPathIntrospector {
   
  @@ -132,10 +134,10 @@
        * </ul>
        */
       public static JXPathBeanInfo getBeanInfo(Class beanClass) {
  -        JXPathBeanInfo beanInfo = (JXPathBeanInfo)byClass.get(beanClass);
  -        if (beanInfo == null){
  +        JXPathBeanInfo beanInfo = (JXPathBeanInfo) byClass.get(beanClass);
  +        if (beanInfo == null) {
               beanInfo = findInformant(beanClass);
  -            if (beanInfo == null){
  +            if (beanInfo == null) {
                   beanInfo = new JXPathBasicBeanInfo(beanClass);
               }
               byClass.put(beanClass, beanInfo);
  @@ -146,17 +148,19 @@
       private static synchronized JXPathBeanInfo findInformant(Class beanClass) {
           String name = beanClass.getName() + "XBeanInfo";
           try {
  -            return (JXPathBeanInfo)instantiate(beanClass, name);
  -        } catch (Exception ex) {
  +            return (JXPathBeanInfo) instantiate(beanClass, name);
  +        }
  +        catch (Exception ex) {
               // Just drop through
           }
   
           // Now try checking if the bean is its own JXPathBeanInfo.
           try {
               if (JXPathBeanInfo.class.isAssignableFrom(beanClass)) {
  -                return (JXPathBeanInfo)beanClass.newInstance();
  +                return (JXPathBeanInfo) beanClass.newInstance();
               }
  -        } catch (Exception ex) {
  +        }
  +        catch (Exception ex) {
               // Just drop through
           }
   
  @@ -169,7 +173,7 @@
        * classloader.
        */
       private static Object instantiate(Class sibling, String className)
  -                 throws Exception {
  +        throws Exception {
   
           // First check with sibling's classloader (if any).
           ClassLoader cl = sibling.getClassLoader();
  @@ -177,7 +181,8 @@
               try {
                   Class cls = cl.loadClass(className);
                   return cls.newInstance();
  -            } catch (Exception ex) {
  +            }
  +            catch (Exception ex) {
                   // Just drop through and try the system classloader.
               }
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message