Search in sources :

Example 6 with UnwrappedOperationInfo

use of org.apache.cxf.service.model.UnwrappedOperationInfo in project cxf by apache.

the class JAXBContextInitializer method begin.

@Override
public void begin(MessagePartInfo part) {
    Class<?> clazz = part.getTypeClass();
    if (clazz == null) {
        return;
    }
    if (Exception.class.isAssignableFrom(clazz)) {
        // exceptions are handled special, make sure we mark it
        part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
    }
    boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
    if (isFromWrapper && !Boolean.TRUE.equals(part.getProperty("messagepart.isheader"))) {
        UnwrappedOperationInfo uop = (UnwrappedOperationInfo) part.getMessageInfo().getOperation();
        OperationInfo op = uop.getWrappedOperation();
        MessageInfo inf = null;
        if (uop.getInput() == part.getMessageInfo()) {
            inf = op.getInput();
        } else if (uop.getOutput() == part.getMessageInfo()) {
            inf = op.getOutput();
        }
        if (inf != null && inf.getFirstMessagePart().getTypeClass() != null) {
            // wrapper type (unless it's a header which wouldn't be in the wrapper)
            return;
        }
    }
    if (isFromWrapper && clazz.isArray() && !Byte.TYPE.equals(clazz.getComponentType())) {
        clazz = clazz.getComponentType();
    }
    Annotation[] a = (Annotation[]) part.getProperty("parameter.annotations");
    checkForAdapter(clazz, a);
    Type genericType = (Type) part.getProperty("generic.type");
    if (genericType != null) {
        boolean isList = Collection.class.isAssignableFrom(clazz);
        if (isFromWrapper) {
            if (genericType instanceof Class && ((Class<?>) genericType).isArray()) {
                Class<?> cl2 = (Class<?>) genericType;
                if (cl2.isArray() && !Byte.TYPE.equals(cl2.getComponentType())) {
                    genericType = cl2.getComponentType();
                }
                addType(genericType);
            } else if (!isList) {
                addType(genericType);
            }
        } else {
            addType(genericType, true);
        }
        if (isList && genericType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) genericType;
            if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof Class) {
                Class<? extends Object> arrayCls = Array.newInstance((Class<?>) pt.getActualTypeArguments()[0], 0).getClass();
                clazz = arrayCls;
                part.setTypeClass(clazz);
                if (isFromWrapper) {
                    addType(clazz.getComponentType(), true);
                }
            } else if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof GenericArrayType) {
                GenericArrayType gat = (GenericArrayType) pt.getActualTypeArguments()[0];
                gat.getGenericComponentType();
                Class<? extends Object> arrayCls = Array.newInstance((Class<?>) gat.getGenericComponentType(), 0).getClass();
                clazz = Array.newInstance(arrayCls, 0).getClass();
                part.setTypeClass(clazz);
                if (isFromWrapper) {
                    addType(clazz.getComponentType(), true);
                }
            }
        }
        if (isFromWrapper && isList) {
            clazz = null;
        }
    }
    if (clazz != null) {
        if (!isFromWrapper && clazz.getAnnotation(XmlRootElement.class) == null && clazz.getAnnotation(XmlType.class) != null && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name())) {
            Object ref = createTypeReference(part.getName(), clazz);
            if (ref != null) {
                typeReferences.add(ref);
            }
        }
        addClass(clazz);
    }
}
Also used : UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) GenericArrayType(java.lang.reflect.GenericArrayType) Annotation(java.lang.annotation.Annotation) MessageInfo(org.apache.cxf.service.model.MessageInfo) XmlType(javax.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) WildcardType(java.lang.reflect.WildcardType) XmlType(javax.xml.bind.annotation.XmlType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Aggregations

OperationInfo (org.apache.cxf.service.model.OperationInfo)6 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)6 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 QName (javax.xml.namespace.QName)3 MessageInfo (org.apache.cxf.service.model.MessageInfo)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 Annotation (java.lang.annotation.Annotation)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)2 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2 TypeVariable (java.lang.reflect.TypeVariable)1 WildcardType (java.lang.reflect.WildcardType)1 Message (javax.wsdl.Message)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)1 XmlType (javax.xml.bind.annotation.XmlType)1 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)1 Message (org.apache.cxf.common.i18n.Message)1