Class ModelUtility<E extends org.eclipse.emf.ecore.EObject,R extends net.ssehub.easy.basics.modelManagement.IModel>

java.lang.Object
net.ssehub.easy.dslCore.ModelUtility<E,R>
Type Parameters:
E - the top-level ECore class
R - the top-level result model class
All Implemented Interfaces:
net.ssehub.easy.basics.modelManagement.IModelLoader<R>

public abstract class ModelUtility<E extends org.eclipse.emf.ecore.EObject,R extends net.ssehub.easy.basics.modelManagement.IModel> extends Object implements net.ssehub.easy.basics.modelManagement.IModelLoader<R>
A basic set of model utilities. Call setResourceInitializer(IResourceInitializer) before using this class.
Author:
Holger Eichelberger
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.ssehub.easy.basics.modelManagement.IModelLoader

    net.ssehub.easy.basics.modelManagement.IModelLoader.IModelInfoHolder<M extends net.ssehub.easy.basics.modelManagement.IModel>, net.ssehub.easy.basics.modelManagement.IModelLoader.LoadResult<M extends net.ssehub.easy.basics.modelManagement.IModel>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Map<Thread,Set<String>>
    Stores information about files currently being loaded in order to prevent infinite recursions in case of errors in dependent projects.
    private static boolean
     
    private org.eclipse.xtext.Grammar
    Stores the XText grammar.
    private com.google.inject.Injector
     
    private static List<ModelUtility<?,?>>
     
    private static IResourceInitializer
     
    private org.eclipse.xtext.resource.XtextResourceSet
    Stores the XText resource set.
    private static final List<ModelUtility<?,?>>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an instance and causes the creation of the injector or schedules the creation.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(StringBuilder builder, String text, String separator)
    Appends a text to builder and inserts separator before if text is not empty.
    Appends a text to builder and inserts a new line before if text is not empty.
    static boolean
    forceUnloadOnParse(boolean force)
     
    abstract String
    Returns the file extension / identifier to react on.
    protected org.eclipse.xtext.Grammar
    Returns the object representation of the actual grammar (and performs a lazy initialization of grammar or resourceSet if required).
    abstract net.ssehub.easy.basics.modelManagement.ModelInfo<R>
    getInfo(URI uri)
    Returns model information from the underlying model repository.
    net.ssehub.easy.basics.modelManagement.ModelInfo<R>
    getInfo(org.eclipse.emf.common.util.URI uri)
    Return model information from the underlying model repository.
    com.google.inject.Injector
    Returns the injector for this language / environment.
    protected abstract ClassLoader
    Returns the actual class loader of the language.
    protected abstract String
    Returns the language name as specified in the xText configuration.
    Returns the actual resource initializer.
    org.eclipse.xtext.resource.XtextResourceSet
    Returns the XText resource set (and performs a lazy initialization of resourceSet if required).
    protected boolean
    handles(File location)
    Returns whether this model utility class handles this type of file.
    protected abstract void
    Initializes instances which depend on resourceInitializer.
    static Iterable<ModelUtility<?,?>>
     
    net.ssehub.easy.basics.modelManagement.IModelLoader.LoadResult<R>
    load(net.ssehub.easy.basics.modelManagement.ModelInfo<R> info, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver)
     
    List<net.ssehub.easy.basics.modelManagement.ModelInfo<R>>
    Obtains project info.
    abstract List<net.ssehub.easy.basics.modelManagement.ModelInfo<R>>
    obtainInfo(org.eclipse.emf.common.util.URI uri)
    Obtains model information.
    parse(File file)
    Parse an IVML model file for standalone application (without editor) with a new default import resolver.
    parse(org.eclipse.emf.common.util.URI uri)
    Parse an IVML model file for standalone application (without editor) with a new default import resolver.
    protected E
    parse(org.eclipse.emf.common.util.URI uri, boolean unload, MessageReceiver receiver, Class<E> cls)
    Parses an uri to obtain the top-level element.
    parse(org.eclipse.emf.common.util.URI uri, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver)
    Parse an IVML model file for standalone application (without editor) with a given import resolver.
    protected org.eclipse.xtext.parser.IParseResult
    parseFragment(String ruleName, String input)
    Parses a grammar fragment.
    void
    scan(File location, net.ssehub.easy.basics.modelManagement.IModelLoader.IModelInfoHolder<R> holder)
     
    protected void
    setInjector(com.google.inject.Injector injector)
    Defines the injector for this language / environment.
    static void
    Defines the resource initializer.
    static final URI
    toNetUri(org.eclipse.emf.common.util.URI uri)
    Converts an Eclipse URI to a java.net.URI.
    void
    validate(org.eclipse.emf.ecore.resource.Resource resource, Consumer<MessageReceiver> messageHandler)
    Validates the given resource.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • resourceInitializer

      private static IResourceInitializer resourceInitializer
    • instances

      private static List<ModelUtility<?,?>> instances
    • SCHEDULED

      private static final List<ModelUtility<?,?>> SCHEDULED
    • forceUnloadOnParse

      private static boolean forceUnloadOnParse
    • beingLoaded

      private Map<Thread,Set<String>> beingLoaded
      Stores information about files currently being loaded in order to prevent infinite recursions in case of errors in dependent projects.
    • resourceSet

      private org.eclipse.xtext.resource.XtextResourceSet resourceSet
      Stores the XText resource set. This attribute is initialized in a lazy way in getResourceSet(). Therefore, do not use this attribute directly but only through getResourceSet().
    • injector

      private com.google.inject.Injector injector
    • grammar

      private org.eclipse.xtext.Grammar grammar
      Stores the XText grammar. This attribute is initialized in a lazy fashion in getGrammar(). Therefore, do not use this attribute directly but only through getGrammar().
  • Constructor Details

    • ModelUtility

      protected ModelUtility()
      Creates an instance and causes the creation of the injector or schedules the creation.
  • Method Details

    • forceUnloadOnParse

      public static boolean forceUnloadOnParse(boolean force)
    • instances

      public static Iterable<ModelUtility<?,?>> instances()
    • setResourceInitializer

      public static void setResourceInitializer(IResourceInitializer initializer)
      Defines the resource initializer.
      Parameters:
      initializer - the initializer
    • initializeAfterResourceInitializer

      protected abstract void initializeAfterResourceInitializer()
      Initializes instances which depend on resourceInitializer.
    • getResourceInitializer

      public static IResourceInitializer getResourceInitializer()
      Returns the actual resource initializer.
      Returns:
      the actual resource initializer
    • toNetUri

      public static final URI toNetUri(org.eclipse.emf.common.util.URI uri) throws URISyntaxException
      Converts an Eclipse URI to a java.net.URI.
      Parameters:
      uri - the URI to convert
      Returns:
      the converted URI
      Throws:
      URISyntaxException - in case of URI syntax errors
    • getResourceSet

      public org.eclipse.xtext.resource.XtextResourceSet getResourceSet()
      Returns the XText resource set (and performs a lazy initialization of resourceSet if required).
      Returns:
      the resource set
    • getInjector

      public com.google.inject.Injector getInjector()
      Returns the injector for this language / environment.
      Returns:
      the injector
    • setInjector

      protected void setInjector(com.google.inject.Injector injector)
      Defines the injector for this language / environment.
      Parameters:
      injector - the injector instance
    • parse

      public TranslationResult<R> parse(File file) throws IOException
      Parse an IVML model file for standalone application (without editor) with a new default import resolver.
      Parameters:
      file - the location of the model
      Returns:
      the created variability model including messages
      Throws:
      IOException - in case of IO problems
    • parse

      public TranslationResult<R> parse(org.eclipse.emf.common.util.URI uri) throws IOException
      Parse an IVML model file for standalone application (without editor) with a new default import resolver.
      Parameters:
      uri - the location of the model, e.g. via URI.createURI("dummy:/example.ex1")
      Returns:
      the created variability model including messages
      Throws:
      IOException - in case of any I/O or URI problem
    • parse

      public abstract TranslationResult<R> parse(org.eclipse.emf.common.util.URI uri, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver) throws IOException
      Parse an IVML model file for standalone application (without editor) with a given import resolver.
      Parameters:
      uri - the location of the model, e.g. via URI.createURI("dummy:/example.ex1")
      resolver - the import resolver (may be null for a new default import resolver)
      Returns:
      the created variability model including messages
      Throws:
      IOException - in case of any I/O or URI problem
    • getGrammar

      protected org.eclipse.xtext.Grammar getGrammar()
      Returns the object representation of the actual grammar (and performs a lazy initialization of grammar or resourceSet if required).
      Returns:
      the grammar
    • getLanguageName

      protected abstract String getLanguageName()
      Returns the language name as specified in the xText configuration. This name can be found as URL in the grammar file or corresponds to the Java path of the grammar-XMI file in src-gen.
      Returns:
      the language name in Java package notation
    • getLanguageClassLoader

      protected abstract ClassLoader getLanguageClassLoader()
      Returns the actual class loader of the language. This loader may be different due to different bundles.
      Returns:
      the class loader
    • parseFragment

      protected org.eclipse.xtext.parser.IParseResult parseFragment(String ruleName, String input)
      Parses a grammar fragment.
      Parameters:
      ruleName - the name of the grammar rule
      input - the text to be parsed
      Returns:
      the parse result if successful, null in case of instantiation problems
    • append

      public static StringBuilder append(StringBuilder builder, String text, String separator)
      Appends a text to builder and inserts separator before if text is not empty.
      Parameters:
      builder - the builder to append to
      text - the text to append
      separator - the separator to be considered
      Returns:
      builder
    • appendWithNewLine

      public static StringBuilder appendWithNewLine(StringBuilder builder, String text)
      Appends a text to builder and inserts a new line before if text is not empty.
      Parameters:
      builder - the builder to append to
      text - the text to append
      Returns:
      builder
    • parse

      protected E parse(org.eclipse.emf.common.util.URI uri, boolean unload, MessageReceiver receiver, Class<E> cls) throws IOException
      Parses an uri to obtain the top-level element.
      Parameters:
      uri - the URI to read
      unload - unload the parsed XText resource, may change AST node adapters and keep source positions internal
      receiver - the message receiver used for storing messages (may be null)
      cls - the class of the result
      Returns:
      the top-level element (or null if not found)
      Throws:
      IOException - in case of any I/O and parsing problems
    • handles

      protected boolean handles(File location)
      Returns whether this model utility class handles this type of file.
      Parameters:
      location - the location to be considered
      Returns:
      true if it handles the specified location, false else
      See Also:
    • scan

      public void scan(File location, net.ssehub.easy.basics.modelManagement.IModelLoader.IModelInfoHolder<R> holder)
      Specified by:
      scan in interface net.ssehub.easy.basics.modelManagement.IModelLoader<E extends org.eclipse.emf.ecore.EObject>
    • obtainInfo

      public List<net.ssehub.easy.basics.modelManagement.ModelInfo<R>> obtainInfo(File file) throws IOException
      Obtains project info.
      Parameters:
      file - the file to read the info from
      Returns:
      the project info instances related to file
      Throws:
      IOException - in case that an I/O error happens during parsing
    • obtainInfo

      public abstract List<net.ssehub.easy.basics.modelManagement.ModelInfo<R>> obtainInfo(org.eclipse.emf.common.util.URI uri) throws IOException
      Obtains model information.
      Parameters:
      uri - the URI to read the info from
      Returns:
      the project info instances related to uri
      Throws:
      IOException - in case that an I/O error happens during parsing
    • getInfo

      public abstract net.ssehub.easy.basics.modelManagement.ModelInfo<R> getInfo(URI uri)
      Returns model information from the underlying model repository.
      Parameters:
      uri - the URI to return the info for
      Returns:
      the project info instance related to uri, may be null for none
    • getInfo

      public net.ssehub.easy.basics.modelManagement.ModelInfo<R> getInfo(org.eclipse.emf.common.util.URI uri)
      Return model information from the underlying model repository.
      Parameters:
      uri - the URI to return the info for
      Returns:
      the project info instance related to uri, may be null for none
      See Also:
    • load

      public net.ssehub.easy.basics.modelManagement.IModelLoader.LoadResult<R> load(net.ssehub.easy.basics.modelManagement.ModelInfo<R> info, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver)
      Specified by:
      load in interface net.ssehub.easy.basics.modelManagement.IModelLoader<E extends org.eclipse.emf.ecore.EObject>
    • getExtension

      public abstract String getExtension()
      Returns the file extension / identifier to react on.
      Returns:
      the extension
    • validate

      public void validate(org.eclipse.emf.ecore.resource.Resource resource, Consumer<MessageReceiver> messageHandler)
      Validates the given resource.
      Parameters:
      resource - the resource
      messageHandler - message handler (may be on UI level)