Author: mjakl
Date: Sun Jun 28 19:58:08 2009
New Revision: 789146

URL: http://svn.apache.org/viewvc?rev=789146&view=rev
Log:
Implemented disco#items for LeafNodes. Fixes VYSPER-84.

Added:
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ItemVisitor.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ServiceDiscoItemsVisitor.java
      - copied, changed from r789139, 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java
Modified:
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeVisitor.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PublishSubscribeModule.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberNotificationVisitor.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
    
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
    
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeTestCase.java
    
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoItemsTestCase.java
    
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubPublishTestCase.java

Added: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ItemVisitor.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ItemVisitor.java?rev=789146&view=auto
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ItemVisitor.java
 (added)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ItemVisitor.java
 Sun Jun 28 19:58:08 2009
@@ -0,0 +1,50 @@
+/*
+ *  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.vysper.xmpp.modules.extension.xep0060_pubsub;
+
+import java.util.List;
+
+import org.apache.vysper.compliance.SpecCompliant;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.Item;
+import org.apache.vysper.xmpp.xmlfragment.XMLElement;
+
+/**
+ * The SubscriberVisitor is used to visit all subscriptions of a node.
+ * 
+ * @author The Apache MINA Project (http://mina.apache.org)
+ */
+...@speccompliant(spec="xep-0060", status= 
SpecCompliant.ComplianceStatus.IN_PROGRESS, coverage = 
SpecCompliant.ComplianceCoverage.UNSUPPORTED)
+public interface ItemVisitor {
+
+    /**
+     * visit is part of the "visitor pattern" and should be used to iterate
+     * over all subscriptions of a node.
+     * 
+     * @param itemID the id of the message
+     * @param payload the payload of the message
+     */
+    void visit(String itemID, XMLElement payload);
+    
+    /**
+     * @return the ordered list of items.
+     */
+    public List<Item> getItemList();
+
+}

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java
 Sun Jun 28 19:58:08 2009
@@ -22,31 +22,41 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
+import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.modules.servicediscovery.management.Item;
+import org.apache.vysper.xmpp.xmlfragment.XMLElement;
 
 /**
+ * This visitor is used to collect all items of a node for disco#items 
requests.
+ * 
  * @author The Apache MINA Project (http://mina.apache.org)
  *
  */
-public class NodeDiscoItemsVisitor implements NodeVisitor {
+public class NodeDiscoItemsVisitor implements ItemVisitor {
 
-    private List<Item> itemList = new ArrayList<Item>();
+    // list to hold the items (ordered)
+    List<Item> itemList = new ArrayList<Item>();
+    // The JID of the pubsub service
+    Entity serviceJID;
+    
+    public NodeDiscoItemsVisitor(Entity serviceJID) {
+        this.serviceJID = serviceJID;
+    }
     
     /**
-     * Prepare the node-list for the disco#items response.
+     * Gets called with each itemID and payload of a node. Builds the answer
+     * for disco#items requests to a node.
      * 
-     * @see 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.NodeVisitor#visit(org.apache.vysper.xmpp.addressing.Entity,
 org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode)
+     * @see 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.ItemVisitor#visit(java.lang.String,
 org.apache.vysper.xmpp.xmlfragment.XMLElement)
      */
-    public void visit(LeafNode ln) {
-        this.itemList.add(new Item(ln.getServerJID(), ln.getTitle(), 
ln.getName()));
+    public void visit(String itemID, XMLElement payload) {
+        itemList.add(new Item(serviceJID, itemID, null));
     }
-
+    
     /**
-     * Return a list of items to be embedded in the disco#items response.
-     * To be called after visit!
+     * @return the ordered list of items.
      */
-    public List<Item> getNodeItemList() {
+    public List<Item> getItemList() {
         return itemList;
     }
 

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeVisitor.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeVisitor.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeVisitor.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeVisitor.java
 Sun Jun 28 19:58:08 2009
@@ -41,6 +41,9 @@
      */
     void visit(LeafNode ln);
 
+    /**
+     * @return the ordered list of items.
+     */
     List<Item> getNodeItemList();
 
 }

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PublishSubscribeModule.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PublishSubscribeModule.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PublishSubscribeModule.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PublishSubscribeModule.java
 Sun Jun 28 19:58:08 2009
@@ -160,9 +160,20 @@
      * @see ItemRequestListener#getItemsFor(InfoRequest)
      */
     public List<Item> getItemsFor(InfoRequest request) throws 
ServiceDiscoveryRequestException {
-        NodeVisitor nv = new NodeDiscoItemsVisitor();
-        root.acceptNodes(nv);
-        return nv.getNodeItemList();
+        List<Item> items = null;
+        
+        if(request.getNode() == null || request.getNode().length() == 0) {
+            NodeVisitor nv = new ServiceDiscoItemsVisitor();
+            root.acceptNodes(nv);
+            items = nv.getNodeItemList();
+        } else {
+            LeafNode node = root.find(request.getNode());
+            ItemVisitor iv = new NodeDiscoItemsVisitor(request.getTo());
+            node.acceptItems(iv);
+            items = iv.getItemList();
+        }
+        
+        return items;
     }
 
     /**

Copied: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ServiceDiscoItemsVisitor.java
 (from r789139, 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java)
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ServiceDiscoItemsVisitor.java?p2=mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ServiceDiscoItemsVisitor.java&p1=mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java&r1=789139&r2=789146&rev=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeDiscoItemsVisitor.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ServiceDiscoItemsVisitor.java
 Sun Jun 28 19:58:08 2009
@@ -29,7 +29,7 @@
  * @author The Apache MINA Project (http://mina.apache.org)
  *
  */
-public class NodeDiscoItemsVisitor implements NodeVisitor {
+public class ServiceDiscoItemsVisitor implements NodeVisitor {
 
     private List<Item> itemList = new ArrayList<Item>();
     

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberNotificationVisitor.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberNotificationVisitor.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberNotificationVisitor.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberNotificationVisitor.java
 Sun Jun 28 19:58:08 2009
@@ -47,13 +47,16 @@
     private StanzaRelay stanzaRelay;
     // The payload.
     private XMLElement item;
+    // The server JID
+    private Entity serverJID;
 
     /**
      * Initialize the visitor with the StanzaRelay and payload.
      * @param stanzaRelay relay for sending the messages.
      * @param item payload for the messages.
      */
-    public SubscriberNotificationVisitor(StanzaRelay stanzaRelay, XMLElement 
item) {
+    public SubscriberNotificationVisitor(Entity serverJID, StanzaRelay 
stanzaRelay, XMLElement item) {
+        this.serverJID = serverJID;
         this.stanzaRelay = stanzaRelay;
         this.item = item;
     }
@@ -64,8 +67,8 @@
      * @param nodeJID the node from which the message comes from
      * @param subscriber the receiver of the notification
      */
-    public void visit(Entity nodeJID, Entity subscriber) {
-        Stanza event = createMessageEventStanza(nodeJID, subscriber, "en", 
item); // TODO extract the hardcoded "en"
+    public void visit(String nodeName, Entity subscriber) {
+        Stanza event = createMessageEventStanza(nodeName, subscriber, "en", 
item); // TODO extract the hardcoded "en"
 
         try {
             stanzaRelay.relay(subscriber, event, dfs);
@@ -84,13 +87,17 @@
      * @param item the payload as XMLElement
      * @return the prepared Stanza object.
      */
-    private Stanza createMessageEventStanza(Entity from, Entity to, String 
lang, XMLElement item) {
+    private Stanza createMessageEventStanza(String nodeName, Entity to, String 
lang, XMLElement item) {
         StanzaBuilder stanzaBuilder = new StanzaBuilder("message");
-        stanzaBuilder.addAttribute("from", 
from.getBareJID().getFullQualifiedName());
+        stanzaBuilder.addAttribute("from", serverJID.getFullQualifiedName());
         stanzaBuilder.addAttribute("to", to.getFullQualifiedName());
         stanzaBuilder.addAttribute("xml:lang", lang);
         stanzaBuilder.startInnerElement("event", 
NamespaceURIs.XEP0060_PUBSUB_EVENT);
+        stanzaBuilder.startInnerElement("items");
+        stanzaBuilder.addAttribute("node", nodeName);
         stanzaBuilder.addPreparedElement(item);
+        stanzaBuilder.endInnerElement(); // items
+        stanzaBuilder.endInnerElement(); // event
         return stanzaBuilder.getFinalStanza();
     }
 

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java
 Sun Jun 28 19:58:08 2009
@@ -34,9 +34,9 @@
      * visit is part of the "visitor pattern" and should be used to iterate
      * over all subscriptions of a node.
      * 
-     * @param nodeJID the node JID of the subscription
+     * @param nodeName the name of the node
      * @param sub the subscriber JID
      */
-    void visit(Entity nodeJID, Entity sub);
+    void visit(String nodeName, Entity sub);
 
 }

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
 Sun Jun 28 19:58:08 2009
@@ -25,6 +25,7 @@
 import org.apache.vysper.compliance.SpecCompliant;
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.delivery.StanzaRelay;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.ItemVisitor;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberNotificationVisitor;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.storageprovider.LeafNodeInMemoryStorageProvider;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.storageprovider.LeafNodeStorageProvider;
@@ -79,7 +80,7 @@
      * @param subscriber the subscriber
      */
     public void subscribe(String id, Entity subscriber) {
-        storage.addSubscriber(serverJID, id, subscriber);
+        storage.addSubscriber(name, id, subscriber);
     }
 
     /**
@@ -88,7 +89,7 @@
      * @return true if the JID is already subscribed
      */
     public boolean isSubscribed(Entity subscriber) {
-        return storage.containsSubscriber(serverJID, subscriber);
+        return storage.containsSubscriber(name, subscriber);
     }
 
     /**
@@ -98,7 +99,7 @@
      */
     
     public boolean isSubscribed(String subscriptionID) {
-        return storage.containsSubscriber(serverJID, subscriptionID);
+        return storage.containsSubscriber(name, subscriptionID);
     }
 
     /**
@@ -108,10 +109,10 @@
      * @return true if the subscription has been removed, false otherwise.
      */
     public boolean unsubscribe(String subscriptionID, Entity subscriber) {
-        Entity sub = storage.getSubscriber(serverJID, subscriptionID);
+        Entity sub = storage.getSubscriber(name, subscriptionID);
 
         if(sub != null && sub.equals(subscriber)) {
-            return storage.removeSubscription(serverJID, subscriptionID);
+            return storage.removeSubscription(name, subscriptionID);
         }
         return false;
     }
@@ -128,7 +129,7 @@
         if(countSubscriptions(subscriber) > 1) {
             throw new MultipleSubscriptionException("Ambigous unsubscription 
request");
         }
-        return storage.removeSubscriber(serverJID, subscriber);
+        return storage.removeSubscriber(name, subscriber);
     }
 
     /**
@@ -137,7 +138,7 @@
      * @return number of subscriptions.
      */
     public int countSubscriptions(Entity subscriber) {
-        return storage.countSubscriptions(serverJID, subscriber);
+        return storage.countSubscriptions(name, subscriber);
     }
 
     /**
@@ -145,7 +146,7 @@
      * @return number of subscriptions.
      */
     public int countSubscriptions() {
-        return storage.countSubscriptions(serverJID);
+        return storage.countSubscriptions(name);
     }
 
     /**
@@ -156,7 +157,7 @@
      * @param item the payload of the message.
      */
     public void publish(Entity sender, StanzaRelay relay, String messageID, 
XMLElement item) {
-        storage.addMessage(serverJID, messageID, item);
+        storage.addMessage(name, messageID, item);
         sendMessageToSubscriber(relay, item);
     }
 
@@ -167,7 +168,7 @@
      * @param item the payload of the message.
      */
     protected void sendMessageToSubscriber(StanzaRelay stanzaRelay, XMLElement 
item) {
-        storage.acceptForEachSubscriber(serverJID, new 
SubscriberNotificationVisitor(stanzaRelay, item));
+        storage.acceptForEachSubscriber(name, new 
SubscriberNotificationVisitor(serverJID, stanzaRelay, item));
     }
 
     /**
@@ -203,4 +204,13 @@
         infoElements.add(new Feature(NamespaceURIs.XEP0060_PUBSUB));
         return infoElements;
     }
+
+    /**
+     * Visits each item ever published to this node.
+     * 
+     * @param iv the visitor
+     */
+    public void acceptItems(ItemVisitor iv) {
+        storage.acceptForEachItem(name, iv);
+    }
 }

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
 Sun Jun 28 19:58:08 2009
@@ -23,6 +23,7 @@
 import java.util.TreeMap;
 
 import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.ItemVisitor;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberVisitor;
 import org.apache.vysper.xmpp.xmlfragment.XMLElement;
 
@@ -50,49 +51,49 @@
     /**
      * Add a subscriber with given subID.
      */
-    public void addSubscriber(Entity nodeJID, String subscriptionID, Entity 
subscriber) {
+    public void addSubscriber(String nodeName, String subscriptionID, Entity 
subscriber) {
         subscribers.put(subscriptionID, subscriber);
     }
 
     /**
      * Check if a subscriber is already known.
      */
-    public boolean containsSubscriber(Entity nodeJID, Entity subscriber) {
+    public boolean containsSubscriber(String nodeName, Entity subscriber) {
         return subscribers.containsValue(subscriber);
     }
 
     /**
      * Check if a subscriptionId is already known.
      */
-    public boolean containsSubscriber(Entity nodeJID, String subscriptionId) {
+    public boolean containsSubscriber(String nodeName, String subscriptionId) {
         return subscribers.containsKey(subscriptionId);
     }
 
     /**
      * Retrieve a subscriber via its subsriptionId.
      */
-    public Entity getSubscriber(Entity nodeJID, String subscriptionId) {
+    public Entity getSubscriber(String nodeName, String subscriptionId) {
         return subscribers.get(subscriptionId);
     }
 
     /**
      * Remove a subscriber via its subscriptionId.
      */
-    public boolean removeSubscription(Entity nodeJID, String subscriptionId) {
+    public boolean removeSubscription(String nodeName, String subscriptionId) {
         return subscribers.remove(subscriptionId) != null;
     }
 
     /**
      * Remove a subscriber via its JID. This removes all subscriptions of the 
JID.
      */
-    public boolean removeSubscriber(Entity nodeJID, Entity subscriber) {
+    public boolean removeSubscriber(String nodeName, Entity subscriber) {
         return subscribers.values().remove(subscriber);
     }
 
     /**
      * Count how often a given subscriber is subscribed.
      */
-    public int countSubscriptions(Entity nodeJID, Entity subscriber) {
+    public int countSubscriptions(String nodeName, Entity subscriber) {
         int count = 0;
         for(Entity sub : subscribers.values()) {
             if(subscriber.equals(sub)) {
@@ -105,23 +106,23 @@
     /**
      * Count how many subscriptions this node has.
      */
-    public int countSubscriptions(Entity nodeJID) {
+    public int countSubscriptions(String nodeName) {
         return subscribers.size();
     }
 
     /**
      * Add a message to the storage.
      */
-    public void addMessage(Entity nodeJID, String messageID, XMLElement item) {
+    public void addMessage(String nodeName, String messageID, XMLElement item) 
{
         messages.put(messageID, item);
     }
 
     /**
      * Accept method (see visitor pattern) to visit all subscribers of this 
node.
      */
-    public void acceptForEachSubscriber(Entity nodeJID, SubscriberVisitor 
subscriberVisitor) {
+    public void acceptForEachSubscriber(String nodeName, SubscriberVisitor 
subscriberVisitor) {
         for(Entity sub : subscribers.values()) {
-            subscriberVisitor.visit(nodeJID, sub);
+            subscriberVisitor.visit(nodeName, sub);
         }
     }
 
@@ -131,4 +132,10 @@
     public void initialize() {
         // empty
     }
+
+    public void acceptForEachItem(String nodeName, ItemVisitor iv) {
+        for(String itemID : messages.keySet()) {
+            iv.visit(itemID, messages.get(itemID));
+        }
+    }
 }

Modified: 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
 Sun Jun 28 19:58:08 2009
@@ -22,6 +22,7 @@
 import org.apache.vysper.compliance.SpecCompliant;
 import org.apache.vysper.storage.StorageProvider;
 import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.ItemVisitor;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberVisitor;
 import org.apache.vysper.xmpp.xmlfragment.XMLElement;
 
@@ -36,85 +37,92 @@
 
     /**
      * Add a subscriber to the LeafNode.
-     * @param nodeJID the node JID to which the subscriber should be added.
+     * @param nodeName the node JID to which the subscriber should be added.
      * @param subscriptionID the ID for the subscription (multiple 
subscription ber subscriber).
      * @param subscriber the JID of the subscriber.
      */
-    public void addSubscriber(Entity nodeJID, String subscriptionID, Entity 
subscriber);
+    public void addSubscriber(String nodeName, String subscriptionID, Entity 
subscriber);
 
     /**
-     * Checks if the node specified by nodeJID has a subscriber with the given 
JID.
-     * @param nodeJID the node to check.
+     * Checks if the node specified by nodeName has a subscriber with the 
given JID.
+     * @param nodeName the node to check.
      * @param subscriber the JID of the subscriber.
      * @return true if this JID is subscribed to the node.
      */
-    public boolean containsSubscriber(Entity nodeJID, Entity subscriber);
+    public boolean containsSubscriber(String nodeName, Entity subscriber);
 
     /**
-     * Checks if the node specified by nodeJID has a subscriber with the given 
subscription ID.
-     * @param nodeJID the node to check.
+     * Checks if the node specified by nodeName has a subscriber with the 
given subscription ID.
+     * @param nodeName the node to check.
      * @param subscriptionId the subscription ID to check.
      * @return true if there is a subscription with the given subscription ID.
      */
-    public boolean containsSubscriber(Entity nodeJID, String subscriptionId);
+    public boolean containsSubscriber(String nodeName, String subscriptionId);
 
     /**
      * Fetches the subscriber for a given subscription ID.
-     * @param nodeJID the JID of the node.
+     * @param nodeName the JID of the node.
      * @param subscriptionId the subscription ID we search for.
      * @return the JID of the subscriber with this subscription ID
      */
-    public Entity getSubscriber(Entity nodeJID, String subscriptionId);
+    public Entity getSubscriber(String nodeName, String subscriptionId);
 
     /**
      * Removes a subscription based on the subscription ID.
-     * @param nodeJID the node from which we remove the subscription.
+     * @param nodeName the node from which we remove the subscription.
      * @param subscriptionId the ID of the subscription to remove.
      * @return true if the subscription has been removed, false otherwise.
      */
-    public boolean removeSubscription(Entity nodeJID, String subscriptionId);
+    public boolean removeSubscription(String nodeName, String subscriptionId);
 
     /**
      * Removes a subscription based on the JID of the subscriber.
-     * @param nodeJID the node from which we remove the subscription.
+     * @param nodeName the node from which we remove the subscription.
      * @param subscriber the JID to remove.
      * @return true if the subscription has been removed, false otherwise.
      */
-    public boolean removeSubscriber(Entity nodeJID, Entity subscriber);
+    public boolean removeSubscriber(String nodeName, Entity subscriber);
 
     /**
      * Count how many subscription a given JID has to a node
-     * @param nodeJID the node to check
+     * @param nodeName the node to check
      * @param subscriber the subscriber JID to check
      * @return the number of subscriptions.
      */
-    public int countSubscriptions(Entity nodeJID, Entity subscriber);
+    public int countSubscriptions(String nodeName, Entity subscriber);
 
     /**
      * Count how many subscriptions a given node has.
-     * @param nodeJID the JID of the node to check.
+     * @param nodeName the JID of the node to check.
      * @return the number of subscriptions (should return the number of 
subscription IDs, not subscribed JIDs).
      */
-    public int countSubscriptions(Entity nodeJID);
+    public int countSubscriptions(String nodeName);
 
     /**
      * Store a published message to a node.
-     * @param nodeJID the node to which we want to store the message.
+     * @param nodeName the node to which we want to store the message.
      * @param messageID the message ID for later retrieval.
      * @param item the payload of the message.
      */
-    public void addMessage(Entity nodeJID, String messageID, XMLElement item);
+    public void addMessage(String nodeName, String messageID, XMLElement item);
 
     /**
      * Call the SubscriberVisitor for each subscription of the given node.
-     * @param nodeJID the node we want to iterate.
+     * @param nodeName the node we want to iterate.
      * @param subscriberVisitor the SubscriberVisitor to call
      */
-    public void acceptForEachSubscriber(Entity nodeJID, SubscriberVisitor 
subscriberVisitor);
+    public void acceptForEachSubscriber(String nodeName, SubscriberVisitor 
subscriberVisitor);
 
     /**
      * Call to do some preliminary tasks after the module has been configured.
      */
     public void initialize();
 
+    /**
+     * Visits each item ever published to the node.
+     * 
+     * @param iv the Visidor.
+     */
+    public void acceptForEachItem(String nodeName, ItemVisitor iv);
+
 }

Modified: 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeTestCase.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeTestCase.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeTestCase.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeTestCase.java
 Sun Jun 28 19:58:08 2009
@@ -54,6 +54,7 @@
     protected IQHandler handler = null;
     protected CollectionNode root = null;
     protected Entity serverEntity = null;
+    protected StanzaReceiverRelay relay = null;
     
     // for debugging
     private SystemOutStanzaWriter stanzaWriter = new SystemOutStanzaWriter();
@@ -88,7 +89,7 @@
     protected TestSessionContext createTestSessionContext(Entity serverEntity) 
{
         SessionStateHolder sessionStateHolder = new SessionStateHolder();
         sessionStateHolder.setState(SessionState.AUTHENTICATED);
-        StanzaReceiverRelay relay = new 
org.apache.vysper.xmpp.delivery.StanzaReceiverRelay();
+        relay = new org.apache.vysper.xmpp.delivery.StanzaReceiverRelay();
         DefaultServerRuntimeContext serverContext = new 
DefaultServerRuntimeContext(serverEntity, relay);
         relay.setServerRuntimeContext(serverContext);
         TestSessionContext tsc = new TestSessionContext(serverContext, 
sessionStateHolder);

Modified: 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoItemsTestCase.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoItemsTestCase.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoItemsTestCase.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoItemsTestCase.java
 Sun Jun 28 19:58:08 2009
@@ -6,6 +6,7 @@
 import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.AbstractPublishSubscribeTestCase;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.AbstractStanzaGenerator;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
 import 
org.apache.vysper.xmpp.modules.servicediscovery.handler.DiscoItemIQHandler;
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.protocol.ResponseStanzaContainer;
@@ -13,7 +14,9 @@
 import org.apache.vysper.xmpp.stanza.IQStanzaType;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.xmlfragment.Attribute;
 import org.apache.vysper.xmpp.xmlfragment.XMLElement;
+import org.apache.vysper.xmpp.xmlfragment.XMLFragment;
 
 
 public class PubSubDiscoItemsTestCase extends AbstractPublishSubscribeTestCase 
{
@@ -97,6 +100,85 @@
         assertNotNull(blogs);
     }
     
+    public void testNodeItemsNone() throws Exception {
+        root.createNode(serverEntity, "news", "News");
+        
+        DefaultDiscoInfoStanzaGenerator sg = 
(DefaultDiscoInfoStanzaGenerator)getDefaultStanzaGenerator();
+        Stanza stanza = sg.getStanza(client, pubsubService.getBareJID(), 
"id123", "news");
+
+        ResponseStanzaContainer result = sendStanza(stanza, true);
+        assertTrue(result.hasResponse());
+        IQStanza response = new IQStanza(result.getResponseStanza());
+
+        assertEquals(IQStanzaType.RESULT.value(),response.getType());
+
+        assertEquals("id123", response.getAttributeValue("id")); // IDs must 
match
+        
+        // get the query Element
+        XMLElement query = response.getFirstInnerElement();
+        List<XMLElement> inner = query.getInnerElements();
+
+        assertEquals("query", query.getName());
+        assertEquals("news", query.getAttributeValue("node"));
+        
+        // since we have no messages, there should be no items.
+        assertEquals(0, inner.size());
+    }
+    
+    public void testNodeItemsSome() throws Exception {
+        LeafNode node = root.createNode(serverEntity, "news", "News");
+        
+        XMLElement item1 = new 
XMLElement("item1","namespace1",(Attribute[])null, (XMLFragment[])null);
+        XMLElement item2 = new 
XMLElement("item2","namespace2",(Attribute[])null, (XMLFragment[])null);
+        XMLElement item3 = new 
XMLElement("item3","namespace3",(Attribute[])null, (XMLFragment[])null);
+        node.publish(client, relay, "itemid1", item1);
+        node.publish(client, relay, "itemid2", item2);
+        node.publish(client, relay, "itemid3", item3);
+        
+        
+        DefaultDiscoInfoStanzaGenerator sg = 
(DefaultDiscoInfoStanzaGenerator)getDefaultStanzaGenerator();
+        Stanza stanza = sg.getStanza(client, pubsubService.getBareJID(), 
"id123", "news");
+
+        ResponseStanzaContainer result = sendStanza(stanza, true);
+        assertTrue(result.hasResponse());
+        IQStanza response = new IQStanza(result.getResponseStanza());
+
+        assertEquals(IQStanzaType.RESULT.value(),response.getType());
+
+        assertEquals("id123", response.getAttributeValue("id")); // IDs must 
match
+        
+        // get the query Element
+        XMLElement query = response.getFirstInnerElement();
+        List<XMLElement> inner = query.getInnerElements();
+
+        assertEquals("query", query.getName());
+        assertEquals("news", query.getAttributeValue("node"));
+        
+        // since we have no messages, there should be no items.
+        assertEquals(3, inner.size());
+        
+        boolean bItem1 = false;
+        boolean bItem2 = false;
+        boolean bItem3 = false;
+        
+        for(XMLElement el : inner) {
+            if(el.getName().equals("item") 
+                    && 
el.getAttributeValue("jid").equals(serverEntity.getFullQualifiedName())) {
+                if(el.getAttributeValue("name").equals("itemid1")) {
+                    bItem1 = true;
+                } else if(el.getAttributeValue("name").equals("itemid2")) {
+                    bItem2 = true;
+                } else if(el.getAttributeValue("name").equals("itemid3")) {
+                    bItem3 = true;
+                }
+            }
+        }
+        
+        assertTrue(bItem1);
+        assertTrue(bItem2);
+        assertTrue(bItem3);
+    }
+    
     class DefaultDiscoInfoStanzaGenerator extends AbstractStanzaGenerator {
         @Override
         protected StanzaBuilder buildInnerElement(Entity client, Entity 
pubsub, StanzaBuilder sb, String node) {

Modified: 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubPublishTestCase.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubPublishTestCase.java?rev=789146&r1=789145&r2=789146&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubPublishTestCase.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubPublishTestCase.java
 Sun Jun 28 19:58:08 2009
@@ -21,7 +21,6 @@
 
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.addressing.EntityImpl;
-import org.apache.vysper.xmpp.delivery.StanzaReceiverRelay;
 import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
 import 
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.AbstractPublishSubscribeTestCase;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
@@ -97,9 +96,10 @@
 
         // verify response
         assertTrue(result.hasResponse());
+        
+        // TODO
 
         // verify that each subscriber received the message
-        StanzaReceiverRelay relay = 
(StanzaReceiverRelay)sessionContext.getServerRuntimeContext().getStanzaRelay();
         assertEquals(3, relay.getCountRelayed()); // three subscribers
     }
 


Reply via email to