Class ResolutionContext<M extends IModel>

  • Type Parameters:
    M - the specific model type

    class ResolutionContext<M extends IModel>
    extends java.lang.Object
    Defines an internal class representing the context of a model import resolution.
    Author:
    Holger Eichelberger
    • 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 happens
        modelUri - the URI to model (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 happens
        modelUri - the URI to model (may be null)
        inProgress - the models being processed at once with model (may be null)
        repository - the model repository
        evaluationContext - 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 resolve
        baseUri - the URI where to start the resolution from (may be a model URI)
        repository - the model repository
        evaluationContext - 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 to model.
        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 enumerate
        results - 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 loading info would 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:
        true if it would cause a loop, false else
      • 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 given context.
        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 given toAdd conflicts to conflicts. conflicts may be null and is created then lazily.
        Type Parameters:
        M - the type of models
        Parameters:
        conflicts - the conflicts set to add the toAdd conflicts to
        toAdd - the conflicts to be added
        Returns:
        conflicts if 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 conflict model and 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 conflict model and its (recursive) imports have with the conflict import statements collected in this context.
        Parameters:
        model - the model information to search for (may be null
        done - 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 model
        version - 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 whether info has a conflict with the conflict import statements collected in this context.
        Parameters:
        info - the model information to search for
        Returns:
        if context implies conflicts on model
        Throws:
        RestrictionEvaluationException - in case of evaluation problems
      • isTopLevel

        public boolean isTopLevel()
        Returns whether this is a top-level or a recursively used context.
        Returns:
        true for top-level, false else
      • considerLoading

        public boolean considerLoading​(boolean isTransitiveEnabled)
        Returns whether model loading shall be considered.
        Parameters:
        isTransitiveEnabled - whether transitive loading is enabled
        Returns:
        true for loading, false else