Class ModelUtility<E extends org.eclipse.emf.ecore.EObject,​R extends IModel>

    • Field Summary

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

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

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.StringBuilder append​(java.lang.StringBuilder builder, java.lang.String text, java.lang.String separator)
      Appends a text to builder and inserts separator before if text is not empty.
      static java.lang.StringBuilder appendWithNewLine​(java.lang.StringBuilder builder, java.lang.String text)
      Appends a text to builder and inserts a new line before if text is not empty.
      abstract java.lang.String getExtension()
      Returns the file extension / identifier to react on.
      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).
      protected com.google.inject.Injector getInjector()
      Returns the injector for this language / environment.
      protected abstract java.lang.ClassLoader getLanguageClassLoader()
      Returns the actual class loader of the language.
      protected abstract java.lang.String getLanguageName()
      Returns the language name as specified in the xText configuration.
      static IResourceInitializer getResourceInitializer()
      Returns the actual resource initializer.
      protected org.eclipse.xtext.resource.XtextResourceSet getResourceSet()
      Returns the XText resource set (and performs a lazy initialization of resourceSet if required).
      protected boolean handles​(java.io.File location)
      Returns whether this model utility class handles this type of file.
      protected abstract void initializeAfterResourceInitializer()
      Initializes instances which depend on resourceInitializer.
      IModelLoader.LoadResult<R> load​(ModelInfo<R> info, ImportResolver<R> resolver)
      Loads the related model.
      java.util.List<ModelInfo<R>> obtainInfo​(java.io.File file)
      Obtains project info.
      abstract java.util.List<ModelInfo<R>> obtainInfo​(org.eclipse.emf.common.util.URI uri)
      Obtains model information.
      TranslationResult<R> parse​(java.io.File file)
      Parse an IVML model file for standalone application (without editor) with a new default import resolver.
      Note: This method is called by de.uni_hildesheim.sse.model.management.VarModel so if you intend to use the management facilities in de.uni_hildesheim.sse.model.management.VarModel let the de.uni_hildesheim.sse.model.management.VarModel do this job for you and do not call this method directly!
      TranslationResult<R> parse​(org.eclipse.emf.common.util.URI uri)
      Parse an IVML model file for standalone application (without editor) with a new default import resolver.
      Note: This method is called by de.uni_hildesheim.sse.model.management.VarModel so if you intend to use the management facilities in de.uni_hildesheim.sse.model.management.VarModel let the de.uni_hildesheim.sse.model.management.VarModel do this job for you and do not call this method directly!
      protected E parse​(org.eclipse.emf.common.util.URI uri, boolean unload, MessageReceiver receiver, java.lang.Class<E> cls)
      Parses an uri to obtain the top-level element.
      abstract TranslationResult<R> parse​(org.eclipse.emf.common.util.URI uri, ImportResolver<R> resolver)
      Parse an IVML model file for standalone application (without editor) with a given import resolver.
      Note: This method is called by de.uni_hildesheim.sse.model.management.VarModel so if you intend to use the management facilities in de.uni_hildesheim.sse.model.management.VarModel let the de.uni_hildesheim.sse.model.management.VarModel do this job for you and do not call this method directly!
      protected org.eclipse.xtext.parser.IParseResult parseFragment​(java.lang.String ruleName, java.lang.String input)
      Parses a grammar fragment.
      void scan​(java.io.File location, IModelLoader.IModelInfoHolder<R> holder)
      Scans a file for model information.
      protected void setInjector​(com.google.inject.Injector injector)
      Defines the injector for this language / environment.
      static void setResourceInitializer​(IResourceInitializer initializer)
      Defines the resource initializer.
      static java.net.URI toNetUri​(org.eclipse.emf.common.util.URI uri)
      Converts an Eclipse URI to a java.net.URI.
      • Methods inherited from class java.lang.Object

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

      • SCHEDULED

        private static final java.util.List<ModelUtility<?,​?>> SCHEDULED
      • beingLoaded

        private java.util.Map<java.lang.Thread,​java.util.Set<java.lang.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 Detail

      • ModelUtility

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

      • 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 java.net.URI toNetUri​(org.eclipse.emf.common.util.URI uri)
                                           throws java.net.URISyntaxException
        Converts an Eclipse URI to a java.net.URI.
        Parameters:
        uri - the URI to convert
        Returns:
        the converted URI
        Throws:
        java.net.URISyntaxException - in case of URI syntax errors
      • getResourceSet

        protected 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

        protected 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​(java.io.File file)
                                   throws java.io.IOException
        Parse an IVML model file for standalone application (without editor) with a new default import resolver.
        Note: This method is called by de.uni_hildesheim.sse.model.management.VarModel so if you intend to use the management facilities in de.uni_hildesheim.sse.model.management.VarModel let the de.uni_hildesheim.sse.model.management.VarModel do this job for you and do not call this method directly!
        Parameters:
        file - the location of the model
        Returns:
        the created variability model including messages
        Throws:
        java.io.IOException - in case of IO problems
      • parse

        public TranslationResult<R> parse​(org.eclipse.emf.common.util.URI uri)
                                   throws java.io.IOException
        Parse an IVML model file for standalone application (without editor) with a new default import resolver.
        Note: This method is called by de.uni_hildesheim.sse.model.management.VarModel so if you intend to use the management facilities in de.uni_hildesheim.sse.model.management.VarModel let the de.uni_hildesheim.sse.model.management.VarModel do this job for you and do not call this method directly!
        Parameters:
        uri - the location of the model, e.g. via URI.createURI("dummy:/example.ex1")
        Returns:
        the created variability model including messages
        Throws:
        java.io.IOException - in case of any I/O or URI problem
      • parse

        public abstract TranslationResult<R> parse​(org.eclipse.emf.common.util.URI uri,
                                                   ImportResolver<R> resolver)
                                            throws java.io.IOException
        Parse an IVML model file for standalone application (without editor) with a given import resolver.
        Note: This method is called by de.uni_hildesheim.sse.model.management.VarModel so if you intend to use the management facilities in de.uni_hildesheim.sse.model.management.VarModel let the de.uni_hildesheim.sse.model.management.VarModel do this job for you and do not call this method directly!
        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:
        java.io.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 java.lang.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 java.lang.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​(java.lang.String ruleName,
                                                                      java.lang.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 java.lang.StringBuilder append​(java.lang.StringBuilder builder,
                                                     java.lang.String text,
                                                     java.lang.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 java.lang.StringBuilder appendWithNewLine​(java.lang.StringBuilder builder,
                                                                java.lang.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,
                          java.lang.Class<E> cls)
                   throws java.io.IOException
        Parses an uri to obtain the top-level element.
        Parameters:
        uri - the URI to read
        unload - unload the parsed XText resource
        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:
        java.io.IOException - in case of any I/O and parsing problems
      • handles

        protected boolean handles​(java.io.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:
        getExtension()
      • scan

        public void scan​(java.io.File location,
                         IModelLoader.IModelInfoHolder<R> holder)
        Description copied from interface: IModelLoader
        Scans a file for model information.
        Specified by:
        scan in interface IModelLoader<E extends org.eclipse.emf.ecore.EObject>
        Parameters:
        location - the file to be scanned
        holder - an instance providing limited access to the model information storage
      • obtainInfo

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

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

        public IModelLoader.LoadResult<R> load​(ModelInfo<R> info,
                                               ImportResolver<R> resolver)
        Description copied from interface: IModelLoader
        Loads the related model.
        Specified by:
        load in interface IModelLoader<E extends org.eclipse.emf.ecore.EObject>
        Parameters:
        info - the model to be loaded (as information object)
        resolver - the import resolver to use (or null for a new default import resolver)
        Returns:
        the loaded model (or null in case of problems)
      • getExtension

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