2 * Copyright (c) 2017 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 java.util.Map.Entry;
13 import javax.xml.stream.XMLStreamException;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.XMLNamespace;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
20 final class SchemaAwareXMLStreamWriterUtils extends XMLStreamWriterUtils implements EffectiveModelContextProvider {
21 private final @NonNull EffectiveModelContext schemaContext;
23 SchemaAwareXMLStreamWriterUtils(final EffectiveModelContext schemaContext) {
24 this.schemaContext = requireNonNull(schemaContext);
28 String encodeInstanceIdentifier(final ValueWriter writer, final YangInstanceIdentifier value)
29 throws XMLStreamException {
30 RandomPrefixInstanceIdentifierSerializer iiCodec = new RandomPrefixInstanceIdentifierSerializer(schemaContext,
31 writer.getNamespaceContext());
32 String serializedValue = iiCodec.serialize(value);
34 for (Entry<XMLNamespace, String> e : iiCodec.getPrefixes()) {
35 writer.writeNamespace(e.getValue(), e.getKey().toString());
38 return serializedValue;
42 public EffectiveModelContext getEffectiveModelContext() {