import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext.PhaseCompletionProgress;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.RecursiveObjectLeaker;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Map<QName,StatementDefinitionContext<?,?,?>> definitions = new HashMap<>();
private final Map<Class<?>,NamespaceBehaviourWithListeners<?, ?, ?>> supportedNamespaces = new HashMap<>();
-
private final Map<ModelProcessingPhase,StatementSupportBundle> supports;
private final Set<SourceSpecificContext> sources = new HashSet<>();
this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null");
}
- public BuildGlobalContext(final Map<ModelProcessingPhase, StatementSupportBundle> supports, final Map<ValidationBundleType,Collection<?>> supportedValidation) {
+ public BuildGlobalContext(final Map<ModelProcessingPhase, StatementSupportBundle> supports, final Map<ValidationBundleType,Collection<?>> supportedValidation) {
super();
this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null");
- Set<Entry<ValidationBundleType, Collection<?>>> validationBundles = supportedValidation.entrySet();
- for (Entry<ValidationBundleType, Collection<?>> validationBundle : validationBundles) {
+ for (Entry<ValidationBundleType, Collection<?>> validationBundle : supportedValidation.entrySet()) {
addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue());
}
}
NamespaceBehaviourWithListeners<?, ?, ?> potential = supportedNamespaces.get(type);
if (potential == null) {
NamespaceBehaviour<K, V, N> potentialRaw = supports.get(currentPhase).getNamespaceBehaviour(type);
- if(potentialRaw != null) {
+ if (potentialRaw != null) {
potential = createNamespaceContext(potentialRaw);
supportedNamespaces.put(type, potential);
} else {
}
Verify.verify(type.equals(potential.getIdentifier()));
- /*
+ /*
* Safe cast, previous checkState checks equivalence of key from which type argument are
* derived
*/
public StatementDefinitionContext<?, ?, ?> getStatementDefinition(final QName name) {
StatementDefinitionContext<?, ?, ?> potential = definitions.get(name);
- if(potential == null) {
+ if (potential == null) {
StatementSupport<?, ?, ?> potentialRaw = supports.get(currentPhase).getStatementDefinition(name);
- if(potentialRaw != null) {
+ if (potentialRaw != null) {
potential = new StatementDefinitionContext<>(potentialRaw);
definitions.put(name, potential);
}
}
public EffectiveModelContext build() throws SourceException, ReactorException {
- for(ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) {
+ for (ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) {
startPhase(phase);
loadPhaseStatements();
completePhaseActions();
private EffectiveModelContext transform() {
Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
- List<DeclaredStatement<?>> rootStatements = new ArrayList<>();
- for(SourceSpecificContext source : sources) {
- DeclaredStatement<?> root = source.getRoot().buildDeclared();
- rootStatements.add(root);
+ List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
+ for (SourceSpecificContext source : sources) {
+ rootStatements.add(source.getRoot().buildDeclared());
}
return new EffectiveModelContext(rootStatements);
}
public EffectiveSchemaContext buildEffective() throws SourceException, ReactorException {
- for(ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) {
+ for (ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) {
startPhase(phase);
loadPhaseStatements();
completePhaseActions();
private EffectiveSchemaContext transformEffective() {
Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
- List<DeclaredStatement<?>> rootStatements = new ArrayList<>();
- List<EffectiveStatement<?,?>> rootEffectiveStatements = new ArrayList<>();
-
- for(SourceSpecificContext source : sources) {
- DeclaredStatement<?> root = source.getRoot().buildDeclared();
- rootStatements.add(root);
+ List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
+ List<EffectiveStatement<?,?>> rootEffectiveStatements = new ArrayList<>(sources.size());
- EffectiveStatement<?,?> rootEffective = source.getRoot().buildEffective();
- rootEffectiveStatements.add(rootEffective);
+ try {
+ for (SourceSpecificContext source : sources) {
+ final RootStatementContext<?, ?, ?> root = source.getRoot();
+ rootStatements.add(root.buildDeclared());
+ rootEffectiveStatements.add(root.buildEffective());
+ }
+ } finally {
+ RecursiveObjectLeaker.cleanup();
}
- return new EffectiveSchemaContext(rootStatements,rootEffectiveStatements);
+ return new EffectiveSchemaContext(rootStatements, rootEffectiveStatements);
}
private void startPhase(final ModelProcessingPhase phase) {
Preconditions.checkState(Objects.equals(finishedPhase, phase.getPreviousPhase()));
- for(SourceSpecificContext source : sources) {
+ for (SourceSpecificContext source : sources) {
source.startPhase(phase);
}
currentPhase = phase;
private void loadPhaseStatements() throws SourceException {
Preconditions.checkState(currentPhase != null);
- for(SourceSpecificContext source : sources) {
+ for (SourceSpecificContext source : sources) {
source.loadStatements();
}
}
}
}
- if(!addedCause) {
+ if (!addedCause) {
addedCause = true;
buildFailure.initCause(sourceEx);
} else {
List<SourceSpecificContext> sourcesToProgress = Lists.newArrayList(sources);
try {
boolean progressing = true;
- while(progressing) {
+ while (progressing) {
// We reset progressing to false.
progressing = false;
Iterator<SourceSpecificContext> currentSource = sourcesToProgress.iterator();
} catch (SourceException e) {
throw Throwables.propagate(e);
}
- if(!sourcesToProgress.isEmpty()) {
+ if (!sourcesToProgress.isEmpty()) {
SomeModifiersUnresolvedException buildFailure = new SomeModifiersUnresolvedException(currentPhase);
buildFailure = addSourceExceptions(buildFailure, sourcesToProgress);
throw buildFailure;
public Set<SourceSpecificContext> getSources() {
return sources;
}
-
}