Object object = null;
String scope = creator.getScope();
boolean create = false;
if (!Modifier.isStatic(method.getModifiers()))
{
WebContext webcx = WebContextFactory.get();
// Check the various scopes to see if it is there
if (scope.equals(Creator.APPLICATION))
{
object = webcx.getServletContext().getAttribute(getName());
}
else if (scope.equals(Creator.SESSION))
{
object = webcx.getSession().getAttribute(getName());
}
else if (scope.equals(Creator.SCRIPT))
{
object = webcx.getScriptSession().getAttribute(getName());
}
else if (scope.equals(Creator.REQUEST))
{
object = webcx.getHttpServletRequest().getAttribute(getName());
}
// Creator.PAGE scope means we create one every time anyway
// If we don't have an object then call the creator
try
{
if (object == null)
{
create = true;
object = creator.getInstance();
}
}
catch (InstantiationException ex)
{
// Allow Jetty RequestRetry exception to propagate to container
Continuation.rethrowIfContinuation(ex);
// We should log this regardless of the accessLogLevel.
log.info("Error creating an instance of the following DWR Creator: " + ((null != creator.getClass()) ? creator.getClass().getName() : "None Specified") + ".", ex);
throw ex;
}
// Remember it for next time
if (create)
{
if (scope.equals(Creator.APPLICATION))
{
// This might also be done at application startup by
// DefaultCreatorManager.addCreator(String, Creator)
webcx.getServletContext().setAttribute(getName(), object);
}
else if (scope.equals(Creator.SESSION))
{
webcx.getSession().setAttribute(getName(), object);
}
else if (scope.equals(Creator.SCRIPT))
{
webcx.getScriptSession().setAttribute(getName(), object);
}
else if (scope.equals(Creator.REQUEST))
{
webcx.getHttpServletRequest().setAttribute(getName(), object);
}
// Creator.PAGE scope means we create one every time anyway
}
}