Search in sources :

Example 1 with JaxbElementInfo

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

the class XmlElementDescription method addXmlInfo.

/**
     * Populate {@link desc} with value, attribute and sub-element information
     */
private static void addXmlInfo(XmlElementDescription desc, JaxbInfo jaxbInfo) {
    JaxbValueInfo valueInfo = jaxbInfo.getElementValue();
    if (valueInfo != null) {
        desc.valueFieldName = valueInfo.getFieldName();
        desc.valueType = ValueDescription.create(desc.valueFieldName, valueInfo.getAtomClass());
        desc.elementText = desc.valueType.getRepresentation();
    }
    for (JaxbAttributeInfo attrInfo : jaxbInfo.getAttributes()) {
        desc.attribs.add(XmlAttributeDescription.create(desc, attrInfo));
    }
    for (JaxbNodeInfo nodeInfo : jaxbInfo.getJaxbNodeInfos()) {
        if (nodeInfo instanceof WrappedElementInfo) {
            desc.children.add(XmlElementDescription.createForWrappedElement(desc, (WrappedElementInfo) nodeInfo));
        } else if (nodeInfo instanceof JaxbElementInfo) {
            desc.children.add(XmlElementDescription.createForElement(desc, (JaxbElementInfo) nodeInfo));
        } else if (nodeInfo instanceof JaxbPseudoNodeChoiceInfo) {
            JaxbPseudoNodeChoiceInfo jaxbChoice = (JaxbPseudoNodeChoiceInfo) nodeInfo;
            ChoiceNode choiceNode = new ChoiceNode(jaxbChoice.isMultiElement());
            desc.children.add(choiceNode);
            for (JaxbElementInfo choice : jaxbChoice.getElements()) {
                choiceNode.addChild(XmlElementDescription.createForElement(desc, choice));
            }
        }
    }
}
Also used : JaxbPseudoNodeChoiceInfo(com.zimbra.soap.util.JaxbPseudoNodeChoiceInfo) JaxbAttributeInfo(com.zimbra.soap.util.JaxbAttributeInfo) JaxbValueInfo(com.zimbra.soap.util.JaxbValueInfo) JaxbNodeInfo(com.zimbra.soap.util.JaxbNodeInfo) JaxbElementInfo(com.zimbra.soap.util.JaxbElementInfo) WrappedElementInfo(com.zimbra.soap.util.WrappedElementInfo)

Example 2 with JaxbElementInfo

use of com.zimbra.soap.util.JaxbElementInfo 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)

Example 3 with JaxbElementInfo

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

the class XmlElementDescription method createForWrappedElement.

private static XmlElementDescription createForWrappedElement(DescriptionNode parent, WrappedElementInfo nodeInfo) {
    XmlElementDescription desc = new XmlElementDescription(true, true, false);
    desc.parent = parent;
    desc.minOccurs = 1;
    desc.targetNamespace = nodeInfo.getNamespace();
    desc.name = nodeInfo.getName();
    desc.isInnerRecursionElement = false;
    desc.jaxbClass = null;
    desc.typeName = "";
    desc.typeIdString = "";
    desc.elementText = "";
    desc.fieldName = null;
    for (JaxbNodeInfo child : nodeInfo.getElements()) {
        if (child instanceof JaxbElementInfo) {
            desc.children.add(XmlElementDescription.createForElement(desc, (JaxbElementInfo) child));
        } else if (child instanceof JaxbPseudoNodeChoiceInfo) {
            JaxbPseudoNodeChoiceInfo jaxbChoice = (JaxbPseudoNodeChoiceInfo) child;
            ChoiceNode choiceNode = new ChoiceNode(jaxbChoice.isMultiElement());
            desc.children.add(choiceNode);
            for (JaxbElementInfo choice : jaxbChoice.getElements()) {
                choiceNode.addChild(XmlElementDescription.createForElement(desc, choice));
            }
        }
    }
    return desc;
}
Also used : JaxbPseudoNodeChoiceInfo(com.zimbra.soap.util.JaxbPseudoNodeChoiceInfo) JaxbNodeInfo(com.zimbra.soap.util.JaxbNodeInfo) JaxbElementInfo(com.zimbra.soap.util.JaxbElementInfo)

Aggregations

JaxbElementInfo (com.zimbra.soap.util.JaxbElementInfo)3 JaxbNodeInfo (com.zimbra.soap.util.JaxbNodeInfo)3 JaxbPseudoNodeChoiceInfo (com.zimbra.soap.util.JaxbPseudoNodeChoiceInfo)2 JaxbAttributeInfo (com.zimbra.soap.util.JaxbAttributeInfo)1 JaxbInfo (com.zimbra.soap.util.JaxbInfo)1 JaxbValueInfo (com.zimbra.soap.util.JaxbValueInfo)1 WrappedElementInfo (com.zimbra.soap.util.WrappedElementInfo)1 Test (org.junit.Test)1