private final TypeMirror adaptingType;
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 = TypeMirrorDecorator.decorate(formalTypeIt.next());
TypeMirror boundTypeMirror = formalTypeIt.next();
if (!(boundTypeMirror instanceof ReferenceType)) {
throw new ValidationException(adapterDeclaration.getPosition(), adapterDeclaration.getQualifiedName() + ": illegal XML adapter: not adapting a reference type (" + boundTypeMirror + ").");
}
else while (boundTypeMirror instanceof TypeVariable) {
//unwrap the type variable to find the bounds.
TypeParameterDeclaration declaration = ((TypeVariable) boundTypeMirror).getDeclaration();
if (declaration == null) {
throw new IllegalStateException(adapterDeclaration.getQualifiedName() + ": unable to find type parameter declaration for type variable " + boundTypeMirror + ".");
}
else if (declaration.getBounds() != null && !declaration.getBounds().isEmpty()) {
boundTypeMirror = declaration.getBounds().iterator().next();
}
else {