2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.codec.xml;
10 import static java.util.Objects.requireNonNull;
12 import javax.xml.namespace.NamespaceContext;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.common.XMLNamespace;
15 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
16 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
22 final class InstanceIdentifierDeserializer extends AbstractInstanceIdentifierCodec {
23 private final @NonNull XmlCodecFactory codecFactory;
24 private final @NonNull NamespaceContext namespaceContext;
26 InstanceIdentifierDeserializer(final DataSchemaContextTree dataContextTree, final XmlCodecFactory codecFactory,
27 final NamespaceContext namespaceContext) {
28 super(dataContextTree);
29 this.codecFactory = requireNonNull(codecFactory);
30 this.namespaceContext = requireNonNull(namespaceContext);
34 protected ModuleEffectiveStatement moduleForPrefix(final String prefix) {
35 final var prefixedNS = namespaceContext.getNamespaceURI(prefix);
36 final var modules = codecFactory.getEffectiveModelContext().findModuleStatements(XMLNamespace.of(prefixedNS))
38 return modules.hasNext() ? modules.next() : null;
42 protected String prefixForNamespace(final XMLNamespace namespace) {
43 // This is serialize() path, we do not support that in this class
44 throw new UnsupportedOperationException("Not implemented");
48 protected Object deserializeKeyValue(final DataSchemaNode schemaNode, final LeafrefResolver resolver,
50 requireNonNull(schemaNode, "schemaNode cannot be null");
51 final XmlCodec<?> objectXmlCodec;
52 if (schemaNode instanceof LeafSchemaNode leafSchemaNode) {
53 objectXmlCodec = codecFactory.codecFor(leafSchemaNode, resolver);
54 } else if (schemaNode instanceof LeafListSchemaNode leafListSchemaNode) {
55 objectXmlCodec = codecFactory.codecFor(leafListSchemaNode, resolver);
57 throw new IllegalArgumentException("schemaNode " + schemaNode
58 + " must be of type LeafSchemaNode or LeafListSchemaNode");
60 return objectXmlCodec.parseValue(namespaceContext, value);