import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
+
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.IncludeEffectiveStatementImpl;
import java.net.URI;
-import java.text.ParseException;
import java.util.Collection;
import java.util.Date;
-
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-
import com.google.common.base.Optional;
public class IncludeStatementImpl extends AbstractDeclaredStatement<String> implements IncludeStatement {
@Override
public EffectiveStatement<String, IncludeStatement> createEffective(
StmtContext<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> ctx) {
- throw new UnsupportedOperationException();
+ return new IncludeEffectiveStatementImpl(ctx);
}
@Override
public void onLinkageDeclared(
final Mutable<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> stmt)
- throws InferenceException, SourceException {
+ throws SourceException {
final ModuleIdentifier includeSubmoduleIdentifier = getIncludeSubmoduleIdentifier(stmt);
ModelActionBuilder includeAction = stmt.newInferenceAction(SOURCE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> requiresCtxPrerequisite = includeAction.requiresCtx(stmt,
SubmoduleNamespace.class, includeSubmoduleIdentifier, SOURCE_LINKAGE);
- final Prerequisite<Mutable<?, ?, ?>> mutatesCtxPrerequisite = includeAction.mutatesCtx(stmt.getRoot(),
- SOURCE_LINKAGE);
includeAction.apply(new InferenceAction() {
@Override
public void apply() throws InferenceException {
- StmtContext<?, ?, ?> includedSubmoduleStmt = requiresCtxPrerequisite.get();
+ StmtContext<?, ?, ?> includedSubModuleContext = requiresCtxPrerequisite.get();
- mutatesCtxPrerequisite.get().addToNs(IncludedModuleContext.class, includeSubmoduleIdentifier,
- includedSubmoduleStmt);
+ stmt.addToNs(IncludedModuleContext.class, includeSubmoduleIdentifier,
+ includedSubModuleContext);
+ stmt.addToNs(IncludedSubmoduleNameToIdentifier.class,
+ stmt.getStatementArgument(), includeSubmoduleIdentifier);
}
@Override
public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
- System.out.println("");
if (failed.contains(requiresCtxPrerequisite)) {
- throw new InferenceException("Included submodule was not found.", stmt
+ throw new InferenceException("Included submodule was not found: "+stmt.getStatementArgument(), stmt
.getStatementSourceReference());
}
}
private static ModuleIdentifier getIncludeSubmoduleIdentifier(Mutable<String, IncludeStatement, ?> stmt) {
String subModuleName = stmt.getStatementArgument();
- String revisionArg = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
- final Optional<Date> revision;
- if (revisionArg != null) {
- try {
- revision = Optional.of(SimpleDateFormatUtil.getRevisionFormat().parse(revisionArg));
- } catch (ParseException e) {
- throw new IllegalArgumentException(e);
- }
- } else {
- revision = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP);
+
+ Date revisionDate = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
+ if (revisionDate == null) {
+ revisionDate = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
}
- return new ModuleIdentifierImpl(subModuleName, Optional.<URI> absent(), revision);
+ return new ModuleIdentifierImpl(subModuleName, Optional.<URI> absent(), Optional.<Date> of(revisionDate));
}
}