Search in sources :

Example 6 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel 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[portNames.size()]));
            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)

Example 7 with JavaModel

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

the class WSDLToJavaProcessor method process.

public void process() throws ToolException {
    super.process();
    JavaModel jmodel = wsdlDefinitionToJavaModel(context.get(ServiceInfo.class));
    context.setJavaModel(jmodel);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Example 8 with JavaModel

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

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

the class JAXWSFrontEndProcessor method process.

@SuppressWarnings("unchecked")
public void process() throws ToolException {
    checkJaxwsClass();
    List<ServiceInfo> services = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
    ServiceInfo serviceInfo = services.get(0);
    JavaInterface jinf = JavaFirstUtil.serviceInfo2JavaInf(serviceInfo);
    String className = (String) context.get(ToolConstants.IMPL_CLASS);
    if (className != null && className.equals(jinf.getFullClassName())) {
        jinf.setName(jinf.getName() + SEI_SUFFIX);
    }
    JavaModel jm = new JavaModel();
    jm.addInterface("inf", jinf);
    jinf.setJavaModel(jm);
    context.put(JavaModel.class, jm);
    context.put(ToolConstants.SERVICE_NAME, serviceInfo.getName());
    EndpointInfo endpointInfo = serviceInfo.getEndpoints().iterator().next();
    context.put(ToolConstants.PORT_NAME, endpointInfo.getName());
    generators.add(new JaxwsSEIGenerator());
    generators.add(new JaxwsImplGenerator());
    generators.add(new JaxwsServerGenerator());
    generators.add(new JaxwsClientGenerator());
    generators.add(new AntGenerator());
    for (AbstractGenerator generator : generators) {
        generator.generate(context);
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JaxwsServerGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsServerGenerator) AbstractGenerator(org.apache.cxf.tools.wsdlto.core.AbstractGenerator) JaxwsImplGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsImplGenerator) JaxwsClientGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsClientGenerator) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxwsSEIGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsSEIGenerator) JavaModel(org.apache.cxf.tools.common.model.JavaModel) ArrayList(java.util.ArrayList) List(java.util.List) AntGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.AntGenerator)

Example 10 with JavaModel

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

the class JaxwsClientGenerator 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();
    QName service = (QName) env.get(ToolConstants.SERVICE_NAME);
    QName port = (QName) env.get(ToolConstants.PORT_NAME);
    for (JavaInterface intf : interfaces.values()) {
        clearAttributes();
        setAttributes("intf", intf);
        setAttributes("service", service);
        setAttributes("port", port);
        setAttributes("address", penv.get(ToolConstants.CFG_ADDRESS));
        setAttributes("seiClass", env.get(ToolConstants.SEI_CLASS));
        setCommonAttributes();
        doWrite(CLIENT_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Client"));
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Aggregations

JavaModel (org.apache.cxf.tools.common.model.JavaModel)24 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)20 QName (javax.xml.namespace.QName)11 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 JavaPort (org.apache.cxf.tools.common.model.JavaPort)6 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)6 Message (org.apache.cxf.common.i18n.Message)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 JavaException (org.apache.cxf.tools.common.model.JavaException)3 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 ToolContext (org.apache.cxf.tools.common.ToolContext)2 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 JavaExceptionClass (org.apache.cxf.tools.common.model.JavaExceptionClass)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)2 AntGenerator (org.apache.cxf.tools.java2wsdl.processor.internal.AntGenerator)2 ClassCollector (org.apache.cxf.tools.util.ClassCollector)2 AbstractGenerator (org.apache.cxf.tools.wsdlto.core.AbstractGenerator)2