Search in sources :

Example 21 with JavaMethod

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

the class WrapperAnnotator method annotate.

public void annotate(JavaAnnotatable ja) {
    JavaMethod method;
    if (ja instanceof JavaMethod) {
        method = (JavaMethod) ja;
    } else {
        throw new RuntimeException("RequestWrapper and ResponseWrapper can only annotate JavaMethod");
    }
    if (wrapperRequest != null) {
        JAnnotation requestAnnotation = new JAnnotation(RequestWrapper.class);
        requestAnnotation.addElement(new JAnnotationElement("localName", wrapperRequest.getType()));
        requestAnnotation.addElement(new JAnnotationElement("targetNamespace", wrapperRequest.getTargetNamespace()));
        requestAnnotation.addElement(new JAnnotationElement("className", wrapperRequest.getClassName()));
        method.addAnnotation("RequestWrapper", requestAnnotation);
        method.getInterface().addImports(requestAnnotation.getImports());
    }
    if (wrapperResponse != null) {
        List<JAnnotationElement> elements = new ArrayList<>();
        elements.add(new JAnnotationElement("localName", wrapperResponse.getType()));
        elements.add(new JAnnotationElement("targetNamespace", wrapperResponse.getTargetNamespace()));
        elements.add(new JAnnotationElement("className", wrapperResponse.getClassName()));
        JAnnotation responseAnnotation = new JAnnotation(ResponseWrapper.class);
        responseAnnotation.getElements().addAll(elements);
        method.addAnnotation("ResponseWrapper", responseAnnotation);
        method.getInterface().addImports(responseAnnotation.getImports());
    }
}
Also used : 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)

Example 22 with JavaMethod

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

the class XmlJavaTypeAdapterAnnotator method annotate.

public void annotate(JavaAnnotatable jn) {
    JAnnotation jaxbAnnotation = new JAnnotation(XmlJavaTypeAdapter.class);
    jaxbAnnotation.addElement(new JAnnotationElement("value", adapter));
    if (jn instanceof JavaParameter) {
        JavaParameter jp = (JavaParameter) jn;
        jp.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
    } else if (jn instanceof JavaMethod) {
        JavaMethod jm = (JavaMethod) jn;
        jm.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
    } else {
        throw new RuntimeException("Annotation of " + jn.getClass() + " not supported.");
    }
    jf.addImport(XmlJavaTypeAdapter.class.getName());
    jf.addImport(adapter.getName());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 23 with JavaMethod

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

the class XmlListAnotator method annotate.

public void annotate(JavaAnnotatable jn) {
    JAnnotation jaxbAnnotation = new JAnnotation(XmlList.class);
    if (jn instanceof JavaParameter) {
        JavaParameter jp = (JavaParameter) jn;
        jp.addAnnotation("XmlList", jaxbAnnotation);
    } else if (jn instanceof JavaMethod) {
        JavaMethod jm = (JavaMethod) jn;
        jm.addAnnotation("XmlList", jaxbAnnotation);
    } else {
        throw new RuntimeException("XmlList can only annotate to JavaParameter or JavaMethod");
    }
    jf.addImport(XmlList.class.getName());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) XmlList(javax.xml.bind.annotation.XmlList)

Example 24 with JavaMethod

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

the class MethodMapperTest method testMapWrappedOperation.

@Test
public void testMapWrappedOperation() throws Exception {
    OperationInfo operation = getOperation();
    operation.setUnwrappedOperation(operation);
    JavaMethod method = new MethodMapper().map(operation);
    assertNotNull(method);
    assertTrue(method.isWrapperStyle());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Test(org.junit.Test)

Example 25 with JavaMethod

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

the class JAXWSContainerTest method testSuppressCodeGen.

@Test
public void testSuppressCodeGen() {
    try {
        JAXWSContainer container = new JAXWSContainer(null);
        ToolContext context = new ToolContext();
        // Do not generate any artifacts, we just want the code model.
        context.put(ToolConstants.CFG_SUPPRESS_GEN, "suppress");
        // Where to put the generated source code
        context.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
        // Delegate jaxb to generate the type classes
        context.put(DataBindingProfile.class, PluginLoader.getInstance().getDataBindingProfile("jaxb"));
        context.put(FrontEndProfile.class, PluginLoader.getInstance().getFrontEndProfile("jaxws"));
        container.setContext(context);
        // Now shoot
        container.execute();
        // At this point you should be able to get the
        // SEI/Service(Client stub)/Exception classes/Types classes
        assertNotNull(output.list());
        assertEquals(0, output.list().length);
        // Now you can get the JavaModel from the context.
        Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) context.get(WSDLToJavaProcessor.MODEL_MAP));
        JavaModel javaModel = map.get(new QName("http://cxf.apache.org/w2j/hello_world_soap_http", "SOAPService"));
        assertNotNull(javaModel);
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        assertEquals(1, interfaces.size());
        JavaInterface intf = interfaces.values().iterator().next();
        String interfaceName = intf.getName();
        assertEquals("Greeter", interfaceName);
        assertEquals("http://cxf.apache.org/w2j/hello_world_soap_http", intf.getNamespace());
        assertEquals("org.apache.cxf.w2j.hello_world_soap_http", intf.getPackageName());
        List<JavaMethod> methods = intf.getMethods();
        assertEquals(6, methods.size());
        Boolean methodSame = false;
        JavaMethod m1 = null;
        for (JavaMethod m2 : methods) {
            if (m2.getName().equals("testDocLitFault")) {
                methodSame = true;
                m1 = m2;
                break;
            }
        }
        assertTrue(methodSame);
        assertNotNull(m1);
        assertEquals(2, m1.getExceptions().size());
        List<String> names = new ArrayList<>();
        for (JavaException exc : m1.getExceptions()) {
            names.add(exc.getName());
        }
        assertTrue("BadRecordLitFault", names.contains("BadRecordLitFault"));
        assertTrue("NoSuchCodeLitFault", names.contains("NoSuchCodeLitFault"));
        String address = null;
        for (JavaServiceClass service : javaModel.getServiceClasses().values()) {
            if ("SOAPService_Test1".equals(service.getName())) {
                continue;
            }
            List<JavaPort> ports = service.getPorts();
            for (JavaPort port : ports) {
                if (interfaceName.equals(port.getPortType())) {
                    address = port.getBindingAdress();
                    break;
                }
            }
            if (!"".equals(address)) {
                break;
            }
        }
        assertEquals("http://localhost:9000/SoapContext/SoapPort", address);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaException(org.apache.cxf.tools.common.model.JavaException) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) JAXWSContainer(org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer) ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) JavaException(org.apache.cxf.tools.common.model.JavaException) JavaPort(org.apache.cxf.tools.common.model.JavaPort) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Test(org.junit.Test)

Aggregations

JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)28 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)14 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)11 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)9 Test (org.junit.Test)9 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)7 OperationInfo (org.apache.cxf.service.model.OperationInfo)6 JavaException (org.apache.cxf.tools.common.model.JavaException)5 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)4 ArrayList (java.util.ArrayList)3 ToolContext (org.apache.cxf.tools.common.ToolContext)3 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 URISyntaxException (java.net.URISyntaxException)2 SOAPBinding (javax.jws.soap.SOAPBinding)2 QName (javax.xml.namespace.QName)2 FaultInfo (org.apache.cxf.service.model.FaultInfo)2 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)2