Search in sources :

Example 1 with JavaPort

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

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

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

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

the class ClientGenerator 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_CLIENT", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        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 = interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Client";
                clientClassName = mapClassName(intf.getPackageName(), clientClassName, penv);
                clearAttributes();
                setAttributes("clientClassName", clientClassName);
                setAttributes("intf", intf);
                setAttributes("service", js);
                setAttributes("port", jp);
                setCommonAttributes();
                doWrite(CLT_TEMPLATE, parseOutputName(intf.getPackageName(), clientClassName));
            }
        }
    }
}
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 5 with JavaPort

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

the class ServiceGenerator 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()) {
        ClassCollector collector = penv.get(ClassCollector.class);
        Map<String, JavaServiceClass> serviceClasses = javaModel.getServiceClasses();
        if (serviceClasses.isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_SERVICE", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        for (JavaServiceClass js : serviceClasses.values()) {
            if (js.getHandlerChains() != null) {
                HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
                handlerGen.setJavaInterface(js);
                handlerGen.generate(getEnvironment());
                JAnnotation annot = handlerGen.getHandlerAnnotation();
                if (handlerGen.getHandlerAnnotation() != null) {
                    boolean existHandlerAnno = false;
                    for (JAnnotation jann : js.getAnnotations()) {
                        if (jann.getType() == HandlerChain.class) {
                            existHandlerAnno = true;
                        }
                    }
                    if (!existHandlerAnno) {
                        js.addAnnotation(annot);
                        js.addImport("javax.jws.HandlerChain");
                    }
                }
            }
            Set<String> portNames = new HashSet<>();
            for (JavaPort port : js.getPorts()) {
                if (!port.getPackageName().equals(js.getPackageName()) && !port.getInterfaceClass().equals(js.getName())) {
                    js.addImport(port.getFullClassName());
                }
                portNames.add(port.getInterfaceClass());
            }
            if ("cxf".equals(env.get(ToolConstants.CFG_FRONTEND))) {
                js.addImport(BindingProvider.class.getName());
                js.addImport(Client.class.getName());
            }
            String url = (String) env.get(ToolConstants.CFG_WSDLURL);
            String location = (String) env.get(ToolConstants.CFG_WSDLLOCATION);
            if (location == null) {
                location = url;
            }
            String serviceSuperclass = (String) env.get("service.superclass");
            String simpleServiceName = serviceSuperclass.substring(serviceSuperclass.lastIndexOf('.') + 1);
            for (String s : collector.getGeneratedFileInfo()) {
                if (s.equals(js.getPackageName() + "." + simpleServiceName)) {
                    simpleServiceName = serviceSuperclass;
                    break;
                }
            }
            clearAttributes();
            boolean useGetResource = false;
            try {
                new URL(location);
            } catch (MalformedURLException e) {
                useGetResource = true;
            }
            setAttributes("cxfPortClassnames", portNames.toArray(new String[0]));
            setAttributes("service", js);
            setAttributes("wsdlLocation", location);
            setAttributes("useGetResource", useGetResource);
            setAttributes("serviceSuperclass", simpleServiceName);
            if (!simpleServiceName.equals(serviceSuperclass)) {
                js.addImport(serviceSuperclass);
            }
            setAttributes("wsdlUrl", url);
            setCommonAttributes();
            String target = (String) env.get("service.target");
            setAttributes("serviceTarget", target);
            if ("jaxws22".equals(target)) {
                setAttributes("jaxws22", true);
            }
            doWrite(SERVICE_TEMPLATE, parseOutputName(js.getPackageName(), js.getName()));
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Message(org.apache.cxf.common.i18n.Message) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) ClassCollector(org.apache.cxf.tools.util.ClassCollector) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) JavaPort(org.apache.cxf.tools.common.model.JavaPort) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaModel(org.apache.cxf.tools.common.model.JavaModel) Client(org.apache.cxf.endpoint.Client) HashSet(java.util.HashSet)

Aggregations

JavaPort (org.apache.cxf.tools.common.model.JavaPort)8 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)7 QName (javax.xml.namespace.QName)6 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)6 JavaModel (org.apache.cxf.tools.common.model.JavaModel)6 Message (org.apache.cxf.common.i18n.Message)5 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)4 HashMap (java.util.HashMap)2 ClassCollector (org.apache.cxf.tools.util.ClassCollector)2 JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)2 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 BindingProvider (javax.xml.ws.BindingProvider)1 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)1 Client (org.apache.cxf.endpoint.Client)1