dmitri      02/05/28 17:41:53

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri
                        JXPathContextReferenceImpl.java
  Log:
  Removed run-time dependency on DOM
  
  Revision  Changes    Path
  1.18      +34 -6     
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
  
  Index: JXPathContextReferenceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- JXPathContextReferenceImpl.java   8 May 2002 23:19:31 -0000       1.17
  +++ JXPathContextReferenceImpl.java   29 May 2002 00:41:53 -0000      1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
 1.17 2002/05/08 23:19:31 dmitri Exp $
  - * $Revision: 1.17 $
  - * $Date: 2002/05/08 23:19:31 $
  + * $Header: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
 1.18 2002/05/29 00:41:53 dmitri Exp $
  + * $Revision: 1.18 $
  + * $Date: 2002/05/29 00:41:53 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -77,14 +77,13 @@
   import org.apache.commons.jxpath.ri.model.beans.CollectionPointerFactory;
   import org.apache.commons.jxpath.ri.model.beans.DynamicPointerFactory;
   import org.apache.commons.jxpath.ri.model.container.ContainerPointerFactory;
  -import org.apache.commons.jxpath.ri.model.dom.DOMPointerFactory;
   import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
    * The reference implementation of JXPathContext.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.17 $ $Date: 2002/05/08 23:19:31 $
  + * @version $Revision: 1.18 $ $Date: 2002/05/29 00:41:53 $
    */
   public class JXPathContextReferenceImpl extends JXPathContext
   {
  @@ -100,7 +99,12 @@
           nodeFactories.add(new CollectionPointerFactory());
           nodeFactories.add(new BeanPointerFactory());
           nodeFactories.add(new DynamicPointerFactory());
  -        nodeFactories.add(new DOMPointerFactory());
  +        Object domFactory = allocateConditionally(
  +                "org.apache.commons.jxpath.ri.model.dom.DOMPointerFactory",
  +                "org.w3c.dom.Node");
  +        if (domFactory != null){
  +            nodeFactories.add(domFactory);
  +        }
           nodeFactories.add(new ContainerPointerFactory());
           createNodeFactoryArray();
       }
  @@ -458,5 +462,29 @@
           }
           throw new JXPathException(
               "Undefined function: " + functionName.toString());
  +    }
  +
  +    /**
  +     * Checks if existenceCheckClass exists on the class path. If so,
  +     * allocates an instance of the specified class, otherwise
  +     * returns null.
  +     */
  +    public static Object allocateConditionally(
  +            String className,
  +            String existenceCheckClassName){
  +        try {
  +            try {
  +                Class.forName(existenceCheckClassName);
  +            }
  +            catch (ClassNotFoundException ex){
  +                return null;
  +            }
  +
  +            Class cls = Class.forName(className);
  +            return cls.newInstance();
  +        }
  +        catch (Exception ex){
  +            throw new JXPathException("Cannot allocate " + className, ex);
  +        }
       }
   }
  
  
  

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

Reply via email to