Class ResolutionContext<M extends IModel>
- java.lang.Object
-
- net.ssehub.easy.basics.modelManagement.ResolutionContext<M>
-
- Type Parameters:
M- the specific model type
class ResolutionContext<M extends IModel> extends java.lang.ObjectDefines an internal class representing the context of a model import resolution.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ModelImport<M>>conflictsprivate IRestrictionEvaluationContextevaluationContextprivate java.util.List<ModelInfo<M>>inProgressprivate Mmodelprivate java.lang.StringmodelNameprivate java.net.URImodelUriprivate IModelRepository<M>repositoryprivate booleantopLevelprivate ModelImport<M>toResolve
-
Constructor Summary
Constructors Constructor Description ResolutionContext(java.lang.String modelName, java.net.URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)Creates a resolution context for resolving a model by name.ResolutionContext(M model, java.net.URI modelUri, java.util.List<ModelInfo<M>> inProgress, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)Creates a resolution context.ResolutionContext(M model, java.net.URI modelUri, ResolutionContext<M> context)Creates a resolution context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConflict(ModelImport<M> conflict)Adds a single conflict to the conflict set of this resolution context.static <M extends IModel>
java.util.List<ModelImport<M>>addConflicts(java.util.List<ModelImport<M>> conflicts, java.util.List<ModelImport<M>> toAdd)Adds the giventoAddconflicts toconflicts.voidaddConflicts(ResolutionContext<M> context)Adds all conflicts of the givencontext.booleanconsiderLoading(boolean isTransitiveEnabled)Returns whether model loading shall be considered.private voidenumerateDependent(ModelLocations.Location location, java.util.List<java.lang.String> results, java.util.Set<ModelLocations.Location> done)Enumerate the dependent locations in terms of model paths.private ModelImport<M>getConflict(java.lang.String modelName, Version version)Returns the first conflict the described model has with the conflict import statements collected in this context.ModelImport<M>getConflict(M model)Returns the first conflictmodeland its (recursive) imports have with the conflict import statements collected in this context.private ModelImport<M>getConflict(M model, java.util.Set<M> done)Returns the first conflictmodeland its (recursive) imports have with the conflict import statements collected in this context.IRestrictionEvaluationContextgetEvaluationContext()Returns the evaluation context for version restrictions.MgetModel()Returns the model defining the context.java.lang.StringgetModelName()Returns the name of the model to resolve.java.util.List<java.lang.String>getModelPaths()Returns the model paths.IModelRepository<M>getModelRepository()Returns the model repository.java.net.URIgetModelURI()Returns the URI tomodel.ModelImport<M>getToResolve()Returns the actual import for resolution.booleanisConflict(ModelInfo<M> info)Returns whetherinfohas a conflict with the conflict import statements collected in this context.booleanisLoop(ModelInfo<M> info)Returns whether loadinginfowould cause in infinite loop in type resolution as it is currently being processed in the same resolution context.booleanisTopLevel()Returns whether this is a top-level or a recursively used context.private voidlazyInitConflicts()Initializes the conflicts set if required.voidsetToResolve(ModelImport<M> toResolve)Changes the actual import for resolution.
-
-
-
Field Detail
-
modelName
private java.lang.String modelName
-
repository
private IModelRepository<M extends IModel> repository
-
toResolve
private ModelImport<M extends IModel> toResolve
-
modelUri
private java.net.URI modelUri
-
evaluationContext
private IRestrictionEvaluationContext evaluationContext
-
conflicts
private java.util.List<ModelImport<M extends IModel>> conflicts
-
topLevel
private boolean topLevel
-
-
Constructor Detail
-
ResolutionContext
public ResolutionContext(M model, java.net.URI modelUri, ResolutionContext<M> context)
Creates a resolution context.- Parameters:
model- the model for which the import resolution happensmodelUri- the URI tomodel(may be null)context- the parent contexts
-
ResolutionContext
public ResolutionContext(M model, java.net.URI modelUri, java.util.List<ModelInfo<M>> inProgress, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)
Creates a resolution context.- Parameters:
model- the model for which the import resolution happensmodelUri- the URI tomodel(may be null)inProgress- the models being processed at once withmodel(may be null)repository- the model repositoryevaluationContext- the context for evaluating import restrictions (variable definitions... interpreted locally)
-
ResolutionContext
public ResolutionContext(java.lang.String modelName, java.net.URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)Creates a resolution context for resolving a model by name.- Parameters:
modelName- the name of the model to resolvebaseUri- the URI where to start the resolution from (may be a model URI)repository- the model repositoryevaluationContext- the context for evaluating import restrictions (variable definitions... interpreted locally)
-
-
Method Detail
-
setToResolve
public void setToResolve(ModelImport<M> toResolve)
Changes the actual import for resolution.- Parameters:
toResolve- the actual import
-
getToResolve
public ModelImport<M> getToResolve()
Returns the actual import for resolution.- Returns:
- the actual import
-
getModelURI
public java.net.URI getModelURI()
Returns the URI tomodel.- Returns:
- the URI (may be null)
-
getModel
public M getModel()
Returns the model defining the context.- Returns:
- the model
-
getModelName
public java.lang.String getModelName()
Returns the name of the model to resolve.- Returns:
- the name of the model
-
getModelRepository
public IModelRepository<M> getModelRepository()
Returns the model repository.- Returns:
- the model repository
-
getModelPaths
public java.util.List<java.lang.String> getModelPaths()
Returns the model paths.- Returns:
- the model paths
-
enumerateDependent
private void enumerateDependent(ModelLocations.Location location, java.util.List<java.lang.String> results, java.util.Set<ModelLocations.Location> done)
Enumerate the dependent locations in terms of model paths.- Parameters:
location- the location to enumerateresults- the resulting model paths (modified as a side effect)done- the already processed locations in order to avoid cycles
-
isLoop
public boolean isLoop(ModelInfo<M> info)
Returns whether loadinginfowould cause in infinite loop in type resolution as it is currently being processed in the same resolution context.- Parameters:
info- the information object to be checked- Returns:
trueif it would cause a loop,falseelse
-
getEvaluationContext
public IRestrictionEvaluationContext getEvaluationContext()
Returns the evaluation context for version restrictions.- Returns:
- the evaluation context
-
lazyInitConflicts
private void lazyInitConflicts()
Initializes the conflicts set if required.
-
addConflicts
public void addConflicts(ResolutionContext<M> context)
Adds all conflicts of the givencontext.- Parameters:
context- the context to consider
-
addConflicts
public static <M extends IModel> java.util.List<ModelImport<M>> addConflicts(java.util.List<ModelImport<M>> conflicts, java.util.List<ModelImport<M>> toAdd)
Adds the giventoAddconflicts toconflicts.conflictsmay be null and is created then lazily.- Type Parameters:
M- the type of models- Parameters:
conflicts- the conflicts set to add thetoAddconflicts totoAdd- the conflicts to be added- Returns:
conflictsif not null, a new list otherwise
-
addConflict
public void addConflict(ModelImport<M> conflict)
Adds a single conflict to the conflict set of this resolution context.- Parameters:
conflict- the conflict
-
getConflict
public ModelImport<M> getConflict(M model) throws RestrictionEvaluationException
Returns the first conflictmodeland its (recursive) imports have with the conflict import statements collected in this context.- Parameters:
model- the model information to search for- Returns:
- the first conflict or null if there is none
- Throws:
RestrictionEvaluationException- in case of evaluation problems
-
getConflict
private ModelImport<M> getConflict(M model, java.util.Set<M> done) throws RestrictionEvaluationException
Returns the first conflictmodeland its (recursive) imports have with the conflict import statements collected in this context.- Parameters:
model- the model information to search for (may be nulldone- the models visited so far (cycle check)- Returns:
- the first conflict or null if there is none
- Throws:
RestrictionEvaluationException- in case of evaluation problems
-
getConflict
private ModelImport<M> getConflict(java.lang.String modelName, Version version) throws RestrictionEvaluationException
Returns the first conflict the described model has with the conflict import statements collected in this context.- Parameters:
modelName- the name of the modelversion- the version of the model (may be null)- Returns:
- the first conflict or null if there is none
- Throws:
RestrictionEvaluationException- in case of evaluation problems
-
isConflict
public boolean isConflict(ModelInfo<M> info) throws RestrictionEvaluationException
Returns whetherinfohas a conflict with the conflict import statements collected in this context.- Parameters:
info- the model information to search for- Returns:
- if
contextimplies conflicts onmodel - Throws:
RestrictionEvaluationException- in case of evaluation problems
-
isTopLevel
public boolean isTopLevel()
Returns whether this is a top-level or a recursively used context.- Returns:
truefor top-level,falseelse
-
considerLoading
public boolean considerLoading(boolean isTransitiveEnabled)
Returns whether model loading shall be considered.- Parameters:
isTransitiveEnabled- whether transitive loading is enabled- Returns:
truefor loading,falseelse
-
-