package org.concord.otrunk.util;

import java.util.Vector;

import org.concord.framework.otrunk.OTObject;

/**
 * 
 * @author sfentress
 *
 */
public class OTSharingManagerImpl implements OTSharingManager
{
	private OTSharingBundle.ResourceSchema registry;
	
	public OTSharingManagerImpl(OTSharingBundle.ResourceSchema registry)
	{
		this.registry = registry;
	}
	
	/**
	 * 
	 * @return all objects being shared
	 */
	public Vector getAllSharedObjects(){
		return registry.getSharedObjects().getVector();
	}
	
	/**
	 * 
	 * @param clazz specific class of object
	 * @return all shared objects of type clazz
	 */
	public Vector getAllSharedObjects(Class clazz){
		Vector allObjects = getAllSharedObjects();
		Vector clazzObjects = new Vector();
		for (int i = 0; i < allObjects.size(); i++) {
			Object obj = allObjects.get(i);
	        if (clazz.isAssignableFrom(obj.getClass())){
	        	clazzObjects.add(obj);
	        }
        }
		return clazzObjects;
	}
	
	/**
	 * This will add the object to the list, if it isn't already there.
	 * 
	 * This should really only add the reference to this
	 * object, but as it stands, it might move the object
	 * from its original location to the shared objects
	 * list...
	 * 
	 * @param obj The OTObject to be shared
	 */
	public void share(OTObject obj){
		if (!registry.getSharedObjects().getVector().contains(obj)){
			registry.getSharedObjects().add(obj);
		}
	}
	
	public void remove(OTObject obj)
    {
	    registry.getSharedObjects().remove(obj);
    }

}

@@ -599,16 +599,58 @@
 pe clazz
+. If null, all shared objects are returned
 %0A%09 */%0A%09p
@@ -741,16 +741,64 @@
 ects();%0A
+%09%09if (clazz == null)%7B%0A%09%09%09return allObjects;%0A%09%09%7D%0A
 %09%09Vector

update sharing manager so filter class can be null