package net.gtaun.shoebill.common;

import net.gtaun.util.event.EventManager;

public class ShoebillContextManager extends AbstractShoebillContext
{
	public ShoebillContextManager(EventManager parentEventManager)
	{
		super(parentEventManager);
	}

	@Override
	protected void onInit()
	{

	}

	@Override
	protected void onDestroy()
	{

	}

	public <ContextType extends AbstractShoebillContext>
	ContextType manage(ContextType context)
	{
		addDestroyable(context);
		context.init();
		return context;
	}

	public void destroy(AbstractShoebillContext context)
	{
		context.destroy();
		removeDestroyable(context);
	}
}

@@ -72,16 +72,37 @@
 nager;%0A%0A
+import java.util.*;%0A%0A
 public c
@@ -163,16 +163,140 @@
 ntext%0A%7B%0A
+%09private Map%3CClass%3C? extends AbstractShoebillContext%3E, Set%3CAbstractShoebillContext%3E%3E contextContainers = new HashMap%3C%3E();%0A%0A%0A
 %09public 
@@ -582,178 +582,1489 @@
 %7B%0A%09%09
-addDestroyable(context);%0A%09%09context.init();%0A%09%09return context;%0A%09%7D%0A%0A%09public void destroy(AbstractShoebillContext context)%0A%09%7B%0A%09%09context.destroy();%0A%09%09removeDestroyable(context
+Class%3C? extends AbstractShoebillContext%3E clazz = context.getClass();%0A%09%09Set%3CAbstractShoebillContext%3E contextCotainer = contextContainers.get(clazz);%0A%09%09if (contextCotainer == null)%0A%09%09%7B%0A%09%09%09contextCotainer = new HashSet%3C%3E();%0A%09%09%09contextContainers.put(clazz, contextCotainer);%0A%09%09%7D%0A%0A%09%09if (contextCotainer.contains(context)) return context;%0A%09%09contextCotainer.add(context);%0A%0A%09%09addDestroyable(context);%0A%09%09context.init();%0A%09%09return context;%0A%09%7D%0A%0A%09public void destroy(AbstractShoebillContext context)%0A%09%7B%0A%09%09Class%3C? extends AbstractShoebillContext%3E clazz = context.getClass();%0A%09%09Set%3CAbstractShoebillContext%3E contextCotainer = contextContainers.get(clazz);%0A%09%09if (contextCotainer == null) return;%0A%09%09contextCotainer.remove(context);%0A%0A%09%09context.destroy();%0A%09%09removeDestroyable(context);%0A%09%7D%0A%0A%09public %3CContextType extends AbstractShoebillContext%3E%0A%09ContextType get(Class%3CContextType%3E clazz)%0A%09%7B%0A%09%09Set%3CAbstractShoebillContext%3E contextCotainer = contextContainers.get(clazz);%0A%09%09if (contextCotainer == null %7C%7C contextCotainer.isEmpty()) return null;%0A%09%09AbstractShoebillContext context = contextCotainer.iterator().next();%0A%09%09return clazz.cast(context);%0A%09%7D%0A%0A%09public %3CContextType extends AbstractShoebillContext%3E%0A%09Set%3CContextType%3E getContexts(Class%3CContextType%3E clazz)%0A%09%7B%0A%09%09Set%3CAbstractShoebillContext%3E contextCotainer = contextContainers.get(clazz);%0A%09%09if (contextCotainer == null %7C%7C contextCotainer.isEmpty()) return Collections.emptySet();%0A%09%09return (Set%3CContextType%3E) Collections.unmodifiableSet(contextCotainer
 );%0A%09

Add ShoebillContextManager.get() and getContexts()