/** * Finds the interface type that declares that the specified declaration implements XmlAdapter. * * @param declaration The declaration. * @return The interface type, or null if none found. */ private static ClassType findXmlAdapterType(ClassDeclaration declaration) { if (Object.class.getName().equals(declaration.getQualifiedName())) { return null; } ClassType superClass = declaration.getSuperclass(); if (XmlAdapter.class.getName().equals(superClass.getDeclaration().getQualifiedName())) { return superClass; } return findXmlAdapterType(superClass.getDeclaration()); }
/** * Finds the interface type that declares that the specified declaration implements XmlAdapter. * * @param declaration The declaration. * @return The interface type, or null if none found. */ private static ClassType findXmlAdapterType(ClassDeclaration declaration) { if (Object.class.getName().equals(declaration.getQualifiedName())) { return null; } ClassType superClass = declaration.getSuperclass(); if (XmlAdapter.class.getName().equals(superClass.getDeclaration().getQualifiedName())) { return superClass; } return findXmlAdapterType(superClass.getDeclaration()); }
public AdapterType(ClassType adapterType) { super(adapterType); ClassDeclaration adapterDeclaration = adapterType.getDeclaration(); ClassType adaptorInterfaceType = findXmlAdapterType(adapterDeclaration); if (adaptorInterfaceType == null) { throw new ValidationException(adapterDeclaration.getPosition(), adapterDeclaration.getQualifiedName() + " is not an instance of javax.xml.bind.annotation.adapters.XmlAdapter."); } Collection<TypeMirror> adaptorTypeArgs = adaptorInterfaceType.getActualTypeArguments(); if ((adaptorTypeArgs == null) || (adaptorTypeArgs.size() != 2)) { throw new ValidationException(adapterDeclaration.getPosition(), adapterDeclaration.getQualifiedName() + " must specify both a value type and a bound type."); } Iterator<TypeMirror> formalTypeIt = adaptorTypeArgs.iterator(); this.adaptingType = formalTypeIt.next(); TypeMirror boundTypeMirror = formalTypeIt.next(); if (!(boundTypeMirror instanceof DeclaredType)) { throw new ValidationException(adapterDeclaration.getPosition(), "Illegal XML adapter: not adapting a declared type (" + boundTypeMirror + ")."); } this.adaptedType = (DeclaredType) boundTypeMirror; }
ClassType adaptorInterfaceType = findXmlAdapterType(adapterDeclaration); if (adaptorInterfaceType == null) { throw new ValidationException(adapterDeclaration.getPosition(), adapterDeclaration.getQualifiedName() + " is not an instance of javax.xml.bind.annotation.adapters.XmlAdapter.");