2 * Copyright (c) 2014 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.model.spi.source;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import com.google.common.io.CharSource;
15 import java.io.InputStream;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
21 * YANG text schema source representation. Exposes an RFC6020 or RFC7950 text representation as an {@link InputStream}.
23 public abstract class YangTextSource extends CharSource implements YangSourceRepresentation {
24 private final @NonNull SourceIdentifier sourceId;
26 protected YangTextSource(final SourceIdentifier sourceId) {
27 this.sourceId = requireNonNull(sourceId);
31 public final Class<YangTextSource> getType() {
32 return YangTextSource.class;
36 public final SourceIdentifier sourceId() {
41 public final String toString() {
42 return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
46 * Add subclass-specific attributes to the output {@link #toString()} output. Since
47 * subclasses are prevented from overriding {@link #toString()} for consistency
48 * reasons, they can add their specific attributes to the resulting string by attaching
49 * attributes to the supplied {@link ToStringHelper}.
51 * @param toStringHelper ToStringHelper onto the attributes can be added
52 * @return ToStringHelper supplied as input argument.
54 protected ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
55 return toStringHelper.add("identifier", sourceId);