Search in sources :

Example 6 with XmlList

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

the class JAXBSchemaInitializer method begin.

@Override
public void begin(MessagePartInfo part) {
    // Check to see if the WSDL information has been filled in for us.
    if (part.getTypeQName() != null || part.getElementQName() != null) {
        checkForExistence(part);
        return;
    }
    Class<?> clazz = part.getTypeClass();
    if (clazz == null) {
        return;
    }
    boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
    boolean isList = false;
    if (clazz.isArray()) {
        if (isFromWrapper && !Byte.TYPE.equals(clazz.getComponentType())) {
            clazz = clazz.getComponentType();
        } else if (!isFromWrapper) {
            Annotation[] anns = (Annotation[]) part.getProperty("parameter.annotations");
            for (Annotation a : anns) {
                if (a instanceof XmlList) {
                    part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
                    clazz = clazz.getComponentType();
                    isList = true;
                }
            }
        }
    }
    Annotation[] anns = (Annotation[]) part.getProperty("parameter.annotations");
    XmlJavaTypeAdapter jta = findFromTypeAdapter(context, clazz, anns);
    JAXBBeanInfo jtaBeanInfo = null;
    if (jta != null) {
        jtaBeanInfo = findFromTypeAdapter(context, jta.value());
    }
    JAXBBeanInfo beanInfo = getBeanInfo(clazz);
    if (jtaBeanInfo != beanInfo && jta != null) {
        beanInfo = jtaBeanInfo;
        if (anns == null) {
            anns = new Annotation[] { jta };
        } else {
            boolean found = false;
            for (Annotation t : anns) {
                if (t == jta) {
                    found = true;
                }
            }
            if (!found) {
                Annotation[] tmp = new Annotation[anns.length + 1];
                System.arraycopy(anns, 0, tmp, 0, anns.length);
                tmp[anns.length] = jta;
                anns = tmp;
            }
        }
        part.setProperty("parameter.annotations", anns);
        part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
    }
    if (beanInfo == null) {
        if (Exception.class.isAssignableFrom(clazz)) {
            QName name = (QName) part.getMessageInfo().getProperty("elementName");
            part.setElementQName(name);
            buildExceptionType(part, clazz);
        }
        return;
    }
    boolean isElement = beanInfo.isElement() && !Boolean.TRUE.equals(part.getMessageInfo().getOperation().getProperty("operation.force.types"));
    boolean hasType = !beanInfo.getTypeNames().isEmpty();
    if (isElement && isFromWrapper && hasType) {
        // if there is both a Global element and a global type, AND we are in a wrapper,
        // make sure we use the type instead of a ref to the element to
        // match the rules for wrapped/unwrapped
        isElement = false;
    }
    part.setElement(isElement);
    if (isElement) {
        QName name = new QName(beanInfo.getElementNamespaceURI(null), beanInfo.getElementLocalName(null));
        XmlSchemaElement el = schemas.getElementByQName(name);
        if (el != null && el.getRef().getTarget() != null) {
            part.setTypeQName(el.getRef().getTargetQName());
        } else {
            part.setElementQName(name);
        }
        part.setXmlSchema(el);
    } else {
        QName typeName = getTypeName(beanInfo);
        if (typeName != null) {
            XmlSchemaType type = schemas.getTypeByQName(typeName);
            if (isList && type instanceof XmlSchemaSimpleType) {
                XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(type.getParent(), false);
                XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                XmlSchemaSimpleType stype = (XmlSchemaSimpleType) type;
                list.setItemTypeName(stype.getQName());
                simpleType.setContent(list);
                part.setXmlSchema(simpleType);
                if (part.getConcreteName() == null) {
                    part.setConcreteName(new QName(null, part.getName().getLocalPart()));
                }
            } else {
                part.setTypeQName(typeName);
                part.setXmlSchema(type);
            }
        }
    }
}
Also used : XmlSchemaSimpleTypeList(org.apache.ws.commons.schema.XmlSchemaSimpleTypeList) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) JAXBBeanInfo(org.apache.cxf.common.jaxb.JAXBBeanInfo) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) Annotation(java.lang.annotation.Annotation) XmlList(javax.xml.bind.annotation.XmlList)

Aggregations

XmlList (javax.xml.bind.annotation.XmlList)6 Annotation (java.lang.annotation.Annotation)5 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)4 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)3 XmlElement (javax.xml.bind.annotation.XmlElement)2 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)2 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)2 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 Method (java.lang.reflect.Method)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 WebMethod (javax.jws.WebMethod)1 QName (javax.xml.namespace.QName)1 JAXBBeanInfo (org.apache.cxf.common.jaxb.JAXBBeanInfo)1 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)1 JavaField (org.apache.cxf.tools.common.model.JavaField)1 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)1 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)1 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)1