You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by ip...@apache.org on 2005/05/04 20:57:31 UTC
svn commit: r168166 - in /incubator/apollo/trunk/src:
java/org/apache/ws/resource/i18n/
java/org/apache/ws/resource/properties/query/
java/org/apache/ws/resource/properties/query/impl/
java/org/apache/ws/resource/properties/query/xpath/
java/org/apache/ws/resource/properties/query/xpath/impl/
java/org/apache/ws/resource/properties/v2004_06/porttype/impl/
java/org/apache/ws/resource/properties/v2004_11/porttype/impl/
java/org/apache/ws/util/xml/ java/org/apache/ws/util/xml/impl/
test/org/apache/ws/resource/properties/v2004_06/porttype/impl/
Author: ips
Date: Wed May 4 11:57:29 2005
New Revision: 168166
URL: http://svn.apache.org/viewcvs?rev=168166&view=rev
Log:
added support to query expression evaluator interface for querying against an arbitrary context (i.e. a DOM Node or an XmlObject); we will be able to leverage this for WSN subscription selectors which are query expressions that are evaluated against notif messages
Added:
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/JaxenXPathExpressionEvaluator.java
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/DomNamespaceContext.java
Removed:
incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/XmlBeansXPathExpressionEvaluator.java
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.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/QueryExpression.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/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/java/org/apache/ws/util/xml/NamespaceContext.java
incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -519,15 +519,15 @@
*/
String NULL_XPATH = "NULL_XPATH";
/**
- * @msg Evaluating XPathExpression: {0} for ResourcePropertySet: {1}
+ * @msg Evaluating XPath expression [{0}] over context [{1}]
*/
- String EVAL_XPATH_RPSET = "EVAL_XPATH_RPSET";
+ String EVAL_XPATH = "EVAL_XPATH";
/**
* @msg XPath query failed: {0} Cause: {1}
*/
String XPATH_FAILED = "XPATH_FAILED";
/**
- * @msg Namespace context on XPathExpression is null or is not a DOM Node.
+ * @msg Namespace context on XPathExpression is null or is not a DomNamespaceContext.
*/
String BAD_XPATH_NAMESPACE_CONTEXT = "BAD_XPATH_NAMESPACE_CONTEXT";
/**
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -29,34 +29,59 @@
*/
public interface ExpressionEvaluator
{
- /**
- * Gets the list of dialects that this evaluator can handle.
- *
- * @return list of dialects supported by this evaluator.
- */
- public URI[] getSupportedDialects( );
+ /**
+ * Gets the list of dialects that this evaluator can handle.
+ *
+ * @return list of dialects supported by this evaluator.
+ */
+ URI[] getSupportedDialects();
- /**
- * Evaluates the expression over a ResourcePropertySet and returns the result.
- *
- * @param queryExpr object passed by client representing query expression.
- * @param resourcePropertySet ResourcePropertySet associated with resource. The expression is evaluated against this
- * set.
- *
- * @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
- * object returned is null an empty query result is returned.
- *
- * @throws UnknownQueryExpressionDialectException
- * if query dialect is unsupported
- * @throws QueryEvaluationErrorException if query evaluation fails
- * @throws InvalidQueryExpressionException
- * if query expression is invalid
- */
- public Object evaluate( QueryExpression queryExpr,
- ResourcePropertySet resourcePropertySet )
- throws UnknownQueryExpressionDialectException,
- QueryEvaluationErrorException,
- InvalidQueryExpressionException;
+ /**
+ * Evaluates the expression over a ResourcePropertySet and returns the result.
+ *
+ * @param queryExpr the query expression to evaluate
+ * @param resourcePropertySet a WSRF resource property set to be used as the evaluation context
+ *
+ * @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
+ * object returned is null an empty query result is returned.
+ *
+ * @throws UnknownQueryExpressionDialectException
+ * if query dialect is unsupported
+ * @throws QueryEvaluationErrorException if query evaluation fails
+ * @throws InvalidQueryExpressionException
+ * if query expression is invalid
+ */
+ Object evaluate( QueryExpression queryExpr,
+ ResourcePropertySet resourcePropertySet )
+ throws UnknownQueryExpressionDialectException,
+ QueryEvaluationErrorException,
+ InvalidQueryExpressionException;
+
+ /**
+ * Evaluates the expression over the specified context object and returns the result.
+ * Implementations that do not need to evaluate query expressions against contexts
+ * other than resource property sets may choose not to implement this method.
+ *
+ * @param queryExpr the query expression to evaluate
+ * @param evalContext the XPath evaluation context; can be any object that represents
+ * an XML InfoSet item (e.g. a DOM {@link org.w3c.dom.Node}
+ *
+ * @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
+ * object returned is null an empty query result is returned.
+ *
+ * @throws UnknownQueryExpressionDialectException
+ * if query dialect is unsupported
+ * @throws QueryEvaluationErrorException if query evaluation fails
+ * @throws InvalidQueryExpressionException
+ * if query expression is invalid
+ */
+ Object evaluate( QueryExpression queryExpr,
+ Object evalContext )
+ 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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -15,6 +15,8 @@
*=============================================================================*/
package org.apache.ws.resource.properties.query;
+import org.apache.ws.util.xml.NamespaceContext;
+
import java.net.URI;
/**
@@ -39,6 +41,6 @@
* 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();
+ NamespaceContext getNamespaceContext();
}
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -24,7 +24,8 @@
import org.apache.ws.resource.properties.query.QueryExpression;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.ws.util.i18n.Messages;
-import org.apache.ws.util.xml.impl.XmlBeansNamespaceContext;
+import org.apache.ws.util.xml.impl.DomNamespaceContext;
+import org.apache.ws.util.xml.NamespaceContext;
import org.apache.xmlbeans.XmlObject;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
@@ -41,12 +42,12 @@
{
private static final Log LOG = LogFactory.getLog( XmlBeansQueryExpression.class );
- public static final Messages MSG = MessagesImpl.getInstance();
+ private static final Messages MSG = MessagesImpl.getInstance();
private XmlObject m_queryExprXBean;
private URI m_dialect;
private Object m_content;
- private Object m_nsContext;
+ private NamespaceContext m_nsContext;
/**
* Creates a new {@link XmlBeansQueryExpression} object.
@@ -89,7 +90,7 @@
{
m_content = XmlBeanUtils.getValue( m_queryExprXBean );
}
- m_nsContext = new XmlBeansNamespaceContext( m_queryExprXBean );
+ m_nsContext = new DomNamespaceContext( m_queryExprXBean.newDomNode() );
if ( LOG.isDebugEnabled() )
{
LOG.debug( MSG.getMessage( Keys.QUERY_EXPR, toString() ) );
@@ -142,12 +143,12 @@
return m_dialect;
}
- public Object getNamespaceContext()
+ public NamespaceContext getNamespaceContext()
{
return m_nsContext;
}
- public void setNamespaceContext( Object nsContext )
+ public void setNamespaceContext( NamespaceContext nsContext )
{
m_nsContext = nsContext;
}
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -36,7 +36,7 @@
{
private static final Log LOG = LogFactory.getLog( AbstractXPathExpressionEvaluator.class.getName( ) );
- public static final Messages MSG = MessagesImpl.getInstance();
+ private static final Messages MSG = MessagesImpl.getInstance();
/**
* DOCUMENT_ME
@@ -65,6 +65,28 @@
return evaluate( new XPathExpression( queryExpr ), resourcePropertySet );
}
+ /**
+ * DOCUMENT_ME
+ *
+ * @param queryExpr DOCUMENT_ME
+ * @param evalContext DOCUMENT_ME
+ * @return DOCUMENT_ME
+ *
+ * @throws UnknownQueryExpressionDialectException
+ * DOCUMENT_ME
+ * @throws QueryEvaluationErrorException DOCUMENT_ME
+ * @throws InvalidQueryExpressionException
+ * DOCUMENT_ME
+ */
+ public Object evaluate( QueryExpression queryExpr,
+ Object evalContext )
+ throws UnknownQueryExpressionDialectException,
+ QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ return evaluate( new XPathExpression( queryExpr ), evalContext );
+ }
+
/**
* DOCUMENT_ME
*
@@ -84,4 +106,25 @@
throws UnknownQueryExpressionDialectException,
QueryEvaluationErrorException,
InvalidQueryExpressionException;
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param expr DOCUMENT_ME
+ * @param evalContext DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws UnknownQueryExpressionDialectException
+ * DOCUMENT_ME
+ * @throws QueryEvaluationErrorException DOCUMENT_ME
+ * @throws InvalidQueryExpressionException
+ * DOCUMENT_ME
+ */
+ protected abstract Object evaluate( XPathExpression expr,
+ Object evalContext )
+ throws UnknownQueryExpressionDialectException,
+ QueryEvaluationErrorException,
+ InvalidQueryExpressionException;
+
}
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -26,6 +26,7 @@
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.apache.ws.util.xml.NamespaceContext;
/**
* LOG-DONE
@@ -39,7 +40,7 @@
public static final Messages MSG = MessagesImpl.getInstance();
private String m_value;
- private Object m_nsContext;
+ private NamespaceContext m_nsContext;
/**
* Creates a new {@link XPathExpression} object.
@@ -79,7 +80,7 @@
*
* @return DOCUMENT_ME
*/
- public Object getNamespaceContext( )
+ public NamespaceContext getNamespaceContext( )
{
return m_nsContext;
}
Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/JaxenXPathExpressionEvaluator.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/JaxenXPathExpressionEvaluator.java?rev=168166&view=auto
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/JaxenXPathExpressionEvaluator.java (added)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/query/xpath/impl/JaxenXPathExpressionEvaluator.java Wed May 4 11:57:29 2005
@@ -0,0 +1,177 @@
+/*=============================================================================*
+ * Copyright 2004 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.resource.properties.query.xpath.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.resource.i18n.Keys;
+import org.apache.ws.resource.i18n.MessagesImpl;
+import org.apache.ws.resource.properties.ResourcePropertySet;
+import org.apache.ws.resource.properties.query.InvalidQueryExpressionException;
+import org.apache.ws.resource.properties.query.QueryConstants;
+import org.apache.ws.resource.properties.query.QueryEvaluationErrorException;
+import org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
+import org.apache.ws.resource.properties.query.xpath.AbstractXPathExpressionEvaluator;
+import org.apache.ws.resource.properties.query.xpath.XPathExpression;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.xml.NamespaceContext;
+import org.apache.xalan.Version;
+import org.apache.xmlbeans.XmlObject;
+import org.jaxen.JaxenException;
+import org.jaxen.XPath;
+import org.jaxen.dom.DOMXPath;
+import org.w3c.dom.Node;
+
+import java.net.URI;
+
+/**
+ * An XPath expression evaluator that utilizes the opensource Jaxen XPath
+ * evaluation engine.
+ *
+ * LOG-DONE
+ */
+public class JaxenXPathExpressionEvaluator
+ extends AbstractXPathExpressionEvaluator
+{
+ private static final Log LOG = LogFactory.getLog( JaxenXPathExpressionEvaluator.class );
+ private static final Messages MSG = MessagesImpl.getInstance();
+ private static final URI[] SUPPORTED_DIALECTS = new URI[]
+ {
+ QueryConstants.DIALECT_URI__XPATH1_0
+ };
+
+ protected Object evaluate( XPathExpression expr, Object evalContext )
+ throws UnknownQueryExpressionDialectException, QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ Node evalContextNode;
+ if ( evalContext instanceof XmlObject )
+ {
+ evalContextNode = ( (XmlObject) evalContext ).newDomNode();
+ }
+ else if ( evalContext instanceof Node )
+ {
+ evalContextNode = (Node) evalContext;
+ }
+ else
+ {
+ throw new IllegalArgumentException(
+ "This evaluator requires the evaluation context to be either an XMLBeans XmlObject or a DOM Node." );
+ }
+ return evaluate( expr, evalContextNode );
+ }
+
+ /**
+ * Creates a DOM representation of the specified resource property set and
+ * evaluates the specified expression against it.
+ *
+ * @param xpathExpr DOCUMENT_ME
+ * @param resourcePropSet DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException
+ * DOCUMENT_ME
+ * @throws org.apache.ws.resource.properties.query.QueryEvaluationErrorException
+ * DOCUMENT_ME
+ * @throws org.apache.ws.resource.properties.query.InvalidQueryExpressionException
+ * DOCUMENT_ME
+ * @throws IllegalArgumentException DOCUMENT_ME
+ * @throws org.apache.ws.resource.properties.faults.InvalidQueryExpressionFaultException
+ * DOCUMENT_ME
+ * @throws org.apache.ws.resource.properties.faults.QueryEvaluationErrorFaultException
+ * DOCUMENT_ME
+ */
+ protected Object evaluate( XPathExpression xpathExpr,
+ ResourcePropertySet resourcePropSet )
+ throws UnknownQueryExpressionDialectException,
+ QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ // TODO: for better performance, we could use the Jaxen Navigator that
+ // comes with XMLBeans v1 to resolve the expression directly
+ // against the resource property set XmlObject; this is low
+ // priority, since XMLBeans v2 no longer includes a Jaxen
+ // integration (it instead includes Saxon)
+ return evaluate( xpathExpr, resourcePropSet.toElement() );
+ }
+
+ protected Object evaluate( XPathExpression xpathExpr, Node evalContextNode )
+ throws UnknownQueryExpressionDialectException, QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ if ( xpathExpr == null )
+ {
+ throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_XPATH ) );
+ }
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( MSG.getMessage( Keys.EVAL_XPATH, xpathExpr,
+ evalContextNode.getNodeName() ) );
+ }
+ if ( xpathExpr.getNamespaceContext() == null || !( xpathExpr.getNamespaceContext() instanceof Node ) )
+ {
+ throw new QueryEvaluationErrorException( MSG.getMessage( Keys.BAD_XPATH_NAMESPACE_CONTEXT ) );
+ }
+ try
+ {
+ XPath xpath = new DOMXPath( xpathExpr.getValue() );
+ xpath.setNamespaceContext( new JaxenNamespaceContext( xpathExpr.getNamespaceContext() ) );
+ return xpath.evaluate( evalContextNode );
+ }
+ catch ( JaxenException je )
+ {
+ throw new QueryEvaluationErrorException( MSG.getMessage( Keys.XPATH_FAILED, xpathExpr.getValue(),
+ je ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public URI[] getSupportedDialects()
+ {
+ return SUPPORTED_DIALECTS;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String toString()
+ {
+ return ( MSG.getMessage( Keys.XALAN_VERSION, Version.getVersion() + ")" ).intern() );
+ }
+
+ protected class JaxenNamespaceContext implements org.jaxen.NamespaceContext
+ {
+ private NamespaceContext m_nsContext;
+
+ public JaxenNamespaceContext( NamespaceContext domNsContext )
+ {
+ m_nsContext = domNsContext;
+ }
+
+ public String translateNamespacePrefixToUri( String prefix )
+ {
+ return m_nsContext.getPrefix( prefix );
+ }
+ }
+
+}
\ No newline at end of file
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -29,11 +29,12 @@
import org.apache.ws.resource.properties.query.xpath.AbstractXPathExpressionEvaluator;
import org.apache.ws.resource.properties.query.xpath.XPathExpression;
import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.xml.impl.DomNamespaceContext;
import org.apache.xalan.Version;
+import org.apache.xmlbeans.XmlObject;
import org.apache.xpath.XPathAPI;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XObject;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -42,125 +43,153 @@
import java.net.URI;
/**
+ * An XPath expression evaluator that utilizes the Xalan-J {@link XPathAPI}
+ * utility class (note, Xalan-J is included with JDK 1.4 but not with JDK
+ * 1.5).
+ *
* LOG-DONE
- * An XPath expression evaluator that utilizes the Xalan-J {@link 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
+ extends AbstractXPathExpressionEvaluator
{
- private static final Log LOG = LogFactory.getLog( XalanXPathExpressionEvaluator.class );
- private static final Messages MSG = MessagesImpl.getInstance();
- private static final URI[] SUPPORTED_DIALECTS = new URI[]
- {
- QueryConstants.DIALECT_URI__XPATH1_0
- };
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public URI[] getSupportedDialects( )
- {
- return SUPPORTED_DIALECTS;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String toString( )
- {
- return ( MSG.getMessage( Keys.XALAN_VERSION,Version.getVersion( ) + ")" ).intern( ));
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param xpathExpr DOCUMENT_ME
- * @param resourcePropSet DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- *
- * @throws UnknownQueryExpressionDialectException
- * DOCUMENT_ME
- * @throws QueryEvaluationErrorException DOCUMENT_ME
- * @throws InvalidQueryExpressionException
- * DOCUMENT_ME
- * @throws IllegalArgumentException DOCUMENT_ME
- * @throws InvalidQueryExpressionFaultException
- * DOCUMENT_ME
- * @throws QueryEvaluationErrorFaultException
- * DOCUMENT_ME
- */
- protected Object evaluate( XPathExpression xpathExpr,
- ResourcePropertySet resourcePropSet )
- throws UnknownQueryExpressionDialectException,
- QueryEvaluationErrorException,
- InvalidQueryExpressionException
- {
- if ( xpathExpr == null )
- {
- throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_XPATH) );
- }
- if(LOG.isDebugEnabled())
- {
- LOG.debug(MSG.getMessage( Keys.EVAL_XPATH_RPSET, xpathExpr,
- resourcePropSet.getMetaData().getName().toString()));
- }
- Element propsDocElem = resourcePropSet.toElement( );
- if ( xpathExpr.getNamespaceContext( ) == null || ! ( xpathExpr.getNamespaceContext() instanceof Node ) )
- {
- throw new QueryEvaluationErrorException( MSG.getMessage( Keys.BAD_XPATH_NAMESPACE_CONTEXT ) );
- }
- Node nsContextElem = (Node) xpathExpr.getNamespaceContext( );
- XObject xResult;
- try
- {
- xResult = XPathAPI.eval( propsDocElem,
- xpathExpr.getValue( ),
- nsContextElem );
- }
- catch ( Exception e )
- {
- throw new QueryEvaluationErrorException( MSG.getMessage( Keys.XPATH_FAILED, xpathExpr.getValue( ),
- e.getLocalizedMessage( )));
- }
-
- return normalizeResult( xResult );
- }
-
- private Object normalizeResult( XObject xResult )
- {
- Object result;
- if ( xResult instanceof XNodeSet )
- {
- NodeList nodeList = null;
- try
- {
- nodeList = ( (XNodeSet) xResult ).nodelist( );
- }
- catch ( TransformerException te )
- {
- throw new JAXRPCException( te );
- }
-
- Node[] nodes = new Node[nodeList.getLength( )];
- for ( int i = 0; i < nodeList.getLength( ); i++ )
- {
- nodes[i] = nodeList.item( i );
- }
-
- result = nodes;
- }
- else
- {
- result = xResult;
- }
+ private static final Log LOG = LogFactory.getLog( XalanXPathExpressionEvaluator.class );
+ private static final Messages MSG = MessagesImpl.getInstance();
+ private static final URI[] SUPPORTED_DIALECTS = new URI[]
+ {
+ QueryConstants.DIALECT_URI__XPATH1_0
+ };
+
+ protected Object evaluate( XPathExpression expr, Object evalContext )
+ throws UnknownQueryExpressionDialectException, QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ Node evalContextNode;
+ if ( evalContext instanceof XmlObject )
+ {
+ evalContextNode = ( (XmlObject) evalContext ).newDomNode();
+ }
+ else if ( evalContext instanceof Node )
+ {
+ evalContextNode = (Node) evalContext;
+ }
+ else
+ {
+ throw new IllegalArgumentException(
+ "This evaluator requires the evaluation context to be either an XMLBeans XmlObject or a DOM Node." );
+ }
+ return evaluate( expr, evalContextNode );
+ }
+
+ /**
+ * Creates a DOM representation of the specified resource property set
+ * and evaluates the specified expression against it.
+ *
+ * @param xpathExpr DOCUMENT_ME
+ * @param resourcePropSet DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws UnknownQueryExpressionDialectException
+ * DOCUMENT_ME
+ * @throws QueryEvaluationErrorException DOCUMENT_ME
+ * @throws InvalidQueryExpressionException
+ * DOCUMENT_ME
+ * @throws IllegalArgumentException DOCUMENT_ME
+ * @throws InvalidQueryExpressionFaultException
+ * DOCUMENT_ME
+ * @throws QueryEvaluationErrorFaultException
+ * DOCUMENT_ME
+ */
+ protected Object evaluate( XPathExpression xpathExpr,
+ ResourcePropertySet resourcePropSet )
+ throws UnknownQueryExpressionDialectException,
+ QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ return evaluate( xpathExpr, resourcePropSet.toElement() );
+ }
+
+ protected Object evaluate( XPathExpression xpathExpr, Node evalContextNode )
+ throws UnknownQueryExpressionDialectException, QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ if ( xpathExpr == null )
+ {
+ throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_XPATH ) );
+ }
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( MSG.getMessage( Keys.EVAL_XPATH, xpathExpr,
+ evalContextNode.getNodeName() ) );
+ }
+ if ( xpathExpr.getNamespaceContext() == null || !( xpathExpr.getNamespaceContext() instanceof DomNamespaceContext ) )
+ {
+ throw new QueryEvaluationErrorException( MSG.getMessage( Keys.BAD_XPATH_NAMESPACE_CONTEXT ) );
+ }
+ DomNamespaceContext domNsContext = (DomNamespaceContext) xpathExpr.getNamespaceContext();
+ XObject xResult;
+ try
+ {
+ xResult = XPathAPI.eval( evalContextNode,
+ xpathExpr.getValue(),
+ domNsContext.getContextNode() );
+ }
+ catch ( Exception e )
+ {
+ throw new QueryEvaluationErrorException( MSG.getMessage( Keys.XPATH_FAILED, xpathExpr.getValue(),
+ e.getLocalizedMessage() ) );
+ }
+ return normalizeResult( xResult );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public URI[] getSupportedDialects()
+ {
+ return SUPPORTED_DIALECTS;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String toString()
+ {
+ return ( MSG.getMessage( Keys.XALAN_VERSION, Version.getVersion() + ")" ).intern() );
+ }
+
+ private Object normalizeResult( XObject xResult )
+ {
+ Object result;
+ if ( xResult instanceof XNodeSet )
+ {
+ NodeList nodeList = null;
+ try
+ {
+ nodeList = ( (XNodeSet) xResult ).nodelist();
+ }
+ catch ( TransformerException te )
+ {
+ throw new JAXRPCException( te );
+ }
+
+ Node[] nodes = new Node[nodeList.getLength()];
+ for ( int i = 0; i < nodeList.getLength(); i++ )
+ {
+ nodes[i] = nodeList.item( i );
+ }
+
+ result = nodes;
+ }
+ else
+ {
+ result = xResult;
+ }
- return result;
- }
+ return result;
+ }
}
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -41,8 +41,6 @@
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesResponseDocument;
import javax.xml.rpc.JAXRPCException;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
import java.lang.reflect.Array;
/**
@@ -108,17 +106,6 @@
QueryResourcePropertiesResponseDocument responseDoc = createResponseDocument();
QueryExpressionType queryExprType = requestDoc.getQueryResourceProperties().getQueryExpression();
XmlBeansQueryExpression queryExpr = new XmlBeansQueryExpression( queryExprType );
- SOAPEnvelope envelope;
- try
- {
- envelope = getResourceContext().getSOAPMessage().getSOAPPart().getEnvelope();
- }
- catch ( SOAPException soape )
- {
- throw new JAXRPCException( MSG.getMessage( Keys.FAILED_TO_EXTRACT_SOAP_ENV, soape ) );
- }
- queryExpr.setNamespaceContext( envelope );
-
refreshAllProperties();
Object result = null;
try
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 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_11.porttype.QueryResourcePropertiesPortType;
import org.apache.ws.resource.properties.v2004_11.impl.NamespaceVersionHolderImpl;
+import org.apache.ws.resource.properties.v2004_11.porttype.QueryResourcePropertiesPortType;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.ws.util.i18n.Messages;
import org.apache.xmlbeans.XmlObject;
@@ -41,8 +41,6 @@
import org.oasisOpen.docs.wsrf.x2004.x11.wsrfWSResourceProperties12Draft05.QueryResourcePropertiesResponseDocument;
import javax.xml.rpc.JAXRPCException;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
import java.lang.reflect.Array;
/**
@@ -108,17 +106,6 @@
QueryResourcePropertiesResponseDocument responseDoc = createResponseDocument();
QueryExpressionType queryExprType = requestDoc.getQueryResourceProperties().getQueryExpression();
XmlBeansQueryExpression queryExpr = new XmlBeansQueryExpression( queryExprType );
- SOAPEnvelope envelope;
- try
- {
- envelope = getResourceContext().getSOAPMessage().getSOAPPart().getEnvelope();
- }
- catch ( SOAPException soape )
- {
- throw new JAXRPCException( MSG.getMessage( Keys.FAILED_TO_EXTRACT_SOAP_ENV, soape ) );
- }
- queryExpr.setNamespaceContext( envelope );
-
refreshAllProperties();
Object result = null;
try
Modified: 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=168166&r1=168165&r2=168166&view=diff
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/xml/NamespaceContext.java (original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/xml/NamespaceContext.java Wed May 4 11:57:29 2005
@@ -28,7 +28,8 @@
/**
* Get Namespace URI bound to a prefix in the current scope.
*
- * @param prefix
+ * @param prefix the prefix to resolve
+ *
* @return
*/
String getNamespaceURI(String prefix);
Added: incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/DomNamespaceContext.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/DomNamespaceContext.java?rev=168166&view=auto
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/DomNamespaceContext.java (added)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/DomNamespaceContext.java Wed May 4 11:57:29 2005
@@ -0,0 +1,104 @@
+/*=============================================================================*
+ * 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.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A namespace context based on a DOM {@link Node}.
+ */
+public class DomNamespaceContext implements NamespaceContext
+{
+
+ private static final String XMLNS_XML =
+ "http://www.w3.org/XML/1998/namespace";
+
+ private Node m_context;
+
+ public DomNamespaceContext( Node context )
+ {
+ m_context = context;
+ }
+
+ /**
+ * Snarfed from Xalan's <code>org.apache.xml.utils.PrefixResolverDefault</code> class.
+ */
+ public String getNamespaceURI( String prefix )
+ {
+ String namespaceURI = null;
+ if ( prefix.equals( "xml" ) )
+ {
+ namespaceURI = XMLNS_XML;
+ }
+ else
+ {
+ Node parent = m_context;
+ int type;
+ while ( ( null != parent ) && ( null == namespaceURI )
+ && ( ( ( type = parent.getNodeType() ) == Node.ELEMENT_NODE )
+ || ( type == Node.ENTITY_REFERENCE_NODE ) ) )
+ {
+ if ( type == Node.ELEMENT_NODE )
+ {
+ NamedNodeMap attribMap = parent.getAttributes();
+ for ( int i = 0; i < attribMap.getLength(); i++ )
+ {
+ Node attrib = attribMap.item( i );
+ String attribName = attrib.getNodeName();
+ boolean isPrefix = attribName.startsWith( "xmlns:" );
+ if ( isPrefix || attribName.equals( "xmlns" ) )
+ {
+ int index = attribName.indexOf( ':' );
+ String declaredPrefix = isPrefix ? attribName.substring( index + 1 ) : "";
+ if ( declaredPrefix.equals( prefix ) )
+ {
+ namespaceURI = attrib.getNodeValue();
+ break;
+ }
+ }
+ }
+ }
+ parent = parent.getParentNode();
+ }
+ }
+ return namespaceURI;
+ }
+
+ public String getPrefix( String namespaceURI )
+ {
+ // TODO
+ return null;
+ }
+
+ public Iterator getPrefixes( String namespaceURI )
+ {
+ List prefixes = new ArrayList();
+ // TODO
+ return prefixes.iterator();
+ }
+
+ public Node getContextNode()
+ {
+ return m_context;
+ }
+
+}
Modified: 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=168166&r1=168165&r2=168166&view=diff
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java (original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/xml/impl/XmlBeansNamespaceContext.java Wed May 4 11:57:29 2005
@@ -16,33 +16,33 @@
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 org.apache.xmlbeans.XmlObject;
-import java.util.Iterator;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
/**
- * TODO
+ * A namespace context based on an XMLBeans {@link XmlObject}.
*/
public class XmlBeansNamespaceContext implements NamespaceContext
{
- private XmlObject m_xmlObj;
+ private XmlObject m_context;
- public XmlBeansNamespaceContext( XmlObject xmlObj )
+ public XmlBeansNamespaceContext( XmlObject context )
{
- if ( xmlObj == null )
- {
- throw new IllegalArgumentException( "A null parameter is not allowed." );
- }
- m_xmlObj = xmlObj;
+ m_context = context;
}
public String getNamespaceURI( String prefix )
{
- XmlCursor cursor = m_xmlObj.newCursor();
+ if ( m_context == null )
+ {
+ return null;
+ }
+ XmlCursor cursor = m_context.newCursor();
try
{
return cursor.namespaceForPrefix( prefix );
@@ -55,7 +55,11 @@
public String getPrefix( String namespaceURI )
{
- XmlCursor cursor = m_xmlObj.newCursor();
+ if ( m_context == null )
+ {
+ return null;
+ }
+ XmlCursor cursor = m_context.newCursor();
try
{
return cursor.prefixForNamespace( namespaceURI );
@@ -75,6 +79,11 @@
prefixes.add( prefix );
}
return prefixes.iterator();
+ }
+
+ public XmlObject getContextXmlObject()
+ {
+ return m_context;
}
}
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=168166&r1=168165&r2=168166&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 May 4 11:57:29 2005
@@ -152,6 +152,7 @@
QueryExpressionType queryExpressionType = queryResourceProperties.addNewQueryExpression();
queryExpressionType.setDialect( dialect.toString() );
XmlBeanUtils.setValue( queryExpressionType, xPathExpr );
+
QueryResourcePropertiesResponseDocument queryResourcePropertiesResponseDocument = provider.queryResourceProperties( doc );
QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourcePropertiesResponse =
queryResourcePropertiesResponseDocument.getQueryResourcePropertiesResponse();
---------------------------------------------------------------------
To unsubscribe, e-mail: apollo-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: apollo-dev-help@ws.apache.org