Package jetbrains.mps.persistence
Class DefaultModelPersistence
- java.lang.Object
 - 
- jetbrains.mps.persistence.DefaultModelPersistence
 
 
- 
- All Implemented Interfaces:
 IndexAwareModelFactory,ModelFactory
public class DefaultModelPersistence extends Object implements ModelFactory, IndexAwareModelFactory
Factory for models stored in .mps files. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultModelPersistence.ContentLoadingExtentOptions- 
Nested classes/interfaces inherited from interface jetbrains.mps.persistence.IndexAwareModelFactory
IndexAwareModelFactory.Callback 
 - 
 
- 
Constructor Summary
Constructors Constructor Description DefaultModelPersistence() 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SModelcreate(DataSource dataSource, SModelName modelName, ModelLoadingOption... options)Creates a new model with the suppliedmodelNameon the givenDataSource.static SModelcreateFromHeader(SModelHeader header, StreamDataSource dataSource)hack, @see BinaryModelPersistence#createFromHeader for detailsstatic Map<String,String>getDigestMap(Reader input)static Map<String,String>getDigestMap(MultiStreamDataSource source, String streamName)static Map<String,String>getDigestMap(StreamDataSource source)List<DataSourceType>getPreferredDataSourceTypes()Declares a list of preferred data source formats, sorted from the most preferred to the less preferred data source type.ModelFactoryTypegetType()Returns an id which is used to get model factory by id in theModelFactoryService.voidindex(InputStream input, IndexAwareModelFactory.Callback callback)Captures references to concepts/nodes/model from a model.SModelload(DataSource dataSource, ModelLoadingOption... options)Loads an existing model from the givenDataSource.booleanneedsUpgrade(DataSource dataSource)Checks if the source content is outdated and needs to be upgraded.SModelDataparseSingleStream(String name, InputStream input)Return either all or part of model data contained in the given input stream for the purpose of indexing.voidsave(SModel model, DataSource dataSource)Saves the model in the factory-specific format (including conversion when needed).booleansupports(DataSource dataSource)Determines whether the provided data source is maintained by this model factory instance.voidupgrade(DataSource dataSource)Loads the model content, and saves it back in the up-to-date format.- 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
- 
Methods inherited from interface org.jetbrains.mps.openapi.persistence.ModelFactory
canCreate 
 - 
 
 - 
 
- 
- 
Method Detail
- 
supports
public boolean supports(@NotNull DataSource dataSource)
Description copied from interface:ModelFactoryDetermines whether the provided data source is maintained by this model factory instance. Call it before calling load/create/upgrade methods in order to avoid theUnsupportedDataSourceException.- Specified by:
 supportsin interfaceModelFactory- Returns:
 - true iff the given data source can be managed by this factory
 
 
- 
create
@NotNull public SModel create(@NotNull DataSource dataSource, @NotNull SModelName modelName, @NotNull ModelLoadingOption... options) throws UnsupportedDataSourceException
Description copied from interface:ModelFactoryCreates a new model with the suppliedmodelNameon the givenDataSource. Might consider additional options provided in theoptionsvarargs. [General rule: options.contain(SomeOption) => SomeOption is on]- Specified by:
 createin interfaceModelFactory- Parameters:
 dataSource- -- location to create the model inmodelName- -- a new model name (note that it might be constructed easily from full-qualifiedString)options- -- custom options- Returns:
 - newly created model
 - Throws:
 UnsupportedDataSourceException- iffModelFactory.supports(DataSource)returns false- See Also:
 ModelLoadingOption
 
- 
load
@NotNull public SModel load(@NotNull DataSource dataSource, @NotNull ModelLoadingOption... options) throws UnsupportedDataSourceException, ModelLoadException
Description copied from interface:ModelFactoryLoads an existing model from the givenDataSource. Might consider additional options provided in theoptionsvarargs. [General rule: options.contain(SomeOption) => SomeOption is on]- Specified by:
 loadin interfaceModelFactory- Parameters:
 dataSource- -- location to load model fromoptions- -- custom options- Returns:
 - loaded model
 - Throws:
 UnsupportedDataSourceException- iffModelFactory.supports(DataSource)returns falseModelLoadException- iff there was an irrecoverable load problem (for instance format was broken or unrecognized)- See Also:
 ModelLoadingOption
 
- 
needsUpgrade
public boolean needsUpgrade(@NotNull DataSource dataSource) throws IOException
Description copied from interface:ModelFactoryChecks if the source content is outdated and needs to be upgraded.- Specified by:
 needsUpgradein interfaceModelFactory- Throws:
 UnsupportedDataSourceException- if the data source is not supportedIOException
 
- 
upgrade
public void upgrade(@NotNull DataSource dataSource) throws IOException
Description copied from interface:ModelFactoryLoads the model content, and saves it back in the up-to-date format.- Specified by:
 upgradein interfaceModelFactory- Throws:
 UnsupportedDataSourceException- if the data source is not supportedIOException
 
- 
save
public void save(@NotNull SModel model, @NotNull DataSource dataSource) throws IOException
Description copied from interface:ModelFactorySaves the model in the factory-specific format (including conversion when needed).- Specified by:
 savein interfaceModelFactory- Throws:
 IOException
 
- 
index
public void index(@NotNull InputStream input, @NotNull IndexAwareModelFactory.Callback callback) throws IOException
Description copied from interface:IndexAwareModelFactoryCaptures references to concepts/nodes/model from a model. API might change if we find certain parameters ineffective (e.g. excessive translation or more information is needed). Preferably, works faster than regular model read.- Specified by:
 indexin interfaceIndexAwareModelFactory- Throws:
 IOException
 
- 
parseSingleStream
public SModelData parseSingleStream(@NotNull String name, @NotNull InputStream input) throws IOException
Description copied from interface:IndexAwareModelFactoryReturn either all or part of model data contained in the given input stream for the purpose of indexing. For multiple file model formats it will be a subset of all model data. The return type may change to a more general {code}ModelFragment{code} of whichSModelDatawill be a special case, applicable in situations when persistence is able to return not only (a subset of) root nodes but also a model reference from the single stream given.- Specified by:
 parseSingleStreamin interfaceIndexAwareModelFactory- Parameters:
 name- Name of the stream, to help model factory decide which part of data source it is.input- An input stream which is a part of a data source accepted by this model factory- Returns:
 - (A subset of) model data contained in the given input stream
 - Throws:
 IOException- See Also:
 MultiStreamDataSource
 
- 
getType
@NotNull public ModelFactoryType getType()
Description copied from interface:ModelFactoryReturns an id which is used to get model factory by id in theModelFactoryService.- Specified by:
 getTypein interfaceModelFactory- Returns:
 - model factory unique identification entity
 
 
- 
getPreferredDataSourceTypes
@NotNull public List<DataSourceType> getPreferredDataSourceTypes()
Description copied from interface:ModelFactoryDeclares a list of preferred data source formats, sorted from the most preferred to the less preferred data source type.- Specified by:
 getPreferredDataSourceTypesin interfaceModelFactory- Returns:
 - a list of data source kinds which might be considered when MPS meets a data source location and needs to choose a model factory which is likely to support the content of the data source. For instance if we have data source types associated with file names (e.g. prefix or suffix) we are able to establish a file name pattern association with a specific model factory. For example each model file which ends with '.mps_binary' suffix would be associated with the corresponding data source type which in turn would be associated with 'MyBinaryModelFactory'.
 
 
- 
getDigestMap
public static Map<String,String> getDigestMap(@NotNull MultiStreamDataSource source, String streamName)
 
- 
getDigestMap
public static Map<String,String> getDigestMap(@NotNull StreamDataSource source)
 
- 
createFromHeader
public static SModel createFromHeader(@NotNull SModelHeader header, @NotNull StreamDataSource dataSource)
hack, @see BinaryModelPersistence#createFromHeader for details 
 - 
 
 -