Search in sources :

Example 1 with XmlSchemaTypes

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);
}
Also used : DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) XmlSchemaType(javax.xml.bind.annotation.XmlSchemaType) XmlSchemaTypes(javax.xml.bind.annotation.XmlSchemaTypes) EnunciateException(com.webcohesion.enunciate.EnunciateException) EnunciateException(com.webcohesion.enunciate.EnunciateException) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

EnunciateException (com.webcohesion.enunciate.EnunciateException)1 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)1 TypeElement (javax.lang.model.element.TypeElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 XmlSchemaType (javax.xml.bind.annotation.XmlSchemaType)1 XmlSchemaTypes (javax.xml.bind.annotation.XmlSchemaTypes)1