assert anno instanceof Locatable;
elementType = nav().getReturnType(m);
T baseClass = nav().getBaseClass(elementType,nav().asDecl(JAXBElement.class));
if(baseClass==null)
throw new IllegalAnnotationException(
Messages.XML_ELEMENT_MAPPING_ON_NON_IXMLELEMENT_METHOD.format(nav().getMethodName(m)),
anno );
tagName = parseElementName(anno);
T[] methodParams = nav().getMethodParameters(m);
// adapter
Adapter<T,C> a = null;
if(methodParams.length>0) {
XmlJavaTypeAdapter adapter = reader().getMethodAnnotation(XmlJavaTypeAdapter.class,m,this);
if(adapter!=null)
a = new Adapter<T,C>(adapter,reader(),nav());
else {
XmlAttachmentRef xsa = reader().getMethodAnnotation(XmlAttachmentRef.class,m,this);
if(xsa!=null) {
TODO.prototype("in APT swaRefAdapter isn't avaialble, so this returns null");
a = new Adapter<T,C>(owner.nav.asDecl(SwaRefAdapter.class),owner.nav);
}
}
}
this.adapter = a;
// T of JAXBElement<T>
tOfJAXBElementT =
methodParams.length>0 ? methodParams[0] // this is more reliable, as it works even for ObjectFactory that sometimes have to return public types
: nav().getTypeArgument(baseClass,0); // fall back to infer from the return type if no parameter.
if(adapter==null) {
T list = nav().getBaseClass(tOfJAXBElementT,nav().asDecl(List.class));
if(list==null) {
isCollection = false;
contentType = builder.getTypeInfo(tOfJAXBElementT,this); // suck this type into the current set.
} else {
isCollection = true;
contentType = builder.getTypeInfo(nav().getTypeArgument(list,0),this);
}
} else {
// but if adapted, use the adapted type
contentType = builder.getTypeInfo(this.adapter.defaultType,this);
isCollection = false;
}
// scope
T s = reader().getClassValue(anno,"scope");
if(s.equals(nav().ref(XmlElementDecl.GLOBAL.class)))
scope = null;
else {
// TODO: what happens if there's an error?
NonElement<T,C> scp = builder.getClassInfo(nav().asDecl(s),this);
if(!(scp instanceof ClassInfo)) {
throw new IllegalAnnotationException(
Messages.SCOPE_IS_NOT_COMPLEXTYPE.format(nav().getTypeName(s)),
anno );
}
scope = (ClassInfo<T,C>)scp;
}