}
else
code=Integer.valueOf(error);
String location = node.getString("location", false, true);
ErrorPageErrorHandler handler = (ErrorPageErrorHandler)context.getErrorHandler();
switch (context.getMetaData().getOrigin("error."+error))
{
case NotSet:
{
//no error page setup for this code or exception yet
if (code>0)
handler.addErrorPage(code,location);
else
handler.addErrorPage(error,location);
context.getMetaData().setOrigin("error."+error, descriptor);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//an error page setup was set in web.xml, only allow other web xml descriptors to override it
if (!(descriptor instanceof FragmentDescriptor))
{
if (descriptor instanceof OverrideDescriptor || descriptor instanceof DefaultsDescriptor)
{
if (code>0)
handler.addErrorPage(code,location);
else
handler.addErrorPage(error,location);
context.getMetaData().setOrigin("error."+error, descriptor);
}
else
throw new IllegalStateException("Duplicate global error-page "+location);
}
break;
}
case WebFragment:
{
//another web fragment set the same error code or exception, if its different its an error
if (!handler.getErrorPages().get(error).equals(location))
throw new IllegalStateException("Conflicting error-code or exception-type "+error+" in "+descriptor.getResource());
break;
}
default:
LOG.warn(new Throwable()); // TODO throw ISE?