use of javax.xml.bind.annotation.XmlSchemaTypes in project enunciate by stoicflame.
the class XmlTypeFactory method loadPackageExplicitTypes.
/**
* Load any explicit schema types specified by the package.
*
* @param pckg The package.
* @param context The context.
* @return Any explicit schema types specified by the package.
*/
protected static Map<String, XmlSchemaType> loadPackageExplicitTypes(PackageElement pckg, EnunciateJaxbContext context) {
Map<String, XmlSchemaType> explicitTypes = new HashMap<String, XmlSchemaType>();
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 (final XmlSchemaType specifiedType : allSpecifiedTypes) {
DecoratedTypeMirror typeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return specifiedType.type();
}
}, context.getContext().getProcessingEnvironment(), XmlSchemaType.DEFAULT.class);
if (typeMirror == null) {
throw new EnunciateException(pckg.getQualifiedName() + ": a type must be specified in " + XmlSchemaType.class.getName() + " at the package-level.");
}
if (!(typeMirror instanceof DeclaredType)) {
throw new EnunciateException(pckg.getQualifiedName() + ": only a declared type can be adapted. Offending type: " + typeMirror);
}
explicitTypes.put(((TypeElement) ((DeclaredType) typeMirror).asElement()).getQualifiedName().toString(), specifiedType);
}
}
return Collections.unmodifiableMap(explicitTypes);
}
Aggregations