I'm trying to make a ServletContextListener that will add my custom lifecycle to the default lifecycle factory with a specified key. However, when I try to get the LifecycleFactory from within the ServletContextListener, the FactoryFinder returns null. I didn't think this was supposed to happen, but I consulted the source and discovered that that would probably be the case. However, another quandry came about after looking at the source. I don't really understand where in the FactoryFinder it gets the default implementations. It seems that unless there is some initialization going on outside the FactoryFinder class, the FactoryFinder should always return null no matter what. What's the deal?
Here is the code below:
public void contextInitialized(ServletContextEvent event) {
try {
// get this application's LifecycleFactory
// lifecycleFactory will be null
LifecycleFactory lifecycleFactory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
// get the default Lifecycle
// throws NullPointerException
Lifecycle lifecycle =
lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
// create a new ApplicationLifecycle from the default Lifecycle
ApplicationLifecycle appLifecycle = new ApplicationLifecycle(lifecycle);
// add the ApplicationLifecycle to the LifecycleFactory with an id
// corresponding to the ApplicationLifecycle's fully qualified name.
lifecycleFactory.addLifecycle(ApplicationLifecycle.class.getName(), appLifecycle);
} catch (Throwable t) {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
t.printStackTrace(System.out);
throw new RuntimeException(t.getMessage());
}
}