labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r713443 - in /labs/vysper/src/main/java/org/apache/vysper/xmpp: modules/roster/ modules/servicediscovery/ modules/servicediscovery/collection/ modules/servicediscovery/handler/ modules/servicediscovery/management/ protocol/
Date Wed, 12 Nov 2008 18:05:05 GMT
Author: berndf
Date: Wed Nov 12 10:05:04 2008
New Revision: 713443

URL: http://svn.apache.org/viewvc?rev=713443&view=rev
Log:
[vysper] facilitate creation of NamespaceHandlerDictionary extensions & improved LABS-228
(service disco).

Removed:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/ItemRequest.java
Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterDictionary.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryDictionary.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceCollector.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Feature.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Identity.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoElement.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoRequest.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/ItemRequestListener.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterDictionary.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterDictionary.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterDictionary.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterDictionary.java
Wed Nov 12 10:05:04 2008
@@ -27,8 +27,6 @@
 public class RosterDictionary extends NamespaceHandlerDictionary {
 
     public RosterDictionary() {
-        super(NamespaceURIs.JABBER_IQ_ROSTER);
-        register(new RosterIQHandler());
-        seal();
+        super(NamespaceURIs.JABBER_IQ_ROSTER, new RosterIQHandler());
     }
 }
\ No newline at end of file

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryDictionary.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryDictionary.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryDictionary.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryDictionary.java
Wed Nov 12 10:05:04 2008
@@ -27,8 +27,6 @@
 public class ServiceDiscoveryDictionary extends NamespaceHandlerDictionary {
 
     public ServiceDiscoveryDictionary() {
-        super(NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO);
-        register(new DiscoInfoIQHandler());
-        seal();
+        super(NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO, new DiscoInfoIQHandler());
     }
 }
\ No newline at end of file

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceCollector.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceCollector.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceCollector.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceCollector.java
Wed Nov 12 10:05:04 2008
@@ -17,12 +17,10 @@
 package org.apache.vysper.xmpp.modules.servicediscovery.collection;
 
 import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
-import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoRequestListener;
-import org.apache.vysper.xmpp.modules.servicediscovery.management.ItemRequestListener;
-import org.apache.vysper.xmpp.modules.servicediscovery.management.ServerInfoRequestListener;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.*;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 /**
  * on an item or info requests, calls all related listeners and collects what they have to
add to the
@@ -30,6 +28,8 @@
  */
 public class ServiceCollector implements ServerRuntimeContextService, ServiceDiscoveryRequestListenerRegistry
{
 
+    private static final Feature DEFAULT_FEATURE = new Feature(NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO);
+
     protected List<InfoRequestListener> infoRequestListeners = new ArrayList<InfoRequestListener>();
     protected List<ServerInfoRequestListener> serverInfoRequestListeners = new ArrayList<ServerInfoRequestListener>();
     protected List<ItemRequestListener> itemRequestListeners = new ArrayList<ItemRequestListener>();
@@ -46,7 +46,68 @@
         itemRequestListeners.add(itemRequestListener);
     }
 
+    /**
+     * collect all server feature and identity info from the listeners
+     */
+    public Set<InfoElement> processServerInfoRequest(InfoRequest infoRequest) {
+        // sorted structure, to place all <feature/> after <identity/> 
+        Set<InfoElement> elements = new TreeSet<InfoElement>(new ElementPartitioningComparator());
+        elements.add(DEFAULT_FEATURE);
+        for (ServerInfoRequestListener serverInfoRequestListener : serverInfoRequestListeners)
{
+            List<InfoElement> elementList = null;
+            try {
+                elementList = serverInfoRequestListener.getServerInfosFor(infoRequest);
+            } catch (Throwable e) {
+                continue;
+            }
+            if (elements != null) elements.addAll(elementList);
+        }
+        return elements;
+    }
+
+    /**
+     * collect all non-server feature and identity info from the listeners
+     */
+    public Set<InfoElement> processInfoRequest(InfoRequest infoRequest) {
+        // sorted structure, to place all <feature/> after <identity/>
+        Set<InfoElement> elements = new TreeSet<InfoElement>(new ElementPartitioningComparator());
+        elements.add(DEFAULT_FEATURE);
+        for (InfoRequestListener infoRequestListener : infoRequestListeners) {
+            List<InfoElement> elementList = null;
+            try {
+                elementList = infoRequestListener.getInfosFor(infoRequest);
+            } catch (Throwable e) {
+                continue;
+            }
+            if (elementList != null) elements.addAll(elementList);
+        }
+        return elements;
+    }
+
+    /**
+     * collect all item info from the listeners
+     */
+    public Set<Item> processItemRequest(InfoRequest infoRequest) {
+        Set<Item> elements = new HashSet<Item>();
+        for (ItemRequestListener itemRequestListener : itemRequestListeners) {
+            List<Item> elementList = null;
+            try {
+                elementList = itemRequestListener.getItemsFor(infoRequest);
+            } catch (Throwable e) {
+                continue;
+            }
+            if (elements != null) elements.addAll(elementList);
+        }
+        return elements;
+    }
+
     public String getServiceName() {
         return SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY;
     }
+
+    static class ElementPartitioningComparator implements Comparator<InfoElement> {
+        public int compare(InfoElement o1, InfoElement o2) {
+            return o1.getElementClassId().compareTo(o2.getElementClassId());
+        }
+    }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java
Wed Nov 12 10:05:04 2008
@@ -18,14 +18,21 @@
 package org.apache.vysper.xmpp.modules.servicediscovery.handler;
 
 import org.apache.vysper.xmpp.modules.core.base.handler.DefaultIQHandler;
+import org.apache.vysper.xmpp.modules.servicediscovery.collection.ServiceCollector;
+import org.apache.vysper.xmpp.modules.servicediscovery.collection.ServiceDiscoveryRequestListenerRegistry;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoElement;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoRequest;
+import org.apache.vysper.xmpp.modules.roster.RosterItem;
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.server.ServerRuntimeContext;
 import org.apache.vysper.xmpp.server.SessionContext;
-import org.apache.vysper.xmpp.stanza.IQStanza;
-import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.server.response.ServerErrorResponses;
+import org.apache.vysper.xmpp.stanza.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Set;
+
 /**
  * handles roster get, set, push & result requests
  */
@@ -40,6 +47,45 @@
 
     @Override
     protected Stanza handleGet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext,
SessionContext sessionContext) {
-        return super.handleGet(stanza, serverRuntimeContext, sessionContext);
+        ServiceCollector serviceCollector = null;
+
+        try {
+            serviceCollector = (ServiceCollector)serverRuntimeContext.getServerRuntimeContextService(ServiceDiscoveryRequestListenerRegistry.SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY);
+        } catch (Exception e) {
+            logger.error("error retrieving ServiceCollector service {}", e);
+            serviceCollector = null;
+        }
+
+        if (serviceCollector == null) {
+            return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.INTERNAL_SERVER_ERROR,
stanza,
+                    StanzaErrorType.CANCEL,
+                    "cannot retrieve IQ-get-info result from internal components",
+                    getErrorLanguage(serverRuntimeContext, sessionContext), null);
+        }
+
+        boolean isServerInfoRequest = serverRuntimeContext.getServerEnitity().equals(stanza.getTo());
+
+        // collect all the info response elements
+        Set<InfoElement> elementSet = null;
+        if (isServerInfoRequest) {
+            elementSet = serviceCollector.processServerInfoRequest(new InfoRequest(stanza.getFrom(),
stanza.getTo()));
+        } else {
+            elementSet = serviceCollector.processInfoRequest(new InfoRequest(stanza.getFrom(),
stanza.getTo()));
+        }
+
+        //TODO check that elementSet contains at least one identity element and on feature
element!
+
+        // render the stanza with information collected
+        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(stanza.getTo(), stanza.getFrom(),
IQStanzaType.RESULT, stanza.getID()).
+            startInnerElement("query").
+            addNamespaceAttribute(NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO);
+
+            for (InfoElement infoElement : elementSet) {
+                infoElement.insertElement(stanzaBuilder);
+            }
+
+        stanzaBuilder.endInnerElement();
+
+        return stanzaBuilder.getFinalStanza();
     }
 }
\ No newline at end of file

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Feature.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Feature.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Feature.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Feature.java
Wed Nov 12 10:05:04 2008
@@ -16,17 +16,30 @@
  ***********************************************************************/
 package org.apache.vysper.xmpp.modules.servicediscovery.management;
 
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+
 /**
  */
 public class Feature implements InfoElement {
     
+    private static final Integer CLASS_ID = 2;
+
     protected String var;
 
     public Feature(String var) {
+        if (var == null || var.length() == 0) throw new IllegalArgumentException("var may
not be null");
         this.var = var;
     }
 
     public String getVar() {
         return var;
     }
+
+    public Integer getElementClassId() {
+        return CLASS_ID;
+    }
+
+    public void insertElement(StanzaBuilder stanzaBuilder) {
+        stanzaBuilder.startInnerElement("feature").addAttribute("var", var).endInnerElement();
+    }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Identity.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Identity.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Identity.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/Identity.java
Wed Nov 12 10:05:04 2008
@@ -16,23 +16,28 @@
  ***********************************************************************/
 package org.apache.vysper.xmpp.modules.servicediscovery.management;
 
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+
 /**
  */
 public class Identity implements InfoElement {
-    
+
+    private static final Integer CLASS_ID = new Integer(1);
+
     protected String category; // required
     protected String type; // required
     protected String name; // optional
 
     public Identity(String category, String type, String name) {
+        if (category == null || category.length() == 0) throw new IllegalArgumentException("category
may not be null");
+        if (type == null || type.length() == 0) throw new IllegalArgumentException("type
may not be null");
         this.category = category;
         this.type = type;
         this.name = name;
     }
 
     public Identity(String category, String type) {
-        this.category = category;
-        this.type = type;
+        this(category, type, null);
     }
 
     public String getCategory() {
@@ -46,4 +51,18 @@
     public String getName() {
         return name;
     }
+
+    public Integer getElementClassId() {
+        return CLASS_ID;
+    }
+
+    public void insertElement(StanzaBuilder stanzaBuilder) {
+        stanzaBuilder.startInnerElement("identity").
+                addAttribute("category", category).
+                addAttribute("type", type);
+                if (name != null) {
+                    stanzaBuilder.addAttribute("name", name);
+                }
+        stanzaBuilder.endInnerElement();
+    }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoElement.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoElement.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoElement.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoElement.java
Wed Nov 12 10:05:04 2008
@@ -16,7 +16,12 @@
  ***********************************************************************/
 package org.apache.vysper.xmpp.modules.servicediscovery.management;
 
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+
 /**
  */
 public interface InfoElement {
+    Integer getElementClassId();
+
+    void insertElement(StanzaBuilder stanzaBuilder);
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoRequest.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoRequest.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoRequest.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/InfoRequest.java
Wed Nov 12 10:05:04 2008
@@ -16,7 +16,25 @@
  ***********************************************************************/
 package org.apache.vysper.xmpp.modules.servicediscovery.management;
 
+import org.apache.vysper.xmpp.addressing.Entity;
+
 /**
  */
 public class InfoRequest {
+
+    private Entity from;
+    private Entity to;
+
+    public InfoRequest(Entity from, Entity to) {
+        this.from = from;
+        this.to = to;
+    }
+
+    public Entity getFrom() {
+        return from;
+    }
+
+    public Entity getTo() {
+        return to;
+    }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/ItemRequestListener.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/ItemRequestListener.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/ItemRequestListener.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/management/ItemRequestListener.java
Wed Nov 12 10:05:04 2008
@@ -24,6 +24,6 @@
  */
 public interface ItemRequestListener {
     
-    public List<Item> getItemsFor(ItemRequest request);
+    public List<Item> getItemsFor(InfoRequest request);
     
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java?rev=713443&r1=713442&r2=713443&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java
Wed Nov 12 10:05:04 2008
@@ -35,6 +35,22 @@
         this.namespaceURI = namespaceURI;
     }
 
+    public NamespaceHandlerDictionary(String namespaceURI, List<StanzaHandler> handlerList)
{
+        this.namespaceURI = namespaceURI;
+        if (handlerList != null) {
+            for (StanzaHandler stanzaHandler : handlerList) {
+                register(stanzaHandler);
+            }
+        }
+        seal();
+    }
+
+    public NamespaceHandlerDictionary(String namespaceURI, StanzaHandler stanzaHandler) {
+        this.namespaceURI = namespaceURI;
+        register(stanzaHandler);
+        seal();
+    }
+
     public String getNamespaceURI() {
         return namespaceURI;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message