package jfun.yan.xfire;
import javax.servlet.ServletContext;
import org.codehaus.xfire.service.Service;
import jfun.yan.Components;
import jfun.yan.Container;
import jfun.yan.factory.Factory;
import jfun.yan.web.YanLoader;
import jfun.yan.xml.NutsProcessor;
import jfun.yan.xml.nut.NutDescriptor;
import jfun.yan.xml.nut.NutIntrospector;
/**
* A loader for loading xfire aware NutsProcessor object.
* <p>
* @author Ben Yu
* Feb 5, 2006 4:17:51 PM
*/
public class XFireLoader extends YanLoader {
private final Object xfire_name;
private static final NutIntrospector introspector = new NutIntrospector();
protected void decorateProcessor(NutsProcessor processor, ServletContext ctxt) throws Exception {
super.decorateProcessor(processor, ctxt);
final NutDescriptor desc = introspector.getNutDescriptor(ServiceNut.class);
desc.setFactory(new Factory(){
public Object create(){
return new ServiceNut(Components.useKey(xfire_name));
}
});
processor.registerNut("service", desc);
}
public synchronized Container initContainer(ClassLoader cloader, ServletContext servletContext) {
final Container yan = super.initContainer(cloader, servletContext);
//eagerly instantiate all exported Service.
yan.getInstancesOfType(Service.class);
return yan;
}
/**
* To create a XFireLoader object.
* @param xfire_name the key of the xfire object.
*/
public XFireLoader(Object xfire_name) {
this.xfire_name = xfire_name;
}
}