incubator-hise-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r.@apache.org
Subject svn commit: r961316 - in /incubator/hise/trunk/hise-services/src: main/java/org/apache/hise/dao/ main/java/org/apache/hise/engine/ main/java/org/apache/hise/engine/jaxws/ main/java/org/apache/hise/runtime/ main/java/org/apache/hise/utils/ test/java/org...
Date Wed, 07 Jul 2010 09:19:33 GMT
Author: rr
Date: Wed Jul  7 09:19:33 2010
New Revision: 961316

URL: http://svn.apache.org/viewvc?rev=961316&view=rev
Log:
HISE-39: XQuery expressions inside HISE contain a lot of duplication (thanks to Paweł Byszewski)

Modified:
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/Task.java
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/jaxws/TaskOperationsImpl.java
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskEvaluator.java
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/utils/XQueryEvaluator.java
    incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskEvaluatorTest.java

Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/Task.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/Task.java?rev=961316&r1=961315&r2=961316&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/Task.java (original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/Task.java Wed Jul
 7 09:19:33 2010
@@ -305,7 +305,7 @@ public class Task extends JpaBase {
     }
 
     public Long getId() {
-        return id;
+    	return id;
     }
 
     public void setId(Long id) {

Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java?rev=961316&r1=961315&r2=961316&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java
(original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java
Wed Jul  7 09:19:33 2010
@@ -119,7 +119,8 @@ public class HISEEngineImpl implements H
     public static String fetchCreatedBy(Node requestHeader) {
         log.debug("header " + DOMUtils.domToString(requestHeader));
         XQueryEvaluator e = new XQueryEvaluator();
-        List r = e.evaluateExpression("declare namespace htd='http://www.example.org/WS-HT';
xs:string(*/htd:initiator)", requestHeader);
+        e.declareNamespace("htd", "http://www.example.org/WS-HT");
+        List r = e.evaluateExpression(" xs:string(*/htd:initiator)", requestHeader);
         return r.size() == 1 ? (String) r.get(0) : "";
     }
     

Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/jaxws/TaskOperationsImpl.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/jaxws/TaskOperationsImpl.java?rev=961316&r1=961315&r2=961316&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/jaxws/TaskOperationsImpl.java
(original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/jaxws/TaskOperationsImpl.java
Wed Jul  7 09:19:33 2010
@@ -72,7 +72,6 @@ import org.w3c.dom.Node;
  * authorized to perform the operation. Stakeholders of the task are not
  * mentioned explicitly. They have the same authorization rights as business
  * administrators.
- * 
  * @author Witek Wołejszo
  * @author Warren Crossing
  */

Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskEvaluator.java?rev=961316&r1=961315&r2=961316&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskEvaluator.java
(original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/TaskEvaluator.java
Wed Jul  7 09:19:33 2010
@@ -61,8 +61,10 @@ public class TaskEvaluator {
 
     private Task task;
     
+    
     public TaskEvaluator(Task task) {
         this.task = task;
+
     }
 
     public static class HtdFunctions {
@@ -86,6 +88,8 @@ public class TaskEvaluator {
         evaluator.declareJavaClass("http://www.example.org/WS-HT", HtdFunctions.class);
         evaluator.bindVariable(QName.valueOf("taskId"), task.getTaskDto().getId());
         evaluator.bindVariable(QName.valueOf("currentEventDateTime"), task.getCurrentEventDateTime());
+        evaluator.declareNamespace("htd", "http://www.example.org/WS-HT");
+        evaluator.declareNamespace("wsa", "http://www.w3.org/2005/08/addressing");
         return evaluator;
     }
     
@@ -125,7 +129,8 @@ public class TaskEvaluator {
         } else {
             Element e = DOMUtils.findElement(QName.valueOf("{http://www.example.org/WS-HT}literal"),
f.getContent());
             if (e != null) {
-                for (String user : (List<String>) buildQueryEvaluator().evaluateExpression("declare
namespace htd='http://www.example.org/WS-HT'; for $i in htd:literal/htd:organizationalEntity/htd:users/htd:user
return string($i)", e)) {
+            	
+                for (String user : (List<String>) buildQueryEvaluator().evaluateExpression("for
$i in htd:literal/htd:organizationalEntity/htd:users/htd:user return string($i)", e)) {
                     TaskOrgEntity x = new TaskOrgEntity();
                     x.setGenericHumanRole(assignmentRole);
                     x.setName(user);
@@ -133,7 +138,7 @@ public class TaskEvaluator {
                     x.setTask(task.getTaskDto());
                     result.add(x);
                 }
-                for (String group : (List<String>) buildQueryEvaluator().evaluateExpression("declare
namespace htd='http://www.example.org/WS-HT'; for $i in htd:literal/htd:organizationalEntity/htd:groups/htd:group
return string($i)", e)) {
+                for (String group : (List<String>) buildQueryEvaluator().evaluateExpression("
for $i in htd:literal/htd:organizationalEntity/htd:groups/htd:group return string($i)", e))
{
                     TaskOrgEntity x = new TaskOrgEntity();
                     x.setGenericHumanRole(assignmentRole);
                     x.setName(group);
@@ -147,7 +152,7 @@ public class TaskEvaluator {
     }
 
     public Node createEprFromHeader(Node header) {
-        return (Node) buildQueryEvaluator().evaluateExpression("<wsa:EndpointReference
xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">{ */wsa:ReplyTo/* }</wsa:EndpointReference>",
header).get(0);
+        return (Node) buildQueryEvaluator().evaluateExpression("<wsa:EndpointReference
 >{ */wsa:ReplyTo/* }</wsa:EndpointReference>", header).get(0);
     }
     
     // private Set<TaskOrgEntity> evaluatePeopleGroup(String groupName) {
@@ -170,7 +175,7 @@ public class TaskEvaluator {
      */
     public Node evaluateApproveResponseHeader() {
         XQueryEvaluator evaluator = buildQueryEvaluator();
-        return (Node) evaluator.evaluateExpression("<htd:taskId xmlns:htd=\"http://www.example.org/WS-HT\">{$taskId}</htd:taskId>",
null).get(0);
+        return (Node) evaluator.evaluateExpression("<htd:taskId>{$taskId}</htd:taskId>",
null).get(0);
     }
 
     

Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/utils/XQueryEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/utils/XQueryEvaluator.java?rev=961316&r1=961315&r2=961316&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/utils/XQueryEvaluator.java
(original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/utils/XQueryEvaluator.java
Wed Jul  7 09:19:33 2010
@@ -60,10 +60,18 @@ public class XQueryEvaluator {
     private Map<QName, Object> vars = new HashMap<QName, Object>();
     private Configuration config = Configuration.makeConfiguration(null, null);
     private JavaExtensionLibrary jel = new JavaExtensionLibrary(config);
+    private StaticQueryContext sqc;
     
     private Object contextObject;
+   
     
-    public void bindVariable(QName var, Object value) {
+    
+    public XQueryEvaluator() {
+		super();
+		sqc = new StaticQueryContext(config);
+	}
+
+	public void bindVariable(QName var, Object value) {
         vars.put(var, value);
     }
     
@@ -91,6 +99,7 @@ public class XQueryEvaluator {
     }
     
     public List evaluateExpression(String expr, org.w3c.dom.Node contextNode) {
+    	//String expr=new String(xqueryNamespace+_expr);
         try {
             contextObjectTL.set(contextObject);
             {
@@ -99,11 +108,12 @@ public class XQueryEvaluator {
                 config.setExtensionBinder("java", fll);
             }
 
-            StaticQueryContext sqc = new StaticQueryContext(config);
+
             for (QName var : vars.keySet()) {
                 sqc.declareGlobalVariable(StructuredQName.fromClarkName(var.toString()),
SequenceType.SINGLE_ITEM, convertJavaToSaxon(vars.get(var)) , false);
             }
             DynamicQueryContext dqc = new DynamicQueryContext(config);
+      
             XQueryExpression e = sqc.compileQuery(expr);
             
             if (contextNode != null) {
@@ -144,4 +154,9 @@ public class XQueryEvaluator {
             contextObjectTL.set(null);
         }
     }
+    
+    public void declareNamespace(String prefix, String uri){
+    		
+    		sqc.declareNamespace(prefix, uri);
+    }
 }

Modified: incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskEvaluatorTest.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskEvaluatorTest.java?rev=961316&r1=961315&r2=961316&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskEvaluatorTest.java
(original)
+++ incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/TaskEvaluatorTest.java
Wed Jul  7 09:19:33 2010
@@ -39,6 +39,7 @@ public class TaskEvaluatorTest {
     @Test
     public void testEval() throws Exception {
         XQueryEvaluator e = new XQueryEvaluator();
+        e.declareNamespace("htd","http://www.example.org/WS-HT");
         List r = e.evaluateExpression("string(*/*/text())", DOMUtils.parse("<a><b/><c>ddx</c></a>"));
         Assert.assertTrue(r.toString().equals("[ddx]"));
     }
@@ -46,15 +47,17 @@ public class TaskEvaluatorTest {
     @Test
     public void testEval2() throws Exception {
         XQueryEvaluator e = new XQueryEvaluator();
+        e.declareNamespace("htd","http://www.example.org/WS-HT");
         e.bindVariable(QName.valueOf("abc"), null);
-        Object r = e.evaluateExpression("declare namespace htd='http://www.example.org/WS-HT';
for $i in htd:literal/htd:organizationalEntity/htd:users/htd:user return string($i)", DOMUtils.parse(getClass().getResourceAsStream("/taskEvaluator.xml")));
+        Object r = e.evaluateExpression("for $i in htd:literal/htd:organizationalEntity/htd:users/htd:user
return string($i)", DOMUtils.parse(getClass().getResourceAsStream("/taskEvaluator.xml")));
         Assert.assertTrue(r.toString().equals("[user1, user2]"));
     }
 
     @Test
     public void testEval3() throws Exception {
         XQueryEvaluator e = new XQueryEvaluator();
-        Object r = e.evaluateExpression("declare namespace htd='http://www.example.org/WS-HT';
for $i in htd:literal/htd:organizationalEntity/htd:users/htd:user return string($i)", DOMUtils.parse(getClass().getResourceAsStream("/taskEvaluator.xml")).getFirstChild());
+        e.declareNamespace("htd","http://www.example.org/WS-HT");
+        Object r = e.evaluateExpression("for $i in htd:literal/htd:organizationalEntity/htd:users/htd:user
return string($i)", DOMUtils.parse(getClass().getResourceAsStream("/taskEvaluator.xml")).getFirstChild());
         Assert.assertTrue(r.toString().equals("[user1, user2]"));
     }
 
@@ -62,6 +65,7 @@ public class TaskEvaluatorTest {
     public void testEval4() throws Exception {
         XQueryEvaluator e = new XQueryEvaluator();
         e.bindVariable(QName.valueOf("abc"), "val");
+        e.declareNamespace("htd","http://www.example.org/WS-HT");
         Object r = e.evaluateExpression(TaskEvaluator.getTemplateExpr(Collections.singletonList((Object)
"123 {$abc} 345")), null);
         Assert.assertEquals(r.toString(), "[123 val 345]");
     }
@@ -95,7 +99,8 @@ public class TaskEvaluatorTest {
     @Test
     public void testEvalGetInput() throws Exception {
         XQueryEvaluator e = buildTaskEvaluator().buildQueryEvaluator();
-        Object r = e.evaluateExpression("declare namespace htd='http://www.example.org/WS-HT';
xs:string(htd:getInput('request')/b)", null);
+        e.declareNamespace("htd","http://www.example.org/WS-HT");
+        Object r = e.evaluateExpression("xs:string(htd:getInput('request')/b)", null);
         Assert.assertTrue(r.toString().equals("[text1]"));
     }
  



Mime
View raw message