summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
f31f6f0)
When encountering a QName value in a leaf, a leaf-list or implied as the
value of a key, we need to properly encode it. The same is true when
parsing, where we have to consult current namespace mapping.
As a side-effect of this, we are also fixing the case of a leaf-list
entry referenced in a path argument -- which is important for all
non-String types.
JIRA: YANGTOOLS-1473
Change-Id: Id50ebd9a3c0c1378f1af8451b86c66e323757eba
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
protected final Object deserializeKeyValue(final DataSchemaNode schemaNode, final LeafrefResolver resolver,
final String value) {
requireNonNull(schemaNode, "schemaNode cannot be null");
protected final Object deserializeKeyValue(final DataSchemaNode schemaNode, final LeafrefResolver resolver,
final String value) {
requireNonNull(schemaNode, "schemaNode cannot be null");
- checkArgument(schemaNode instanceof LeafSchemaNode, "schemaNode must be of type LeafSchemaNode");
- return codecFactory.codecFor((LeafSchemaNode) schemaNode, resolver).parseValue(null, value);
+ if (schemaNode instanceof LeafSchemaNode leafSchemaNode) {
+ return codecFactory.codecFor(leafSchemaNode, resolver).parseValue(null, value);
+ } else if (schemaNode instanceof LeafListSchemaNode leafListSchemaNode) {
+ return codecFactory.codecFor(leafListSchemaNode, resolver).parseValue(null, value);
+ }
+ throw new IllegalArgumentException("schemaNode " + schemaNode
+ + " must be of type LeafSchemaNode or LeafListSchemaNode");
- @Disabled("YT-1473: QName values need to be recognized and properly encoded via identity codec")
void testSerializeIdentityRefSame() throws Exception {
assertSerdes("/foo:bar[qname='one']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, FOO_ONE));
}
@Test
void testSerializeIdentityRefSame() throws Exception {
assertSerdes("/foo:bar[qname='one']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, FOO_ONE));
}
@Test
- @Disabled("YT-1473: QName values need to be recognized and properly encoded via identity codec")
void testSerializeIdentityRefOther() throws Exception {
// No escaping is needed, use double quotes and escape
assertSerdes("/foo:bar[qname='bar:two']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, BAR_TWO));
void testSerializeIdentityRefOther() throws Exception {
// No escaping is needed, use double quotes and escape
assertSerdes("/foo:bar[qname='bar:two']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, BAR_TWO));
- @Disabled("YT-1473: QName values need to be recognized and properly encoded via identity codec")
void testSerializeIdentityValue() throws Exception {
assertSerdes("/bar:foo[.='foo:one']", buildYangInstanceIdentifier(BAR_FOO, FOO_ONE));
assertSerdes("/bar:foo[.='two']", buildYangInstanceIdentifier(BAR_FOO, BAR_TWO));
void testSerializeIdentityValue() throws Exception {
assertSerdes("/bar:foo[.='foo:one']", buildYangInstanceIdentifier(BAR_FOO, FOO_ONE));
assertSerdes("/bar:foo[.='two']", buildYangInstanceIdentifier(BAR_FOO, BAR_TWO));
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
*/
package org.opendaylight.yangtools.yang.data.codec.xml;
-import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import java.util.ArrayDeque;
import static java.util.Objects.requireNonNull;
import java.util.ArrayDeque;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
protected Object deserializeKeyValue(final DataSchemaNode schemaNode, final LeafrefResolver resolver,
final String value) {
requireNonNull(schemaNode, "schemaNode cannot be null");
protected Object deserializeKeyValue(final DataSchemaNode schemaNode, final LeafrefResolver resolver,
final String value) {
requireNonNull(schemaNode, "schemaNode cannot be null");
- checkArgument(schemaNode instanceof LeafSchemaNode, "schemaNode must be of type LeafSchemaNode");
- final XmlCodec<?> objectXmlCodec = codecFactory.codecFor((LeafSchemaNode) schemaNode, resolver);
+ final XmlCodec<?> objectXmlCodec;
+ if (schemaNode instanceof LeafSchemaNode leafSchemaNode) {
+ objectXmlCodec = codecFactory.codecFor(leafSchemaNode, resolver);
+ } else if (schemaNode instanceof LeafListSchemaNode leafListSchemaNode) {
+ objectXmlCodec = codecFactory.codecFor(leafListSchemaNode, resolver);
+ } else {
+ throw new IllegalArgumentException("schemaNode " + schemaNode
+ + " must be of type LeafSchemaNode or LeafListSchemaNode");
+ }
return objectXmlCodec.parseValue(getNamespaceContext(), value);
}
return objectXmlCodec.parseValue(getNamespaceContext(), value);
}
- @Disabled("YT-1473: QName values need to be recognized and properly encoded via identity codec")
void testSerializeIdentity() throws Exception {
assertSerdes("/foo:bar[foo:qname='foo:one']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, FOO_ONE));
assertSerdes("/foo:bar[foo:qname='bar:two']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, BAR_TWO));
void testSerializeIdentity() throws Exception {
assertSerdes("/foo:bar[foo:qname='foo:one']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, FOO_ONE));
assertSerdes("/foo:bar[foo:qname='bar:two']", buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, BAR_TWO));
- @Disabled("YT-1473: QName values need to be recognized and properly encoded via identity codec")
void testSerializeIdentityValue() throws Exception {
assertSerdes("/bar:foo[.='foo:one']", buildYangInstanceIdentifier(BAR_FOO, FOO_ONE));
assertSerdes("/bar:foo[.='bar:two']", buildYangInstanceIdentifier(BAR_FOO, BAR_TWO));
void testSerializeIdentityValue() throws Exception {
assertSerdes("/bar:foo[.='foo:one']", buildYangInstanceIdentifier(BAR_FOO, FOO_ONE));
assertSerdes("/bar:foo[.='bar:two']", buildYangInstanceIdentifier(BAR_FOO, BAR_TWO));
- private static StringBuilder appendValue(final StringBuilder sb, final QNameModule currentModule,
+ private StringBuilder appendValue(final StringBuilder sb, final QNameModule currentModule,
+ if (value instanceof QName qname) {
+ // QName implies identity-ref, which can never be escaped
+ return appendQName(sb.append('\''), qname, currentModule).append('\'');
+ }
+
final var str = String.valueOf(value);
// We have two specifications here: Section 6.1.3 of both RFC6020 and RFC7950:
final var str = String.valueOf(value);
// We have two specifications here: Section 6.1.3 of both RFC6020 and RFC7950:
// Break-out from method for leaf-list case
if (key == null && currentNode.isLeaf()) {
checkValid(offset == data.length(), "Leaf argument must be last argument of instance identifier.");
// Break-out from method for leaf-list case
if (key == null && currentNode.isLeaf()) {
checkValid(offset == data.length(), "Leaf argument must be last argument of instance identifier.");
- return new NodeWithValue<>(name, keyValue);
+ final Object value = codec.deserializeKeyValue(currentNode.getDataSchemaNode(),
+ type -> resolveLeafref(currentNode.getIdentifier().getNodeType(), type), keyValue);
+ return new NodeWithValue<>(name, value);
}
final DataSchemaContextNode<?> keyNode = currentNode.getChild(key);
checkValid(keyNode != null, "%s is not correct schema node identifier.", key);
}
final DataSchemaContextNode<?> keyNode = currentNode.getChild(key);
checkValid(keyNode != null, "%s is not correct schema node identifier.", key);