X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fimpl%2FXmlReader.java;h=5b95f0de1ada80408f24670c310dce35a306ab5d;hb=da4cff5c3a5bc732fb046b563b886a7aaab67c30;hp=014e839f2665c7e9aa7c89c5a9f344aaef377b7b;hpb=9212fed678702583f4a555641208cf1c7b45b829;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlReader.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlReader.java index 014e839f26..5b95f0de1a 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlReader.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlReader.java @@ -1,3 +1,10 @@ +/* + * 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.sal.rest.impl; import static com.google.common.base.Preconditions.checkArgument; @@ -14,8 +21,8 @@ import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; -import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO; import org.opendaylight.controller.sal.restconf.impl.EmptyNodeWrapper; +import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO; import org.opendaylight.controller.sal.restconf.impl.NodeWrapper; import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper; import org.opendaylight.yangtools.yang.data.api.Node; @@ -148,6 +155,7 @@ public class XmlReader { final Characters chars = innerEvent.asCharacters(); if (!chars.isWhiteSpace()) { data = innerEvent.asCharacters().getData(); + data = data + getAdditionalData(eventReader.nextEvent()); } } else if (innerEvent.isEndElement()) { if (startElement.getLocation().getCharacterOffset() == innerEvent.getLocation().getCharacterOffset()) { @@ -157,6 +165,21 @@ public class XmlReader { } } } + return data == null ? null : data.trim(); + } + + private String getAdditionalData(XMLEvent event) throws XMLStreamException { + String data = ""; + if (eventReader.hasNext()) { + final XMLEvent innerEvent = eventReader.peek(); + if (innerEvent.isCharacters() && !innerEvent.isEndElement()) { + final Characters chars = innerEvent.asCharacters(); + if (!chars.isWhiteSpace()) { + data = innerEvent.asCharacters().getData(); + data = data + getAdditionalData(eventReader.nextEvent()); + } + } + } return data; } @@ -169,23 +192,23 @@ public class XmlReader { return namespaceURI.isEmpty() ? null : URI.create(namespaceURI); } - /** - * @param value - * value of startElement - * @param startElement - * element containing value - * @return if value is "prefix:value" then {@link IdentityValuesDTO} else the same - * string as parameter "value" - */ private Object resolveValueOfElement(String value, StartElement startElement) { - String[] namespaceAndValue = value.split(":"); - if (namespaceAndValue.length != 2) { // it is not "prefix:value" - return value; + // it could be instance-identifier Built-In Type + if (value.startsWith("/")) { + IdentityValuesDTO iiValue = RestUtil.asInstanceIdentifier(value, new RestUtil.PrefixMapingFromXml(startElement)); + if (iiValue != null) { + return iiValue; + } } - String namespace = startElement.getNamespaceContext().getNamespaceURI(namespaceAndValue[0]); - if (namespace != null && !namespace.isEmpty()) { - return new IdentityValuesDTO(namespace, namespaceAndValue[1], namespaceAndValue[0]); + // it could be identityref Built-In Type + String[] namespaceAndValue = value.split(":"); + if (namespaceAndValue.length == 2) { + String namespace = startElement.getNamespaceContext().getNamespaceURI(namespaceAndValue[0]); + if (namespace != null && !namespace.isEmpty()) { + return new IdentityValuesDTO(namespace, namespaceAndValue[1], namespaceAndValue[0],value); + } } + // it is not "prefix:value" but just "value" return value; }