final Class<?> cls = exceptionType.getPhysical();
if (cls == FaultException.class) {
return true;
}
DataType faultType = (DataType)exceptionType.getLogical();
Class<?> faultBean = null;
final WebFault fault = cls.getAnnotation(WebFault.class);
if (fault != null) {
if (!"".equals(fault.name()) || !"".equals(fault.targetNamespace())) {
QName faultQName = ((XMLType)faultType.getLogical()).getElementName();
String faultNS =
"".equals(fault.targetNamespace()) ? faultQName.getNamespaceURI() : fault.targetNamespace();
String faultLocal = "".equals(fault.name()) ? faultQName.getLocalPart() : fault.name();
faultName = new QName(faultNS, faultLocal);
XMLType xmlType = new XMLType(faultName, null);
faultType.setLogical(xmlType);
}
if (!"".equals(fault.faultBean())) {
faultBean = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
public Class<?> run() {
try {
return Class.forName(fault.faultBean(), false, cls.getClassLoader());
} catch (ClassNotFoundException e) {
throw new ServiceRuntimeException(e);
}
}
});
} else {
Method m;
try {
m = cls.getMethod("getFaultInfo", (Class[])null);
faultBean = m.getReturnType();
} catch (NoSuchMethodException e) {
// Ignore
}
}
}
if (faultBean == null) {
final String faultBeanClassName = CodeGenerationHelper.getPackagePrefix(cls) + cls.getSimpleName() + "Bean";
final QName qname = faultName;
faultType = AccessController.doPrivileged(new PrivilegedAction<DataType<XMLType>>() {
public DataType<XMLType> run() {
try {
Class<?> faultBean = Class.forName(faultBeanClassName, false, cls.getClassLoader());
return new DataTypeImpl<XMLType>(faultBean, new XMLType(qname, qname));
} catch (ClassNotFoundException e) {
if (generatingFaultBean) {
Class<? extends Throwable> t = (Class<? extends Throwable>)cls;
ClassLoader parent =
operation == null ? t.getClassLoader() : ((JavaInterface)operation.getInterface())
.getJavaClass().getClassLoader();
GeneratedClassLoader cl = new GeneratedClassLoader(parent);
GeneratedDataTypeImpl dt = new GeneratedDataTypeImpl(xmlAdapterExtensionPoint, t, cl);
return dt;
} else {
return new DataTypeImpl<XMLType>(cls, new XMLType(qname, qname));
}
}
}
});
} else {
faultType.setDataBinding(null);
faultType.setGenericType(faultBean);
faultType.setPhysical(faultBean);
}
// TODO: Use the databinding framework to introspect the fault bean class
if (faultType.getDataBinding() == null && dataBindingExtensionPoint != null) {
faultBean = faultType.getPhysical();
result =
dataBindingExtensionPoint.introspectType(faultType, operation);
}
((DataType) exceptionType).setLogical(faultType);
/*
The introspection of the fault DT may not have calculated the correct element name,
though we may have already done this in this method. Let's look at the DataType now
that introspection is done, and, if it has an XMLType, let's set the element to the
'faultName' if we calculated one.
*/
if ((faultName != null) && (faultType.getLogical() instanceof XMLType)) {
XMLType faultTypeXML = (XMLType)faultType.getLogical();
// The element name (if set) should match the fault name
faultTypeXML.setElementName(faultName);
}
return result;