labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gse...@apache.org
Subject svn commit: r652483 - /labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
Date Thu, 01 May 2008 11:50:23 GMT
Author: gseitz
Date: Thu May  1 04:50:23 2008
New Revision: 652483

URL: http://svn.apache.org/viewvc?rev=652483&view=rev
Log:
[vysper] added methods to retrieve available/interested resources

Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java?rev=652483&r1=652482&r2=652483&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
Thu May  1 04:50:23 2008
@@ -51,13 +51,13 @@
 
 	public String bindSession(SessionContext sessionContext) {
 		if (sessionContext == null) {
-            throw new IllegalArgumentException("session context cannot be NULL");
-        }
-        if (sessionContext.getInitiatingEntity() == null) {
-            throw new IllegalStateException(
-                                "session context must have a initiating entity set");
-        }
-        String resourceId = resourceIdGenerator.create();
+			throw new IllegalArgumentException("session context cannot be NULL");
+		}
+		if (sessionContext.getInitiatingEntity() == null) {
+			throw new IllegalStateException(
+					"session context must have a initiating entity set");
+		}
+		String resourceId = resourceIdGenerator.create();
 
 		synchronized (boundResources) {
 			synchronized (entityResources) {
@@ -138,12 +138,14 @@
 
 	public SessionContext getSessionContext(String resourceId) {
 		SessionData data = boundResources.get(resourceId);
-        if (data == null) return null;
-        return data.context;
+		if (data == null)
+			return null;
+		return data.context;
 	}
 
 	private Entity getBareEntity(Entity entity) {
-		if (!entity.isResourceSet()) return entity; // bare already
+		if (!entity.isResourceSet())
+			return entity; // bare already
 		return new EntityImpl(entity.getNode(), entity.getDomain(), null);
 	}
 
@@ -203,8 +205,10 @@
 	 */
 	public void setResourceState(String resourceId, ResourceState state) {
 		SessionData data = boundResources.get(resourceId);
-        if (data == null) throw new IllegalArgumentException("resource not registered: "
+ resourceId);
-        data.state = state;
+		if (data == null)
+			throw new IllegalArgumentException("resource not registered: "
+					+ resourceId);
+		data.state = state;
 	}
 
 	/**
@@ -216,8 +220,9 @@
 	 */
 	public ResourceState getResourceState(String resourceId) {
 		SessionData data = boundResources.get(resourceId);
-        if (data == null) return null;
-        return data.state;
+		if (data == null)
+			return null;
+		return data.state;
 	}
 
 	/**
@@ -252,4 +257,28 @@
 	public boolean isResourceInterested(String resourceId) {
 		return ResourceState.INTERESTED.equals(getResourceState(resourceId));
 	}
+
+	public List<String> getInterestedResources(Entity entity) {
+		return filterResources(entity, ResourceState.INTERESTED);
+	}
+
+	public List<String> getAvailableResources(Entity entity) {
+		return filterResources(entity, ResourceState.AVAILABLE);
+	}
+
+	private List<String> filterResources(Entity entity, ResourceState state) {
+		if (state == null || entity == null) {
+			throw new IllegalArgumentException(
+					"entity or resourcestate must not be null");
+		}
+
+		List<String> resources = getResourceList(entity);
+		List<String> result = new ArrayList<String>();
+		for (String resource : resources) {
+			if (state.equals(getResourceState(resource))) {
+				result.add(resource);
+			}
+		}
+		return result;
+	}
 }



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


Mime
View raw message