Author: ips
Date: Wed Apr 27 13:24:22 2005
New Revision: 165041

URL: http://svn.apache.org/viewcvs?rev=165041&view=rev
Log:
refactored query expressions so that QueryExpression itself contains its 
namespace context

Added:
    incubator/apollo/trunk/src/java/org/apache/ws/util/xml/
    incubator/apollo/trunk/src/java/org/apache/ws/util/xml/NamespaceContext.java
    incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/
    
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java
Modified:
    incubator/apollo/trunk/project.xml
    incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySet.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/ExpressionEvaluator.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryEngine.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryExpression.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/QueryEngineImpl.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/XmlBeansQueryExpression.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/AbstractXPathExpressionEvaluator.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/XPathExpression.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XalanXPathExpressionEvaluator.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XmlBeansXPathExpressionEvaluator.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_11/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
    
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java

Modified: incubator/apollo/trunk/project.xml
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/project.xml?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- incubator/apollo/trunk/project.xml (original)
+++ incubator/apollo/trunk/project.xml Wed Apr 27 13:24:22 2005
@@ -173,13 +173,13 @@
     </dependency>
 
     <dependency>
-      <groupId>commonj</groupId>
-      <artifactId>commonj-twm</artifactId>
-      <version>1.0</version>
+      <groupId>apollo</groupId>
+      <artifactId>commonj-twm-api</artifactId>
+      <version>1.1</version>
       <url>http://dev2dev.bea.com/technologies/commonj/twm/</url>
       <properties>
-        <license>CommonjTwmLicense.txt</license>
-        <usage>Needed for timer apis.</usage>
+        <license>ApacheLicense-2.0.txt</license>
+        <usage>Timer APIs used for scheduled resource termination</usage>
         <war.bundle>true</war.bundle>
       </properties>
     </dependency>

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java 
(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java Wed 
Apr 27 13:24:22 2005
@@ -527,6 +527,10 @@
      */
     String XPATH_FAILED = "XPATH_FAILED";
     /**
+     * @msg Namespace context on XPathExpression is null or is not a DOM Node.
+     */
+    String BAD_XPATH_NAMESPACE_CONTEXT = "BAD_XPATH_NAMESPACE_CONTEXT";
+    /**
      * @msg QueryEngine encountered an error during a refresh. Cause: {0}
      */
     String QUERY_ENG_INIT_ERROR = "QUERY_ENG_INIT_ERROR";

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySet.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySet.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySet.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySet.java
 Wed Apr 27 13:24:22 2005
@@ -30,6 +30,7 @@
 import org.apache.ws.util.i18n.Messages;
 import org.apache.xmlbeans.SchemaProperty;
 import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -282,7 +283,7 @@
      */
     public String toXML()
     {
-        return m_propsDocXBean.toString();
+        return m_propsDocXBean.xmlText( new XmlOptions().setSavePrettyPrint() 
);
     }
 
     /**

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/ExpressionEvaluator.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/ExpressionEvaluator.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/ExpressionEvaluator.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/ExpressionEvaluator.java
 Wed Apr 27 13:24:22 2005
@@ -16,7 +16,6 @@
 package org.apache.ws.resource.properties.query;
 
 import org.apache.ws.resource.properties.ResourcePropertySet;
-import org.w3c.dom.Element;
 
 import java.net.URI;
 
@@ -55,9 +54,8 @@
     * @throws InvalidQueryExpressionException
     *                                       if query expression is invalid
     */
-   public Object evaluate( QueryExpression     queryExpr,
-                           ResourcePropertySet resourcePropertySet,
-                           Element             nsContext )
+   public Object evaluate( QueryExpression queryExpr,
+                           ResourcePropertySet resourcePropertySet )
    throws UnknownQueryExpressionDialectException, 
           QueryEvaluationErrorException, 
           InvalidQueryExpressionException;

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryEngine.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryEngine.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryEngine.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryEngine.java
 Wed Apr 27 13:24:22 2005
@@ -64,8 +64,6 @@
     *
     * @param queryExpr       query expression
     * @param resourcePropSet resource properties set to execute the query 
against
-    * @param nsContext       a DOM element to use as the context for resolving 
namespace prefixes
-    *
     * @return the result of the evaluation which depends on the expression. 
The results must be an xml serializable
     *         object in order to be passed back correctly to a remote client. 
The easiest way of achieving this is to
     *         model it as a Bean, or simply return a <code>SOAPElment</code> 
or <code>DOM Element</code>. If the result
@@ -77,9 +75,8 @@
     * @throws InvalidQueryExpressionException
     *                                       if query expression is invalid
     */
-   Object executeQuery( QueryExpression     queryExpr,
-                        ResourcePropertySet resourcePropSet,
-                        Element             nsContext )
+   Object executeQuery( QueryExpression queryExpr,
+                        ResourcePropertySet resourcePropSet )
    throws UnknownQueryExpressionDialectException, 
           QueryEvaluationErrorException, 
           InvalidQueryExpressionException;

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryExpression.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryExpression.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryExpression.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/QueryExpression.java
 Wed Apr 27 13:24:22 2005
@@ -15,28 +15,30 @@
  
*=============================================================================*/
 package org.apache.ws.resource.properties.query;
 
-import org.w3c.dom.Node;
-
 import java.net.URI;
 
 /**
- * Java representation of the wsrp:QueryExpressionType XML schema type.
+ * Java representation of the wsrf-rp:QueryExpressionType XML schema type.
  *
  * @author Ian P. Springer
  */
 public interface QueryExpression
 {
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   Node getContent(  );
 
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   URI getDialect(  );
+    /**
+     * Returns the dialect of this query expression.
+     */
+    URI getDialect();
+
+    /**
+     * Returns the content of this query expression (typically a String).
+     */
+    Object getContent();
+
+    /**
+     * Returns a namespace context object (e.g. a DOM Element) that can be used
+     * to resolve prefixes within this query expression's content.
+     */
+    Object getNamespaceContext();
+
 }

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/QueryEngineImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/QueryEngineImpl.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/QueryEngineImpl.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/QueryEngineImpl.java
 Wed Apr 27 13:24:22 2005
@@ -29,12 +29,9 @@
 import org.apache.ws.resource.properties.query.QueryEvaluationErrorException;
 import org.apache.ws.resource.properties.query.QueryExpression;
 import 
org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
-import 
org.apache.ws.resource.properties.query.xpath.impl.XmlBeansXPathExpressionEvaluator;
 import 
org.apache.ws.resource.properties.query.xpath.impl.XalanXPathExpressionEvaluator;
-import org.apache.ws.util.JaxpUtils;
 import org.apache.ws.util.i18n.Messages;
 import org.apache.ws.util.jndi.JNDIUtils;
-import org.w3c.dom.Element;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -49,8 +46,8 @@
 
 /**
  * LOG-DONE
- * Executes queries on resource property sets. The engine looks for evaluators 
under "java:comp/env/query/eval"
- * context.
+ * Executes queries on resource property sets. The engine looks for evaluators 
under the
+ * "wsrf/query/eval" JNDI context.
  *
  * @see ResourcePropertySet
  */
@@ -102,8 +99,6 @@
     *
     * @param queryExpr           DOCUMENT_ME
     * @param resourcePropertySet DOCUMENT_ME
-    * @param nsContext           DOCUMENT_ME
-    *
     * @return DOCUMENT_ME
     *
     * @throws UnknownQueryExpressionDialectException
@@ -114,9 +109,8 @@
     * @throws UnknownQueryExpressionDialectFaultException
     *                                       DOCUMENT_ME
     */
-   public Object executeQuery( QueryExpression     queryExpr,
-                               ResourcePropertySet resourcePropertySet,
-                               Element             nsContext )
+   public Object executeQuery( QueryExpression queryExpr,
+                               ResourcePropertySet resourcePropertySet )
    throws UnknownQueryExpressionDialectException, 
           QueryEvaluationErrorException, 
           InvalidQueryExpressionException
@@ -128,32 +122,11 @@
       }
       if(LOG.isDebugEnabled())
       {
-          DebugLogQueryExpression(queryExpr, resourcePropertySet);
+          LOG.debug(MSG.getMessage( Keys.EXEC_QUERY) + ": " + queryExpr +
+                     MSG.getMessage( Keys.ON_RP_SET) + 
resourcePropertySet.getMetaData().getName().toString());
       }
-      return evaluator.evaluate( queryExpr, resourcePropertySet, nsContext );
+      return evaluator.evaluate( queryExpr, resourcePropertySet );
    }
-
-    private void DebugLogQueryExpression(QueryExpression queryExpr, 
ResourcePropertySet resourcePropertySet)
-    {
-        if(queryExpr instanceof XmlBeansQueryExpression)
-        {
-           LOG.debug(MSG.getMessage( Keys.EXEC_QUERY) + ": " + 
((XmlBeansQueryExpression)queryExpr).toString() +
-                     MSG.getMessage( Keys.ON_RP_SET) + 
resourcePropertySet.getMetaData().getName().toString());
-        }
-        else
-        {
-            try
-            {
-                LOG.debug(MSG.getMessage( Keys.EXEC_QUERY)+ ": " + 
JaxpUtils.toString(queryExpr.getContent()) + MSG.getMessage( Keys.FOR_DIALECT) +
-                          queryExpr.getDialect().toString() +
-                          MSG.getMessage( Keys.ON_RP_SET) + 
resourcePropertySet.getMetaData().getName().toString());
-            }
-            catch (Exception e)
-            {
-                LOG.debug(MSG.getMessage( Keys.EXEC_QUERY)+MSG.getMessage( 
Keys.ON_RP_SET) + resourcePropertySet.getMetaData().getName().toString());
-            }
-        }
-    }
 
     /**
     * Reinitializes the evaluators list from JNDI context. If any evaluators 
were added using [EMAIL PROTECTED]

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/XmlBeansQueryExpression.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/XmlBeansQueryExpression.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/XmlBeansQueryExpression.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/impl/XmlBeansQueryExpression.java
 Wed Apr 27 13:24:22 2005
@@ -22,15 +22,11 @@
 import org.apache.ws.resource.i18n.Keys;
 import org.apache.ws.resource.i18n.MessagesImpl;
 import org.apache.ws.resource.properties.query.QueryExpression;
-import org.apache.ws.util.JaxpUtils;
 import org.apache.ws.util.XmlBeanUtils;
 import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.xml.impl.XmlBeansNamespaceContext;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
 import 
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
 
 import javax.xml.rpc.JAXRPCException;
 import java.net.URI;
@@ -43,12 +39,14 @@
 public class XmlBeansQueryExpression
         implements QueryExpression, XmlObjectWrapper
 {
+
     private static final Log LOG = LogFactory.getLog( 
XmlBeansQueryExpression.class );
     public static final Messages MSG = MessagesImpl.getInstance();
 
     private XmlObject m_queryExprXBean;
     private URI m_dialect;
-    private Node m_content;
+    private Object m_content;
+    private Object m_nsContext;
 
     /**
      * Creates a new [EMAIL PROTECTED] XmlBeansQueryExpression} object.
@@ -59,75 +57,68 @@
      */
     public XmlBeansQueryExpression( QueryExpressionType queryExprXBean )
     {
-        m_queryExprXBean = queryExprXBean;
-        try
-        {
-            m_dialect = new URI( queryExprXBean.getDialect() );
-        }
-        catch ( Exception e )
-        {
-            throw new JAXRPCException( MSG.getMessage( 
Keys.FAILED_INIT_DIALECT, e ) );
-        }
+        this( queryExprXBean, getDialect( queryExprXBean ) );
+    }
+
+    /**
+     * Creates a new [EMAIL PROTECTED] XmlBeansQueryExpression} object.
+     *
+     * @param queryExprXBean DOCUMENT_ME
+     *
+     * @throws JAXRPCException          DOCUMENT_ME
+     */
+    public 
XmlBeansQueryExpression(org.oasisOpen.docs.wsrf.x2004.x11.wsrfWSResourceProperties12Draft05.QueryExpressionType
 queryExprXBean)
+    {
+        this( queryExprXBean, getDialect( queryExprXBean ) );
+    }
 
-        XmlObject[] childElems = XmlBeanUtils.getChildElements( queryExprXBean 
);
+    protected XmlBeansQueryExpression( XmlObject xBean, URI dialect )
+    {
+        m_queryExprXBean = xBean;
+        m_dialect = dialect;
+        XmlObject[] childElems = XmlBeanUtils.getChildElements( 
m_queryExprXBean );
         if ( childElems.length > 1 )
         {
             throw new JAXRPCException( MSG.getMessage( 
Keys.QUERY_ONLY_ONE_NODE ) );
         }
-
         if ( childElems.length == 1 )
         {
-            m_content = ( (DocumentFragment) childElems[0].newDomNode() 
).getFirstChild();
+            m_content = childElems[0];
         }
         else
         {
-            Node queryExprNode = ( (DocumentFragment) 
queryExprXBean.newDomNode( new XmlOptions().setSaveOuter() ) ).getFirstChild();
-            m_content = queryExprNode.getFirstChild();
-            if ( ( m_content == null ) || !( m_content instanceof Text ) )
-            {
-                throw new JAXRPCException( MSG.getMessage( 
Keys.QUERY_MUST_HAVE_ELEM_OR_TXT ) );
-            }
+            m_content = XmlBeanUtils.getValue( m_queryExprXBean );
         }
+        m_nsContext = new XmlBeansNamespaceContext( m_queryExprXBean );
         if ( LOG.isDebugEnabled() )
         {
             LOG.debug( MSG.getMessage( Keys.QUERY_EXPR, toString() ) );
         }
     }
 
-    public 
XmlBeansQueryExpression(org.oasisOpen.docs.wsrf.x2004.x11.wsrfWSResourceProperties12Draft05.QueryExpressionType
 queryExprElem)
+    private static URI getDialect(
+            
org.oasisOpen.docs.wsrf.x2004.x11.wsrfWSResourceProperties12Draft05.QueryExpressionType
 queryExprElem )
     {
-        m_queryExprXBean = queryExprElem;
         try
         {
-            m_dialect = new URI( queryExprElem.getDialect() );
+            return new URI( queryExprElem.getDialect() );
         }
         catch ( Exception e )
         {
             throw new JAXRPCException( MSG.getMessage( 
Keys.FAILED_INIT_DIALECT, e ) );
         }
+    }
 
-        XmlObject[] childElems = XmlBeanUtils.getChildElements( queryExprElem 
);
-        if ( childElems.length > 1 )
-        {
-            throw new JAXRPCException( MSG.getMessage( 
Keys.QUERY_ONLY_ONE_NODE ) );
-        }
-
-        if ( childElems.length == 1 )
-        {
-            m_content = ( (DocumentFragment) childElems[0].newDomNode() 
).getFirstChild();
-        }
-        else
+    private static URI getDialect(
+            
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType
 queryExprElem )
+    {
+        try
         {
-            Node queryExprNode = ( (DocumentFragment) 
queryExprElem.newDomNode( new XmlOptions().setSaveOuter() ) ).getFirstChild();
-            m_content = queryExprNode.getFirstChild();
-            if ( ( m_content == null ) || !( m_content instanceof Text ) )
-            {
-                throw new JAXRPCException( MSG.getMessage( 
Keys.QUERY_MUST_HAVE_ELEM_OR_TXT ) );
-            }
+            return new URI( queryExprElem.getDialect() );
         }
-        if ( LOG.isDebugEnabled() )
+        catch ( Exception e )
         {
-            LOG.debug( MSG.getMessage( Keys.QUERY_EXPR, toString() ) );
+            throw new JAXRPCException( MSG.getMessage( 
Keys.FAILED_INIT_DIALECT, e ) );
         }
     }
 
@@ -136,7 +127,7 @@
      *
      * @return DOCUMENT_ME
      */
-    public Node getContent()
+    public Object getContent()
     {
         return m_content;
     }
@@ -151,6 +142,16 @@
         return m_dialect;
     }
 
+    public Object getNamespaceContext()
+    {
+        return m_nsContext;
+    }
+
+    public void setNamespaceContext( Object nsContext )
+    {
+        m_nsContext = nsContext;
+    }
+
     /**
      * DOCUMENT_ME
      *
@@ -158,21 +159,8 @@
      */
     public String toString()
     {
-        String contentString;
-        try
-        {
-            contentString = JaxpUtils.toString( m_content );
-        }
-        catch ( Exception e )
-        {
-            contentString = MSG.getMessage( Keys.NAME ) + "=" + 
m_content.getNodeName() + ", " +
-                    MSG.getMessage( Keys.VALUE ) +
-                    "=" +
-                    m_content.getNodeValue();
-        }
-
         return new ToStringBuilder( this ).append( MSG.getMessage( 
Keys.DIALECT ), m_dialect ).append(
-                MSG.getMessage( Keys.CONTENT ), contentString )
+                MSG.getMessage( Keys.CONTENT ), m_content )
                 .toString();
     }
 
@@ -180,4 +168,5 @@
     {
         return m_queryExprXBean;
     }
+
 }

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/AbstractXPathExpressionEvaluator.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/AbstractXPathExpressionEvaluator.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/AbstractXPathExpressionEvaluator.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/AbstractXPathExpressionEvaluator.java
 Wed Apr 27 13:24:22 2005
@@ -26,7 +26,6 @@
 import org.apache.ws.resource.properties.query.QueryExpression;
 import 
org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
 import org.apache.ws.util.i18n.Messages;
-import org.w3c.dom.Element;
 
 /**
  * LOG-DONE
@@ -38,13 +37,12 @@
 
    private static final Log LOG = LogFactory.getLog( 
AbstractXPathExpressionEvaluator.class.getName(  ) );
    public static final Messages MSG = MessagesImpl.getInstance();
+
    /**
     * DOCUMENT_ME
     *
     * @param queryExpr           DOCUMENT_ME
     * @param resourcePropertySet DOCUMENT_ME
-    * @param nsContext           DOCUMENT_ME
-    *
     * @return DOCUMENT_ME
     *
     * @throws UnknownQueryExpressionDialectException
@@ -53,20 +51,18 @@
     * @throws InvalidQueryExpressionException
     *                                       DOCUMENT_ME
     */
-   public Object evaluate( QueryExpression     queryExpr,
-                           ResourcePropertySet resourcePropertySet,
-                           Element             nsContext )
+   public Object evaluate( QueryExpression queryExpr,
+                           ResourcePropertySet resourcePropertySet )
    throws UnknownQueryExpressionDialectException, 
           QueryEvaluationErrorException, 
           InvalidQueryExpressionException
    {
-      XPathExpression xpathExpr = new XPathExpression( queryExpr, nsContext );
       if ( LOG.isDebugEnabled(  ) )
       {
-         LOG.debug( MSG.getMessage( Keys.XPATH, xpathExpr.getValue(  ) ));
+         LOG.debug( MSG.getMessage( Keys.XPATH, queryExpr.getContent() ));
          LOG.debug( MSG.getMessage( Keys.PROP_DOC,resourcePropertySet.toXML() 
));
-      }
-      return evaluate( xpathExpr, resourcePropertySet );
+      }      
+      return evaluate( new XPathExpression( queryExpr ), resourcePropertySet );
    }
 
    /**

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/XPathExpression.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/XPathExpression.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/XPathExpression.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/XPathExpression.java
 Wed Apr 27 13:24:22 2005
@@ -25,13 +25,11 @@
 import org.apache.ws.resource.properties.query.QueryConstants;
 import org.apache.ws.resource.properties.query.QueryExpression;
 import 
org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
-import org.apache.ws.util.JaxpUtils;
 import org.apache.ws.util.i18n.Messages;
-import org.w3c.dom.Element;
 
 /**
  * LOG-DONE
- * An XPath expression.
+ * An XPath expression
  *
  * @author Ian P. Springer
  */
@@ -39,20 +37,19 @@
 {
    private static final Log LOG = LogFactory.getLog( XPathExpression.class );
    public static final Messages MSG = MessagesImpl.getInstance();
+
    private String  m_value;
-   private Element m_nsContext;
+   private Object m_nsContext;
 
    /**
     * Creates a new [EMAIL PROTECTED] XPathExpression} object.
     *
     * @param queryExpr DOCUMENT_ME
-    * @param nsContext DOCUMENT_ME
     *
     * @throws UnknownQueryExpressionDialectFaultException
     *          DOCUMENT_ME
     */
-   public XPathExpression( QueryExpression queryExpr,
-                           Element         nsContext )
+   public XPathExpression( QueryExpression queryExpr )
    throws InvalidQueryExpressionException, 
           UnknownQueryExpressionDialectException
    {
@@ -60,17 +57,16 @@
       {
          throw new UnknownQueryExpressionDialectException( 
queryExpr.getDialect(  ) );
       }
-      m_value = queryExpr.getContent(  ).getNodeValue(  );
-      if ( m_value == null )
+      if ( queryExpr.getContent(  ) == null || ! ( queryExpr.getContent(  ) 
instanceof String ) )
       {
          throw new InvalidQueryExpressionException( queryExpr );
       }
-      m_value = m_value.trim();
+      m_value = ((String) queryExpr.getContent()).trim();
       if ( m_value.length() == 0 )
       {
          throw new InvalidQueryExpressionException( queryExpr );
       }
-      m_nsContext = nsContext;
+      m_nsContext = queryExpr.getNamespaceContext();
 
       if(LOG.isDebugEnabled())
       {
@@ -83,7 +79,7 @@
     *
     * @return DOCUMENT_ME
     */
-   public Element getNamespaceContext(  )
+   public Object getNamespaceContext(  )
    {
       return m_nsContext;
    }
@@ -105,17 +101,7 @@
     */
    public String toString(  )
    {
-      String nsContextString;
-      try
-      {
-         nsContextString = m_nsContext.toString();
-      }
-      catch ( Exception e )
-      {
-         nsContextString = MSG.getMessage( Keys.NAME)+"=" + 
m_nsContext.getNodeName(  ) + ", "+ MSG.getMessage( Keys.VALUE)+"=" + 
m_nsContext.getNodeValue(  );
-      }
-
-      return new ToStringBuilder( this ).append( MSG.getMessage( Keys.VALUE), 
m_value ).append( MSG.getMessage( Keys.NMSPCECTX), nsContextString )
+      return new ToStringBuilder( this ).append( MSG.getMessage( Keys.VALUE), 
m_value )
                                         .toString(  );
    }
 }

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XalanXPathExpressionEvaluator.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XalanXPathExpressionEvaluator.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XalanXPathExpressionEvaluator.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XalanXPathExpressionEvaluator.java
 Wed Apr 27 13:24:22 2005
@@ -43,14 +43,15 @@
 
 /**
  * LOG-DONE
- * Evaluator supporting XPath queries using Xalan-J XPathAPI. The 
implementation creates resource property document on
- * the fly and runs the query against it.
+ * An XPath expression evaluator that utilizes the Xalan-J [EMAIL PROTECTED] 
XPathAPI} utility class.
+ * The implementation of evaluate() creates a DOM representation of resource 
property set
+ * on the fly and runs the specified query against it.
  */
 public class XalanXPathExpressionEvaluator
    extends AbstractXPathExpressionEvaluator
 {
    private static final Log LOG = LogFactory.getLog( 
XalanXPathExpressionEvaluator.class );
-   public static final Messages MSG = MessagesImpl.getInstance();
+   private static final Messages MSG = MessagesImpl.getInstance();
    private static final URI[] SUPPORTED_DIALECTS = new URI[]
                                                    {
                                                       
QueryConstants.DIALECT_URI__XPATH1_0
@@ -111,12 +112,11 @@
                     resourcePropSet.getMetaData().getName().toString()));
       }
       Element propsDocElem = resourcePropSet.toElement(  );
-      Element nsContextElem = xpathExpr.getNamespaceContext(  );
-      if ( nsContextElem == null )
+      if ( xpathExpr.getNamespaceContext(  ) == null || ! ( 
xpathExpr.getNamespaceContext() instanceof Node ) )
       {
-         nsContextElem = propsDocElem;
+          throw new QueryEvaluationErrorException( MSG.getMessage( 
Keys.BAD_XPATH_NAMESPACE_CONTEXT ) );
       }
-
+      Node nsContextElem = (Node) xpathExpr.getNamespaceContext(  );
       XObject xResult;
       try
       {

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XmlBeansXPathExpressionEvaluator.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XmlBeansXPathExpressionEvaluator.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XmlBeansXPathExpressionEvaluator.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XmlBeansXPathExpressionEvaluator.java
 Wed Apr 27 13:24:22 2005
@@ -37,7 +37,8 @@
 import java.net.URI;
 
 /**
- * XPath expression evaluator that leverages the XMLBeans [EMAIL PROTECTED] 
XmlObject#selectPath(String)} API.
+ * XPath expression evaluator that leverages the XMLBeans
+ * [EMAIL PROTECTED] XmlObject#selectPath(String)} API.
  *
  * @author Ian P. Springer
  */
@@ -45,7 +46,7 @@
    extends AbstractXPathExpressionEvaluator
 {
    private static final Log LOG = LogFactory.getLog( 
XmlBeansXPathExpressionEvaluator.class );
-   public static final Messages MSG = MessagesImpl.getInstance();
+   private static final Messages MSG = MessagesImpl.getInstance();
    private static final URI[] SUPPORTED_DIALECTS = new URI[]
                                                    {
                                                       
QueryConstants.DIALECT_URI__XPATH1_0
@@ -123,7 +124,6 @@
       // NOTE: the expression's namespace context is currently not used by 
this evaluator,
       //       since XMLBeans v1 does not support specifying a namespace 
context when calling
       //       selectPath()
-
       try
       {
          return propsDocXBean.selectPath( xpathExpr.getValue(  ) );

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesPortTypeImpl.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
 Wed Apr 27 13:24:22 2005
@@ -31,8 +31,8 @@
 import 
org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
 import org.apache.ws.resource.properties.query.impl.QueryEngineImpl;
 import org.apache.ws.resource.properties.query.impl.XmlBeansQueryExpression;
-import 
org.apache.ws.resource.properties.v2004_06.porttype.QueryResourcePropertiesPortType;
 import 
org.apache.ws.resource.properties.v2004_06.impl.NamespaceVersionHolderImpl;
+import 
org.apache.ws.resource.properties.v2004_06.porttype.QueryResourcePropertiesPortType;
 import org.apache.ws.util.XmlBeanUtils;
 import org.apache.ws.util.i18n.Messages;
 import org.apache.xmlbeans.XmlObject;
@@ -106,8 +106,8 @@
         }
 
         QueryResourcePropertiesResponseDocument responseDoc = 
createResponseDocument();
-        QueryExpressionType queryExprElem =
-                requestDoc.getQueryResourceProperties().getQueryExpression();
+        QueryExpressionType queryExprType = 
requestDoc.getQueryResourceProperties().getQueryExpression();
+        XmlBeansQueryExpression queryExpr = new XmlBeansQueryExpression( 
queryExprType );
         SOAPEnvelope envelope;
         try
         {
@@ -117,16 +117,14 @@
         {
             throw new JAXRPCException( MSG.getMessage( 
Keys.FAILED_TO_EXTRACT_SOAP_ENV, soape ) );
         }
-
-        XmlBeansQueryExpression queryExpr = new XmlBeansQueryExpression( 
queryExprElem );
+        queryExpr.setNamespaceContext( envelope );
 
         refreshAllProperties();
         Object result = null;
         try
         {
             result = QUERY_ENGINE.executeQuery( queryExpr,
-                    getProperties(),
-                    envelope );
+                    getProperties() );
         }
         catch ( UnknownQueryExpressionDialectException uqede )
         {

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_11/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_11/porttype/impl/QueryResourcePropertiesPortTypeImpl.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_11/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v2004_11/porttype/impl/QueryResourcePropertiesPortTypeImpl.java
 Wed Apr 27 13:24:22 2005
@@ -106,8 +106,8 @@
         }
 
         QueryResourcePropertiesResponseDocument responseDoc = 
createResponseDocument();
-        QueryExpressionType queryExprElem =
-                requestDoc.getQueryResourceProperties().getQueryExpression();
+        QueryExpressionType queryExprType = 
requestDoc.getQueryResourceProperties().getQueryExpression();
+        XmlBeansQueryExpression queryExpr = new XmlBeansQueryExpression( 
queryExprType );
         SOAPEnvelope envelope;
         try
         {
@@ -117,16 +117,14 @@
         {
             throw new JAXRPCException( MSG.getMessage( 
Keys.FAILED_TO_EXTRACT_SOAP_ENV, soape ) );
         }
-
-        XmlBeansQueryExpression queryExpr = new XmlBeansQueryExpression( 
queryExprElem );
+        queryExpr.setNamespaceContext( envelope );
 
         refreshAllProperties();
         Object result = null;
         try
         {
             result = QUERY_ENGINE.executeQuery( queryExpr,
-                    getProperties(),
-                    envelope );
+                    getProperties() );
         }
         catch ( UnknownQueryExpressionDialectException uqede )
         {

Added: 
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/NamespaceContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/xml/NamespaceContext.java?rev=165041&view=auto
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/NamespaceContext.java 
(added)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/NamespaceContext.java 
Wed Apr 27 13:24:22 2005
@@ -0,0 +1,52 @@
+/*=============================================================================*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ 
*=============================================================================*/
+package org.apache.ws.util.xml;
+
+import java.util.Iterator;
+
+/**
+ * Interface for read only XML Namespace context processing.
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
+ */
+public interface NamespaceContext
+{
+
+    /**
+     * Get Namespace URI bound to a prefix in the current scope.
+     *
+     * @param prefix
+     * @return
+     */
+    String getNamespaceURI(String prefix);
+
+    /**
+     * Get prefix bound to Namespace URI in the current scope.
+     *
+     * @param namespaceURI
+     * @return
+     */
+    String getPrefix(String namespaceURI);
+
+    /**
+     * Get all prefixes bound to a Namespace URI in the current scope.
+     *
+     * @param namespaceURI
+     * @return
+     */
+    Iterator getPrefixes(String namespaceURI);
+
+}

Added: 
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java?rev=165041&view=auto
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java
 (added)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java
 Wed Apr 27 13:24:22 2005
@@ -0,0 +1,80 @@
+/*=============================================================================*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ 
*=============================================================================*/
+package org.apache.ws.util.xml.impl;
+
+import org.apache.ws.util.xml.NamespaceContext;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlCursor;
+
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * TODO
+ */
+public class XmlBeansNamespaceContext implements NamespaceContext
+{
+
+    private XmlObject m_xmlObj;
+
+    public XmlBeansNamespaceContext( XmlObject xmlObj )
+    {
+        if ( xmlObj == null )
+        {
+            throw new IllegalArgumentException( "A null parameter is not 
allowed." );
+        }
+        m_xmlObj = xmlObj;
+    }
+
+    public String getNamespaceURI( String prefix )
+    {
+        XmlCursor cursor = m_xmlObj.newCursor();
+        try
+        {
+            return cursor.namespaceForPrefix( prefix );
+        }
+        finally
+        {
+            cursor.dispose();
+        }
+    }
+
+    public String getPrefix( String namespaceURI )
+    {
+        XmlCursor cursor = m_xmlObj.newCursor();
+        try
+        {
+            return cursor.prefixForNamespace( namespaceURI );
+        }
+        finally
+        {
+            cursor.dispose();
+        }
+    }
+
+    public Iterator getPrefixes( String namespaceURI )
+    {
+        List prefixes = new ArrayList();
+        String prefix = getPrefix( namespaceURI );
+        if ( prefix != null )
+        {
+           prefixes.add( prefix );
+        }
+        return prefixes.iterator();
+    }
+
+}

Modified: 
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java?rev=165041&r1=165040&r2=165041&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java
 (original)
+++ 
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java
 Wed Apr 27 13:24:22 2005
@@ -37,6 +37,7 @@
 
 /**
  * Test case for [EMAIL PROTECTED] QueryResourcePropertiesPortTypeImpl}.
+ * TODO: add some tests with query expressions that contain prefixes
  *
  * @author Sal Campana, Ian Springer
  */



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

Reply via email to