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.stmt.test;
10 import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.IMPORT;
11 import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.MODULE;
12 import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.NAMESPACE;
13 import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.*;
15 import java.util.Arrays;
16 import java.util.List;
17 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
19 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
20 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
23 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
24 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
26 class ImportBasicTestStatementSource implements StatementStreamSource {
28 private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
30 private final String name;
31 private final List<String> imports;
32 private StatementWriter writer;
33 private StatementSourceReference REF = new StatementSourceReference() {
36 public StatementSource getStatementSource() {
37 return StatementSource.DECLARATION;
42 public ImportBasicTestStatementSource(String name, String... imports) {
44 this.imports = Arrays.asList(imports);
48 public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
49 throws SourceException {
61 public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
67 public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
68 PrefixToModule prefixes) throws SourceException {
76 protected void extensions() throws SourceException {
80 protected void body() throws SourceException {
81 // stmt(YangVersion).arg("1");end();
82 // stmt(Description).arg("Here goes description of this module");end();
83 // stmt(Contact).arg("Here goes our address...");end();
85 // stmt(Revision).arg("2015-03-12");
86 // stmt(Description).arg("This revision brings this and that...");end();
87 // stmt(Reference).arg("Learn more here...");end();
90 stmt(CONTAINER).arg(name+":my-container-with-prefix");
91 // stmt(Leaf).arg("MyContainerLeaf");
92 // stmt(Type).arg("string");end();
93 // stmt(Config).arg("TRUE");end();
95 // stmt(Choice).arg("choose-your-destiny");
96 // stmt(Default).arg("destiny-one");end();
97 // stmt(Case).arg("destiny-one");
98 // stmt(Leaf).arg("destiny-one-leaf");end();
100 // stmt(Case).arg("destiny-two");
101 // stmt(Mandatory).arg("true");
102 // stmt(Container).arg("InnerContainer");
103 // stmt(Leaf).arg("leaf-of-deep");end();
107 // stmt(Container).arg("MyContainerInContainer");
108 // stmt(Must).arg("xpath expression");
109 // stmt(Leaf).arg("MyContainerInContainerLeaf");
110 // stmt(Type).arg("string");end();
112 // stmt(Deviation).arg("/tst:test/tst:element");
113 // stmt(Deviate).arg("add");end();
117 stmt(CONTAINER).arg("my-container-without-prefix").end();
120 for(String imp : imports) {
122 stmt(CONTAINER).arg(imp+":my-container-with-imported-prefix"+i).end();
127 ImportBasicTestStatementSource header() throws SourceException {
128 stmt(MODULE).arg(name); {
129 stmt(NAMESPACE).arg(getNamespace()).end();
130 stmt(PREFIX).arg(name).end();
131 stmt(REVISION).arg("2000-01-01").end();
132 for(String imp : imports) {
133 stmt(IMPORT).arg(imp);
134 stmt(PREFIX).arg(imp).end();
135 stmt(REVISION_DATE).arg("2000-01-01").end();
142 private String getNamespace() {
143 return NS_PREFIX + name;
146 protected ImportBasicTestStatementSource arg(String arg) throws SourceException {
147 writer.argumentValue(arg, REF);
151 protected ImportBasicTestStatementSource stmt(Rfc6020Mapping stmt) throws SourceException {
152 writer.startStatement(stmt.getStatementName(), REF);
156 protected ImportBasicTestStatementSource end() throws SourceException {
157 writer.endStatement(REF);