You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by be...@apache.org on 2008/06/19 19:52:19 UTC

svn commit: r669599 - in /labs/vysper/src: main/java/org/apache/vysper/xmpp/modules/core/im/handler/ main/java/org/apache/vysper/xmpp/protocol/ test/java/org/apache/vysper/xmpp/modules/roster/handler/

Author: berndf
Date: Thu Jun 19 10:52:19 2008
New Revision: 669599

URL: http://svn.apache.org/viewvc?rev=669599&view=rev
Log:
[vysper] separate the handler code into two: subscribe- and available-related (LABS-101, LABS-132, LABS-133)

Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandlerTestCase.java

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java?rev=669599&r1=669598&r2=669599&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java Thu Jun 19 10:52:19 2008
@@ -17,49 +17,30 @@
 
 package org.apache.vysper.xmpp.modules.core.im.handler;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.vysper.compliance.SpecCompliant;
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.addressing.EntityImpl;
 import org.apache.vysper.xmpp.delivery.DeliveryException;
-import org.apache.vysper.xmpp.delivery.StanzaRelay;
 import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
-import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
 import org.apache.vysper.xmpp.resourcebinding.ResourceState;
-import org.apache.vysper.xmpp.server.ServerRuntimeContext;
 import org.apache.vysper.xmpp.server.SessionContext;
 import org.apache.vysper.xmpp.stanza.PresenceStanza;
+import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
+import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.*;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanzaVerifier;
-import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
-import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.*;
 import org.apache.vysper.xmpp.xmlfragment.XMLElement;
-import org.apache.vysper.xmpp.modules.core.base.handler.XMPPCoreStanzaHandler;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
- * handling presence stanzas
+ * handling presence stanzas related to availability
  */
-public class PresenceHandler extends XMPPCoreStanzaHandler {
-	public String getName() {
-		return "presence";
-	}
-
-	protected boolean verifyType(Stanza stanza) {
-		return PresenceStanza.isOfType(stanza);
-	}
-
-	protected Stanza executeCore(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
-        PresenceStanza presenceStanza = (PresenceStanza)stanza;
-        return executeCorePresence(sessionContext, presenceStanza);
-
-
-    }
+public class PresenceAvailabilityHandler  {
 
     /*package*/ Stanza executeCorePresence(SessionContext sessionContext, PresenceStanza presenceStanza) {
         // TODO: either use the resource associated with the session
@@ -76,8 +57,6 @@
         boolean isOutbound = !hasFrom && hasTo && !sessionContext.isServerToServer();
 
         PresenceStanzaType type = presenceStanza.getPresenceType();
-        boolean subscriptionRelated = type != null && isSubscriptionType(type);
-
 
         if (!hasTo && !hasType) {
             ResourceState resourceState = registry.getResourceState(registry.getFirstResourceForSession(sessionContext));
@@ -107,27 +86,11 @@
                     throw new RuntimeException("not implemented yet");
                 
                 case SUBSCRIBE:
-                    // RFC3921bis-04#3.1.2
-                    handleOutboundSubscriptionRequest(stampedStanza, sessionContext, registry);
-                    break;
-                
                 case SUBSCRIBED:
-                    // RFC3921bis-04#3.1.5
-                    handleOutboundSubscriptionApproval(stampedStanza, sessionContext, registry);
-                    break;
-                
                 case UNAVAILABLE:
-                    throw new RuntimeException("not implemented yet");
-                
                 case UNSUBSCRIBE:
-                    // RFC3921bis-04#3.3.2
-                    handleOutboundUnsubscription(stampedStanza, sessionContext, registry);
-                    break;
-                
                 case UNSUBSCRIBED:
-                    // RFC3921bis-04#3.2.2
-                    handleOutboundSubscriptionCancellation(stampedStanza, sessionContext, registry);
-                    break;
+                    throw new RuntimeException("case not handled in availability handler" + type.value());
                 
                 default:
                     throw new RuntimeException("unhandled case " + type.value());
@@ -147,24 +110,14 @@
                 case PROBE:
                     handleInboundPresenceProbe(presenceStanza, sessionContext, registry);
 
-                case SUBSCRIBE:
-                    // RFC3921bis-04#3.1.3
-                    return handleInboundSubscriptionRequest(presenceStanza, sessionContext, registry);
-
-                case SUBSCRIBED:
-                    // RFC3921bis-04#3.1.6
-                    return handleInboundSubscriptionApproval(presenceStanza, sessionContext, registry);
-
                 case UNAVAILABLE:
                     throw new RuntimeException("not implemented yet");
 
+                case SUBSCRIBE:
+                case SUBSCRIBED:
                 case UNSUBSCRIBE:
-                    // RFC3921bis-04#3.3.3
-                    handleInboundUnsubscription(presenceStanza, sessionContext, registry);
-
                 case UNSUBSCRIBED:
-                    // RFC3921bis-04#3.2.3
-                    handleInboundSubscriptionCancellation(presenceStanza, sessionContext, registry);
+                    throw new RuntimeException("case not handled in availability handler" + type.value());
 
                 default:
                     throw new RuntimeException("unhandled case " + type.value());
@@ -225,211 +178,6 @@
 		return null;
 	}
 
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.3.3")
-	private void handleInboundUnsubscription(PresenceStanza stanza, SessionContext sessionContext, ResourceRegistry registry) {
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		// TODO: remove subscription from user to contact
-
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the right subscription: 'none' or 'to'
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-
-			relayStanza(userResource, push, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.3.2")
-	private void handleOutboundUnsubscription(PresenceStanza stanza,
-                                           SessionContext sessionContext, ResourceRegistry registry) {
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		relayStanza(contact, stanza, sessionContext);
-
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the correct subscription state: 'none' or 'from'
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-			relayStanza(userResource, push, sessionContext);
-		}
-
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.2.3")
-	private void handleInboundSubscriptionCancellation(PresenceStanza stanza,
-                                                    SessionContext sessionContext, ResourceRegistry registry) {
-		// TODO: update roster for user
-		// TODO: if current subscription is either 'both' or
-
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the correct subscription state
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-			relayStanza(userResource, push, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.2.2")
-	private void handleOutboundSubscriptionCancellation(PresenceStanza stanza,
-                                                     SessionContext sessionContext, ResourceRegistry registry) {
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		relayStanza(contact, stanza, sessionContext);
-
-		// send roster push to all of the user's interested resources
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the right subscription: 'to' or 'none'
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-
-			relayStanza(userResource, push, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.1.5")
-	private void handleOutboundSubscriptionApproval(PresenceStanza stanza,
-                                                 SessionContext sessionContext, ResourceRegistry registry) {
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		relayStanza(contact, stanza, sessionContext);
-
-		// send roster push to all of the user's interested resources
-		List<String> resources = registry.getInterestedResources(user);
-
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"from");
-
-			relayStanza(userResource, push, sessionContext);
-		}
-
-		// send presence information from user's available resource to the
-		// contact
-		resources = registry.getAvailableResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			Stanza presence = buildPresenceStanza(userResource, contact.getBareJID(), null, null);
-
-			relayStanza(contact, presence, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.1.6")
-	private Stanza handleInboundSubscriptionApproval(PresenceStanza stanza,
-                                                  SessionContext sessionContext, ResourceRegistry registry) {
-
-		// TODO: check if contact is in users roster with
-		// subscription="from||none" && ask="subscribe"
-		if (true /* condition is met */) {
-			Entity user = stanza.getTo();
-			Entity contact = stanza.getFrom();
-			// send roster push to all interested resources
-			List<String> resources = registry.getInterestedResources(user);
-			for (String resource : resources) {
-				Entity userResource = new EntityImpl(user, resource);
-				Stanza push = buildRosterPushStanza(userResource, sessionContext.nextSequenceValue(), 
-                        contact.getBareJID(), "to");
-				relayStanza(userResource, push, sessionContext);
-			}
-		} else {
-			// silently drop the stanza
-		}
-
-		return null;
-	}
-
-	@SpecCompliant(spec = "RFC3920bis-04", section = "3.1.3")
-	private Stanza handleInboundSubscriptionRequest(PresenceStanza stanza,
-                                                 SessionContext sessionContext, ResourceRegistry registry) {
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		// TODO: verify that user actually exists on this server
-		if (false) {
-			// user does not exist
-			return buildPresenceStanza(user.getBareJID(), contact.getBareJID(), UNSUBSCRIBED, stanza);
-		}
-		// assert: user exists
-
-		// TODO: check whether user already has a subscription to
-		// contact
-		if (false) {
-			return buildPresenceStanza(user.getBareJID(), contact.getBareJID(), SUBSCRIBED, stanza);
-		}
-
-		// user exists and doesn't have a subscription
-		// to the contact and user is currently online (# of
-		// interested resources > 0)
-		List<String> interestedResources = registry
-				.getInterestedResources(user);
-		if (interestedResources.isEmpty() == false) {
-			for (String resource : interestedResources) {
-				Entity userResource = new EntityImpl(user, resource);
-				relayStanza(userResource, stanza, sessionContext);
-			}
-		} else {
-
-			// contact exists, contact doesn't have a subscription
-			// to user and contact is currently offline
-			// TODO: store the subscription request in a msg queue for contact
-			// TODO: only store the subscription request once to prevent spam
-		}
-		return null;
-	}
-
-	@SpecCompliant(spec = "RFC3920bis-04", section = "3.1.2")
-	private void handleOutboundSubscriptionRequest(PresenceStanza stanza,
-                                                SessionContext sessionContext, ResourceRegistry registry) {
-		ServerRuntimeContext serverRuntimeContext = sessionContext.getServerRuntimeContext();
-		StanzaRelay stanzaRelay = serverRuntimeContext.getStanzaRelay();
-
-		// relay the stanza to the contact's server
-		try {
-			stanzaRelay.relay(stanza.getTo(), stanza, new IgnoreFailureStrategy());
-		} catch (DeliveryException e) {
-			e.printStackTrace();
-		}
-
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		// send roster push to all of the user's interested resources
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"none");
-			try {
-				stanzaRelay.relay(userResource, push, new IgnoreFailureStrategy());
-			} catch (DeliveryException e) {
-				e.printStackTrace();
-			}
-		}
-	}
-
 	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.2")
 	private void handleOutboundInitialPresence(PresenceStanza stanza,
                                             SessionContext sessionContext, ResourceRegistry registry, Entity initiatingEntity) {
@@ -502,31 +250,6 @@
         return (PresenceStanza) XMPPCoreStanza.getWrapper(builder.getFinalStanza());
 	}
 
-	private Stanza buildRosterPushStanza(Entity to, String id,
-			Entity bareJidOfRosterItem, String subscription, String ask) {
-		StanzaBuilder builder = new StanzaBuilder("iq");
-		builder.addAttribute("to", to.getFullQualifiedName());
-		builder.addAttribute("type", "set");
-		builder.addAttribute("id", id);
-		builder.startInnerElement("query", NamespaceURIs.JABBER_IQ_ROSTER);
-		builder.startInnerElement("item");
-		builder.addAttribute("jid", bareJidOfRosterItem.getBareJID().getFullQualifiedName());
-		builder.addAttribute("subscription", subscription);
-		if (ask != null) {
-			builder.addAttribute("ask", ask);
-		}
-		builder.endInnerElement();
-		builder.endInnerElement();
-
-		return builder.getFinalStanza();
-	}
-
-	private Stanza buildRosterPushStanza(Entity to, String id,
-			Entity bareJidOfRosterItem, String subscription) {
-		return buildRosterPushStanza(to, id, bareJidOfRosterItem, subscription,
-				null);
-	}
-
 	private void relayStanza(Entity receiver, Stanza stanza, SessionContext sessionContext) {
 		try {
 			sessionContext.getServerRuntimeContext().getStanzaRelay().relay(receiver, stanza, new IgnoreFailureStrategy());

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandler.java?rev=669599&r1=669598&r2=669599&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandler.java Thu Jun 19 10:52:19 2008
@@ -17,35 +17,23 @@
 
 package org.apache.vysper.xmpp.modules.core.im.handler;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.vysper.compliance.SpecCompliant;
-import org.apache.vysper.xmpp.addressing.Entity;
-import org.apache.vysper.xmpp.addressing.EntityImpl;
-import org.apache.vysper.xmpp.delivery.DeliveryException;
-import org.apache.vysper.xmpp.delivery.StanzaRelay;
-import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
-import org.apache.vysper.xmpp.protocol.NamespaceURIs;
-import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
-import org.apache.vysper.xmpp.resourcebinding.ResourceState;
-import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.modules.core.base.handler.XMPPCoreStanzaHandler;
 import org.apache.vysper.xmpp.server.SessionContext;
 import org.apache.vysper.xmpp.stanza.PresenceStanza;
+import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
+import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.isSubscriptionType;
 import org.apache.vysper.xmpp.stanza.Stanza;
-import org.apache.vysper.xmpp.stanza.StanzaBuilder;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
-import org.apache.vysper.xmpp.stanza.XMPPCoreStanzaVerifier;
-import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
-import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.*;
-import org.apache.vysper.xmpp.xmlfragment.XMLElement;
-import org.apache.vysper.xmpp.modules.core.base.handler.XMPPCoreStanzaHandler;
 
 /**
  * handling presence stanzas
  */
 public class PresenceHandler extends XMPPCoreStanzaHandler {
-	public String getName() {
+    
+    private final static PresenceAvailabilityHandler AVAILABILITY_HANDLER = new PresenceAvailabilityHandler();
+    private final static PresenceSubscriptionHandler SUBSCRIPTION_HANDLER = new PresenceSubscriptionHandler();
+    
+    public String getName() {
 		return "presence";
 	}
 
@@ -56,483 +44,12 @@
 	protected Stanza executeCore(XMPPCoreStanza stanza,
 			SessionContext sessionContext) {
         PresenceStanza presenceStanza = (PresenceStanza)stanza;
-        return executeCorePresence(sessionContext, presenceStanza);
-
-
-    }
-
-    /*package*/ Stanza executeCorePresence(SessionContext sessionContext, PresenceStanza presenceStanza) {
-        // TODO: either use the resource associated with the session
-        // (initiatingEntity)
-        // or in case of multiple resources, use the from attribute or return an
-        // error if the from attribute is not present.
-        Entity initiatingEntity = sessionContext.getInitiatingEntity();
-        XMPPCoreStanzaVerifier verifier = presenceStanza.getCoreVerifier();
-        ResourceRegistry registry = sessionContext.getServerRuntimeContext().getResourceRegistry();
-
-        boolean hasFrom = verifier.attributePresent("from");
-        boolean hasTo = verifier.attributePresent("to");
-        boolean hasType = verifier.attributePresent("type");
-        boolean isOutbound = !hasFrom && hasTo && !sessionContext.isServerToServer();
-
+        
         PresenceStanzaType type = presenceStanza.getPresenceType();
         boolean subscriptionRelated = type != null && isSubscriptionType(type);
-
-
-        if (!hasTo && !hasType) {
-            ResourceState resourceState = registry.getResourceState(registry.getFirstResourceForSession(sessionContext));
-
-            if (resourceState != null && resourceState == ResourceState.AVAILABLE) {
-                handleOutboundPresenceUpdate(presenceStanza, sessionContext, registry, initiatingEntity);
-            } else {
-                // TODO check for resourceState != ResourceState.INTERESTED ? 
-                // RFC3921bis-04#4.2.2 Initial Presence
-                handleOutboundInitialPresence(presenceStanza, sessionContext, registry, initiatingEntity);
-            }
-
-        } else if (isOutbound && hasType) {
-			// this is an outbound subscription
-			// request/approval/cancellation/unsubscription
-			// stamp it with the bare JID of the user
-			Entity user = initiatingEntity;
-			PresenceStanza stampedStanza = buildPresenceStanza(user.getBareJID(), 
-                    presenceStanza.getTo().getBareJID(), presenceStanza.getPresenceType(), null);
-
-            switch (type) {
-
-                case ERROR:
-                    throw new RuntimeException("not implemented yet");
-                    
-                case PROBE:
-                    throw new RuntimeException("not implemented yet");
-                
-                case SUBSCRIBE:
-                    // RFC3921bis-04#3.1.2
-                    handleOutboundSubscriptionRequest(stampedStanza, sessionContext, registry);
-                    break;
-                
-                case SUBSCRIBED:
-                    // RFC3921bis-04#3.1.5
-                    handleOutboundSubscriptionApproval(stampedStanza, sessionContext, registry);
-                    break;
-                
-                case UNAVAILABLE:
-                    throw new RuntimeException("not implemented yet");
-                
-                case UNSUBSCRIBE:
-                    // RFC3921bis-04#3.3.2
-                    handleOutboundUnsubscription(stampedStanza, sessionContext, registry);
-                    break;
-                
-                case UNSUBSCRIBED:
-                    // RFC3921bis-04#3.2.2
-                    handleOutboundSubscriptionCancellation(stampedStanza, sessionContext, registry);
-                    break;
-                
-                default:
-                    throw new RuntimeException("unhandled case " + type.value());
-            }
-            
-		} else if (hasFrom && hasTo && !hasType) {
-			// RFC3921bis-04#4.2.3
-			handleInboundInitialPresence(presenceStanza, sessionContext, registry);
-		
-        } else if (hasFrom && hasTo && hasType) {
-
-            switch (type) {
-
-                case ERROR:
-                    throw new RuntimeException("not implemented yet");
-                    
-                case PROBE:
-                    handleInboundPresenceProbe(presenceStanza, sessionContext, registry);
-
-                case SUBSCRIBE:
-                    // RFC3921bis-04#3.1.3
-                    return handleInboundSubscriptionRequest(presenceStanza, sessionContext, registry);
-
-                case SUBSCRIBED:
-                    // RFC3921bis-04#3.1.6
-                    return handleInboundSubscriptionApproval(presenceStanza, sessionContext, registry);
-
-                case UNAVAILABLE:
-                    throw new RuntimeException("not implemented yet");
-
-                case UNSUBSCRIBE:
-                    // RFC3921bis-04#3.3.3
-                    handleInboundUnsubscription(presenceStanza, sessionContext, registry);
-
-                case UNSUBSCRIBED:
-                    // RFC3921bis-04#3.2.3
-                    handleInboundSubscriptionCancellation(presenceStanza, sessionContext, registry);
-
-                default:
-                    throw new RuntimeException("unhandled case " + type.value());
-                    
-            }
-
-		} else if (hasFrom && hasTo) {
-            throw new RuntimeException("unhandled direct presence stanza");
-        } else if (hasType && type == UNAVAILABLE) {
-            handleInboundUnavailable(presenceStanza, sessionContext);
-        } else {
-            System.err.println("unhandled presence case");
-        }
-
-        return null;
-    }
-
-    private void handleOutboundPresenceUpdate(PresenceStanza stanza, SessionContext sessionContext, 
-                                              ResourceRegistry registry, Entity initiatingEntity) {
-        updateResourcePriority(registry, initiatingEntity, stanza.getPrioritySafe());
-        System.out.println("C: has updated his presence");
-    }
-
-    private void handleInboundUnavailable(PresenceStanza presenceStanza, SessionContext sessionContext) {
-        ResourceRegistry registry = sessionContext.getServerRuntimeContext().getResourceRegistry();
-
-        String firstResource = registry.getFirstResourceForSession(sessionContext);
-        if (firstResource != null) {
-            registry.setResourceState(firstResource, ResourceState.UNAVAILABLE);
-        }
-        // TODO propagate to _all_ resources for this entity.
         
-        System.out.println("C: has become unavailable");
-    }
-
-    @SpecCompliant(spec = "RFC3921bis-04", section = "4.3.2")
-	private XMPPCoreStanza handleInboundPresenceProbe(PresenceStanza stanza, SessionContext sessionContext, ResourceRegistry registry) {
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		// TODO: check whether user actually exists on the server
-		// TODO: check whether contact is in roster other than 'From', 'From
-		// +
-		// Pending Out' or 'Both'
-		if (false) {
-			return buildPresenceStanza(user.getBareJID(), contact.getBareJID(), UNSUBSCRIBED, stanza);
-		}
-
-		List<String> resources = registry.getAvailableResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			XMPPCoreStanza presence = null;
-			// TODO: get last presence stanza sent from the user and relay it to
-			// the contact
-			relayStanza(contact, presence, sessionContext);
-		}
-
-		return null;
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.3.3")
-	private void handleInboundUnsubscription(PresenceStanza stanza, SessionContext sessionContext, ResourceRegistry registry) {
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		// TODO: remove subscription from user to contact
-
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the right subscription: 'none' or 'to'
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-
-			relayStanza(userResource, push, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.3.2")
-	private void handleOutboundUnsubscription(PresenceStanza stanza,
-                                           SessionContext sessionContext, ResourceRegistry registry) {
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		relayStanza(contact, stanza, sessionContext);
-
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the correct subscription state: 'none' or 'from'
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-			relayStanza(userResource, push, sessionContext);
-		}
-
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.2.3")
-	private void handleInboundSubscriptionCancellation(PresenceStanza stanza,
-                                                    SessionContext sessionContext, ResourceRegistry registry) {
-		// TODO: update roster for user
-		// TODO: if current subscription is either 'both' or
-
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the correct subscription state
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-			relayStanza(userResource, push, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.2.2")
-	private void handleOutboundSubscriptionCancellation(PresenceStanza stanza,
-                                                     SessionContext sessionContext, ResourceRegistry registry) {
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		relayStanza(contact, stanza, sessionContext);
-
-		// send roster push to all of the user's interested resources
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			// TODO: determine the right subscription: 'to' or 'none'
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"???");
-
-			relayStanza(userResource, push, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.1.5")
-	private void handleOutboundSubscriptionApproval(PresenceStanza stanza,
-                                                 SessionContext sessionContext, ResourceRegistry registry) {
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		relayStanza(contact, stanza, sessionContext);
-
-		// send roster push to all of the user's interested resources
-		List<String> resources = registry.getInterestedResources(user);
-
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"from");
-
-			relayStanza(userResource, push, sessionContext);
-		}
-
-		// send presence information from user's available resource to the
-		// contact
-		resources = registry.getAvailableResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			Stanza presence = buildPresenceStanza(userResource, contact.getBareJID(), null, null);
-
-			relayStanza(contact, presence, sessionContext);
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "3.1.6")
-	private Stanza handleInboundSubscriptionApproval(PresenceStanza stanza,
-                                                  SessionContext sessionContext, ResourceRegistry registry) {
-
-		// TODO: check if contact is in users roster with
-		// subscription="from||none" && ask="subscribe"
-		if (true /* condition is met */) {
-			Entity user = stanza.getTo();
-			Entity contact = stanza.getFrom();
-			// send roster push to all interested resources
-			List<String> resources = registry.getInterestedResources(user);
-			for (String resource : resources) {
-				Entity userResource = new EntityImpl(user, resource);
-				Stanza push = buildRosterPushStanza(userResource, sessionContext.nextSequenceValue(), 
-                        contact.getBareJID(), "to");
-				relayStanza(userResource, push, sessionContext);
-			}
-		} else {
-			// silently drop the stanza
-		}
-
-		return null;
-	}
-
-	@SpecCompliant(spec = "RFC3920bis-04", section = "3.1.3")
-	private Stanza handleInboundSubscriptionRequest(PresenceStanza stanza,
-                                                 SessionContext sessionContext, ResourceRegistry registry) {
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		// TODO: verify that user actually exists on this server
-		if (false) {
-			// user does not exist
-			return buildPresenceStanza(user.getBareJID(), contact.getBareJID(), UNSUBSCRIBED, stanza);
-		}
-		// assert: user exists
-
-		// TODO: check whether user already has a subscription to
-		// contact
-		if (false) {
-			return buildPresenceStanza(user.getBareJID(), contact.getBareJID(), SUBSCRIBED, stanza);
-		}
-
-		// user exists and doesn't have a subscription
-		// to the contact and user is currently online (# of
-		// interested resources > 0)
-		List<String> interestedResources = registry
-				.getInterestedResources(user);
-		if (interestedResources.isEmpty() == false) {
-			for (String resource : interestedResources) {
-				Entity userResource = new EntityImpl(user, resource);
-				relayStanza(userResource, stanza, sessionContext);
-			}
-		} else {
-
-			// contact exists, contact doesn't have a subscription
-			// to user and contact is currently offline
-			// TODO: store the subscription request in a msg queue for contact
-			// TODO: only store the subscription request once to prevent spam
-		}
-		return null;
-	}
-
-	@SpecCompliant(spec = "RFC3920bis-04", section = "3.1.2")
-	private void handleOutboundSubscriptionRequest(PresenceStanza stanza,
-                                                SessionContext sessionContext, ResourceRegistry registry) {
-		ServerRuntimeContext serverRuntimeContext = sessionContext.getServerRuntimeContext();
-		StanzaRelay stanzaRelay = serverRuntimeContext.getStanzaRelay();
-
-		// relay the stanza to the contact's server
-		try {
-			stanzaRelay.relay(stanza.getTo(), stanza, new IgnoreFailureStrategy());
-		} catch (DeliveryException e) {
-			e.printStackTrace();
-		}
-
-		Entity user = stanza.getFrom();
-		Entity contact = stanza.getTo();
-
-		// send roster push to all of the user's interested resources
-		List<String> resources = registry.getInterestedResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			Stanza push = buildRosterPushStanza(userResource,
-					sessionContext.nextSequenceValue(), contact.getBareJID(),
-					"none");
-			try {
-				stanzaRelay.relay(userResource, push, new IgnoreFailureStrategy());
-			} catch (DeliveryException e) {
-				e.printStackTrace();
-			}
-		}
-	}
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.2")
-	private void handleOutboundInitialPresence(PresenceStanza stanza,
-                                            SessionContext sessionContext, ResourceRegistry registry, Entity initiatingEntity) {
-        String resourceID = registry.getFirstResourceForSession(sessionContext);
-        Entity user = (resourceID != null) ? new EntityImpl(initiatingEntity, resourceID) : stanza.getFrom();
-        if (user == null) {
-            // return error stanza
-        }
-        registry.setResourceState(user.getResource(), ResourceState.AVAILABLE);
-
-        // send probes to all contacts of the current jid where
-        // 'subscription' is either 'to' or 'both'
-        // and jid is not blocking inbound presence notification
-        // TODO: retrieve list of contacts that match the criteria mentioned
-        // above
-        List<Entity> contacts1 = new ArrayList<Entity>();
-        List<Entity> contacts = contacts1;
-        for (Entity contact : contacts) {
-            Stanza probeStanza = buildPresenceStanza(user, contact, null, null);
-            relayStanza(contact, probeStanza, sessionContext);
-        }
-
-        // broadcast initial presence from full JID to contacts
-        // in roster with 'subscription' either 'from' or 'both'
-        // and not user is blocking outbound presence notifications
-        // TODO: retrieve list of contacts that match the criteria mentioned
-        // above
-        contacts = new ArrayList<Entity>();
-        for (Entity contact : contacts) {
-            Stanza presenceStanza = buildPresenceStanza(user, contact, null, null);
-            relayStanza(contact, presenceStanza, sessionContext);
-        }
-
-        // TODO: also broadcast presence notification to all resources of
-        // current entity.
-        List<String> resources = registry.getAvailableResources(user);
-        for (String resource : resources) {
-            Entity otherResource = new EntityImpl(user, resource);
-            Stanza presenceStanza = buildPresenceStanza(user, otherResource, null, null);
-            relayStanza(otherResource, presenceStanza, sessionContext);
-        }
-
+        if (!subscriptionRelated) return AVAILABILITY_HANDLER.executeCorePresence(sessionContext, presenceStanza);
+        else return SUBSCRIPTION_HANDLER.executeCorePresence(sessionContext, presenceStanza);
     }
 
-	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.3")
-	private void handleInboundInitialPresence(PresenceStanza stanza,
-                                           SessionContext sessionContext, ResourceRegistry registry) {
-        updateResourcePriority(registry, sessionContext.getInitiatingEntity(), stanza.getPrioritySafe());
-		Entity user = stanza.getTo();
-		List<String> resources = registry.getAvailableResources(user);
-
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			relayStanza(userResource, stanza, sessionContext);
-		}
-	}
-
-    /**
-     * the presence priority is optional, but if contained, it might become relevant for 
-     * message delivery (see RFC3921bis-05#8.3.1.1)
-     */
-    private void updateResourcePriority(ResourceRegistry registry, Entity initiatingEntity, int priority) {
-        if (initiatingEntity == null || initiatingEntity.getResource() == null) return;
-        registry.setResourcePriority(initiatingEntity.getResource(), priority);
-    }
-
-    private PresenceStanza buildPresenceStanza(Entity from, Entity to, PresenceStanzaType type, XMLElement innerElements) {
-        StanzaBuilder builder = StanzaBuilder.createPresenceStanza(from, to, null, type, null, null);
-        if (innerElements != null) builder.addPreparedElement(innerElements);
-        return (PresenceStanza) XMPPCoreStanza.getWrapper(builder.getFinalStanza());
-	}
-
-	private Stanza buildRosterPushStanza(Entity to, String id,
-			Entity bareJidOfRosterItem, String subscription, String ask) {
-		StanzaBuilder builder = new StanzaBuilder("iq");
-		builder.addAttribute("to", to.getFullQualifiedName());
-		builder.addAttribute("type", "set");
-		builder.addAttribute("id", id);
-		builder.startInnerElement("query", NamespaceURIs.JABBER_IQ_ROSTER);
-		builder.startInnerElement("item");
-		builder.addAttribute("jid", bareJidOfRosterItem.getBareJID().getFullQualifiedName());
-		builder.addAttribute("subscription", subscription);
-		if (ask != null) {
-			builder.addAttribute("ask", ask);
-		}
-		builder.endInnerElement();
-		builder.endInnerElement();
-
-		return builder.getFinalStanza();
-	}
-
-	private Stanza buildRosterPushStanza(Entity to, String id,
-			Entity bareJidOfRosterItem, String subscription) {
-		return buildRosterPushStanza(to, id, bareJidOfRosterItem, subscription,
-				null);
-	}
-
-	private void relayStanza(Entity receiver, Stanza stanza, SessionContext sessionContext) {
-		try {
-			sessionContext.getServerRuntimeContext().getStanzaRelay().relay(receiver, stanza, new IgnoreFailureStrategy());
-		} catch (DeliveryException e) {
-			e.printStackTrace();
-		}
-	}
-
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java?rev=669599&r1=669598&r2=669599&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java Thu Jun 19 10:52:19 2008
@@ -17,9 +17,6 @@
 
 package org.apache.vysper.xmpp.modules.core.im.handler;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.vysper.compliance.SpecCompliant;
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.addressing.EntityImpl;
@@ -28,38 +25,23 @@
 import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
-import org.apache.vysper.xmpp.resourcebinding.ResourceState;
 import org.apache.vysper.xmpp.server.ServerRuntimeContext;
 import org.apache.vysper.xmpp.server.SessionContext;
 import org.apache.vysper.xmpp.stanza.PresenceStanza;
+import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
+import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.*;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanzaVerifier;
-import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
-import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.*;
 import org.apache.vysper.xmpp.xmlfragment.XMLElement;
-import org.apache.vysper.xmpp.modules.core.base.handler.XMPPCoreStanzaHandler;
+
+import java.util.List;
 
 /**
- * handling presence stanzas
+ * handling presence stanzas of type subscription
  */
-public class PresenceHandler extends XMPPCoreStanzaHandler {
-	public String getName() {
-		return "presence";
-	}
-
-	protected boolean verifyType(Stanza stanza) {
-		return PresenceStanza.isOfType(stanza);
-	}
-
-	protected Stanza executeCore(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
-        PresenceStanza presenceStanza = (PresenceStanza)stanza;
-        return executeCorePresence(sessionContext, presenceStanza);
-
-
-    }
+public class PresenceSubscriptionHandler {
 
     /*package*/ Stanza executeCorePresence(SessionContext sessionContext, PresenceStanza presenceStanza) {
         // TODO: either use the resource associated with the session
@@ -80,16 +62,7 @@
 
 
         if (!hasTo && !hasType) {
-            ResourceState resourceState = registry.getResourceState(registry.getFirstResourceForSession(sessionContext));
-
-            if (resourceState != null && resourceState == ResourceState.AVAILABLE) {
-                handleOutboundPresenceUpdate(presenceStanza, sessionContext, registry, initiatingEntity);
-            } else {
-                // TODO check for resourceState != ResourceState.INTERESTED ? 
-                // RFC3921bis-04#4.2.2 Initial Presence
-                handleOutboundInitialPresence(presenceStanza, sessionContext, registry, initiatingEntity);
-            }
-
+            throw new RuntimeException("not implemented yet");
         } else if (isOutbound && hasType) {
 			// this is an outbound subscription
 			// request/approval/cancellation/unsubscription
@@ -133,19 +106,14 @@
                     throw new RuntimeException("unhandled case " + type.value());
             }
             
-		} else if (hasFrom && hasTo && !hasType) {
-			// RFC3921bis-04#4.2.3
-			handleInboundInitialPresence(presenceStanza, sessionContext, registry);
-		
         } else if (hasFrom && hasTo && hasType) {
 
             switch (type) {
 
                 case ERROR:
-                    throw new RuntimeException("not implemented yet");
-                    
                 case PROBE:
-                    handleInboundPresenceProbe(presenceStanza, sessionContext, registry);
+                case UNAVAILABLE:
+                    throw new RuntimeException("case not handled in subscription handler" + type.value());
 
                 case SUBSCRIBE:
                     // RFC3921bis-04#3.1.3
@@ -155,9 +123,6 @@
                     // RFC3921bis-04#3.1.6
                     return handleInboundSubscriptionApproval(presenceStanza, sessionContext, registry);
 
-                case UNAVAILABLE:
-                    throw new RuntimeException("not implemented yet");
-
                 case UNSUBSCRIBE:
                     // RFC3921bis-04#3.3.3
                     handleInboundUnsubscription(presenceStanza, sessionContext, registry);
@@ -173,8 +138,6 @@
 
 		} else if (hasFrom && hasTo) {
             throw new RuntimeException("unhandled direct presence stanza");
-        } else if (hasType && type == UNAVAILABLE) {
-            handleInboundUnavailable(presenceStanza, sessionContext);
         } else {
             System.err.println("unhandled presence case");
         }
@@ -182,49 +145,6 @@
         return null;
     }
 
-    private void handleOutboundPresenceUpdate(PresenceStanza stanza, SessionContext sessionContext, 
-                                              ResourceRegistry registry, Entity initiatingEntity) {
-        updateResourcePriority(registry, initiatingEntity, stanza.getPrioritySafe());
-        System.out.println("C: has updated his presence");
-    }
-
-    private void handleInboundUnavailable(PresenceStanza presenceStanza, SessionContext sessionContext) {
-        ResourceRegistry registry = sessionContext.getServerRuntimeContext().getResourceRegistry();
-
-        String firstResource = registry.getFirstResourceForSession(sessionContext);
-        if (firstResource != null) {
-            registry.setResourceState(firstResource, ResourceState.UNAVAILABLE);
-        }
-        // TODO propagate to _all_ resources for this entity.
-        
-        System.out.println("C: has become unavailable");
-    }
-
-    @SpecCompliant(spec = "RFC3921bis-04", section = "4.3.2")
-	private XMPPCoreStanza handleInboundPresenceProbe(PresenceStanza stanza, SessionContext sessionContext, ResourceRegistry registry) {
-		Entity contact = stanza.getFrom();
-		Entity user = stanza.getTo();
-
-		// TODO: check whether user actually exists on the server
-		// TODO: check whether contact is in roster other than 'From', 'From
-		// +
-		// Pending Out' or 'Both'
-		if (false) {
-			return buildPresenceStanza(user.getBareJID(), contact.getBareJID(), UNSUBSCRIBED, stanza);
-		}
-
-		List<String> resources = registry.getAvailableResources(user);
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			XMPPCoreStanza presence = null;
-			// TODO: get last presence stanza sent from the user and relay it to
-			// the contact
-			relayStanza(contact, presence, sessionContext);
-		}
-
-		return null;
-	}
-
 	@SpecCompliant(spec = "RFC3921bis-04", section = "3.3.3")
 	private void handleInboundUnsubscription(PresenceStanza stanza, SessionContext sessionContext, ResourceRegistry registry) {
 		Entity contact = stanza.getFrom();
@@ -430,72 +350,6 @@
 		}
 	}
 
-	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.2")
-	private void handleOutboundInitialPresence(PresenceStanza stanza,
-                                            SessionContext sessionContext, ResourceRegistry registry, Entity initiatingEntity) {
-        String resourceID = registry.getFirstResourceForSession(sessionContext);
-        Entity user = (resourceID != null) ? new EntityImpl(initiatingEntity, resourceID) : stanza.getFrom();
-        if (user == null) {
-            // return error stanza
-        }
-        registry.setResourceState(user.getResource(), ResourceState.AVAILABLE);
-
-        // send probes to all contacts of the current jid where
-        // 'subscription' is either 'to' or 'both'
-        // and jid is not blocking inbound presence notification
-        // TODO: retrieve list of contacts that match the criteria mentioned
-        // above
-        List<Entity> contacts1 = new ArrayList<Entity>();
-        List<Entity> contacts = contacts1;
-        for (Entity contact : contacts) {
-            Stanza probeStanza = buildPresenceStanza(user, contact, null, null);
-            relayStanza(contact, probeStanza, sessionContext);
-        }
-
-        // broadcast initial presence from full JID to contacts
-        // in roster with 'subscription' either 'from' or 'both'
-        // and not user is blocking outbound presence notifications
-        // TODO: retrieve list of contacts that match the criteria mentioned
-        // above
-        contacts = new ArrayList<Entity>();
-        for (Entity contact : contacts) {
-            Stanza presenceStanza = buildPresenceStanza(user, contact, null, null);
-            relayStanza(contact, presenceStanza, sessionContext);
-        }
-
-        // TODO: also broadcast presence notification to all resources of
-        // current entity.
-        List<String> resources = registry.getAvailableResources(user);
-        for (String resource : resources) {
-            Entity otherResource = new EntityImpl(user, resource);
-            Stanza presenceStanza = buildPresenceStanza(user, otherResource, null, null);
-            relayStanza(otherResource, presenceStanza, sessionContext);
-        }
-
-    }
-
-	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.3")
-	private void handleInboundInitialPresence(PresenceStanza stanza,
-                                           SessionContext sessionContext, ResourceRegistry registry) {
-        updateResourcePriority(registry, sessionContext.getInitiatingEntity(), stanza.getPrioritySafe());
-		Entity user = stanza.getTo();
-		List<String> resources = registry.getAvailableResources(user);
-
-		for (String resource : resources) {
-			Entity userResource = new EntityImpl(user, resource);
-			relayStanza(userResource, stanza, sessionContext);
-		}
-	}
-
-    /**
-     * the presence priority is optional, but if contained, it might become relevant for 
-     * message delivery (see RFC3921bis-05#8.3.1.1)
-     */
-    private void updateResourcePriority(ResourceRegistry registry, Entity initiatingEntity, int priority) {
-        if (initiatingEntity == null || initiatingEntity.getResource() == null) return;
-        registry.setResourcePriority(initiatingEntity.getResource(), priority);
-    }
-
     private PresenceStanza buildPresenceStanza(Entity from, Entity to, PresenceStanzaType type, XMLElement innerElements) {
         StanzaBuilder builder = StanzaBuilder.createPresenceStanza(from, to, null, type, null, null);
         if (innerElements != null) builder.addPreparedElement(innerElements);

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java?rev=669599&r1=669598&r2=669599&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java Thu Jun 19 10:52:19 2008
@@ -26,7 +26,6 @@
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
 import org.apache.vysper.xmpp.xmlfragment.XMLElement;
 
-import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
 

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandlerTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandlerTestCase.java?rev=669599&r1=669598&r2=669599&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandlerTestCase.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandlerTestCase.java Thu Jun 19 10:52:19 2008
@@ -8,7 +8,6 @@
 import org.apache.vysper.xmpp.addressing.EntityImpl;
 import org.apache.vysper.xmpp.resourcebinding.ResourceState;
 import org.apache.vysper.xmpp.modules.roster.persistence.MemoryRosterManager;
-import org.apache.vysper.xmpp.modules.core.im.handler.PresenceHandler;
 
 /**
  */



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