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/11/11 21:55:38 UTC
svn commit: r713163 - in /labs/vysper/src/main/java/org/apache/vysper/xmpp:
modules/ modules/core/base/handler/ modules/core/bind/handler/
modules/roster/ modules/roster/handler/ modules/servicediscovery/
modules/servicediscovery/collection/ modules/se...
Author: berndf
Date: Tue Nov 11 12:55:37 2008
New Revision: 713163
URL: http://svn.apache.org/viewvc?rev=713163&view=rev
Log:
[vysper] improve the module concept: now requires much less coding. same with most IQ handlers, they now extend abstract default implementation and only override what they need. LABS-228 (service disco) profits from this, too.
Added:
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultDiscoAwareModule.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultModule.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceDiscoveryRequestListenerRegistry.java
Modified:
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/Module.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/IQHandler.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandler.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryModule.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/server/DefaultServerRuntimeContext.java
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultDiscoAwareModule.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultDiscoAwareModule.java?rev=713163&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultDiscoAwareModule.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultDiscoAwareModule.java Tue Nov 11 12:55:37 2008
@@ -0,0 +1,83 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.modules;
+
+import org.apache.vysper.xmpp.modules.servicediscovery.collection.ServiceDiscoveryRequestListenerRegistry;
+import static org.apache.vysper.xmpp.modules.servicediscovery.collection.ServiceDiscoveryRequestListenerRegistry.SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoRequestListener;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ServerInfoRequestListener;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ItemRequestListener;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ */
+abstract public class DefaultDiscoAwareModule extends DefaultModule {
+
+ final Logger logger = LoggerFactory.getLogger(DefaultDiscoAwareModule.class);
+
+ @Override
+ public void initialize(ServerRuntimeContext serverRuntimeContext) {
+ super.initialize(serverRuntimeContext);
+
+ ServerRuntimeContextService service = serverRuntimeContext.getServerRuntimeContextService(SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY);
+ if (service == null) {
+ logger.error("cannot register disco request listeners: no registry service found");
+ return;
+ }
+
+ ServiceDiscoveryRequestListenerRegistry requestListenerRegistry = (ServiceDiscoveryRequestListenerRegistry) service;
+
+ List<InfoRequestListener> infoRequestListeners = new ArrayList<InfoRequestListener>();
+ addInfoRequestListeners(infoRequestListeners);
+ for (InfoRequestListener infoRequestListener : infoRequestListeners) {
+ if (infoRequestListener == null) continue;
+ requestListenerRegistry.addInfoRequestListener(infoRequestListener);
+ }
+
+ List<ServerInfoRequestListener> serverInfoRequestListeners = new ArrayList<ServerInfoRequestListener>();
+ addServerInfoRequestListeners(serverInfoRequestListeners);
+ for (ServerInfoRequestListener serverInfoRequestListener : serverInfoRequestListeners) {
+ if (serverInfoRequestListener == null) continue;
+ requestListenerRegistry.addServerInfoRequestListener(serverInfoRequestListener);
+ }
+
+ List<ItemRequestListener> itemRequestListeners = new ArrayList<ItemRequestListener>();
+ addItemRequestListeners(itemRequestListeners);
+ for (ItemRequestListener itemRequestListener : itemRequestListeners) {
+ if (itemRequestListener == null) continue;
+ requestListenerRegistry.addItemRequestListener(itemRequestListener);
+ }
+
+ }
+
+ protected void addInfoRequestListeners(List<InfoRequestListener> infoRequestListeners) {
+ // emtpy default implementation
+ }
+
+ protected void addServerInfoRequestListeners(List<ServerInfoRequestListener> serverInfoRequestListeners) {
+ // emtpy default implementation
+ }
+
+ protected void addItemRequestListeners(List<ItemRequestListener> itemRequestListeners) {
+ // emtpy default implementation
+ }
+}
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultModule.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultModule.java?rev=713163&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultModule.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/DefaultModule.java Tue Nov 11 12:55:37 2008
@@ -0,0 +1,56 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.modules;
+
+import org.apache.vysper.xmpp.protocol.HandlerDictionary;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ */
+public abstract class DefaultModule implements Module {
+
+ public abstract String getName();
+
+ public abstract String getVersion();
+
+ public List<HandlerDictionary> getHandlerDictionaries() {
+ List<HandlerDictionary> dictionary = new ArrayList<HandlerDictionary>();
+ addHandlerDictionaries(dictionary);
+ return dictionary;
+ }
+
+ protected void addHandlerDictionaries(List<HandlerDictionary> dictionary) {
+ // empty default implementation
+ }
+
+ public List<ServerRuntimeContextService> getServerServices() {
+ List<ServerRuntimeContextService> serviceList = new ArrayList<ServerRuntimeContextService>();
+ addServerServices(serviceList);
+ return serviceList;
+ }
+
+ protected void addServerServices(List<ServerRuntimeContextService> serviceList) {
+ // empty default implementation
+ }
+
+ public void initialize(ServerRuntimeContext serverRuntimeContext) {
+ // empty default implementation
+ }
+}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/Module.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/Module.java?rev=713163&r1=713162&r2=713163&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/Module.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/Module.java Tue Nov 11 12:55:37 2008
@@ -17,6 +17,7 @@
package org.apache.vysper.xmpp.modules;
import org.apache.vysper.xmpp.protocol.HandlerDictionary;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
import java.util.List;
@@ -40,4 +41,14 @@
*/
List<ServerRuntimeContextService> getServerServices();
+ /**
+ * allows for the module to do some initialization in the light of the server runtime context
+ * it runs in. this can for example be used to hook up with service discovery.
+ * the server runtime context calls the initialize() method <i>after</i> the whole list of modules
+ * it has received has been processed with respect to HandlerDictionaries and
+ * ServerRuntimeContextService. if however, modules come late, e.g. they are added in a second batch
+ * this applies for all the second batch modules, but initialize() will not be called again for the
+ * first one.
+ */
+ void initialize(ServerRuntimeContext serverRuntimeContext);
}
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java?rev=713163&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java Tue Nov 11 12:55:37 2008
@@ -0,0 +1,87 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.modules.core.base.handler;
+
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.StanzaErrorCondition;
+import org.apache.vysper.xmpp.stanza.StanzaErrorType;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.server.response.ServerErrorResponses;
+import org.apache.vysper.xmpp.writer.DenseStanzaLogRenderer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * IQ implementation with default handling for get/set/error/result stanza types
+ * this is the recommended superclass for own handler implementations
+ */
+public abstract class DefaultIQHandler extends IQHandler {
+
+ final Logger logger = LoggerFactory.getLogger(DefaultIQHandler.class);
+
+ @Override
+ protected abstract boolean verifyNamespace(Stanza stanza);
+
+ @Override
+ protected Stanza executeIQLogic(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+
+ switch (stanza.getIQType()) {
+ case ERROR:
+ handleError(stanza, serverRuntimeContext, sessionContext);
+ return null;
+ case GET:
+ return handleGet(stanza, serverRuntimeContext, sessionContext);
+ case RESULT:
+ return handleResult(stanza, serverRuntimeContext, sessionContext);
+ case SET:
+ return handleSet(stanza, serverRuntimeContext, sessionContext);
+ default:
+ throw new RuntimeException("iq stanza type not supported: " + stanza.getIQType().value());
+ }
+ }
+
+ protected Stanza handleResult(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ logger.warn("IQ 'result' stanza not handled by {}: {}", getClass().getCanonicalName(), DenseStanzaLogRenderer.render(stanza));
+ return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.FEATURE_NOT_IMPLEMENTED, stanza,
+ StanzaErrorType.CANCEL,
+ "iq stanza of type 'result' is not handled for this namespace",
+ getErrorLanguage(serverRuntimeContext, sessionContext), null);
+ }
+
+ protected Stanza handleGet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ logger.warn("IQ 'get' stanza not handled by {}: {}", getClass().getCanonicalName(), DenseStanzaLogRenderer.render(stanza));
+ return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.FEATURE_NOT_IMPLEMENTED, stanza,
+ StanzaErrorType.CANCEL,
+ "iq stanza of type 'get' is not handled for this namespace",
+ getErrorLanguage(serverRuntimeContext, sessionContext), null);
+ }
+
+ protected void handleError(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ logger.warn("IQ 'error' stanza not handled by {}: {}", getClass().getCanonicalName(), DenseStanzaLogRenderer.render(stanza));
+ throw new RuntimeException("iq stanza type ERROR not yet handled");
+ }
+
+ protected Stanza handleSet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ logger.warn("IQ 'set' stanza not handled by {}: {}", getClass().getCanonicalName(), DenseStanzaLogRenderer.render(stanza));
+ return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.FEATURE_NOT_IMPLEMENTED, stanza,
+ StanzaErrorType.CANCEL,
+ "iq stanza of type 'set' is not handled for this namespace",
+ getErrorLanguage(serverRuntimeContext, sessionContext), null);
+ }
+}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/IQHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/IQHandler.java?rev=713163&r1=713162&r2=713163&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/IQHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/IQHandler.java Tue Nov 11 12:55:37 2008
@@ -34,6 +34,7 @@
/**
* handling IQ stanzas (request/response)
+ * @see org.apache.vysper.xmpp.modules.core.base.handler.DefaultIQHandler for your own IQ handler implementations
*/
public class IQHandler extends XMPPCoreStanzaHandler {
@@ -107,7 +108,7 @@
return executeIQLogic(stanza, serverRuntimeContext, sessionContext);
}
- private String getErrorLanguage(ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ protected String getErrorLanguage(ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
if (sessionContext != null) return sessionContext.getXMLLang();
return serverRuntimeContext.getDefaultXMLLang();
}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java?rev=713163&r1=713162&r2=713163&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java Tue Nov 11 12:55:37 2008
@@ -17,7 +17,6 @@
package org.apache.vysper.xmpp.modules.core.bind.handler;
-import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
import org.apache.vysper.xmpp.protocol.NamespaceURIs;
import org.apache.vysper.xmpp.server.SessionContext;
import org.apache.vysper.xmpp.server.ServerRuntimeContext;
@@ -28,11 +27,12 @@
import org.apache.vysper.xmpp.state.resourcebinding.BindException;
import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.modules.core.base.handler.DefaultIQHandler;
/**
* handles bind requests
*/
-public class BindIQHandler extends IQHandler {
+public class BindIQHandler extends DefaultIQHandler {
@Override
protected boolean verifyNamespace(Stanza stanza) {
@@ -40,28 +40,7 @@
}
@Override
- protected Stanza executeIQLogic(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
-
- switch (stanza.getIQType()) {
-
- case ERROR:
- new RuntimeException("iq stanza type ERROR not yet handled");
- case GET:
- new RuntimeException("iq stanza type GET not yet handled");
- break;
- case RESULT:
- new RuntimeException("iq stanza type RESULT not yet handled");
- break;
- case SET:
- return bindNewResource(stanza, sessionContext);
- default:
- new RuntimeException("iq stanza type not supported: " + stanza.getIQType());
- }
-
- return null;
- }
-
- private Stanza bindNewResource(IQStanza stanza, SessionContext sessionContext) {
+ protected Stanza handleSet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
// As per RFC3920.7, the client may propose a resource id to the server:
//
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java?rev=713163&r1=713162&r2=713163&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java Tue Nov 11 12:55:37 2008
@@ -16,18 +16,17 @@
***********************************************************************/
package org.apache.vysper.xmpp.modules.roster;
-import org.apache.vysper.xmpp.modules.Module;
+import org.apache.vysper.xmpp.modules.DefaultModule;
import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
import org.apache.vysper.xmpp.modules.roster.persistence.MemoryRosterManager;
import org.apache.vysper.xmpp.protocol.HandlerDictionary;
import java.util.List;
-import java.util.ArrayList;
/**
* all the roster stuff assembled in a module
*/
-public class RosterModule implements Module {
+public class RosterModule extends DefaultModule {
public String getName() {
return "roster";
@@ -37,16 +36,13 @@
return "1.0beta";
}
- public List<HandlerDictionary> getHandlerDictionaries() {
- List<HandlerDictionary> dictionary = new ArrayList<HandlerDictionary>();
+ @Override
+ protected void addHandlerDictionaries(List<HandlerDictionary> dictionary) {
dictionary.add(new RosterDictionary());
- return dictionary;
}
- public List<ServerRuntimeContextService> getServerServices() {
- List<ServerRuntimeContextService> serviceList = new ArrayList<ServerRuntimeContextService>();
+ @Override
+ protected void addServerServices(List<ServerRuntimeContextService> serviceList) {
serviceList.add(new MemoryRosterManager());
- return serviceList;
}
-
}
\ No newline at end of file
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandler.java?rev=713163&r1=713162&r2=713163&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/handler/RosterIQHandler.java Tue Nov 11 12:55:37 2008
@@ -20,7 +20,7 @@
import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.addressing.EntityFormatException;
import org.apache.vysper.xmpp.addressing.EntityImpl;
-import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
+import org.apache.vysper.xmpp.modules.core.base.handler.DefaultIQHandler;
import org.apache.vysper.xmpp.modules.roster.AskSubscriptionType;
import org.apache.vysper.xmpp.modules.roster.Roster;
import org.apache.vysper.xmpp.modules.roster.RosterBadRequestException;
@@ -57,7 +57,7 @@
/**
* handles roster get, set, push & result requests
*/
-public class RosterIQHandler extends IQHandler {
+public class RosterIQHandler extends DefaultIQHandler {
final Logger logger = LoggerFactory.getLogger(RosterIQHandler.class);
@@ -67,33 +67,10 @@
}
@Override
- protected Stanza executeIQLogic(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ protected Stanza handleGet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
- // TODO check the session for resource state
-
- switch (stanza.getIQType()) {
-
- case ERROR:
- new RuntimeException("iq stanza type ERROR not yet handled");
- case GET:
- return retrieveRoster(stanza, sessionContext);
- case RESULT:
- new RuntimeException("iq stanza type RESULT not yet handled");
- break;
- case SET:
- return handleRosterSet(stanza, sessionContext);
- default:
- new RuntimeException("iq stanza type not supported: " + stanza.getIQType());
- }
-
- return null;
- }
-
- private Stanza retrieveRoster(IQStanza stanza, SessionContext sessionContext) {
-
- ServerRuntimeContext serverContext = sessionContext.getServerRuntimeContext();
- ResourceRegistry registry = serverContext.getResourceRegistry();
- RosterManager rosterManager = (RosterManager)serverContext.getServerRuntimeContextService(RosterManager.SERVER_SERVICE_ROSTERMANAGER);
+ ResourceRegistry registry = serverRuntimeContext.getResourceRegistry();
+ RosterManager rosterManager = (RosterManager)serverRuntimeContext.getServerRuntimeContextService(RosterManager.SERVER_SERVICE_ROSTERMANAGER);
if (rosterManager == null) {
return handleCannotRetrieveRoster(stanza, sessionContext);
@@ -157,10 +134,10 @@
</iq>
*/
- protected Stanza handleRosterSet(IQStanza stanza, SessionContext sessionContext) {
- ServerRuntimeContext serverContext = sessionContext.getServerRuntimeContext();
- ResourceRegistry registry = serverContext.getResourceRegistry();
- RosterManager rosterManager = (RosterManager)serverContext.getServerRuntimeContextService(RosterManager.SERVER_SERVICE_ROSTERMANAGER);
+ @Override
+ protected Stanza handleSet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ ResourceRegistry registry = serverRuntimeContext.getResourceRegistry();
+ RosterManager rosterManager = (RosterManager)serverRuntimeContext.getServerRuntimeContextService(RosterManager.SERVER_SERVICE_ROSTERMANAGER);
if (rosterManager == null) {
return handleCannotRetrieveRoster(stanza, sessionContext);
@@ -209,7 +186,7 @@
return RosterStanzaUtils.createRosterItemIQ(user, stanza.getID(), IQStanzaType.RESULT, existingItem);
}
- private RosterItem parseRosterItem(IQStanza stanza) throws RosterBadRequestException, RosterNotAcceptableException {
+ protected RosterItem parseRosterItem(IQStanza stanza) throws RosterBadRequestException, RosterNotAcceptableException {
XMLElement queryElement;
try {
queryElement = stanza.getSingleInnerElementsNamed("query");
@@ -273,7 +250,7 @@
return rosterItem;
}
- private Stanza handleCannotRetrieveRoster(IQStanza stanza, SessionContext sessionContext) {
+ protected Stanza handleCannotRetrieveRoster(IQStanza stanza, SessionContext sessionContext) {
throw new RuntimeException("gracefully handling roster management problem not implemented");
}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryModule.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryModule.java?rev=713163&r1=713162&r2=713163&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryModule.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/ServiceDiscoveryModule.java Tue Nov 11 12:55:37 2008
@@ -16,18 +16,17 @@
***********************************************************************/
package org.apache.vysper.xmpp.modules.servicediscovery;
-import org.apache.vysper.xmpp.modules.Module;
+import org.apache.vysper.xmpp.modules.DefaultModule;
import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
import org.apache.vysper.xmpp.modules.servicediscovery.collection.ServiceCollector;
import org.apache.vysper.xmpp.protocol.HandlerDictionary;
-import java.util.ArrayList;
import java.util.List;
/**
* all the roster stuff assembled in a module
*/
-public class ServiceDiscoveryModule implements Module {
+public class ServiceDiscoveryModule extends DefaultModule {
public String getName() {
return "servicediscovery";
@@ -37,16 +36,13 @@
return "1.0beta";
}
- public List<HandlerDictionary> getHandlerDictionaries() {
- List<HandlerDictionary> dictionary = new ArrayList<HandlerDictionary>();
+ @Override
+ protected void addHandlerDictionaries(List<HandlerDictionary> dictionary) {
dictionary.add(new ServiceDiscoveryDictionary());
- return dictionary;
}
- public List<ServerRuntimeContextService> getServerServices() {
- List<ServerRuntimeContextService> serviceList = new ArrayList<ServerRuntimeContextService>();
+ @Override
+ protected void addServerServices(List<ServerRuntimeContextService> serviceList) {
serviceList.add(new ServiceCollector());
- return serviceList;
}
-
}
\ 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=713163&r1=713162&r2=713163&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 Tue Nov 11 12:55:37 2008
@@ -16,10 +16,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.ServerRuntimeContextService;
import java.util.ArrayList;
import java.util.List;
@@ -28,10 +28,8 @@
* on an item or info requests, calls all related listeners and collects what they have to add to the
* response. compiles the responded infos and items.
*/
-public class ServiceCollector implements ServerRuntimeContextService {
+public class ServiceCollector implements ServerRuntimeContextService, ServiceDiscoveryRequestListenerRegistry {
- public static final String SERVICE_DISCOVERY_COLLECTOR = "serviceDiscoveryCollector";
-
protected List<InfoRequestListener> infoRequestListeners = new ArrayList<InfoRequestListener>();
protected List<ServerInfoRequestListener> serverInfoRequestListeners = new ArrayList<ServerInfoRequestListener>();
protected List<ItemRequestListener> itemRequestListeners = new ArrayList<ItemRequestListener>();
@@ -49,6 +47,6 @@
}
public String getServiceName() {
- return SERVICE_DISCOVERY_COLLECTOR;
+ return SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY;
}
}
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceDiscoveryRequestListenerRegistry.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceDiscoveryRequestListenerRegistry.java?rev=713163&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceDiscoveryRequestListenerRegistry.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/collection/ServiceDiscoveryRequestListenerRegistry.java Tue Nov 11 12:55:37 2008
@@ -0,0 +1,34 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.modules.servicediscovery.collection;
+
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoRequestListener;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ServerInfoRequestListener;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ItemRequestListener;
+
+/**
+ */
+public interface ServiceDiscoveryRequestListenerRegistry {
+
+ public static final String SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY = "discoRequestListenerRegistry";
+
+ void addInfoRequestListener(InfoRequestListener infoRequestListener);
+
+ void addServerInfoRequestListener(ServerInfoRequestListener infoRequestListener);
+
+ void addItemRequestListener(ItemRequestListener itemRequestListener);
+}
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=713163&r1=713162&r2=713163&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 Tue Nov 11 12:55:37 2008
@@ -17,7 +17,7 @@
package org.apache.vysper.xmpp.modules.servicediscovery.handler;
-import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
+import org.apache.vysper.xmpp.modules.core.base.handler.DefaultIQHandler;
import org.apache.vysper.xmpp.protocol.NamespaceURIs;
import org.apache.vysper.xmpp.server.ServerRuntimeContext;
import org.apache.vysper.xmpp.server.SessionContext;
@@ -29,7 +29,7 @@
/**
* handles roster get, set, push & result requests
*/
-public class DiscoInfoIQHandler extends IQHandler {
+public class DiscoInfoIQHandler extends DefaultIQHandler {
final Logger logger = LoggerFactory.getLogger(DiscoInfoIQHandler.class);
@@ -39,30 +39,7 @@
}
@Override
- protected Stanza executeIQLogic(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
-
- switch (stanza.getIQType()) {
-
- case ERROR:
- new RuntimeException("disco info stanza type ERROR not yet handled");
- case GET:
- return retrieveInfoItems(stanza, sessionContext);
- case RESULT:
- new RuntimeException("disco info stanza type RESULT not yet handled");
- break;
- case SET:
- new RuntimeException("disco info stanza type RESULT not yet handled");
- break;
- default:
- new RuntimeException("disco info stanza type not supported: " + stanza.getIQType());
- }
-
- return null;
+ protected Stanza handleGet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) {
+ return super.handleGet(stanza, serverRuntimeContext, sessionContext);
}
-
- protected Stanza retrieveInfoItems(IQStanza stanza, SessionContext sessionContext) {
- return null;
- }
-
-
}
\ No newline at end of file
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java?rev=713163&r1=713162&r2=713163&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java Tue Nov 11 12:55:37 2008
@@ -201,6 +201,9 @@
for (Module module : modules) {
addModule(module);
}
+ for (Module module : modules) {
+ module.initialize(this);
+ }
}
public void addModule(Module module) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org