*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-
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.stmt.rfc6020.effective.ImportEffectiveStatementImpl;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import com.google.common.base.Optional;
import java.net.URI;
import java.text.ParseException;
@Override
public EffectiveStatement<String, ImportStatement> createEffective(
StmtContext<String, ImportStatement, EffectiveStatement<String, ImportStatement>> ctx) {
- throw new UnsupportedOperationException();
+ return new ImportEffectiveStatementImpl(ctx);
}
@Override
- public void onLinkageDeclared(final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> stmt)
- throws InferenceException, SourceException {
+ public void onLinkageDeclared(
+ final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> stmt)
+ throws SourceException {
final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt);
ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> imported;
final Prerequisite<Mutable<?, ?, ?>> linkageTarget;
imported = importAction.requiresCtx(stmt, ModuleNamespace.class, impIdentifier, SOURCE_LINKAGE);
- linkageTarget = importAction.mutatesCtx(stmt.getRoot(),SOURCE_LINKAGE);
+ linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE);
+
+ String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
+ stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, impIdentifier);
importAction.apply(new InferenceAction() {
@Override
public void apply() throws InferenceException {
StmtContext<?, ?, ?> importedModule = imported.get();
- // URI importedNs =
- // importedModule.firstSubstatement(NamespaceStatement.class).argument();
- // String prefix =
- // stmt.firstSubstatement(PrefixStatement.class).argument();
linkageTarget.get().addToNs(ImportedModuleContext.class, impIdentifier, importedModule);
- // prefixTarget.get().addToNs(PrefixToModule.class, prefix,
- // QNameModule.create(importedNs, null));
}
@Override
});
}
- private static ModuleIdentifier getImportedModuleIdentifier(Mutable<String, ImportStatement, ?> stmt) throws SourceException {
+ private static ModuleIdentifier getImportedModuleIdentifier(Mutable<String, ImportStatement, ?> stmt)
+ throws SourceException {
+
String moduleName = stmt.getStatementArgument();
String revisionArg = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
final Optional<Date> revision;
try {
revision = Optional.of(SimpleDateFormatUtil.getRevisionFormat().parse(revisionArg));
} catch (ParseException e) {
- throw new SourceException(
- String.format("Revision value %s is not in required format yyyy-MM-dd", revisionArg),
- stmt.getStatementSourceReference(), e);
+ throw new SourceException(String.format("Revision value %s is not in required format yyyy-MM-dd",
+ revisionArg), stmt.getStatementSourceReference(), e);
}
} else {
- revision = Optional.absent();
+ revision = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP);
}
return new ModuleIdentifierImpl(moduleName, Optional.<URI> absent(), revision);
}