Search in sources :

Example 41 with MessagePartInfo

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

the class WrapperClassGenerator method createWrapperClass.

// CHECKSTYLE:OFF
private void createWrapperClass(MessagePartInfo wrapperPart, MessageInfo messageInfo, OperationInfo op, Method method, boolean isRequest, Set<Class<?>> wrapperBeans, JaxWsServiceFactoryBean factory, InterfaceInfo interfaceInfo, boolean qualified) {
    ASMHelper.ClassWriter cw = helper.createClassWriter();
    if (cw == null) {
        LOG.warning(op.getName() + " requires a wrapper bean but problems with" + " ASM has prevented creating one. Operation may not work correctly.");
        return;
    }
    QName wrapperElement = messageInfo.getName();
    boolean anonymous = factory.getAnonymousWrapperTypes();
    String pkg = getPackageName(method) + ".jaxws_asm" + (anonymous ? "_an" : "");
    String className = pkg + "." + StringUtils.capitalize(op.getName().getLocalPart());
    if (!isRequest) {
        className = className + "Response";
    }
    String pname = pkg + ".package-info";
    Class<?> def = findClass(pname, method.getDeclaringClass());
    if (def == null) {
        generatePackageInfo(pname, wrapperElement.getNamespaceURI(), method.getDeclaringClass(), method, interfaceInfo, qualified);
    }
    def = findClass(className, method.getDeclaringClass());
    String origClassName = className;
    int count = 0;
    while (def != null) {
        Boolean b = messageInfo.getProperty("parameterized", Boolean.class);
        if (b != null && b) {
            className = origClassName + (++count);
            def = findClass(className, method.getDeclaringClass());
        } else {
            wrapperPart.setTypeClass(def);
            wrapperBeans.add(def);
            return;
        }
    }
    String classFileName = StringUtils.periodToSlashes(className);
    OpcodesProxy opCodes = helper.getOpCodes();
    cw.visit(opCodes.V1_5, opCodes.ACC_PUBLIC + opCodes.ACC_SUPER, classFileName, null, "java/lang/Object", null);
    ASMHelper.AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true);
    av0.visit("name", wrapperElement.getLocalPart());
    av0.visit("namespace", wrapperElement.getNamespaceURI());
    av0.visitEnd();
    av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlAccessorType;", true);
    av0.visitEnum("value", "Ljavax/xml/bind/annotation/XmlAccessType;", "FIELD");
    av0.visitEnd();
    av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true);
    if (!anonymous) {
        av0.visit("name", wrapperElement.getLocalPart());
        av0.visit("namespace", wrapperElement.getNamespaceURI());
    } else {
        av0.visit("name", "");
    }
    av0.visitEnd();
    // add constructor
    ASMHelper.MethodVisitor mv = cw.visitMethod(opCodes.ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    ASMHelper.Label lbegin = helper.createLabel();
    mv.visitLabel(lbegin);
    mv.visitVarInsn(opCodes.ALOAD, 0);
    mv.visitMethodInsn(opCodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(opCodes.RETURN);
    ASMHelper.Label lend = helper.createLabel();
    mv.visitLabel(lend);
    mv.visitLocalVariable("this", "L" + classFileName + ";", null, lbegin, lend, 0);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
        generateMessagePart(cw, mpi, method, classFileName, factory);
    }
    cw.visitEnd();
    Class<?> clz = loadClass(className, method.getDeclaringClass(), cw.toByteArray());
    wrapperPart.setTypeClass(clz);
    wrapperBeans.add(clz);
}
Also used : QName(javax.xml.namespace.QName) ASMHelper(org.apache.cxf.common.util.ASMHelper) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) OpcodesProxy(org.apache.cxf.common.util.OpcodesProxy)

Example 42 with MessagePartInfo

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

the class AegisDatabinding method initializeMessage.

protected void initializeMessage(Service s, TypeMapping serviceTM, AbstractMessageContainer container, int partType, Set<AegisType> deps) {
    if (container == null) {
        return;
    }
    for (MessagePartInfo part : container.getMessageParts()) {
        AegisType type = getParameterType(s, serviceTM, part, partType);
        if (part.getXmlSchema() == null) {
            // schema hasn't been filled in yet
            if (type.isAbstract()) {
                part.setTypeQName(type.getSchemaType());
            } else {
                part.setElementQName(type.getSchemaType());
            }
        }
        Annotation[] anns = part.getProperty("parameter.annotations", Annotation[].class);
        long miValue = -1;
        if (type.hasMinOccurs()) {
            miValue = type.getMinOccurs();
        }
        Integer i = AnnotationReader.getMinOccurs(anns);
        if (i != null) {
            miValue = i;
        }
        if (miValue > 0) {
            part.setProperty("minOccurs", Long.toString(miValue));
        }
        // However, this if at least allow .aegis.xml files to get control.
        if (part.getProperty("nillable") == null) {
            boolean isNil = type.isNillable();
            Boolean b = AnnotationReader.isNillable(anns);
            if (b != null || (miValue != 0 && isNil)) {
                part.setProperty("nillable", b == null ? isNil : b);
            }
        /*
                if (miValue == -1 && (b == null ? isNil : b)) {
                    part.setProperty("minOccurs", "1");
                }
                */
        }
        if (type.hasMaxOccurs()) {
            String moValue;
            long mo = type.getMaxOccurs();
            if (mo != Long.MAX_VALUE) {
                moValue = Long.toString(mo);
                part.setProperty("maxOccurs", moValue);
            }
        }
        part2Type.put(part, type);
        // QName elName = getSuggestedName(service, op, param)
        deps.add(type);
        type.getTypeMapping().register(type);
        addDependencies(deps, type);
    }
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Annotation(java.lang.annotation.Annotation)

Example 43 with MessagePartInfo

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

the class ServiceModelVisitor method visitOperation.

private void visitOperation(OperationInfo o) {
    MessageInfo in = o.getInput();
    if (in != null) {
        begin(in);
        for (MessagePartInfo part : in.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(in);
    }
    MessageInfo out = o.getOutput();
    if (out != null) {
        begin(out);
        for (MessagePartInfo part : out.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(out);
    }
    for (FaultInfo f : o.getFaults()) {
        begin(f);
        for (MessagePartInfo part : f.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(f);
    }
    if (o.isUnwrappedCapable()) {
        OperationInfo uop = o.getUnwrappedOperation();
        begin(uop);
        visitOperation(o.getUnwrappedOperation());
        end(uop);
    }
}
Also used : UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 44 with MessagePartInfo

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

the class ParameterProcessor method buildParamModelsWithoutOrdering.

private void buildParamModelsWithoutOrdering(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
    boolean wrapped = method.isWrapperStyle();
    if (wrapped) {
        if (inputMessage != null) {
            List<MessagePartInfo> inputParts = inputMessage.getMessageParts();
            MessagePartInfo inputPart = !inputParts.isEmpty() ? inputParts.iterator().next() : null;
            List<QName> inputWrapElement = null;
            if (inputPart != null && inputPart.isElement()) {
                inputWrapElement = ProcessorUtil.getWrappedElementQNames(context, inputPart.getElementQName());
            }
            if (inputWrapElement != null) {
                for (QName item : inputWrapElement) {
                    String fullJavaName = dataBinding.getWrappedElementType(inputPart.getElementQName(), item);
                    if (StringUtils.isEmpty(fullJavaName)) {
                        wrapped = false;
                        break;
                    }
                }
            }
        }
        if (outputMessage != null) {
            List<MessagePartInfo> outputParts = outputMessage.getMessageParts();
            MessagePartInfo outputPart = !outputParts.isEmpty() ? outputParts.iterator().next() : null;
            List<QName> outputWrapElement = null;
            if (outputPart != null && outputPart.isElement()) {
                outputWrapElement = ProcessorUtil.getWrappedElementQNames(context, outputPart.getElementQName());
            }
            if (outputWrapElement != null) {
                for (QName item : outputWrapElement) {
                    String fullJavaName = dataBinding.getWrappedElementType(outputPart.getElementQName(), item);
                    if (StringUtils.isEmpty(fullJavaName)) {
                        wrapped = false;
                        break;
                    }
                }
            }
        }
        if (!wrapped) {
            // could not map one of the parameters to a java type, need to drop down to bare style
            method.setWrapperStyle(false);
        }
    }
    if (inputMessage != null) {
        if (method.isWrapperStyle()) {
            processWrappedInput(method, inputMessage);
        } else {
            processInput(method, inputMessage);
        }
    }
    if (outputMessage == null) {
        processReturn(method, null);
    } else {
        if (method.isWrapperStyle()) {
            processWrappedOutput(method, inputMessage, outputMessage);
        } else {
            processOutput(method, inputMessage, outputMessage);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 45 with MessagePartInfo

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

the class ParameterProcessor method isValidOrdering.

private boolean isValidOrdering(List<String> parameterOrder, MessageInfo inputMessage, MessageInfo outputMessage) {
    Iterator<String> params = parameterOrder.iterator();
    List<MessagePartInfo> inputParts = inputMessage.getMessageParts();
    List<MessagePartInfo> outputParts;
    if (outputMessage != null) {
        outputParts = outputMessage.getMessageParts();
    } else {
        outputParts = new ArrayList<>();
    }
    while (params.hasNext()) {
        String param = params.next();
        MessagePartInfo inPart = null;
        MessagePartInfo outPart = null;
        for (MessagePartInfo part : inputParts) {
            if (param.equals(part.getName().getLocalPart())) {
                inPart = part;
                break;
            }
        }
        // check output parts
        for (MessagePartInfo part : outputParts) {
            if (param.equals(part.getName().getLocalPart())) {
                outPart = part;
                break;
            }
        }
        if (inPart == null && outPart == null) {
            return false;
        } else if (inPart != null && outPart != null) {
            if (inPart.isElement() != outPart.isElement()) {
                return false;
            }
            if (inPart.isElement() && !inPart.getElementQName().equals(outPart.getElementQName())) {
                return false;
            } else if (!inPart.isElement() && !inPart.getTypeQName().equals(outPart.getTypeQName())) {
                return false;
            }
        }
    }
    return true;
}
Also used : MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)163 QName (javax.xml.namespace.QName)99 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)46 MessageInfo (org.apache.cxf.service.model.MessageInfo)38 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)29 Fault (org.apache.cxf.interceptor.Fault)21 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)19 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)13 Method (java.lang.reflect.Method)12