Search in sources :

Example 1 with JAnnotationElement

use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.

the class HandlerConfigGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Element e = this.intf.getHandlerChains();
    List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(e, ToolConstants.HANDLER_CHAINS_URI, ToolConstants.HANDLER_CHAIN);
    if (!elemList.isEmpty()) {
        String fName = ProcessorUtil.getHandlerConfigFileName(this.intf.getName());
        handlerChainAnnotation = new JAnnotation(HandlerChain.class);
        handlerChainAnnotation.addElement(new JAnnotationElement("name", HANDLER_CHAIN_NAME));
        handlerChainAnnotation.addElement(new JAnnotationElement("file", fName + ".xml"));
        generateHandlerChainFile(e, parseOutputName(this.intf.getPackageName(), fName, ".xml"));
    }
}
Also used : HandlerChain(javax.jws.HandlerChain) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) Element(org.w3c.dom.Element) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement)

Example 2 with JAnnotationElement

use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.

the class SEIGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        if (interfaces.isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_SEI", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            continue;
        }
        for (JavaInterface intf : interfaces.values()) {
            if (hasHandlerConfig(intf)) {
                HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
                // REVISIT: find a better way to handle Handler gen, should not
                // pass JavaInterface around.
                handlerGen.setJavaInterface(intf);
                handlerGen.generate(getEnvironment());
                JAnnotation annot = handlerGen.getHandlerAnnotation();
                if (handlerGen.getHandlerAnnotation() != null) {
                    boolean existHandlerAnno = false;
                    for (JAnnotation jann : intf.getAnnotations()) {
                        if (jann.getType() == HandlerChain.class) {
                            existHandlerAnno = true;
                        }
                    }
                    if (!existHandlerAnno) {
                        intf.addAnnotation(annot);
                        intf.addImport("javax.jws.HandlerChain");
                    }
                }
            }
            if (penv.containsKey(ToolConstants.RUNTIME_DATABINDING_CLASS)) {
                JAnnotation ann = new JAnnotation(DataBinding.class);
                JAnnotationElement el = new JAnnotationElement(null, penv.get(ToolConstants.RUNTIME_DATABINDING_CLASS), true);
                ann.addElement(el);
                intf.addAnnotation(ann);
            }
            clearAttributes();
            setAttributes("intf", intf);
            String seiSc = "";
            for (String s : intf.getSuperInterfaces()) {
                if (!seiSc.isEmpty()) {
                    seiSc += ", ";
                } else {
                    seiSc = "extends ";
                }
                seiSc += s;
            }
            if (!StringUtils.isEmpty(seiSc)) {
                seiSc += " ";
            }
            setAttributes("seiSuperinterfaceString", seiSc);
            setCommonAttributes();
            doWrite(SEI_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName()));
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement)

Example 3 with JAnnotationElement

use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.

the class OperationProcessor method addCallbackMethod.

private void addCallbackMethod(JavaMethod method) throws ToolException {
    JavaMethod callbackMethod = new JavaMethod(method.getInterface());
    callbackMethod.setAsync(true);
    callbackMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
    callbackMethod.setStyle(method.getStyle());
    callbackMethod.setWrapperStyle(method.isWrapperStyle());
    callbackMethod.setSoapAction(method.getSoapAction());
    callbackMethod.setOperationName(method.getOperationName());
    JavaReturn future = new JavaReturn();
    future.setClassName("Future<?>");
    callbackMethod.setReturn(future);
    // REVISIT: test the operation name in the annotation
    callbackMethod.annotate(new WebMethodAnnotator());
    callbackMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
    callbackMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
    callbackMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
    boolean convertOutToAsync = !method.isWrapperStyle() && "void".equals(method.getReturn().getClassName());
    String asyncCname = null;
    for (JavaParameter param : method.getParameters()) {
        if (convertOutToAsync) {
            if (param.isHolder()) {
                if (param.isINOUT()) {
                    JavaParameter p2 = new JavaParameter();
                    p2.setName(param.getName());
                    p2.setClassName(param.getHolderName());
                    p2.setStyle(JavaType.Style.IN);
                    callbackMethod.addParameter(p2);
                    for (String s : param.getAnnotationTags()) {
                        JAnnotation ann = param.getAnnotation(s);
                        p2.addAnnotation(s, ann);
                    }
                } else if (!param.isHeader() && asyncCname == null) {
                    asyncCname = param.getClassName();
                }
            } else {
                callbackMethod.addParameter(param);
            }
        } else {
            callbackMethod.addParameter(param);
        }
    }
    JavaParameter asyncHandler = new JavaParameter();
    asyncHandler.setName("asyncHandler");
    asyncHandler.setCallback(true);
    asyncHandler.setClassName(getAsyncClassName(method, "AsyncHandler", asyncCname));
    asyncHandler.setStyle(JavaType.Style.IN);
    callbackMethod.addParameter(asyncHandler);
    JAnnotation asyncHandlerAnnotation = new JAnnotation(WebParam.class);
    asyncHandlerAnnotation.addElement(new JAnnotationElement("name", "asyncHandler"));
    asyncHandlerAnnotation.addElement(new JAnnotationElement("targetNamespace", ""));
    asyncHandler.addAnnotation("WebParam", asyncHandlerAnnotation);
    method.getInterface().addImport("javax.jws.WebParam");
    method.getInterface().addMethod(callbackMethod);
}
Also used : JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) WebMethodAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator)

Example 4 with JAnnotationElement

use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.

the class ServiceProcessor method processOperation.

private void processOperation(JavaModel model, BindingOperationInfo bop, BindingInfo binding) throws ToolException {
    boolean enableOpMime = false;
    JAXWSBinding bind = binding.getExtensor(JAXWSBinding.class);
    if (bind != null && bind.isEnableMime()) {
        enableOpMime = true;
    }
    JAXWSBinding bopBinding = bop.getExtensor(JAXWSBinding.class);
    if (bopBinding != null && bopBinding.isEnableMime()) {
        enableOpMime = true;
        if (bopBinding.getJaxwsParas() != null) {
            jaxwsBinding.setJaxwsParas(bopBinding.getJaxwsParas());
        }
    }
    JavaInterface jf = null;
    for (JavaInterface jf2 : model.getInterfaces().values()) {
        if (binding.getInterface().getName().getLocalPart().equals(jf2.getWebServiceName())) {
            jf = jf2;
        }
    }
    if (jf == null) {
        throw new ToolException("No Java Interface available");
    }
    if (isSoapBinding()) {
        SoapBinding soapBinding = (SoapBinding) bindingObj;
        if (SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()) == null) {
            jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
        } else {
            jf.setSOAPStyle(SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()));
        }
    } else {
        // REVISIT: fix for xml binding
        jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
    }
    Object[] methods = jf.getMethods().toArray();
    for (int i = 0; i < methods.length; i++) {
        JavaMethod jm = (JavaMethod) methods[i];
        if (jm.getOperationName() != null && jm.getOperationName().equals(bop.getName().getLocalPart())) {
            if (isSoapBinding()) {
                // TODO: add customize here
                // doCustomizeOperation(jf, jm, bop);
                Map<String, Object> prop = getSoapOperationProp(bop);
                String soapAction = prop.get(soapOPAction) == null ? "" : (String) prop.get(soapOPAction);
                String soapStyle = prop.get(soapOPStyle) == null ? "" : (String) prop.get(soapOPStyle);
                jm.setSoapAction(soapAction);
                if (SOAPBindingUtil.getSoapStyle(soapStyle) == null && this.bindingObj == null) {
                    org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_STYLE_NOT_DEFINED", LOG);
                    throw new ToolException(msg);
                }
                if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
                    jm.setSoapStyle(jf.getSOAPStyle());
                } else {
                    jm.setSoapStyle(SOAPBindingUtil.getSoapStyle(soapStyle));
                }
            } else {
                // REVISIT: fix for xml binding
                jm.setSoapStyle(jf.getSOAPStyle());
            }
            if (jm.getSoapStyle().equals(javax.jws.soap.SOAPBinding.Style.RPC)) {
                jm.getAnnotationMap().remove("SOAPBinding");
            }
            OperationProcessor processor = new OperationProcessor(context);
            int headerType = isNonWrappable(bop);
            OperationInfo opinfo = bop.getOperationInfo();
            JAXWSBinding opBinding = opinfo.getExtensor(JAXWSBinding.class);
            JAXWSBinding infBinding = opinfo.getInterface().getExtensor(JAXWSBinding.class);
            boolean enableMime = enableOpMime;
            boolean enableWrapperStyle = true;
            if (infBinding != null && infBinding.isSetEnableWrapperStyle()) {
                enableWrapperStyle = infBinding.isEnableWrapperStyle();
            }
            if (infBinding != null && infBinding.isSetEnableMime()) {
                enableMime = infBinding.isEnableMime();
            }
            if (opBinding != null && opBinding.isSetEnableWrapperStyle()) {
                enableWrapperStyle = opBinding.isEnableWrapperStyle();
            }
            if (opBinding != null && opBinding.isSetEnableMime()) {
                enableMime = opBinding.isEnableMime();
            }
            if (jaxwsBinding.isEnableMime() || enableMime) {
                jm.setMimeEnable(true);
            }
            if ((jm.isWrapperStyle() && headerType > this.noHEADER) || !jaxwsBinding.isEnableWrapperStyle() || (jm.enableMime() && jm.isWrapperStyle()) || !enableWrapperStyle) {
                // changed wrapper style
                jm.setWrapperStyle(false);
                processor.processMethod(jm, bop.getOperationInfo());
                jm.getAnnotationMap().remove("ResponseWrapper");
                jm.getAnnotationMap().remove("RequestWrapper");
            } else {
                processor.processMethod(jm, bop.getOperationInfo());
            }
            if (headerType == this.resultHeader) {
                JAnnotation resultAnno = jm.getAnnotationMap().get("WebResult");
                if (resultAnno != null) {
                    resultAnno.addElement(new JAnnotationElement("header", true, true));
                }
            }
            processParameter(jm, bop);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) Message(org.apache.cxf.common.i18n.Message) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) ToolException(org.apache.cxf.tools.common.ToolException)

Example 5 with JAnnotationElement

use of org.apache.cxf.tools.common.model.JAnnotationElement in project cxf by apache.

the class SoapBindingAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaMethod method;
    if (ja instanceof JavaMethod) {
        method = (JavaMethod) ja;
    } else {
        throw new RuntimeException("SOAPBindingAnnotator can only annotate JavaMethod");
    }
    if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT) {
        if (!method.isWrapperStyle() && !SOAPBinding.ParameterStyle.BARE.equals(method.getInterface().getSOAPParameterStyle())) {
            JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
            bindingAnnotation.addElement(new JAnnotationElement("parameterStyle", SOAPBinding.ParameterStyle.BARE));
            method.addAnnotation("SOAPBinding", bindingAnnotation);
        } else if (method.isWrapperStyle() && SOAPBinding.ParameterStyle.BARE.equals(method.getInterface().getSOAPParameterStyle())) {
            JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
            bindingAnnotation.addElement(new JAnnotationElement("parameterStyle", SOAPBinding.ParameterStyle.WRAPPED));
            method.addAnnotation("SOAPBinding", bindingAnnotation);
        }
    } else if (!SOAPBinding.Style.RPC.equals(method.getInterface().getSOAPStyle())) {
        JAnnotation bindingAnnotation = new JAnnotation(SOAPBinding.class);
        bindingAnnotation.addElement(new JAnnotationElement("style", SOAPBinding.Style.RPC));
        method.addAnnotation("SOAPBinding", bindingAnnotation);
    }
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) SOAPBinding(javax.jws.soap.SOAPBinding)

Aggregations

JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)20 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)20 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)11 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)6 ArrayList (java.util.ArrayList)4 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)3 Test (org.junit.Test)3 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)2 Message (org.apache.cxf.common.i18n.Message)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 Annotation (java.lang.annotation.Annotation)1 HandlerChain (javax.jws.HandlerChain)1 SOAPBinding (javax.jws.soap.SOAPBinding)1 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlList (javax.xml.bind.annotation.XmlList)1 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)1 XmlType (javax.xml.bind.annotation.XmlType)1 QName (javax.xml.namespace.QName)1 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)1