Search in sources :

Example 6 with JavaInterface

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

the class WSDLToJavaProcessor method wsdlDefinitionToJavaModel.

private JavaModel wsdlDefinitionToJavaModel(ServiceInfo serviceInfo) throws ToolException {
    JavaModel javaModel = null;
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) context.get(MODEL_MAP));
    if (map == null) {
        map = new LinkedHashMap<QName, JavaModel>();
        context.put(MODEL_MAP, map);
    }
    if (map.containsKey(serviceInfo.getName())) {
        javaModel = map.get(serviceInfo.getName());
    } else {
        javaModel = new JavaModel();
        map.put(serviceInfo.getName(), javaModel);
    }
    context.put(JavaModel.class, javaModel);
    List<JavaInterface> interfaces = new ArrayList<>();
    interfaces.addAll(javaModel.getInterfaces().values());
    PortTypeProcessor portTypeProcessor = new PortTypeProcessor(context);
    portTypeProcessor.process(serviceInfo);
    ServiceProcessor serviceProcessor = new ServiceProcessor(context);
    serviceProcessor.process(serviceInfo);
    for (JavaInterface intf : javaModel.getInterfaces().values()) {
        if (!interfaces.contains(intf)) {
            intf.annotate(new WebServiceAnnotator());
            intf.annotate(new XmlSeeAlsoAnnotator(context.get(ClassCollector.class)));
            intf.annotate(new BindingAnnotator());
        }
    }
    return javaModel;
}
Also used : PortTypeProcessor(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.PortTypeProcessor) ServiceProcessor(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.ServiceProcessor) XmlSeeAlsoAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.XmlSeeAlsoAnnotator) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) ArrayList(java.util.ArrayList) WebServiceAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebServiceAnnotator) BindingAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.BindingAnnotator)

Example 7 with JavaInterface

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

the class PortTypeProcessor method getInterface.

public static JavaInterface getInterface(ToolContext context, ServiceInfo serviceInfo, InterfaceInfo interfaceInfo) throws ToolException {
    JavaInterface intf = interfaceInfo.getProperty("JavaInterface", JavaInterface.class);
    if (intf == null) {
        intf = new InterfaceMapper(context).map(interfaceInfo);
        JAXWSBinding jaxwsBinding = null;
        if (serviceInfo.getDescription() != null) {
            jaxwsBinding = serviceInfo.getDescription().getExtensor(JAXWSBinding.class);
        }
        JAXWSBinding infBinding = interfaceInfo.getExtensor(JAXWSBinding.class);
        if (infBinding != null && infBinding.getPackage() != null) {
            intf.setPackageName(infBinding.getPackage());
        } else if (jaxwsBinding != null && jaxwsBinding.getPackage() != null) {
            intf.setPackageName(jaxwsBinding.getPackage());
        }
        if (infBinding != null && !infBinding.getPackageJavaDoc().equals("")) {
            intf.setPackageJavaDoc(infBinding.getPackageJavaDoc());
        } else if (jaxwsBinding != null && !jaxwsBinding.getPackageJavaDoc().equals("")) {
            intf.setPackageJavaDoc(jaxwsBinding.getPackageJavaDoc());
        }
        String name = intf.getName();
        if (infBinding != null && infBinding.getJaxwsClass() != null && infBinding.getJaxwsClass().getClassName() != null) {
            name = infBinding.getJaxwsClass().getClassName();
            if (name.contains(".")) {
                intf.setPackageName(name.substring(0, name.lastIndexOf('.')));
                name = name.substring(name.lastIndexOf('.') + 1);
            }
            intf.setClassJavaDoc(infBinding.getJaxwsClass().getComments());
        }
        if (StringUtils.isEmpty(intf.getClassJavaDoc())) {
            intf.setClassJavaDoc(interfaceInfo.getDocumentation());
        }
        ClassCollector collector = context.get(ClassCollector.class);
        if (context.optionSet(ToolConstants.CFG_AUTORESOLVE)) {
            int count = 0;
            String checkName = name;
            while (collector.isReserved(intf.getPackageName(), checkName)) {
                checkName = name + "_" + (++count);
            }
            name = checkName;
        } else if (collector.isReserved(intf.getPackageName(), name)) {
            throw new ToolException("RESERVED_SEI_NAME", LOG, name);
        }
        interfaceInfo.setProperty("InterfaceName", name);
        intf.setName(name);
        collector.addSeiClassName(intf.getPackageName(), intf.getName(), intf.getPackageName() + "." + intf.getName());
        interfaceInfo.setProperty("JavaInterface", intf);
        if (context.containsKey(ToolConstants.CFG_SEI_SUPER)) {
            String[] supers = context.getArray(ToolConstants.CFG_SEI_SUPER);
            for (String s : supers) {
                intf.addSuperInterface(s);
            }
        }
    }
    return intf;
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) ClassCollector(org.apache.cxf.tools.util.ClassCollector) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) ToolException(org.apache.cxf.tools.common.ToolException) InterfaceMapper(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.mapper.InterfaceMapper)

Example 8 with JavaInterface

use of org.apache.cxf.tools.common.model.JavaInterface 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 9 with JavaInterface

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

the class WSActionAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaMethod method;
    if (ja instanceof JavaMethod) {
        method = (JavaMethod) ja;
    } else {
        throw new RuntimeException("Action can only annotate JavaMethod");
    }
    boolean required = false;
    JavaInterface intf = method.getInterface();
    MessageInfo inputMessage = operation.getInput();
    MessageInfo outputMessage = operation.getOutput();
    JAnnotation actionAnnotation = new JAnnotation(Action.class);
    if (inputMessage.getExtensionAttributes() != null) {
        String inputAction = getAction(inputMessage);
        if (inputAction != null) {
            actionAnnotation.addElement(new JAnnotationElement("input", inputAction));
            required = true;
        }
    }
    if (outputMessage != null && outputMessage.getExtensionAttributes() != null) {
        String outputAction = getAction(outputMessage);
        if (outputAction != null) {
            actionAnnotation.addElement(new JAnnotationElement("output", outputAction));
            required = true;
        }
    }
    if (operation.hasFaults()) {
        List<JAnnotation> faultAnnotations = new ArrayList<>();
        for (FaultInfo faultInfo : operation.getFaults()) {
            if (faultInfo.getExtensionAttributes() != null) {
                String faultAction = getAction(faultInfo);
                if (faultAction == null) {
                    continue;
                }
                JavaException exceptionClass = getExceptionClass(method, faultInfo);
                if (!StringUtils.isEmpty(exceptionClass.getPackageName()) && !exceptionClass.getPackageName().equals(intf.getPackageName())) {
                    intf.addImport(exceptionClass.getClassName());
                }
                JAnnotation faultAnnotation = new JAnnotation(FaultAction.class);
                faultAnnotation.addElement(new JAnnotationElement("className", exceptionClass));
                faultAnnotation.addElement(new JAnnotationElement("value", faultAction));
                faultAnnotations.add(faultAnnotation);
                required = true;
            }
        }
        actionAnnotation.addElement(new JAnnotationElement("fault", faultAnnotations));
    }
    if (required) {
        method.addAnnotation("Action", actionAnnotation);
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) FaultInfo(org.apache.cxf.service.model.FaultInfo) JavaException(org.apache.cxf.tools.common.model.JavaException) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) ArrayList(java.util.ArrayList) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 10 with JavaInterface

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

the class XmlSeeAlsoAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    if (collector == null || collector.getTypesPackages().isEmpty()) {
        return;
    }
    JavaInterface intf = null;
    if (ja instanceof JavaInterface) {
        intf = (JavaInterface) ja;
    } else {
        throw new RuntimeException("XmlSeeAlso can only annotate JavaInterface");
    }
    JAnnotation jaxbAnnotation = new JAnnotation(XmlSeeAlso.class);
    intf.addImports(jaxbAnnotation.getImports());
    List<JavaType> types = new ArrayList<>();
    for (String pkg : collector.getTypesPackages()) {
        if (pkg.equals(intf.getPackageName())) {
            types.add(new JavaType(null, "ObjectFactory", null));
        } else {
            types.add(new JavaType(null, pkg + ".ObjectFactory", null));
        }
    }
    jaxbAnnotation.addElement(new JAnnotationElement(null, types));
    intf.addAnnotation(jaxbAnnotation);
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaType(org.apache.cxf.tools.common.model.JavaType) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) ArrayList(java.util.ArrayList)

Aggregations

JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)33 JavaModel (org.apache.cxf.tools.common.model.JavaModel)20 QName (javax.xml.namespace.QName)11 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)7 ArrayList (java.util.ArrayList)6 Message (org.apache.cxf.common.i18n.Message)6 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)6 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)6 JavaPort (org.apache.cxf.tools.common.model.JavaPort)6 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)5 JavaException (org.apache.cxf.tools.common.model.JavaException)5 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)5 OperationInfo (org.apache.cxf.service.model.OperationInfo)4 ToolContext (org.apache.cxf.tools.common.ToolContext)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 ToolException (org.apache.cxf.tools.common.ToolException)3 JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)3 GenericArrayType (java.lang.reflect.GenericArrayType)2