public static void setContextEvent(final ServletContextEvent contextEvent) throws DeployerException {
// First, try to get the source on the given context event
Object source = contextEvent.getSource();
if (source == null) {
throw new DeployerException("No source object on the given contextEvent '" + contextEvent + "'.");
}
// try to get getContextHandler method on this source object
Method getContextHandlerMethod = getMethod(source.getClass(), "getContextHandler");
if (getContextHandlerMethod == null) {
throw new DeployerException("No getContextHandler method was found on the '" + source + "' object");
}
// get Handler
Object contextHandler = invoke(getContextHandlerMethod, source);
if (contextHandler == null) {
throw new DeployerException("No context handler object was returned from the '" + source + "' object");
}
// get the getServer method
Method getServerMethod = getMethod(contextHandler.getClass(), "getServer");
if (getServerMethod == null) {
throw new DeployerException("No getServer method was found on the '" + contextHandler + "' object");
}
// Set the jetty server
jettyServer = invoke(getServerMethod, contextHandler);
// No server ?
if (jettyServer == null) {
throw new DeployerException("No Jetty server found on the servlet context event '" + contextEvent + "'.");
}
}