Author: lischke
Date: Tue Jan 18 01:42:18 2005
New Revision: 125474

URL: http://svn.apache.org/viewcvs?view=rev&rev=125474
Log:
added SubscriptStore impls
Added:
   incubator/hermes/trunk/src/java/org/apache/ws/eventing/SubscriberStore.java
   incubator/hermes/trunk/src/java/org/apache/ws/eventing/YFilterStore.java

Added: 
incubator/hermes/trunk/src/java/org/apache/ws/eventing/SubscriberStore.java
Url: 
http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/eventing/SubscriberStore.java?view=auto&rev=125474
==============================================================================
--- (empty file)
+++ incubator/hermes/trunk/src/java/org/apache/ws/eventing/SubscriberStore.java 
Tue Jan 18 01:42:18 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2001-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.eventing;
+
+import org.apache.axis.message.*;
+import javax.xml.soap.*;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+/**
+ *
+ * @author  Stefan Lischke
+ */
+public class SubscriberStore implements org.apache.ws.pubsub.SubscriptionStore 
{
+    private java.util.HashMap subs;
+     
+    /** Creates a new instance of SubscriberStore */
+    public SubscriberStore() {
+        subs=  new java.util.HashMap();    
+    }
+    /**
+     * A handle to the unique Singleton instance.
+     */
+    static private SubscriberStore _instance = null;
+    
+    /**
+     * @return The unique instance of this class.
+     */
+    static public SubscriberStore instance() {
+        if(null == _instance) {
+            _instance = new SubscriberStore();
+        }
+        return _instance;
+    }
+    
+    
+    public String addSubscription(org.apache.ws.pubsub.Subscription ss) {
+        Subscription s = (Subscription)ss;
+        subs.put(s.getID(),s);
+        return(s.getID());
+    }
+    
+    public org.apache.ws.pubsub.Subscription getSubscription(String id) {
+        if(subs.containsKey(id)){
+            Subscription s = (Subscription)subs.get(id);
+            return s;
+        }else
+        return null;//    throw new RuntimeException("Cannot find Subscription 
with id "+id);
+
+    }
+    
+    public void notify(Object message) {
+        org.apache.axis.message.SOAPEnvelope env = 
(org.apache.axis.message.SOAPEnvelope)message;
+        String id;
+        try{
+        javax.xml.soap.SOAPHeader h = env.getHeader();
+        NodeList it = 
h.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2004/08/eventing";, 
"Identifier");
+        if(it.getLength()==0)
+            throw new javax.xml.soap.SOAPException("<wse:Identifier> Tag is 
missing in the Header.... i dunno which Subscription you mean");
+        Node idnode = it.item(0);
+        
if((idnode.getFirstChild()!=null)&&(idnode.getFirstChild().getNodeType()==Node.TEXT_NODE))
+           id = idnode.getFirstChild().getNodeValue();
+        else
+            throw new javax.xml.soap.SOAPException("<wse:Identifier> Tag is 
empty in the Header.... i dunno which Subscription you mean");
+
+        //check ResourceProperties for SubscriptionID
+
+        System.out.println("SubscriberStore notify "+id);
+        org.apache.ws.pubsub.Subscription s = getSubscription(id);
+        if(s!=null)
+            s.getNotificationConsumer().notify(s,message);
+        }catch(javax.xml.soap.SOAPException e){
+            e.printStackTrace();
+        }
+        }
+    
+    public void removeSubscription(String id) {
+        subs.remove(id);
+    }
+    
+}

Added: incubator/hermes/trunk/src/java/org/apache/ws/eventing/YFilterStore.java
Url: 
http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/eventing/YFilterStore.java?view=auto&rev=125474
==============================================================================
--- (empty file)
+++ incubator/hermes/trunk/src/java/org/apache/ws/eventing/YFilterStore.java    
Tue Jan 18 01:42:18 2005
@@ -0,0 +1,126 @@
+/* Generated by Together */

+

+package org.apache.ws.eventing;

+import org.w3c.dom.Element;

+

+import java.util.List;

+

+import org.apache.axis.utils.XMLUtils;

+

+import org.apache.axis.message.addressing.*;

+import org.apache.axis.message.*;

+

+

+import edu.berkeley.cs.db.yfilter.filter.*;

+import edu.berkeley.cs.db.yfilterplus.queryparser.*;

+import edu.berkeley.cs.db.yfilterplus.xmltree.*;

+

+import org.apache.ws.pubsub.*;

+public class YFilterStore implements org.apache.ws.pubsub.SubscriptionStore{

+    

+    public int c=0;

+    

+    private java.util.HashMap subs;

+    private java.util.HashMap queriesBack;

+    private String[] queries;

+    

+    EXfilterBasic yfilter;

+    

+    public YFilterStore(){

+        yfilter = new EXfilterBasic();

+        subs=  new java.util.HashMap();

+        queriesBack=  new java.util.HashMap();

+        queries=  new String[1000000];

+    }

+    /**

+     * A handle to the unique Singleton instance.

+     */

+    static private YFilterStore _instance = null;

+    

+    /**

+     * @return The unique instance of this class.

+     */

+    static public YFilterStore instance() {

+        if(null == _instance) {

+            _instance = new YFilterStore();

+        }

+        return _instance;

+    }

+    

+    public String addSubscription(org.apache.ws.pubsub.Subscription ss){

+        try{

+            c++;

+            if(ss instanceof org.apache.ws.eventing.Subscription){

+                org.apache.ws.eventing.Subscription s = 
(org.apache.ws.eventing.Subscription)ss;

+                Query query = XPQuery.parseQuery(s.getFilterString(),c);

+                String id = "subscriptionID"+c;

+                System.out.println("addSubscription "+id+" query :"+query);

+                yfilter.addQuery(query);

+                s.setID(id);

+                s.setNotificationConsumer(new ForwardConsumer());

+                

+                subs.put(id, s);

+                queriesBack.put(id,query);

+                queries[c]=id;

+                return(id);

+            }else{

+                throw new Exception("only org.wseventing.Subscription are 
supported right now");

+            }

+        }catch(Exception e){

+            e.printStackTrace();

+            return "errorID";

+        }

+    }

+    

+    public org.apache.ws.pubsub.Subscription getSubscription(String id){

+        if(subs.containsKey(id)){

+            Subscription s = (Subscription)subs.get(id);

+            return s;

+        }else

+            throw new RuntimeException("Cannot find Subscription with id "+id);

+    }

+    

+    public void removeSubscription(String id){

+        System.out.println("removeSubscription : "+id);

+        Query q=(Query)queriesBack.get(id);

+        yfilter.deleteQuery(q,q.getQueryId());

+    }

+    

+    public void notify(Object message) {

+        org.apache.axis.message.SOAPEnvelope env = 
(org.apache.axis.message.SOAPEnvelope)message;

+        //first check dialect

+        try{

+            System.out.println("Notify: ");

+            String xml =XMLUtils.ElementToString(env.getBody());

+            System.out.println("--"+xml+"--");

+            //copy

+            

+            //first parse and drive YFilter,

+            XMLTree tree = new XMLTree(new java.io.StringReader(xml));

+            yfilter.setEventSequence(tree.getEvents());

+            yfilter.startParsing();

+            //xfilterTest.startParsing(xmlFile);

+            

+            // print the matched queries //

+            if (SystemGlobals.hasQueries) {

+                yfilter.printQueryResults(System.out);

+            }else{

+                System.out.println("no match");

+            }

+            //get matches

+            java.util.Iterator it= yfilter.getMatchedQueries().iterator();

+            while(it.hasNext()){

+                Integer qid = (Integer) it.next();

+                String sid = queries[qid.intValue()];

+                org.apache.ws.pubsub.Subscription s = getSubscription(sid);

+                //notify matches

+                System.out.println("notify : "+sid);

+                s.getNotificationConsumer().notify(s,message);

+            }

+            yfilter.clear();

+            

+        }catch(Exception e){

+            e.printStackTrace();

+        }

+    }

+}


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

Reply via email to