2 * Copyright (c) 2015 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.api.schema.stream;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16 * Utility class for adapting {@link NormalizedNodeStreamWriter}s to their {@link DataSchemaNodeAware} counterparts
17 * which ignore the provided schema node.
20 public final class DataSchemaNodeAwareAdaptor {
21 private DataSchemaNodeAwareAdaptor() {
22 throw new UnsupportedOperationException();
25 public static SchemaAwareNormalizedNodeStreamAttributeWriter forAttributeWriter(
26 @Nonnull final NormalizedNodeStreamAttributeWriter writer) {
27 Preconditions.checkNotNull(writer, "Writer must not be null");
29 if (writer instanceof SchemaAwareNormalizedNodeStreamAttributeWriter) {
30 return (SchemaAwareNormalizedNodeStreamAttributeWriter) writer;
33 return new AttributeWriter() {
35 protected NormalizedNodeStreamAttributeWriter delegate() {
41 public static SchemaAwareNormalizedNodeStreamWriter forWriter(@Nonnull final NormalizedNodeStreamWriter writer) {
42 Preconditions.checkNotNull(writer, "Writer must not be null");
44 if (writer instanceof SchemaAwareNormalizedNodeStreamWriter) {
45 return (SchemaAwareNormalizedNodeStreamWriter) writer;
47 if (writer instanceof NormalizedNodeStreamAttributeWriter) {
48 return forAttributeWriter((NormalizedNodeStreamAttributeWriter) writer);
53 protected NormalizedNodeStreamWriter delegate() {
59 private static abstract class AttributeWriter extends ForwardingNormalizedNodeStreamAttributeWriter
60 implements SchemaAwareNormalizedNodeStreamAttributeWriter {
62 public void nextDataSchemaNode(final DataSchemaNode schema) {
67 private static abstract class Writer extends ForwardingNormalizedNodeStreamWriter
68 implements SchemaAwareNormalizedNodeStreamWriter {
70 public void nextDataSchemaNode(final DataSchemaNode schema) {