*
* @param accessor The accessor.
* @return The XML type, or null if none was specified.
*/
public static XmlType findExplicitSchemaType(Accessor accessor) {
TypeMirror typeMirror = unwrapComponentType(accessor.getAccessorType());
XmlType xmlType = null;
XmlSchemaType schemaType = accessor.getAnnotation(XmlSchemaType.class);
if ((schemaType == null) && (typeMirror instanceof DeclaredType)) {
PackageDeclaration pckg = accessor.getDeclaringType().getPackage();
String packageName = pckg.getQualifiedName();
HashMap<String, XmlSchemaType> explicitTypes = EXPLICIT_ELEMENTS_BY_PACKAGE.get(packageName);
if (explicitTypes == null) {
explicitTypes = new HashMap<String, XmlSchemaType>();
EXPLICIT_ELEMENTS_BY_PACKAGE.put(packageName, explicitTypes);
XmlSchemaType schemaTypeInfo = pckg.getAnnotation(XmlSchemaType.class);
XmlSchemaTypes schemaTypes = pckg.getAnnotation(XmlSchemaTypes.class);
if ((schemaTypeInfo != null) || (schemaTypes != null)) {
ArrayList<XmlSchemaType> allSpecifiedTypes = new ArrayList<XmlSchemaType>();
if (schemaTypeInfo != null) {
allSpecifiedTypes.add(schemaTypeInfo);
}
if (schemaTypes != null) {
allSpecifiedTypes.addAll(Arrays.asList(schemaTypes.value()));
}
for (XmlSchemaType specifiedType : allSpecifiedTypes) {
String typeFqn;
try {
Class specifiedClass = specifiedType.type();
if (specifiedClass == XmlSchemaType.DEFAULT.class) {
throw new ValidationException(pckg.getPosition(), pckg.getQualifiedName() + ": a type must be specified in " + XmlSchemaType.class.getName() + " at the package-level.");
}
typeFqn = specifiedClass.getName();
}
catch (MirroredTypeException e) {
TypeMirror explicitTypeMirror = e.getTypeMirror();
if (!(explicitTypeMirror instanceof DeclaredType)) {
throw new ValidationException(pckg.getPosition(), pckg.getQualifiedName() + ": only a declared type can be adapted. Offending type: " + explicitTypeMirror);
}
typeFqn = ((DeclaredType) explicitTypeMirror).getDeclaration().getQualifiedName();
}