Search in sources :

Example 1 with JavaInterface

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

the class AntGenerator 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()) {
        if (javaModel.getServiceClasses().isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_ANT", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        Map<String, String> clientClassNamesMap = new HashMap<>();
        Map<String, String> serverClassNamesMap = new HashMap<>();
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        int index = 1;
        for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
            for (JavaPort jp : js.getPorts()) {
                String interfaceName = jp.getInterfaceClass();
                JavaInterface intf = interfaces.get(interfaceName);
                if (intf == null) {
                    interfaceName = jp.getPortType();
                    intf = interfaces.get(interfaceName);
                }
                String clientClassName = intf.getPackageName() + "." + interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Client";
                String serverClassName = intf.getPackageName() + "." + interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Server";
                String clientTargetName = interfaceName + "Client";
                boolean collison = false;
                if (clientClassNamesMap.keySet().contains(clientTargetName)) {
                    clientTargetName = clientTargetName + index;
                    collison = true;
                }
                String serverTargetName = interfaceName + "Server";
                if (serverClassNamesMap.keySet().contains(serverTargetName)) {
                    serverTargetName = serverTargetName + index;
                    collison = true;
                }
                if (collison) {
                    index++;
                }
                clientClassNamesMap.put(clientTargetName, clientClassName);
                serverClassNamesMap.put(serverTargetName, serverClassName);
            }
        }
        clearAttributes();
        setAttributes("clientClassNamesMap", clientClassNamesMap);
        setAttributes("serverClassNamesMap", serverClassNamesMap);
        setAttributes("wsdlLocation", javaModel.getLocation());
        setCommonAttributes();
        doWrite(ANT_TEMPLATE, parseOutputName(null, "build", ".xml"));
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) HashMap(java.util.HashMap) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) JavaPort(org.apache.cxf.tools.common.model.JavaPort) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Example 2 with JavaInterface

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

the class ImplGenerator 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();
        Map<String, JavaServiceClass> services = javaModel.getServiceClasses();
        if (!services.values().isEmpty()) {
            for (JavaServiceClass javaservice : services.values()) {
                for (JavaPort jport : javaservice.getPorts()) {
                    JavaInterface intf = interfaces.get(jport.getInterfaceClass());
                    outputImpl(intf, javaservice, jport.getPortName(), penv);
                }
            }
        } else {
            for (Map.Entry<String, JavaInterface> entry : interfaces.entrySet()) {
                outputImpl(entry.getValue(), null, "", penv);
            }
        }
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) HashMap(java.util.HashMap) Map(java.util.Map) JavaPort(org.apache.cxf.tools.common.model.JavaPort)

Example 3 with JavaInterface

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

the class ServerGenerator 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()) {
        String address = "CHANGE_ME";
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        if (javaModel.getServiceClasses().isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_SRV", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
            for (JavaPort jp : js.getPorts()) {
                String interfaceName = jp.getInterfaceClass();
                JavaInterface intf = interfaces.get(interfaceName);
                if (intf == null) {
                    interfaceName = jp.getPortType();
                    intf = interfaces.get(interfaceName);
                }
                address = StringUtils.isEmpty(jp.getBindingAdress()) ? address : jp.getBindingAdress();
                String serverClassName = interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Server";
                serverClassName = mapClassName(intf.getPackageName(), serverClassName, penv);
                clearAttributes();
                setAttributes("serverClassName", serverClassName);
                setAttributes("intf", intf);
                String name = getImplName(jp.getPortName(), js.getServiceName(), intf, penv);
                setAttributes("impl", name);
                setAttributes("address", address);
                setCommonAttributes();
                doWrite(SRV_TEMPLATE, parseOutputName(intf.getPackageName(), serverClassName));
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaPort(org.apache.cxf.tools.common.model.JavaPort)

Example 4 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 {
    final JavaModel javaModel;
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) context.get(MODEL_MAP));
    if (map == null) {
        map = new LinkedHashMap<>();
        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 5 with JavaInterface

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

the class SimpleImplGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    JavaModel javaModel = env.get(JavaModel.class);
    if (passthrough()) {
        return;
    }
    Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
    for (JavaInterface intf : interfaces.values()) {
        clearAttributes();
        setAttributes("intf", intf);
        setAttributes("seiClass", env.get(ToolConstants.SEI_CLASS));
        setCommonAttributes();
        doWrite(IMPL_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Impl"));
        env.put(ToolConstants.IMPL_CLASS, intf.getFullClassName() + "Impl");
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

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