- private String getStringRepresentation(final Object result) {
- final SimpleType<?> simpleType = SimpleTypeResolver.getSimpleType(result.getClass().getName());
- final Optional<String> mappedAttributeOpt = new SimpleAttributeMappingStrategy(simpleType).mapAttribute(result);
- return mappedAttributeOpt.isPresent() ? mappedAttributeOpt.get() : "";
+ private Element toXml(Document doc, Object result, AttributeIfc returnType, String namespace, String elementName) throws NetconfDocumentedException {
+ AttributeMappingStrategy<?, ? extends OpenType<?>> mappingStrategy = new ObjectMapper().prepareStrategy(returnType);
+ Optional<?> mappedAttributeOpt = mappingStrategy.mapAttribute(result);
+ Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, returnType.getOpenType());
+
+ // FIXME: multiple return values defined as leaf-list and list in yang should not be wrapped in output xml element,
+ // they need to be appended directly under rpc-reply element
+ //
+ // Either allow List of Elements to be returned from NetconfOperation or
+ // pass reference to parent output xml element for netconf operations to
+ // append result(s) on their own
+ Element tempParent = XmlUtil.createElement(doc, "output", Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+ new ObjectXmlWriter().prepareWritingStrategy(elementName, returnType, doc).writeElement(tempParent, namespace, mappedAttributeOpt.get());
+
+ XmlElement xmlElement = XmlElement.fromDomElement(tempParent);
+ return xmlElement.getChildElements().size() > 1 ? tempParent : xmlElement.getOnlyChildElement().getDomElement();