X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fcli%2Freader%2Fimpl%2FAnyXmlReader.java;fp=opendaylight%2Fnetconf%2Fnetconf-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fcli%2Freader%2Fimpl%2FAnyXmlReader.java;h=0000000000000000000000000000000000000000;hp=a8d2590f562edc1cddc1965efe9726c3d9015d32;hb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;hpb=071a641d7c12c0e6112d5ce0afe806b54f116ed2 diff --git a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/impl/AnyXmlReader.java b/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/impl/AnyXmlReader.java deleted file mode 100644 index a8d2590f56..0000000000 --- a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/impl/AnyXmlReader.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.netconf.cli.reader.impl; - -import static org.opendaylight.controller.netconf.cli.io.IOUtil.isSkipInput; -import static org.opendaylight.controller.netconf.cli.io.IOUtil.listType; - -import com.google.common.base.Optional; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.opendaylight.controller.netconf.cli.io.BaseConsoleContext; -import org.opendaylight.controller.netconf.cli.io.ConsoleContext; -import org.opendaylight.controller.netconf.cli.io.ConsoleIO; -import org.opendaylight.controller.netconf.cli.reader.AbstractReader; -import org.opendaylight.controller.netconf.cli.reader.ReadingException; -import org.opendaylight.controller.netconf.util.xml.XmlUtil; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; -import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory; -import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -public class AnyXmlReader extends AbstractReader { - - public AnyXmlReader(final ConsoleIO console, final SchemaContext schemaContext) { - super(console, schemaContext); - } - - public AnyXmlReader(final ConsoleIO console, final SchemaContext schemaContext, final boolean readConfigNode) { - super(console, schemaContext, readConfigNode); - } - - @Override - protected List> readWithContext(final AnyXmlSchemaNode schemaNode) throws IOException, ReadingException { - console.writeLn(listType(schemaNode) + " " + schemaNode.getQName().getLocalName()); - - final String rawValue = console.read(); - - DataContainerChild newNode = null; - if (!isSkipInput(rawValue)) { - final Optional> value = tryParse(rawValue, schemaNode); - - if (value.isPresent()) { - newNode = ImmutableContainerNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(schemaNode.getQName())) - .withChild(value.get()).build(); - } else { - newNode = ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(schemaNode.getQName())).withValue(rawValue).build(); - } - } - - final List> newNodes = new ArrayList<>(); - newNodes.add(newNode); - return newNodes; - } - - private Optional> tryParse(final String rawValue, final AnyXmlSchemaNode schemaNode) { - try { - final Document dom = XmlUtil.readXmlToDocument(rawValue); - return Optional.> of( - DomToNormalizedNodeParserFactory. - getInstance(DomUtils.defaultValueCodecProvider(), getSchemaContext()). - getAnyXmlNodeParser(). - parse(Collections.singletonList(dom.getDocumentElement()), schemaNode) - ); - } catch (SAXException | IOException e) { - // TODO log - return Optional.absent(); - } - } - - @Override - protected ConsoleContext getContext(final AnyXmlSchemaNode schemaNode) { - return new BaseConsoleContext<>(schemaNode); - } -}