Package jetbrains.mps.persistence
Class DefaultModelRoot
- java.lang.Object
 - 
- jetbrains.mps.extapi.persistence.ModelRootBase
 - 
- jetbrains.mps.extapi.persistence.FileBasedModelRoot
 - 
- jetbrains.mps.persistence.DefaultModelRoot
 
 
 
 
- 
- All Implemented Interfaces:
 CopyableModelRoot<DefaultModelRoot>,FileListener,FileSystemListener,ModelRoot
public class DefaultModelRoot extends FileBasedModelRoot implements CopyableModelRoot<DefaultModelRoot>
This model root is responsible for loading models from the source roots as well as for creating models and register them in itself. It looks forDataSourceFactoryFromNameandDataSourceFactoryFromURLinstances through theDataSourceFactoryRuleServiceand finds properModelFactoryinstances via theModelFactoryRegistrydata source kind to model factory association. See a variety of model creation methods below. SeecollectModels(SourceRoot)for traversing logic of this model root. It is used by MPS to store all the kinds of models (except the java sources and classes stubs) -- therefore the poor naming. PLAN: It makes sense to unite this concept with other file-system-based model root concepts. Probably it is going to be transformed into a singleFileSystemModelRootentity which will be suitable for any model storage system which has a tree-like storage.- Since:
 - 11/9/12
 
 
- 
- 
Field Summary
- 
Fields inherited from class jetbrains.mps.extapi.persistence.FileBasedModelRoot
CONTENT_PATH, EXCLUDED, LOCATION, SOURCE_ROOTS 
 - 
 
- 
Constructor Summary
Constructors Constructor Description DefaultModelRoot()Deprecated.UsecreateDescriptor(IFile, IFile...)if you need to populate ModuleDescriptor. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancanCreateModel(String modelName)booleancanCreateModels()There are model roots which are read-only and fix the result ofModelRoot.getModels()right away from the construction FIXME it is strange to have two similar methods: we are better to merge this method into the methodModelRoot.canCreateModel(java.lang.String).voidcopyTo(DefaultModelRoot targetModelRoot)Copies this model root contents to thetargetModelRoot .static ModelRootDescriptorcreateDescriptor(IFile contentRoot, IFile... modelDir)Build a descriptor that could be added to aModuleDescriptorto facilitate instantiation of a model root of this specific type when a module loads.SModelcreateFileModel(String modelName, SourceRoot sourceRoot)Creates a new file based model in the default source root.SModelcreateModel(String modelName)Creates model in the default source root via default factorySModelcreateModel(SModelName modelName, SourceRoot sourceRoot, DataSourceFactoryFromName dataSourceFactory, ModelFactory modelFactory)Creates a new model via given factory with given name and under the provided sourceRoot in this ModelRoot.SModelcreateModel(SModelName modelName, SourceRoot sourceRoot, DataSourceType dataSourceType, ModelFactoryType modelFactoryType)Creates a new model via given factory with given name and under the provided sourceRoot in this ModelRoot.SModelcreatePerRootModel(String modelName, SourceRoot sourceRoot)Creates a new folder-based (per-root by default) model in the default source root.static ModelRootDescriptorcreateSingleFolderDescriptor(IFile modelDir)Same ascreateDescriptor(IFile, IFile...)limited to a single location with source model filesSModelgetModel(SModelId id)List<SourceRootKind>getSupportedFileKinds1()To become abstract in the 3.5StringgetType()A customizable categorization identifier, such as JavaStubsIterable<SModel>loadModels()returns all models under the model root if some model is already loaded and registered, it is recommended to return the loaded one instead of loading another timevoidrename(FileDataSource dataSource, String newName)ModelRootDescriptortoDescriptor()Deprecated.- 
Methods inherited from class jetbrains.mps.extapi.persistence.FileBasedModelRoot
addFile, addSourceRoot, attach, containsFile, deleteFile, dispose, equals, getContentDirectory, getContentRoot, getFiles, getFileSystem, getFileToListen, getPresentation, getSourceRoots, getSupportedFileKinds, hashCode, load, relativize, relativize, removeSourceRoot, save, setContentDirectory, setContentRoot, update 
- 
Methods inherited from class jetbrains.mps.extapi.persistence.ModelRootBase
assertCanChange, assertCanRead, getModels, getModule, getRepository, isRegistered, registerModel, setModule, toString, update 
- 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait 
- 
Methods inherited from interface jetbrains.mps.vfs.refresh.FileListener
listeningPreferences 
- 
Methods inherited from interface jetbrains.mps.vfs.refresh.FileSystemListener
getListenerDependencies 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
DefaultModelRoot
@Deprecated public DefaultModelRoot()
Deprecated.UsecreateDescriptor(IFile, IFile...)if you need to populate ModuleDescriptor. Proper cons (package-local) shall get invoked from ModelRootFactory only.FIXME must be made package-local or protected (as long as there's subclass) FIXME one must have either factory creation or a public constructor not both [AP] 
 - 
 
- 
Method Detail
- 
getSupportedFileKinds1
@NotNull public List<SourceRootKind> getSupportedFileKinds1()
Description copied from class:FileBasedModelRootTo become abstract in the 3.5- Overrides:
 getSupportedFileKinds1in classFileBasedModelRoot
 
- 
getType
public String getType()
Description copied from interface:ModelRootA customizable categorization identifier, such as JavaStubs 
- 
loadModels
@NotNull public Iterable<SModel> loadModels()
Description copied from class:ModelRootBasereturns all models under the model root if some model is already loaded and registered, it is recommended to return the loaded one instead of loading another time- Specified by:
 loadModelsin classModelRootBase- Returns:
 - a sequence of models
 
 
- 
canCreateModels
public boolean canCreateModels()
Description copied from interface:ModelRootThere are model roots which are read-only and fix the result ofModelRoot.getModels()right away from the construction FIXME it is strange to have two similar methods: we are better to merge this method into the methodModelRoot.canCreateModel(java.lang.String).- Specified by:
 canCreateModelsin interfaceModelRoot- Overrides:
 canCreateModelsin classModelRootBase- Returns:
 - whether this model root is read-only in the way described above
 
 
- 
canCreateModel
public boolean canCreateModel(@NotNull String modelName)
- Specified by:
 canCreateModelin interfaceModelRoot- Parameters:
 modelName- -- the same as in theModelRoot.createModel(String)- Returns:
 - whether a model with a name 
modelNamecan be created under this model root. 
 
- 
createModel
@Nullable public SModel createModel(@NotNull String modelName)
Creates model in the default source root via default factory- Specified by:
 createModelin interfaceModelRoot- Parameters:
 modelName- -- might fq name or just simple short model name. Up to implementor- Returns:
 - null if there was IOException
 - See Also:
 DefaultModelRoot.Defaults.sourceRoot(jetbrains.mps.extapi.persistence.FileBasedModelRoot)
 
- 
createPerRootModel
@Nullable public SModel createPerRootModel(@NotNull String modelName, @Nullable SourceRoot sourceRoot) throws ModelCannotBeCreatedException
Creates a new folder-based (per-root by default) model in the default source root.- Returns:
 - null if there was IOException
 - Throws:
 ModelCannotBeCreatedException- See Also:
 DefaultModelRoot.Defaults
 
- 
createFileModel
@Nullable public SModel createFileModel(@NotNull String modelName, @Nullable SourceRoot sourceRoot) throws ModelCannotBeCreatedException
Creates a new file based model in the default source root.- Returns:
 - null if there was IOException
 - Throws:
 ModelCannotBeCreatedException- See Also:
 DefaultModelRoot.Defaults
 
- 
createModel
@NotNull public SModel createModel(@NotNull SModelName modelName, @Nullable SourceRoot sourceRoot, @Nullable DataSourceType dataSourceType, @Nullable ModelFactoryType modelFactoryType) throws ModelCannotBeCreatedException
Creates a new model via given factory with given name and under the provided sourceRoot in this ModelRoot. Whenever the parameter is null the default one is used.- Throws:
 ModelCannotBeCreatedException
 
- 
createModel
@NotNull public SModel createModel(@NotNull SModelName modelName, @Nullable SourceRoot sourceRoot, @Nullable DataSourceFactoryFromName dataSourceFactory, @Nullable ModelFactory modelFactory) throws ModelCannotBeCreatedException
Creates a new model via given factory with given name and under the provided sourceRoot in this ModelRoot. Whenever the parameter is null the default one is used. The most 'heavy' method (parameter-wise):- Parameters:
 modelName- -- controls the name of the new modelsourceRoot- -- the source root to create the new model indataSourceFactory- -- data source factory which methodDataSourceFactoryFromName.create(SModelName, SourceRoot)is going to be used to create a new data source from the given model name and source rootmodelFactory- -- model factory which defines the persisting strategy of the new model. Note thatmodelFactoryis independent enough from thedataSourceFactoryand data sources it creates.- Returns:
 - new SModel instance with the given name, generated data source lying under the source root,
        registered in this model root which is created via the given 
modelFactory - Throws:
 ModelCannotBeCreatedException- See Also:
 DefaultModelRoot.Defaults
 
- 
rename
public void rename(FileDataSource dataSource, String newName) throws DataSourceFactoryNotFoundException, NoSourceRootsInModelRootException, SourceRootDoesNotExistException
 
- 
copyTo
public void copyTo(@NotNull DefaultModelRoot targetModelRoot) throws CopyNotSupportedException
Description copied from interface:CopyableModelRootCopies this model root contents to thetargetModelRoot . the resulting model root must be equal to the prototype- Specified by:
 copyToin interfaceCopyableModelRoot<DefaultModelRoot>- Throws:
 CopyNotSupportedException
 
- 
toDescriptor
@Deprecated public ModelRootDescriptor toDescriptor()
Deprecated.Obviously whilst the model root descriptors are in theAbstractModulewe need this method 
- 
createDescriptor
@NotNull public static ModelRootDescriptor createDescriptor(@NotNull IFile contentRoot, IFile... modelDir)
Build a descriptor that could be added to aModuleDescriptorto facilitate instantiation of a model root of this specific type when a module loads. With ModelRootDescriptor/ModuleDescriptor being a mechanism to create/update SModule information, we need a way to construct a descriptor that would end up as DefaultModelRoot. Since there's no relevant API inModelRootDescriptoritself (which is questionable btw, provided approach for Language/Generator/Solution module descriptor is different), and exposing Memento keys of this root implementation is bad, these factory methods give an way to construct descriptor for most common scenarios. Present approach is that ModelRootDescriptor controls nothing and accepts plain strings, while objects like ModelRootDescriptor/ModuleDescriptor deal with files. DefaultModelRoot is initialized with MRD and constraints/manipulates low-level persistence data. From that perspective the right way to create ModelRootDescriptor is to configure it with plain strings. OTOH, in many cases we've got IFile already, and it looks odd to go to strings when IFile is handy. Besides, need to be very careful to mangle strings properly to place sourceRoots relative to content root without using IFile/File objects. FIXME Perhaps, need a similar method with String parameters to satisfy both worlds?- Parameters:
 contentRoot- root folder for model locationsmodelDir- at least one folder (usually under contentRoot; could be equal to it) with model source files- Returns:
 - descriptor for a default model root
 
 
- 
createSingleFolderDescriptor
@NotNull public static ModelRootDescriptor createSingleFolderDescriptor(@NotNull IFile modelDir)
Same ascreateDescriptor(IFile, IFile...)limited to a single location with source model files- Parameters:
 modelDir- folder with model source files, serves both as content root and as a source location- Returns:
 - descriptor for a default model root
 
 
 - 
 
 -