Package net.ssehub.easy.dslCore
Class ModelUtility<E extends org.eclipse.emf.ecore.EObject,R extends IModel>
- java.lang.Object
-
- net.ssehub.easy.dslCore.ModelUtility<E,R>
-
- Type Parameters:
E- the top-level ECore classR- the top-level result model class
- All Implemented Interfaces:
IModelLoader<R>
- Direct Known Subclasses:
BuildLangModelUtility,ModelUtility,TemplateLangModelUtility
public abstract class ModelUtility<E extends org.eclipse.emf.ecore.EObject,R extends IModel> extends java.lang.Object implements IModelLoader<R>
A basic set of model utilities. CallsetResourceInitializer(IResourceInitializer)before using this class.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.basics.modelManagement.IModelLoader
IModelLoader.IModelInfoHolder<M extends IModel>, IModelLoader.LoadResult<M extends IModel>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Thread,java.util.Set<java.lang.String>>beingLoadedStores information about files currently being loaded in order to prevent infinite recursions in case of errors in dependent projects.private org.eclipse.xtext.GrammargrammarStores the XText grammar.private com.google.inject.Injectorinjectorprivate static IResourceInitializerresourceInitializerprivate org.eclipse.xtext.resource.XtextResourceSetresourceSetStores the XText resource set.private static java.util.List<ModelUtility<?,?>>SCHEDULED
-
Constructor Summary
Constructors Modifier Constructor Description protectedModelUtility()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.StringBuilderappend(java.lang.StringBuilder builder, java.lang.String text, java.lang.String separator)Appends atexttobuilderand insertsseparatorbefore iftextis not empty.static java.lang.StringBuilderappendWithNewLine(java.lang.StringBuilder builder, java.lang.String text)Appends atexttobuilderand inserts a new line before iftextis not empty.abstract java.lang.StringgetExtension()Returns the file extension / identifier to react on.protected org.eclipse.xtext.GrammargetGrammar()Returns the object representation of the actual grammar (and performs a lazy initialization ofgrammarorresourceSetif required).protected com.google.inject.InjectorgetInjector()Returns the injector for this language / environment.protected abstract java.lang.ClassLoadergetLanguageClassLoader()Returns the actual class loader of the language.protected abstract java.lang.StringgetLanguageName()Returns the language name as specified in the xText configuration.static IResourceInitializergetResourceInitializer()Returns the actual resource initializer.protected org.eclipse.xtext.resource.XtextResourceSetgetResourceSet()Returns the XText resource set (and performs a lazy initialization ofresourceSetif required).protected booleanhandles(java.io.File location)Returns whether this model utility class handles this type of file.protected abstract voidinitializeAfterResourceInitializer()Initializes instances which depend onresourceInitializer.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 byde.uni_hildesheim.sse.model.management.VarModelso if you intend to use the management facilities inde.uni_hildesheim.sse.model.management.VarModellet thede.uni_hildesheim.sse.model.management.VarModeldo 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 byde.uni_hildesheim.sse.model.management.VarModelso if you intend to use the management facilities inde.uni_hildesheim.sse.model.management.VarModellet thede.uni_hildesheim.sse.model.management.VarModeldo this job for you and do not call this method directly!protected Eparse(org.eclipse.emf.common.util.URI uri, boolean unload, MessageReceiver receiver, java.lang.Class<E> cls)Parses anurito 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 byde.uni_hildesheim.sse.model.management.VarModelso if you intend to use the management facilities inde.uni_hildesheim.sse.model.management.VarModellet thede.uni_hildesheim.sse.model.management.VarModeldo this job for you and do not call this method directly!protected org.eclipse.xtext.parser.IParseResultparseFragment(java.lang.String ruleName, java.lang.String input)Parses a grammar fragment.voidscan(java.io.File location, IModelLoader.IModelInfoHolder<R> holder)Scans a file for model information.protected voidsetInjector(com.google.inject.Injector injector)Defines the injector for this language / environment.static voidsetResourceInitializer(IResourceInitializer initializer)Defines the resource initializer.static java.net.URItoNetUri(org.eclipse.emf.common.util.URI uri)Converts an Eclipse URI to a java.net.URI.
-
-
-
Field Detail
-
resourceInitializer
private static IResourceInitializer resourceInitializer
-
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 ingetResourceSet(). Therefore, do not use this attribute directly but only throughgetResourceSet().
-
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 ingetGrammar(). Therefore, do not use this attribute directly but only throughgetGrammar().
-
-
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 onresourceInitializer.
-
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.URISyntaxExceptionConverts 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 ofresourceSetif 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 byde.uni_hildesheim.sse.model.management.VarModelso if you intend to use the management facilities inde.uni_hildesheim.sse.model.management.VarModellet thede.uni_hildesheim.sse.model.management.VarModeldo 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 byde.uni_hildesheim.sse.model.management.VarModelso if you intend to use the management facilities inde.uni_hildesheim.sse.model.management.VarModellet thede.uni_hildesheim.sse.model.management.VarModeldo 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 byde.uni_hildesheim.sse.model.management.VarModelso if you intend to use the management facilities inde.uni_hildesheim.sse.model.management.VarModellet thede.uni_hildesheim.sse.model.management.VarModeldo 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 ofgrammarorresourceSetif 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 ruleinput- 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 atexttobuilderand insertsseparatorbefore iftextis not empty.- Parameters:
builder- the builder to append totext- the text to appendseparator- the separator to be considered- Returns:
builder
-
appendWithNewLine
public static java.lang.StringBuilder appendWithNewLine(java.lang.StringBuilder builder, java.lang.String text)Appends atexttobuilderand inserts a new line before iftextis not empty.- Parameters:
builder- the builder to append totext- 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 anurito obtain the top-level element.- Parameters:
uri- the URI to readunload- unload the parsed XText resourcereceiver- 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:
trueif it handles the specified location,falseelse- See Also:
getExtension()
-
scan
public void scan(java.io.File location, IModelLoader.IModelInfoHolder<R> holder)Description copied from interface:IModelLoaderScans a file for model information.- Specified by:
scanin interfaceIModelLoader<E extends org.eclipse.emf.ecore.EObject>- Parameters:
location- the file to be scannedholder- 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:IModelLoaderLoads the related model.- Specified by:
loadin interfaceIModelLoader<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
-
-