Class DefaultImportResolver<M extends IModel>
- java.lang.Object
-
- net.ssehub.easy.basics.modelManagement.ImportResolver<M>
-
- net.ssehub.easy.basics.modelManagement.DefaultImportResolver<M>
-
- Type Parameters:
M- the specific model type
- Direct Known Subclasses:
BuildLangImportResolver,DefaultImportResolver
public class DefaultImportResolver<M extends IModel> extends ImportResolver<M>
A model imports resolver. Due to the instance data needed to perform cyclic model resolution, instances of this class are not reentrant during processing of one model and its imported models. Either instances are pooled or created individually per model translation.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowCyclesprivate ModelInfo<M>conflictMarkerstatic booleanIMPORT_WITH_VERSIONAllows to switch easily to the primitive (non-version checking) variant.private java.util.Map<ModelInfo<M>,M>localModelOverride
-
Constructor Summary
Constructors Constructor Description DefaultImportResolver()Creates a resolver instance which, by default, does not allow cycles in the model imports.DefaultImportResolver(boolean allowCycles)Creates a resolver instance which may allow cycles.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<ModelImport<M>>add(java.util.List<ModelImport<M>> orig, java.util.List<ModelImport<M>> add)Addsaddtoorig.private java.util.List<ModelImport<M>>addConflict(java.util.List<ModelImport<M>> conflicts, ModelImport<M> conflict)Adds the givenconflictconflicts toconflicts.protected voidcannotResolveImport(ModelImport<M> imp, java.util.List<IMessage> messages, java.net.URI modelURI, IRestrictionEvaluationContext context)Is called ifimpcan finally not be resolved.private voidcheckImportCycles(M model, java.util.List<IMessage> messages, java.util.Set<M> done)Checks the import structure ofmodelfor cycles.protected booleancheckImported(ModelImport<M> imp, M model, java.util.List<IMessage> messages)Checks the imported interfaces for obvious import problems, such as importing models with interfaces as a whole.voidclear()Clears this instance for reuse.private ModelInfo<M>determineMatching(ResolutionContext<M> context, java.util.List<VersionedModelInfos<M>> versions, IVersionRestriction restriction)Determine the model matching the import restrictions.private voidhandleImport(ResolutionContext<M> context, ModelImport<?> imp, java.util.List<ModelImport<M>> todo)Handles an import.private voidhandleImports(ResolutionContext<M> context, M model, java.util.List<ModelImport<M>> todo)Handles all imports for the given model.private java.util.List<ModelImport<M>>load(ResolutionContext<M> context, java.util.HashSet<M> done, ModelInfo<M> toLoad, java.util.List<IMessage> messages, ModelImport<M> imp, java.util.List<ModelImport<M>> conflicts)Loads the given model information, checks it for conflicts.Mresolve(java.lang.String modelName, IVersionRestriction restrictions, java.net.URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)Resolves the denoted model considering the givenrestrictions.private java.util.List<ModelImport<M>>resolve(ResolutionContext<M> context, java.util.HashSet<M> done, java.util.List<IMessage> messages)Resolves the import represented bycontext.private java.util.List<ModelImport<M>>resolve(ResolutionContext<M> context, java.util.HashSet<M> done, java.util.List<IMessage> messages, java.util.List<VersionedModelInfos<M>> versions, ModelImport<M> imp)Resolves the import / conflict represented byimp.java.util.List<IMessage>resolveImports(M model, java.net.URI uri, java.util.List<ModelInfo<M>> inProgress, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)Resolves the imports of the givenmodeland returns messages on failures.private java.util.List<ModelImport<M>>resolveImports(ResolutionContext<M> context, java.util.HashSet<M> done, java.util.List<IMessage> messages)Resolves the imports of the model in the givencontextand returns messages on failures.private MresolveSingle(java.lang.String modelName, IVersionRestriction restrictions, java.net.URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)Resolves a single, non-wildcard model import.private voidsetUnresolved(M model, java.util.List<ModelImport<M>> conflicts)Sets the givenmodeland its import recursively to unresolved.private voidsetUnresolved(M model, ModelImport<M> imp, java.util.List<ModelImport<M>> conflicts)Sets the given import inmodeland its imports recursively to unresolved.-
Methods inherited from class net.ssehub.easy.basics.modelManagement.ImportResolver
addDeferredLoader, getProcessingListener, isTransitiveLoadingEnabled, notifyProcessing, setProcessingListener, setTransitiveLoading
-
-
-
-
Field Detail
-
IMPORT_WITH_VERSION
public static final boolean IMPORT_WITH_VERSION
Allows to switch easily to the primitive (non-version checking) variant.- See Also:
- Constant Field Values
-
localModelOverride
private final java.util.Map<ModelInfo<M extends IModel>,M extends IModel> localModelOverride
-
allowCycles
private boolean allowCycles
-
-
Constructor Detail
-
DefaultImportResolver
public DefaultImportResolver()
Creates a resolver instance which, by default, does not allow cycles in the model imports.
-
DefaultImportResolver
public DefaultImportResolver(boolean allowCycles)
Creates a resolver instance which may allow cycles.- Parameters:
allowCycles- iftrue, allow and resolve cycles, iffalseemit an error
-
-
Method Detail
-
clear
public void clear()
Description copied from class:ImportResolverClears this instance for reuse.- Overrides:
clearin classImportResolver<M extends IModel>
-
resolveImports
public java.util.List<IMessage> resolveImports(M model, java.net.URI uri, java.util.List<ModelInfo<M>> inProgress, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)
Description copied from class:ImportResolverResolves the imports of the givenmodeland returns messages on failures. Exceptions might be appropriate here but the caller shall be able to decide how to handle the level of detail, i.e. whether the first message shall be emitted or all. May modifymodelas a side effect.- Specified by:
resolveImportsin classImportResolver<M extends IModel>- Parameters:
model- the model to be resolveduri- the URI of the model to resolve (in order to find the closest model, may be null)inProgress- the model information objects of the models currently being processed at once (may be null)repository- the model repositoryevaluationContext- the context for evaluating import restrictions (variable definitions... interpreted locally)- Returns:
- messages which occur during resolution
-
checkImportCycles
private void checkImportCycles(M model, java.util.List<IMessage> messages, java.util.Set<M> done)
Checks the import structure ofmodelfor cycles.- Parameters:
model- the (root) model to be checkedmessages- which occur during resolution,nullor empty if none (modified as a side effect)done- for detecting cyclic imports (modified as a side effect)
-
resolveImports
private java.util.List<ModelImport<M>> resolveImports(ResolutionContext<M> context, java.util.HashSet<M> done, java.util.List<IMessage> messages)
Resolves the imports of the model in the givencontextand returns messages on failures. Exceptions might be appropriate here but the caller shall be able to decide how to handle the level of detail, i.e. whether the first message shall be emitted or all.- Parameters:
context- the context of the models to be resolveddone- for detecting cyclic imports (modified as a side effect)messages- which occur during resolution,nullor empty if none (modified as a side effect)- Returns:
- the conflicting model imports, null if there are none
-
setUnresolved
private void setUnresolved(M model, java.util.List<ModelImport<M>> conflicts)
Sets the givenmodeland its import recursively to unresolved.- Parameters:
model- the model to be set to unresolvedconflicts- the conflicts to unresolve exclusively, i.e., if not null other imports are not modified, otherwise all imports are set to unresolved
-
setUnresolved
private void setUnresolved(M model, ModelImport<M> imp, java.util.List<ModelImport<M>> conflicts)
Sets the given import inmodeland its imports recursively to unresolved.- Parameters:
model- the model containingimpimp- the import to be set to unresolvedconflicts- the conflicts to unresolve exclusively, i.e., if not null other imports are not modified, otherwise all imports are set to unresolved
-
handleImports
private void handleImports(ResolutionContext<M> context, M model, java.util.List<ModelImport<M>> todo)
Handles all imports for the given model.- Parameters:
context- the resolution contextmodel- the model to handle the importstodo- the imports to be handled in the calling step (may be null, then no todo list is built up)
-
handleImport
private void handleImport(ResolutionContext<M> context, ModelImport<?> imp, java.util.List<ModelImport<M>> todo)
Handles an import. If it denotes a conflict, it is added to the context, other totodo.- Parameters:
context- the context of the models to be resolved (may be modified as a side effect)imp- the import to be handledtodo- the imports to be handled in the calling step (may be null, then no todo list is built up)
-
determineMatching
private ModelInfo<M> determineMatching(ResolutionContext<M> context, java.util.List<VersionedModelInfos<M>> versions, IVersionRestriction restriction) throws ModelManagementException
Determine the model matching the import restrictions. If multiple matching models exist, return the model with the highest version number.- Parameters:
context- the import contextversions- the already known and matching model information objectsrestriction- the version restriction (may be null)- Returns:
- the matching model (null if there no model was found or
conflictMarkerif no matching model was determined due to conflicts on all possible candidates) - Throws:
ModelManagementException- in case of restriction evaluation problems
-
addConflict
private java.util.List<ModelImport<M>> addConflict(java.util.List<ModelImport<M>> conflicts, ModelImport<M> conflict)
Adds the givenconflictconflicts toconflicts.conflictsmay be null and is created then lazily.- Parameters:
conflicts- the conflicts set to add thetoAddconflicts toconflict- the conflicts to be added- Returns:
conflictsif not null, a new list otherwise
-
resolve
private java.util.List<ModelImport<M>> resolve(ResolutionContext<M> context, java.util.HashSet<M> done, java.util.List<IMessage> messages, java.util.List<VersionedModelInfos<M>> versions, ModelImport<M> imp)
Resolves the import / conflict represented byimp.- Parameters:
context- the import contextdone- for detecting cyclic imports (modified as a side effect)messages- which occur during resolution,nullor empty if none (modified as a side effect)versions- the already known and matching model information objectsimp- the import to be resolved- Returns:
- the conflicting model imports, null if there are none
-
cannotResolveImport
protected void cannotResolveImport(ModelImport<M> imp, java.util.List<IMessage> messages, java.net.URI modelURI, IRestrictionEvaluationContext context)
Is called ifimpcan finally not be resolved.- Parameters:
imp- the import to be resolvedmessages- which occur during resolution,nullor empty if none (modified as a side effect)modelURI- the URI of the modelcontext- the restriction evaluation context
-
load
private java.util.List<ModelImport<M>> load(ResolutionContext<M> context, java.util.HashSet<M> done, ModelInfo<M> toLoad, java.util.List<IMessage> messages, ModelImport<M> imp, java.util.List<ModelImport<M>> conflicts)
Loads the given model information, checks it for conflicts.- Parameters:
context- the import contextdone- for detecting cyclic imports (modified as a side effect)toLoad- the model to loadmessages- which occur during resolution,nullor empty if none (modified as a side effect)imp- the import to be resolvedconflicts- the actual import conflicts (may be null if none were detected so far)- Returns:
- the actual import conflicts
-
checkImported
protected boolean checkImported(ModelImport<M> imp, M model, java.util.List<IMessage> messages)
Checks the imported interfaces for obvious import problems, such as importing models with interfaces as a whole.- Parameters:
imp- the import to be resolvedmodel- the model which may resolve the importmessages- which occur during resolution,nullor empty if none (modified as a side effect)- Returns:
trueif the import is fine,trueif problems were detected
-
resolve
public M resolve(java.lang.String modelName, IVersionRestriction restrictions, java.net.URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext) throws ModelManagementException
Description copied from class:ImportResolverResolves the denoted model considering the givenrestrictions.- Specified by:
resolvein classImportResolver<M extends IModel>- Parameters:
modelName- the name of the modelrestrictions- the version restriction (may be null if there is none)baseUri- the URI to start resolving from (may be the URI of a model)repository- the model repositoryevaluationContext- the context for evaluating import restrictions (variable definitions... interpreted locally)- Returns:
- the resolved model
- Throws:
ModelManagementException- in case of resolution failures
-
resolveSingle
private M resolveSingle(java.lang.String modelName, IVersionRestriction restrictions, java.net.URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext) throws ModelManagementException
Resolves a single, non-wildcard model import.- Parameters:
modelName- the name of the modelrestrictions- optional version restrictions (may be null if there is none)baseUri- the URI to start resolving from (may be the URI of a model)repository- the model repositoryevaluationContext- the context for evaluating import restrictions (variable definitions... interpreted locally)- Returns:
- the resolved model
- Throws:
ModelManagementException- in case of resolution failures
-
resolve
private java.util.List<ModelImport<M>> resolve(ResolutionContext<M> context, java.util.HashSet<M> done, java.util.List<IMessage> messages)
Resolves the import represented bycontext.- Parameters:
context- the context to resolve (including the import to resolve)done- for detecting cyclic imports (modified as a side effect)messages- which occur during resolution,nullor empty if none (modified as a side effect)- Returns:
- the conflicting model imports, null if there are none
-
add
private java.util.List<ModelImport<M>> add(java.util.List<ModelImport<M>> orig, java.util.List<ModelImport<M>> add)
Addsaddtoorig.- Parameters:
orig- the original list, may be nulladd- the list to add, may be null- Returns:
origwithaddoraddiforigis null
-
-