servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r526251 - in /incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools: ./ model/ support/
Date Fri, 06 Apr 2007 18:57:40 GMT
Author: gnodet
Date: Fri Apr  6 11:57:39 2007
New Revision: 526251

URL: http://svn.apache.org/viewvc?view=rev&rev=526251
Log:
SM-924: Namespace support in servicemix-drools

Added:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java
  (with props)
Modified:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java?view=diff&rev=526251&r1=526250&r2=526251
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/DroolsEndpoint.java
Fri Apr  6 11:57:39 2007
@@ -25,6 +25,7 @@
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 
 import org.apache.servicemix.common.DefaultComponent;
@@ -46,7 +47,8 @@
     private RuleBase ruleBase;
     private Resource ruleBaseResource;
     private URL ruleBaseURL;
-    
+    private NamespaceContext namespaceContext;
+
     public DroolsEndpoint() {
         super();
     }
@@ -100,7 +102,21 @@
     public void setRuleBaseURL(URL ruleBaseURL) {
         this.ruleBaseURL = ruleBaseURL;
     }
-    
+
+    /**
+     * @return the namespaceContext
+     */
+    public NamespaceContext getNamespaceContext() {
+        return namespaceContext;
+    }
+
+    /**
+     * @param namespaceContext the namespaceContext to set
+     */
+    public void setNamespaceContext(NamespaceContext namespaceContext) {
+        this.namespaceContext = namespaceContext;
+    }
+
     public void validate() throws DeploymentException {
         super.validate();
         if (ruleBase == null && ruleBaseResource == null && ruleBaseURL ==
null) {

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java?view=diff&rev=526251&r1=526250&r2=526251
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Exchange.java
Fri Apr  6 11:57:39 2007
@@ -23,6 +23,7 @@
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.messaging.RobustInOnly;
+import javax.xml.namespace.NamespaceContext;
 
 public class Exchange {
 
@@ -39,9 +40,11 @@
     private Message in;
     private Message out;
     private Message fault;
+    private NamespaceContext namespaceContext;
     
-    public Exchange(MessageExchange exchange) {
+    public Exchange(MessageExchange exchange, NamespaceContext namespaceContext) {
         this.exchange = exchange;
+        this.namespaceContext = namespaceContext;
         update();
     }
     
@@ -101,22 +104,23 @@
     
     protected Message getMessage(String name) {
         NormalizedMessage msg = exchange.getMessage(name);
-        return msg != null ? new Message(msg) : null;
+        return msg != null ? new Message(msg, this.namespaceContext) : null;
     }
     
     protected void update() {
         if (in == null) {
             NormalizedMessage msg = exchange.getMessage("in");
-            in = msg != null ? new Message(msg) : null;
+            in = msg != null ? new Message(msg, this.namespaceContext) : null;
         }
         if (out == null) {
             NormalizedMessage msg = exchange.getMessage("out");
-            out = msg != null ? new Message(msg) : null;
+            out = msg != null ? new Message(msg, this.namespaceContext) : null;
         }
         if (fault == null) {
             javax.jbi.messaging.Fault msg = exchange.getFault();
-            fault = msg != null ? new Fault(msg) : null;
+            fault = msg != null ? new Fault(msg,this.namespaceContext) : null;
         }
     }
     
 }
+

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java?view=diff&rev=526251&r1=526250&r2=526251
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Fault.java
Fri Apr  6 11:57:39 2007
@@ -16,10 +16,12 @@
  */
 package org.apache.servicemix.drools.model;
 
+import javax.xml.namespace.NamespaceContext;
+
 public class Fault extends Message {
 
-    public Fault(javax.jbi.messaging.Fault message) {
-        super(message);
+    public Fault(javax.jbi.messaging.Fault message, NamespaceContext namespaceContext) {
+        super(message, namespaceContext);
     }
 
 }

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java?view=diff&rev=526251&r1=526250&r2=526251
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/JbiHelper.java
Fri Apr  6 11:57:39 2007
@@ -52,7 +52,7 @@
                      MessageExchange exchange,
                      WorkingMemory memory) {
         this.endpoint = endpoint;
-        this.exchange = new Exchange(exchange);
+        this.exchange = new Exchange(exchange, endpoint.getNamespaceContext());
         this.memory = memory;
         this.exchangeFactHandle = this.memory.assertObject(this.exchange);
     }

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java?view=diff&rev=526251&r1=526250&r2=526251
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/model/Message.java
Fri Apr  6 11:57:39 2007
@@ -17,10 +17,12 @@
 package org.apache.servicemix.drools.model;
 
 import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 
 import org.apache.servicemix.expression.JAXPBooleanXPathExpression;
+import org.apache.servicemix.expression.JAXPStringXPathExpression;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.w3c.dom.Element;
 
@@ -29,10 +31,12 @@
     private final static SourceTransformer TRANFORMER = new SourceTransformer();
     
     private final NormalizedMessage message;
+    private final NamespaceContext namespaceContext;
     
-    public Message(NormalizedMessage message) {
+    public Message(NormalizedMessage message, NamespaceContext namespaceContext) {
         this.message = message;
         // Make sure message is re-readable
+        this.namespaceContext = namespaceContext;
         Source content = message.getContent();
         if (content != null) {
             try {
@@ -51,9 +55,22 @@
     
     public boolean xpath(String xpath) throws Exception {
         JAXPBooleanXPathExpression expression = new JAXPBooleanXPathExpression(xpath);
+        if (this.namespaceContext != null) {
+            expression.setNamespaceContext(this.namespaceContext);
+        }
         Boolean b = (Boolean) expression.evaluate(null, message);
         return b.booleanValue();
     }
+    
+    public String valueOf(String xpath) throws Exception {
+        JAXPStringXPathExpression expression = new JAXPStringXPathExpression(xpath);
+        if (this.namespaceContext != null) {
+        	expression.setNamespaceContext(this.namespaceContext);
+        }
+        String res = (String)expression.evaluate(null, message);
+        return res;
+    }
+    
     
     public Object getProperty(String name) {
         return message.getProperty(name);

Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java?view=auto&rev=526251
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java
(added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java
Fri Apr  6 11:57:39 2007
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.servicemix.drools.support;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * A simple namespace context with a clean xbean configuration.
+ *
+ * @org.apache.xbean.XBean element="namespace-context"
+ *                         description="A NamespaceContext implementation"
+ * @author gnodet
+ * @version $Revision$
+ */
+public class NamespaceContextImpl implements NamespaceContext {
+
+    /**
+     * map containing bound namespaces, keyed by their prefix. A LinkedHashMap
+     * is used to ensure that {@link #getPrefix(String)} always returns the same
+     * prefix, unless that prefix is removed.
+     */
+    private Map namespaces = new LinkedHashMap();
+    
+    /**
+     * Constructs a SimpleNamespaceContext with no parent context or namespace
+     * declarations.
+     */
+    public NamespaceContextImpl() {
+    }
+    
+    /**
+     * Constructs a SimpleNamespaceContext with no parent context that contains
+     * the specified prefixes.
+     * 
+     * @param namespaces A Map of namespace URIs, keyed by their prefixes.
+     */
+    public NamespaceContextImpl(Map namespaces) {
+        setNamespaces(namespaces);
+    }
+    
+    /**
+     * @org.apache.xbean.Map entryName="namespace" keyName="prefix"
+     * @return Returns the namespaces.
+     */
+    public Map getNamespaces() {
+        return namespaces;
+    }
+
+    /**
+     * @param namespaces The namespaces to set.
+     */
+    public void setNamespaces(Map namespaces) {
+        this.namespaces.clear();
+        if (namespaces != null) {
+            this.namespaces.putAll(namespaces);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(java.lang.String)
+     */
+    public String getNamespaceURI(String prefix) {
+        if (prefix == null) {
+            throw new IllegalArgumentException("prefix argument was null");
+        } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
+            return XMLConstants.XML_NS_URI;
+        } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+            return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+        } else if (namespaces.containsKey(prefix)) {
+            String uri = (String) namespaces.get(prefix);
+            if (uri.length() == 0) {
+                return null;
+            } else {
+                return uri;
+            }
+        } else {
+            return null;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.namespace.NamespaceContext#getPrefix(java.lang.String)
+     */
+    public String getPrefix(String nsURI) {
+        if (nsURI == null) {
+            throw new IllegalArgumentException("nsURI was null");
+        } else if (nsURI.length() == 0) {
+            throw new IllegalArgumentException("nsURI was empty");
+        } else if (nsURI.equals(XMLConstants.XML_NS_URI)) {
+            return XMLConstants.XML_NS_PREFIX;
+        } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+            return XMLConstants.XMLNS_ATTRIBUTE;
+        }
+        Iterator iter = namespaces.entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry entry = (Map.Entry) iter.next();
+            String uri = (String) entry.getValue();
+            if (uri.equals(nsURI)) {
+                return (String) entry.getKey();
+            }
+        }
+        if (nsURI.length() == 0) {
+            return "";
+        } else {
+            return null;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String)
+     */
+    public Iterator getPrefixes(String nsURI) {
+        if (nsURI == null) {
+            throw new IllegalArgumentException("nsURI was null");
+        } else if (nsURI.length() == 0) {
+            throw new IllegalArgumentException("nsURI was empty");
+        } else if (nsURI.equals(XMLConstants.XML_NS_URI)) {
+            return Collections.singleton(XMLConstants.XML_NS_PREFIX).iterator();
+        } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+            return Collections.singleton(XMLConstants.XMLNS_ATTRIBUTE).iterator();
+        }
+        Set prefixes = null;
+        Iterator iter = namespaces.entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry entry = (Map.Entry) iter.next();
+            String uri = (String) entry.getValue();
+            if (uri.equals(nsURI)) {
+                if (prefixes == null) {
+                    prefixes = new HashSet();
+                }
+                prefixes.add(entry.getKey());
+            }
+        }
+        if (prefixes != null) {
+            return Collections.unmodifiableSet(prefixes).iterator();
+        } else if (nsURI.length() == 0) {
+            return Collections.singleton("").iterator();
+        } else {
+            return Collections.EMPTY_LIST.iterator();
+        }
+    }
+    
+}
+

Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-drools/src/main/java/org/apache/servicemix/drools/support/NamespaceContextImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message