package research.align;
import manager.ManagerInterface;
import manager.IllegalParameterException;
import context.Context;
import component.FComponent;
import javax.swing.*;
import java.util.Hashtable;
/**
* Created by IntelliJ IDEA.
* User: saturn
* Date: 2003-10-15
* Time: 20:31:20
* To change this template use Options | File Templates.
*/
public class Manager implements ManagerInterface, ConstantDefinition{
public static ManagerInterface getInstance() {
return new Manager();
}
protected Context cont = null;
protected Manager() {
if (cont == null) {
try {
cont = (Context) context.Manager.getInstance().getInstance(context.Manager.CONTEXT, Context.class);
} catch (IllegalParameterException ipe) {
//nerver arrive here
}
}
}
public Context getContext() {
return cont;
}
public Object getInstance(String name, Class type) throws IllegalParameterException {
if((!ALIGN_AND_DISTRIBUTION_SERVICE_NAME.equals(name))||(!FComponent.class.equals(type)))
throw new IllegalParameterException("IllegalParameterException");
AlignAndDistService alignAndDistService = new AlignAndDistService();
Context cont = alignAndDistService.getContext();
ActionMap actionMap = alignAndDistService.getActionMap();
Hashtable interfaces = new Hashtable();
Hashtable classes = new Hashtable();
interfaces.put(CONTEXT_INTERFACE, cont);
classes.put(CONTEXT_INTERFACE, Context.class);
Object[] keys = actionMap.keys();
for(int i = 0; i < keys.length; i++){
interfaces.put(keys[i], actionMap.get(keys[i]));
classes.put(keys[i], Action.class);
}
ManagerInterface mi = component.Manager.getInstance();
mi.getContext().putValue(component.Manager.INTERFACES, interfaces);
mi.getContext().putValue(component.Manager.CLASSES, classes);
mi.getContext().putValue(component.Manager.NAME, ALIGN_AND_DISTRIBUTION_SERVICE_NAME);
try {
return (FComponent) mi.getInstance(component.Manager.NGOBJECT, FComponent.class);
}
catch(IllegalParameterException ipe){
return null;
}
}
}