2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.binding;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.base.MoreObjects.ToStringHelper;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Base utility class for providing YANG module info backed by class resources.
22 * @author Robert Varga
26 public abstract class ResourceYangModuleInfo implements YangModuleInfo {
28 public final InputStream openYangTextStream() throws IOException {
29 final InputStream ret = ResourceYangModuleInfo.this.getClass()
30 .getResourceAsStream(verifyNotNull(resourceName()));
32 throw new IOException("Failed to open resource " + resourceName());
38 public final String toString() {
39 return addToStringHelperAttributes(MoreObjects.toStringHelper(this)).toString();
42 protected ToStringHelper addToStringHelperAttributes(final ToStringHelper helper) {
43 return helper.add("resource", verifyNotNull(resourceName()));
46 protected abstract String resourceName();