- 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();
- }
-
- private Object executeOperation(final ConfigRegistryClient configRegistryClient, final ObjectName on,
- final String name, final Map<String, AttributeConfigElement> attributes) {
- final Object[] params = new Object[attributes.size()];
- final String[] signature = new String[attributes.size()];
-
- int i = 0;
- for (final AttributeConfigElement attribute : attributes.values()) {
- final Optional<?> resolvedValueOpt = attribute.getResolvedValue();
-
- params[i] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get() : attribute.getResolvedDefaultValue();
- signature[i] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get().getClass().getName() : attribute
- .getResolvedDefaultValue().getClass().getName();
- i++;
- }
-
- return configRegistryClient.invokeMethod(on, name, params, signature);
- }
-
- public NetconfOperationExecution fromXml(final XmlElement xml) throws NetconfDocumentedException {
- final String namespace;
- try {
- namespace = xml.getNamespace();
- } catch (MissingNameSpaceException e) {
- logger.trace("Can't get namespace from xml element due to {}",e);
- throw NetconfDocumentedException.wrap(e);
- }
- final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE);
- final String operationName = xml.getName();
-
- final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath(
- contextInstanceElement.getTextContent(), operationName, namespace);
-
- final Rpcs rpcs = mapRpcs(yangStoreSnapshot.getModuleMXBeanEntryMap());
-
- final ModuleRpcs rpcMapping = rpcs.getRpcMapping(id);
- final InstanceRuntimeRpc instanceRuntimeRpc = rpcMapping.getRpc(id.getRuntimeBeanName(), operationName);
-
- // TODO move to Rpcs after xpath attribute is redesigned
-
- final ObjectName on = id.getObjectName(rpcMapping);
- Map<String, AttributeConfigElement> attributes = instanceRuntimeRpc.fromXml(xml);
- attributes = sortAttributes(attributes, xml);
-
- return new NetconfOperationExecution(on, instanceRuntimeRpc.getName(), attributes,
- instanceRuntimeRpc.getReturnType(), namespace);
- }