Commit 86fb6e82 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

no message


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@267 b35dd754-fafc-0310-a699-88a17e54d16e
parent 70b96a67
package org.jivesoftware.messenger;
public interface Component {
void processPacket(XMPPPacket packet);
}
package org.jivesoftware.messenger;
import java.util.HashMap;
import java.util.Map;
import org.jivesoftware.util.StringUtils;
public class ComponentManager {
private Map<String, Component> components = new HashMap<String, Component>();
static private ComponentManager singleton;
private final static Object LOCK = new Object();
/**
* Returns the singleton instance of <CODE>ComponentManager</CODE>,
* creating it if necessary.
* <p/>
*
* @return the singleton instance of <Code>UserManager</CODE>
*/
public static ComponentManager getInstance() {
// Synchronize on LOCK to ensure that we don't end up creating
// two singletons.
synchronized (LOCK) {
if (null == singleton) {
ComponentManager controller = new ComponentManager();
singleton = controller;
return controller;
}
}
return singleton;
}
private ComponentManager() {
}
public void addComponent(String jid, Component component){
jid = validateJID(jid);
components.put(jid, component);
}
public void removeComponent(String jid){
components.remove(validateJID(jid));
}
public Component getComponent(String jid){
if(components.containsKey(validateJID(jid))){
return components.get(validateJID(jid));
}
else {
String serverName = StringUtils.parseServer(validateJID(jid));
int index = serverName.indexOf(".");
if(index != -1){
String serviceName = serverName.substring(0, index);
jid = serviceName;
}
}
return components.get(validateJID(jid));
}
private String validateJID(String jid){
jid = jid.trim().toLowerCase();
return jid;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment