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;
}
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());
}
}
}
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));
}
Aggregations