Search in sources :

Example 6 with JaxbInfo

use of com.zimbra.soap.util.JaxbInfo in project zm-mailbox by Zimbra.

the class WsdlDocGenerator method processJaxbClasses.

public static Root processJaxbClasses(Map<String, ApiClassDocumentation> javadocInfo, List<Class<?>> classes) {
    Map<Package, String> pkgToNamespace = Maps.newHashMap();
    Root root = new Root();
    for (Class<?> jaxbClass : classes) {
        JaxbInfo jaxbInfo = JaxbInfo.getFromCache(jaxbClass);
        String namespace = getNamespace(jaxbClass, pkgToNamespace);
        Service svc = root.getServiceForNamespace(namespace);
        if (svc == null) {
            svc = root.addService(new Service(namespace.replaceFirst("urn:", ""), namespace));
            String svcDesc = serviceDescriptions.get(namespace);
            if (svcDesc == null) {
                throw new RuntimeException("No service description exists for namespace " + namespace);
            } else {
                svc.setDescription(svcDesc);
            }
        }
        String cmdName;
        Command cmd;
        XmlElementDescription desc;
        String className = jaxbClass.getName();
        className = jaxbInfo.getRootElementName();
        if (className.endsWith("Request")) {
            cmdName = className.substring(0, className.lastIndexOf("Request"));
            cmd = svc.getCommand(namespace, cmdName);
            if (cmd == null) {
                cmd = svc.addCommand(new Command(svc, cmdName, namespace));
            }
            desc = XmlElementDescription.createTopLevel(jaxbInfo, namespace, jaxbInfo.getRootElementName());
            markupDuplicateElements(desc);
            cmd.setDescription(desc.getDescription());
            cmd.setRootRequestElement(desc);
        // getJavaDocInfoForCommand(cmd, jaxbClass);
        } else if (className.endsWith("Response")) {
            cmdName = className.substring(0, className.lastIndexOf("Response"));
            cmd = svc.getCommand(namespace, cmdName);
            if (cmd == null) {
                cmd = svc.addCommand(new Command(svc, cmdName, namespace));
            }
            desc = XmlElementDescription.createTopLevel(jaxbInfo, namespace, jaxbInfo.getRootElementName());
            markupDuplicateElements(desc);
            cmd.setRootResponseElement(desc);
        } else {
            throw new RuntimeException(String.format("Cannot handle top level class %s.  Expecting Request or Response", className));
        }
    }
    populateWithJavadocInfo(root, javadocInfo);
    return root;
}
Also used : JaxbInfo(com.zimbra.soap.util.JaxbInfo)

Example 7 with JaxbInfo

use of com.zimbra.soap.util.JaxbInfo in project zm-mailbox by Zimbra.

the class JaxbToElementTest method jaxbElementNameOrderXmlElementWrapperTest.

@Test
public void jaxbElementNameOrderXmlElementWrapperTest() throws Exception {
    JaxbInfo jaxbInfo = JaxbInfo.getFromCache(GetWhiteBlackListResponse.class);
    List<List<org.dom4j.QName>> expectedOrder = Lists.newArrayList();
    expectedOrder.add(Lists.newArrayList(new org.dom4j.QName(AccountConstants.E_WHITE_LIST, AccountConstants.NAMESPACE)));
    expectedOrder.add(Lists.newArrayList(new org.dom4j.QName(AccountConstants.E_BLACK_LIST, AccountConstants.NAMESPACE)));
    List<List<org.dom4j.QName>> nameOrder = jaxbInfo.getElementNameOrder();
    Assert.assertTrue(String.format("Number of entries in order expected=%d actual=%d", expectedOrder.size(), nameOrder.size()), expectedOrder.size() == nameOrder.size());
    for (int ndx = 0; ndx < nameOrder.size(); ndx++) {
        List<QName> expected = expectedOrder.get(ndx);
        List<QName> actual = nameOrder.get(ndx);
        Assert.assertTrue(String.format("Number of entries at pos %d expected=%d actual=%d", ndx, expected.size(), actual.size()), expected.size() == actual.size());
        for (int cnt = 0; cnt < actual.size(); cnt++) {
            QName qExpected = expected.get(cnt);
            QName qActual = actual.get(cnt);
            Assert.assertEquals(String.format("Element name at pos %d/%d", ndx, cnt), qExpected.getName(), qActual.getName());
            Assert.assertEquals(String.format("Element namespaceURI at pos %d/%d", ndx, cnt), qExpected.getNamespaceURI(), qActual.getNamespaceURI());
        }
    }
}
Also used : QName(org.dom4j.QName) List(java.util.List) JaxbInfo(com.zimbra.soap.util.JaxbInfo) Test(org.junit.Test)

Example 8 with JaxbInfo

use of com.zimbra.soap.util.JaxbInfo in project zm-mailbox by Zimbra.

the class JaxbToElementTest method jaxbInfoSuperclassElems.

@Test
public void jaxbInfoSuperclassElems() throws Exception {
    JaxbInfo jaxbInfo = JaxbInfo.getFromCache(CreateAccountRequest.class);
    Iterable<String> attrNames = jaxbInfo.getAttributeNames();
    Assert.assertEquals("Number of attributes for CreateAccountRequest", 2, Iterables.size(attrNames));
    Iterable<String> elemNames = jaxbInfo.getElementNames();
    Assert.assertEquals("Number of elements for CreateAccountRequest", 1, Iterables.size(elemNames));
    Assert.assertTrue("Has <a>", -1 != Iterables.indexOf(elemNames, Predicates.equalTo(MailConstants.E_A)));
    Iterable<JaxbNodeInfo> nodeInfos = jaxbInfo.getJaxbNodeInfos();
    Assert.assertEquals("Number of nodeInfos for CreateAccountRequest", 1, Iterables.size(nodeInfos));
    JaxbNodeInfo nodeInfo = Iterables.get(nodeInfos, 0);
    Assert.assertEquals("NodeInfo name ", MailConstants.E_A, nodeInfo.getName());
    if (!(nodeInfo instanceof JaxbElementInfo)) {
        Assert.fail("Expecting JaxbElementInfo but got " + nodeInfo.getClass().getName());
    } else {
        JaxbElementInfo elemInfo = (JaxbElementInfo) nodeInfo;
        Assert.assertEquals("Class associated with <a>", Attr.class, elemInfo.getAtomClass());
    }
    JaxbNodeInfo node = jaxbInfo.getElemNodeInfo(MailConstants.E_A);
    Assert.assertNotNull("has NodeInfo for Element <a>", node);
    Assert.assertTrue("hasElement <a>", jaxbInfo.hasElement(MailConstants.E_A));
}
Also used : JaxbNodeInfo(com.zimbra.soap.util.JaxbNodeInfo) JaxbElementInfo(com.zimbra.soap.util.JaxbElementInfo) JaxbInfo(com.zimbra.soap.util.JaxbInfo) Test(org.junit.Test)

Aggregations

JaxbInfo (com.zimbra.soap.util.JaxbInfo)8 Test (org.junit.Test)4 List (java.util.List)3 Element (com.zimbra.common.soap.Element)2 QName (org.dom4j.QName)2 ServiceException (com.zimbra.common.service.ServiceException)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 MessagePartHit (com.zimbra.cs.index.MessagePartHit)1 Message (com.zimbra.cs.mailbox.Message)1 JaxbElementInfo (com.zimbra.soap.util.JaxbElementInfo)1 JaxbNodeInfo (com.zimbra.soap.util.JaxbNodeInfo)1 JAXBElement (javax.xml.bind.JAXBElement)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1