Search in sources :

Example 1 with DataTypeReferenceImpl

use of com.webcohesion.enunciate.modules.jaxb.api.impl.DataTypeReferenceImpl in project enunciate by stoicflame.

the class QNameForMediaTypeMethod method exec.

public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The QNameForType method must have a type mirror as a parameter.");
    }
    TemplateModel from = (TemplateModel) list.get(0);
    Object unwrapped = FreemarkerUtil.unwrap(from);
    if (unwrapped instanceof MediaTypeDescriptor) {
        MediaTypeDescriptor mt = (MediaTypeDescriptor) unwrapped;
        DataTypeReference typeReference = mt.getDataType();
        if (typeReference != null) {
            if (typeReference instanceof DataTypeReferenceImpl) {
                return ((DataTypeReferenceImpl) typeReference).getElementQName();
            } else if (associateJsonWithXml && mt.getMediaType().endsWith("json")) {
                DataType dataType = typeReference.getValue();
                if (dataType != null) {
                    XmlType knownType = this.context.getKnownType(dataType.getJavaElement());
                    if (knownType != null) {
                        return knownType.getQname();
                    }
                    TypeDefinition typeDefinition = this.context.findTypeDefinition(dataType.getJavaElement());
                    if (typeDefinition != null) {
                        return typeDefinition.getQname();
                    }
                }
            }
        }
    }
    return null;
}
Also used : MediaTypeDescriptor(com.webcohesion.enunciate.api.resources.MediaTypeDescriptor) TemplateModelException(freemarker.template.TemplateModelException) DataTypeReference(com.webcohesion.enunciate.api.datatype.DataTypeReference) DataTypeReferenceImpl(com.webcohesion.enunciate.modules.jaxb.api.impl.DataTypeReferenceImpl) DataType(com.webcohesion.enunciate.api.datatype.DataType) TemplateModel(freemarker.template.TemplateModel) XmlType(com.webcohesion.enunciate.modules.jaxb.model.types.XmlType) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)

Aggregations

DataType (com.webcohesion.enunciate.api.datatype.DataType)1 DataTypeReference (com.webcohesion.enunciate.api.datatype.DataTypeReference)1 MediaTypeDescriptor (com.webcohesion.enunciate.api.resources.MediaTypeDescriptor)1 DataTypeReferenceImpl (com.webcohesion.enunciate.modules.jaxb.api.impl.DataTypeReferenceImpl)1 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)1 XmlType (com.webcohesion.enunciate.modules.jaxb.model.types.XmlType)1 TemplateModel (freemarker.template.TemplateModel)1 TemplateModelException (freemarker.template.TemplateModelException)1