Search in sources :

Example 1 with XmlMimeType

use of javax.xml.bind.annotation.XmlMimeType in project cxf by apache.

the class ReflectionServiceFactoryBean method addMimeType.

private void addMimeType(final XmlSchemaElement element, final Annotation[] annotations) {
    if (annotations != null) {
        for (Annotation annotation : annotations) {
            if (annotation instanceof XmlMimeType) {
                MimeAttribute attr = new MimeAttribute();
                attr.setValue(((XmlMimeType) annotation).value());
                element.addMetaInfo(MimeAttribute.MIME_QNAME, attr);
            }
        }
    }
}
Also used : MimeAttribute(org.apache.cxf.databinding.source.mime.MimeAttribute) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) Annotation(java.lang.annotation.Annotation)

Example 2 with XmlMimeType

use of javax.xml.bind.annotation.XmlMimeType in project cxf by apache.

the class WrapperBeanFieldAnnotator method annotate.

public void annotate(final JavaAnnotatable field) {
    JavaField jField = null;
    if (field instanceof JavaField) {
        jField = (JavaField) field;
    } else {
        throw new RuntimeException("WrapperBeanFiledAnnotator expect JavaField as input");
    }
    String rawName = jField.getRawName();
    boolean hasEl = false;
    for (Annotation ann : jField.getJaxbAnnotaions()) {
        if (ann instanceof XmlMimeType) {
            JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
            mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType) ann).value()));
            jField.addAnnotation(mimeAnno);
        } else if (ann instanceof XmlJavaTypeAdapter) {
            JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
            jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter) ann).value()));
            jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter) ann).type()));
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlAttachmentRef) {
            JAnnotation jaxbAnn = new JAnnotation(XmlAttachmentRef.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlList) {
            JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlElement) {
            hasEl = true;
            XmlElement el = (XmlElement) ann;
            JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
            xmlElementAnnotation.addElement(new JAnnotationElement("name", el.name()));
            if (!StringUtils.isEmpty(el.namespace())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("namespace", el.namespace()));
            }
            if (el.nillable()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("nillable", el.nillable(), true));
            }
            if (el.required()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("required", el.required(), true));
            }
            if (!StringUtils.isEmpty(el.defaultValue())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("defaultValue", el.defaultValue()));
            }
            jField.addAnnotation(xmlElementAnnotation);
        }
    }
    if (!hasEl) {
        JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
        xmlElementAnnotation.addElement(new JAnnotationElement("name", rawName));
        if (!StringUtils.isEmpty(jField.getTargetNamespace())) {
            xmlElementAnnotation.addElement(new JAnnotationElement("namespace", jField.getTargetNamespace()));
        }
        jField.addAnnotation(xmlElementAnnotation);
    }
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) XmlAttachmentRef(javax.xml.bind.annotation.XmlAttachmentRef) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) XmlElement(javax.xml.bind.annotation.XmlElement) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) Annotation(java.lang.annotation.Annotation) XmlList(javax.xml.bind.annotation.XmlList)

Example 3 with XmlMimeType

use of javax.xml.bind.annotation.XmlMimeType in project jbossws-cxf by jbossws.

the class SOAP11EndpointBean method namespace.

@XmlMimeType("text/plain")
public DataHandler namespace(@XmlMimeType("text/plain") DataHandler data) {
    try {
        String name = (String) getContent(data);
        String type = (String) data.getContentType();
        log.info("User " + name + " requested namespace with content type [" + type + "]");
        return new DataHandler("Hello " + name, "text/plain");
    } catch (IOException e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) XmlMimeType(javax.xml.bind.annotation.XmlMimeType)

Example 4 with XmlMimeType

use of javax.xml.bind.annotation.XmlMimeType in project jbossws-cxf by jbossws.

the class SOAP12EndpointBean method namespace.

@XmlMimeType("text/plain")
public DataHandler namespace(@XmlMimeType("text/plain") DataHandler data) {
    try {
        String name = (String) getContent(data);
        String type = (String) data.getContentType();
        log.info("User " + name + " requested namespace with content type [" + type + "]");
        return new DataHandler("Hello " + name, "text/plain");
    } catch (IOException e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) XmlMimeType(javax.xml.bind.annotation.XmlMimeType)

Example 5 with XmlMimeType

use of javax.xml.bind.annotation.XmlMimeType in project jbossws-cxf by jbossws.

the class EndpointBean method namespace.

@XmlMimeType("text/plain")
public DataHandler namespace(@XmlMimeType("text/plain") DataHandler data) {
    try {
        String name = (String) getContent(data);
        String type = (String) data.getContentType();
        log.info("User " + name + " requested namespace with content type [" + type + "]");
        return new DataHandler("Hello " + name, "text/plain");
    } catch (IOException e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) XmlMimeType(javax.xml.bind.annotation.XmlMimeType)

Aggregations

XmlMimeType (javax.xml.bind.annotation.XmlMimeType)7 IOException (java.io.IOException)4 DataHandler (javax.activation.DataHandler)4 WebServiceException (javax.xml.ws.WebServiceException)4 Annotation (java.lang.annotation.Annotation)3 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)2 XmlElement (javax.xml.bind.annotation.XmlElement)2 XmlList (javax.xml.bind.annotation.XmlList)2 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)2 InputStream (java.io.InputStream)1 WebMethod (javax.jws.WebMethod)1 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)1 MimeAttribute (org.apache.cxf.databinding.source.mime.MimeAttribute)1 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)1 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)1 JavaField (org.apache.cxf.tools.common.model.JavaField)1