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
9 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
16 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
18 abstract class ContextBuilder<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
20 private final StatementDefinitionContext<A, D, E> definition;
21 private final StatementSourceReference stmtRef;
22 private String rawArg;
23 private StatementSourceReference argRef;
25 public ContextBuilder(StatementDefinitionContext<A, D, E> def, StatementSourceReference sourceRef) {
26 this.definition = def;
27 this.stmtRef = sourceRef;
30 public void setArgument(@Nonnull String argument, @Nonnull StatementSourceReference argumentSource) {
31 Preconditions.checkArgument(definition.hasArgument(), "Statement does not take argument.");
32 this.rawArg = Preconditions.checkNotNull(argument);
33 this.argRef = Preconditions.checkNotNull(argumentSource);
36 public String getRawArgument() {
40 public StatementSourceReference getStamementSource() {
44 public StatementSourceReference getArgumentSource() {
48 public StatementDefinitionContext<A, D, E> getDefinition() {
52 public StatementIdentifier createIdentifier() {
53 return new StatementIdentifier(definition.getStatementName(), rawArg);
56 public abstract StatementContextBase<A, D, E> build() throws SourceException;