Class ImportResolver<M extends IModel>

  • Type Parameters:
    M - the specific model type
    Direct Known Subclasses:
    DefaultImportResolver

    public abstract class ImportResolver<M extends IModel>
    extends java.lang.Object
    Basic implementation of a model import resolver. Import resolvers may have a model processing listener to inform about loading new models. Please note that this listener is not bound to a specific project as it is the case for use with ModelManagement. Further, this class enables deferred loading, i.e., (cyclic) models that perform processing of declarations first and then require later subsequent resolution of model elements.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • ImportResolver

        public ImportResolver()
    • Method Detail

      • setProcessingListener

        public IModelProcessingListener<M> setProcessingListener​(IModelProcessingListener<M> processingListener)
        Defines the actual processing listener.
        Parameters:
        processingListener - the listener (may be null for none)
        Returns:
        the previous listener (may be null for none)
      • getProcessingListener

        public IModelProcessingListener<M> getProcessingListener()
        Returns the processing listener.
        Returns:
        the processing listener (may be null)
      • notifyProcessing

        protected void notifyProcessing​(ModelInfo<M> info,
                                        IModelProcessingListener.Type type,
                                        boolean started)
        Notifies the processing listener if defined.
        Parameters:
        info - the information object the operation is performed on
        type - the processing type
        started - whether the operation started or ended
      • clear

        public void clear()
        Clears this instance for reuse.
      • resolveImports

        public abstract 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 given model and 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 modify model as a side effect.
        Parameters:
        model - the model to be resolved
        uri - 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 repository
        evaluationContext - the context for evaluating import restrictions (variable definitions... interpreted locally)
        Returns:
        messages which occur during resolution
      • resolve

        public abstract M resolve​(java.lang.String modelName,
                                  IVersionRestriction restriction,
                                  java.net.URI baseUri,
                                  IModelRepository<M> repository,
                                  IRestrictionEvaluationContext evaluationContext)
                           throws ModelManagementException
        Resolves the denoted model considering the given restrictions.
        Parameters:
        modelName - the name of the model
        restriction - 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 repository
        evaluationContext - the context for evaluating import restrictions (variable definitions... interpreted locally)
        Returns:
        the resolved model
        Throws:
        ModelManagementException - in case of resolution failures
      • setTransitiveLoading

        public boolean setTransitiveLoading​(boolean transitiveLoading)
        Enables or disables transitive loading. By default, transitive loading is enabled, i.e., while resolution unknown models are loaded and resolved. If disabled, such models are not resolved at all.
        Parameters:
        transitiveLoading - whether transitive loading is enabled
        Returns:
        the value of the transitive loading before setting the value
      • isTransitiveLoadingEnabled

        public boolean isTransitiveLoadingEnabled()
        Returns whether transitive loading is enabled.
        Returns:
        true if transitive loading is enabled, false else
      • addDeferredLoader

        public void addDeferredLoader​(IDeferredModelLoader<M> loader)
        Adds a deferred loader.
        Parameters:
        loader - the loader