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;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
28 class ImportBasicTestStatementSource implements StatementStreamSource {
30 private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
32 private final String name;
33 private final List<String> imports;
34 private StatementWriter writer;
35 private StatementSourceReference REF = new StatementSourceReference() {
38 public StatementSource getStatementSource() {
39 return StatementSource.DECLARATION;
44 public ImportBasicTestStatementSource(String name, String... imports) {
46 this.imports = Arrays.asList(imports);
50 public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
51 throws SourceException {
63 public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
69 public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
70 PrefixToModule prefixes) throws SourceException {
78 protected void extensions() throws SourceException {
82 protected void body() throws SourceException {
83 // stmt(YangVersion).arg("1");end();
84 // stmt(Description).arg("Here goes description of this module");end();
85 // stmt(Contact).arg("Here goes our address...");end();
87 // stmt(Revision).arg("2015-03-12");
88 // stmt(Description).arg("This revision brings this and that...");end();
89 // stmt(Reference).arg("Learn more here...");end();
92 stmt(CONTAINER).arg(name+":my-container-with-prefix");
93 // stmt(Leaf).arg("MyContainerLeaf");
94 // stmt(Type).arg("string");end();
95 // stmt(Config).arg("TRUE");end();
97 // stmt(Choice).arg("choose-your-destiny");
98 // stmt(Default).arg("destiny-one");end();
99 // stmt(Case).arg("destiny-one");
100 // stmt(Leaf).arg("destiny-one-leaf");end();
102 // stmt(Case).arg("destiny-two");
103 // stmt(Mandatory).arg("true");
104 // stmt(Container).arg("InnerContainer");
105 // stmt(Leaf).arg("leaf-of-deep");end();
109 // stmt(Container).arg("MyContainerInContainer");
110 // stmt(Must).arg("xpath expression");
111 // stmt(Leaf).arg("MyContainerInContainerLeaf");
112 // stmt(Type).arg("string");end();
114 // stmt(Deviation).arg("/tst:test/tst:element");
115 // stmt(Deviate).arg("add");end();
119 stmt(CONTAINER).arg("my-container-without-prefix").end();
122 for(String imp : imports) {
124 stmt(CONTAINER).arg(imp+":my-container-with-imported-prefix"+i).end();
129 ImportBasicTestStatementSource header() throws SourceException {
130 stmt(MODULE).arg(name); {
131 stmt(NAMESPACE).arg(getNamespace()).end();
132 stmt(PREFIX).arg(name).end();
133 stmt(REVISION).arg("2000-01-01").end();
134 for(String imp : imports) {
135 stmt(IMPORT).arg(imp);
136 stmt(PREFIX).arg(imp).end();
137 stmt(REVISION_DATE).arg("2000-01-01").end();
144 private String getNamespace() {
145 return NS_PREFIX + name;
148 protected ImportBasicTestStatementSource arg(String arg) throws SourceException {
149 writer.argumentValue(arg, REF);
153 protected ImportBasicTestStatementSource stmt(Rfc6020Mapping stmt) throws SourceException {
154 writer.startStatement(stmt.getStatementName(), REF);
158 protected ImportBasicTestStatementSource end() throws SourceException {
159 writer.endStatement(REF);