Commit in servicemix/sandbox/src on MAIN
main/java/org/servicemix/components/router/Action.java+30added 1.1
                                          /Predicate.java+31added 1.1
                                          /RoutingRule.java+74added 1.1
                                          /package.html+10added 1.1
main/java/org/servicemix/components/yfilter/XPathRule.java+28added 1.1
                                           /XPathRuleComponent.java+37added 1.1
test/java/org/servicemix/components/yfilter/YFilterTest.java+98added 1.1
+308
7 added files
added yfilter support to the sandbox area - its still too early for yfilter as its XPath support needs plenty of work

servicemix/sandbox/src/main/java/org/servicemix/components/router
Action.java added at 1.1
diff -N Action.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Action.java	2 Aug 2005 12:37:53 -0000	1.1
@@ -0,0 +1,30 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.servicemix.components.router;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public interface Action {
+
+    public void execute(MessageExchange exchange, NormalizedMessage message) throws MessagingException;
+}

servicemix/sandbox/src/main/java/org/servicemix/components/router
Predicate.java added at 1.1
diff -N Predicate.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Predicate.java	2 Aug 2005 12:37:53 -0000	1.1
@@ -0,0 +1,31 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.servicemix.components.router;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.component.ComponentContext;
+
+/**
+ * A simple predicate which evaluates to true or false given the current
+ * context and message exchange.
+ * 
+ * @version $Revision: 1.1 $
+ */
+public interface Predicate {
+    boolean evaluate(ComponentContext context, MessageExchange exchange);
+}

servicemix/sandbox/src/main/java/org/servicemix/components/router
RoutingRule.java added at 1.1
diff -N RoutingRule.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RoutingRule.java	2 Aug 2005 12:37:53 -0000	1.1
@@ -0,0 +1,74 @@
+/**
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.servicemix.components.router;
+
+import org.servicemix.jbi.resolver.EndpointFilter;
+import org.servicemix.jbi.resolver.EndpointResolver;
+import org.servicemix.jbi.resolver.NullEndpointFilter;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+
+/**
+ * A simple routing rule which if the predicate is matched then the message is forwarded to
+ * the given endpoint.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class RoutingRule {
+    private Predicate predicate;
+    private EndpointResolver resolver;
+    private EndpointFilter filter = NullEndpointFilter.getInstance();
+
+    public EndpointFilter getFilter() {
+        return filter;
+    }
+
+    public void setFilter(EndpointFilter filter) {
+        this.filter = filter;
+    }
+
+    public Predicate getPredicate() {
+        return predicate;
+    }
+
+    public void setPredicate(Predicate predicate) {
+        this.predicate = predicate;
+    }
+
+    public EndpointResolver getResolver() {
+        return resolver;
+    }
+
+    public void setResolver(EndpointResolver resolver) {
+        this.resolver = resolver;
+    }
+
+    public void onMessageExchange(ComponentContext context, MessageExchange exchange) throws JBIException {
+        if (predicate.evaluate(context, exchange)) {
+
+            // lets forward the message on to the endpoint
+            ServiceEndpoint endpoint = resolver.resolveEndpoint(context, exchange, filter);
+            exchange.setEndpoint(endpoint);
+        }
+    }
+
+
+}

servicemix/sandbox/src/main/java/org/servicemix/components/router
package.html added at 1.1
diff -N package.html
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ package.html	2 Aug 2005 12:37:53 -0000	1.1
@@ -0,0 +1,10 @@
+<html>
+<head>
+</head>
+<body>
+
+A simple router component which based on boolean predicates will route normalized messages
+to different endpoints.
+
+</body>
+</html>

servicemix/sandbox/src/main/java/org/servicemix/components/yfilter
XPathRule.java added at 1.1
diff -N XPathRule.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ XPathRule.java	2 Aug 2005 12:37:53 -0000	1.1
@@ -0,0 +1,28 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.servicemix.components.yfilter;
+
+import org.servicemix.components.router.Action;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class XPathRule {
+    private String xpath;
+    private Action action;
+}

servicemix/sandbox/src/main/java/org/servicemix/components/yfilter
XPathRuleComponent.java added at 1.1
diff -N XPathRuleComponent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ XPathRuleComponent.java	2 Aug 2005 12:37:53 -0000	1.1
@@ -0,0 +1,37 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.servicemix.components.yfilter;
+
+import org.servicemix.jbi.binding.OutBinding;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * A component which uses <a href="">YFilter</a> to perform many
+ * XPath or XQuery based rules or predicates on the incoming document
+ * content and fire the actions associated with the rule.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class XPathRuleComponent extends OutBinding {
+
+    protected void process(MessageExchange messageExchange, NormalizedMessage message) throws MessagingException {
+    }
+}

servicemix/sandbox/src/test/java/org/servicemix/components/yfilter
YFilterTest.java added at 1.1
diff -N YFilterTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ YFilterTest.java	2 Aug 2005 12:37:53 -0000	1.1
@@ -0,0 +1,98 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.servicemix.components.yfilter;
+
+import junit.framework.TestCase;
+import edu.berkeley.cs.db.yfilter.filter.EXfilterBasic;
+import edu.berkeley.cs.db.yfilterplus.queryparser.Query;
+import edu.berkeley.cs.db.yfilterplus.queryparser.QueryParser;
+import edu.berkeley.cs.db.yfilterplus.queryparser.XPQueryParser;
+import edu.berkeley.cs.db.yfilterplus.queryparser.xpathparser.XPathParser;
+import edu.berkeley.cs.db.yfilterplus.queryparser.xpathparser.PathQuery;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import java.io.StringReader;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class YFilterTest extends TestCase {
+    protected EXfilterBasic filter = new EXfilterBasic();
+
+    protected String[] queries = { "/[EMAIL PROTECTED] = 'abc']", "/foo[name = 'James']", "/[EMAIL PROTECTED] = 'def']", "/foo[name = 'Rob']"};
+
+    public void testYFilter() throws Exception {
+        Integer[] queryArray = new Integer[queries.length];
+        for (int i = 0; i < queries.length; i++) {
+            String query = queries[i];
+            queryArray[i]  = addQuery(query);
+        }
+        filter.allocateStreams();
+
+        // now lets parse the XML Document
+        parseXml("<foo bar='abc'><name>James</name></foo>");
+
+        // now lets assert the results
+        ArrayList matchedQueries = filter.getMatchedQueries();
+
+        assertEquals("Should match 2 queries: " + matchedQueries, 2, matchedQueries.size());
+
+        assertEquals("First matching query", queryArray[0], matchedQueries.get(0));
+        assertEquals("Second matching query", queryArray[1], matchedQueries.get(1));
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected Integer addQuery(String queryText) throws Exception {
+        Query query = parseQuery(queryText);
+        return new Integer(filter.addQuery(query));
+    }
+
+    protected Query parseQuery(String queryText) throws Exception {
+        XPathParser p = new XPathParser(queryText);
+        p.setDebug(true);
+        java_cup.runtime.Symbol s = p.parse();
+        if (s == null) {
+            throw new Exception("Failed to parse: " + queryText);
+        }
+        PathQuery parsedQuery = (PathQuery)s.value;
+        Query query = XPQueryParser.compile(parsedQuery);
+        return query;
+    }
+
+    protected void parseXml(String xmlText) throws ParserConfigurationException, SAXException, IOException {
+        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+        parserFactory.setNamespaceAware(true);
+        SAXParser parser = parserFactory.newSAXParser();
+        XMLReader xmlReader = parser.getXMLReader();
+        xmlReader.setContentHandler(filter);
+        xmlReader.setDTDHandler(filter);
+        xmlReader.parse(new InputSource(new StringReader(xmlText)));
+    }
+}
CVSspam 0.2.8



Reply via email to