use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.
the class XmlTypeVisitor method visitDeclared.
@Override
public XmlType visitDeclared(DeclaredType declaredType, Context context) {
Element declaredElement = declaredType.asElement();
String fqn = declaredElement instanceof TypeElement ? ((TypeElement) declaredElement).getQualifiedName().toString() : declaredType.toString();
if (context.getStack().contains(fqn)) {
// break the recursion.
return KnownXmlType.ANY_TYPE;
}
context.getStack().push(fqn);
try {
AdapterType adapterType = JAXBUtil.findAdapterType(declaredElement, context.getContext());
if (adapterType != null) {
adapterType.getAdaptingType().accept(this, context);
} else {
MapType mapType = MapType.findMapType(declaredType, context.getContext());
if (mapType != null) {
XmlType keyType = mapType.getKeyType().accept(this, new Context(context.getContext(), false, false, context.stack));
XmlType valueType = mapType.getValueType().accept(this, new Context(context.getContext(), false, false, context.stack));
return new MapXmlType(keyType, valueType);
} else {
switch(declaredElement.getKind()) {
case ENUM:
case CLASS:
XmlType knownType = context.getContext().getKnownType(declaredElement);
if (knownType != null) {
return knownType;
} else {
// type not known, not specified. Last chance: look for the type definition.
TypeDefinition typeDefinition = context.getContext().findTypeDefinition(declaredElement);
if (typeDefinition != null) {
return new XmlClassType(typeDefinition);
}
}
break;
}
}
}
return KnownXmlType.ANY_TYPE;
} finally {
context.getStack().pop();
}
}
use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.
the class JAXBUtil method findAdapterType.
protected static AdapterType findAdapterType(DecoratedTypeMirror maybeContainedAdaptedType, Element referer, PackageElement pckg, EnunciateJaxbContext context) {
DecoratedProcessingEnvironment env = context.getContext().getProcessingEnvironment();
TypeMirror adaptedType = TypeMirrorUtils.getComponentType(maybeContainedAdaptedType, env);
adaptedType = adaptedType == null ? maybeContainedAdaptedType : adaptedType;
XmlJavaTypeAdapter typeAdapterInfo = referer != null ? referer.getAnnotation(XmlJavaTypeAdapter.class) : null;
if (adaptedType instanceof DeclaredType) {
if (typeAdapterInfo == null) {
typeAdapterInfo = ((DeclaredType) adaptedType).asElement().getAnnotation(XmlJavaTypeAdapter.class);
}
if ((typeAdapterInfo == null) && (pckg != null)) {
TypeElement typeDeclaration = (TypeElement) ((DeclaredType) adaptedType).asElement();
typeAdapterInfo = getAdaptersOfPackage(pckg, context).get(typeDeclaration.getQualifiedName().toString());
}
}
if (typeAdapterInfo != null) {
final XmlJavaTypeAdapter finalInfo = typeAdapterInfo;
DecoratedTypeMirror adapterTypeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return finalInfo.value();
}
}, env);
if (adapterTypeMirror instanceof DecoratedDeclaredType) {
AdapterType adapterType = new AdapterType((DecoratedDeclaredType) adapterTypeMirror, context.getContext());
if (!context.getContext().getProcessingEnvironment().getTypeUtils().isSameType(adapterType.getAdaptingType(), adaptedType)) {
return adapterType;
}
}
}
return null;
}
use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.
the class ClientClassnameForMethod method convert.
@Override
public String convert(TypeElement declaration) throws TemplateModelException {
AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
if (declaration.getKind() == ElementKind.CLASS) {
DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
// for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
return convert(superType);
}
}
if (declaration.getKind() == ElementKind.INTERFACE && eraseInterfaces) {
return "java.lang.Object";
}
String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
ClientName specifiedName = declaration.getAnnotation(ClientName.class);
String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
return convertedPackage + getPackageSeparator() + simpleName;
}
use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.
the class TypeNameForMethod method convert.
@Override
public String convert(TypeElement declaration) throws TemplateModelException {
String fqn = declaration.getQualifiedName().toString();
if (classConversions.containsKey(fqn)) {
return classConversions.get(fqn);
} else if (declaration.getKind() == ElementKind.ENUM) {
return "string";
} else if (isCollection(declaration) || isMap(declaration)) {
return "array";
}
AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
ClientName specifiedName = declaration.getAnnotation(ClientName.class);
String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
return "\\" + convertedPackage + getPackageSeparator() + simpleName;
}
use of com.webcohesion.enunciate.modules.jaxb.model.adapters.AdapterType in project enunciate by stoicflame.
the class ClientClassnameForMethod method convert.
@Override
public String convert(TypeElement declaration) throws TemplateModelException {
String fqn = declaration.getQualifiedName().toString();
if (classConversions.containsKey(fqn)) {
return classConversions.get(fqn);
} else if (isCollection(declaration)) {
return "global::System.Collections.ArrayList";
}
AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
if (declaration.getKind() == ElementKind.CLASS) {
DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
// for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
return convert(superType);
}
}
String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
ClientName specifiedName = declaration.getAnnotation(ClientName.class);
String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
return convertedPackage + getPackageSeparator() + simpleName;
}
Aggregations