Class DefaultModelLessDataHolder
- java.lang.Object
-
- org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder
-
- All Implemented Interfaces:
DataHolder,ModelLessDataHolder
- Direct Known Subclasses:
DefaultModifiableModelLessDataHolder
public class DefaultModelLessDataHolder extends Object implements ModelLessDataHolder
Default implementation for data holder without model
-
-
Field Summary
Fields Modifier and Type Field Description protected Optional<? extends ModelLessDataHolder>_parentParent of the currentDataHolderprotected RepositoryData_repositoryDataRepository data to use to store data in the repositoryprotected ModelLessDataHolder_rootRootDataHolderprotected AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType>_typeExtensionPointExtension point to use to get available element types
-
Constructor Summary
Constructors Constructor Description DefaultModelLessDataHolder(AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> typeExtensionPoint, RepositoryData repositoryData)Creates a default model free data holderDefaultModelLessDataHolder(AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> typeExtensionPoint, RepositoryData repositoryData, Optional<? extends ModelLessDataHolder> parent, Optional<? extends ModelLessDataHolder> root)Creates a default model free data holder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ModelLessComposite_getComposite(String name)Retrieves the composite with the given nameprotected static ModelLessDataHolder_getParentValue(ModelLessDataHolder dataHolder, String dataPath)Retrieves the data holder, last parent segment of the given data path Example : call this method with a path like 'my-composite1/my-composite2/my-data' will retrieve the composite 'my-composite2' in the composite 'my-composite1'private RepositoryModelItemType_getType(String dataName)protected static boolean_hasNonEmptyValue(ModelLessDataHolder dataHolder, String dataPath, RepositoryModelItemType dataType)Checks if there is a non empty value for the data at the given pathvoiddataToSAX(ContentHandler contentHandler, String dataPath, DataContext context)Generates SAX events for the data at the given data path in the currentDataHolderDo not generate any event if there is no values at the given pathvoiddataToSAX(ContentHandler contentHandler, DataContext context)Generates SAX events for data contained in thisDataHolderModelLessCompositegetComposite(String compositePath)Retrieves the composite at the given pathCollection<String>getDataNames()Retrieves the names of data contained by this data holder Retrieves only the data at first level, does not check composite dataOptional<? extends ModelLessDataHolder>getParentDataHolder()Retrieves the optional parent of the currentDataHolderThere can be no parent if the currentDataHolderis the rootRepositoryDatagetRepositoryData()Retrieves the repository data used by thisDataHolderModelLessDataHoldergetRootDataHolder()Retrieves theDataHolderthat is the root of the current oneRepositoryModelItemTypegetType(String dataPath)Retrieves the type of the data at the given path<T> TgetValue(String dataPath)Retrieves the value of the data at the given path The type of the value will be deduced from the stored data.<T> TgetValue(String dataPath, T defaultValue)Retrieves the value of the data at the given path if exists and is not empty, or the default value<T> TgetValueOfType(String dataPath, String dataTypeId)Retrieves the value of the data at the given path<T> TgetValueOfType(String dataPath, String dataTypeId, T defaultValue)Retrieves the value of the data at the given path if exists and is not empty, or the default valuebooleanhasNonEmptyValue(String dataPath)Checks if there is a non empty value for the data at the given pathbooleanhasValue(String dataPath)Checks if there is a value for the data at the given pathbooleanisMultiple(String dataPath)Checks if the value of the data at the given path is multiple-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ametys.plugins.repository.data.holder.DataHolder
copyTo, dataToSAX
-
Methods inherited from interface org.ametys.plugins.repository.data.holder.ModelLessDataHolder
dataToSAX
-
-
-
-
Field Detail
-
_typeExtensionPoint
protected AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _typeExtensionPoint
Extension point to use to get available element types
-
_repositoryData
protected RepositoryData _repositoryData
Repository data to use to store data in the repository
-
_parent
protected Optional<? extends ModelLessDataHolder> _parent
Parent of the currentDataHolder
-
_root
protected ModelLessDataHolder _root
RootDataHolder
-
-
Constructor Detail
-
DefaultModelLessDataHolder
public DefaultModelLessDataHolder(AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> typeExtensionPoint, RepositoryData repositoryData)
Creates a default model free data holder- Parameters:
typeExtensionPoint- the extension point to use to get available element typesrepositoryData- the repository data to use
-
DefaultModelLessDataHolder
public DefaultModelLessDataHolder(AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> typeExtensionPoint, RepositoryData repositoryData, Optional<? extends ModelLessDataHolder> parent, Optional<? extends ModelLessDataHolder> root)
Creates a default model free data holder- Parameters:
typeExtensionPoint- the extension point to use to get available element typesparent- the parent of the createdDataHolder, empty if the createdDataHolderis the rootDataHolderroot- the rootDataAwareAmetysObjectrepositoryData- the repository data to use
-
-
Method Detail
-
getComposite
public ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException
Description copied from interface:ModelLessDataHolderRetrieves the composite at the given path- Specified by:
getCompositein interfaceDataHolder- Specified by:
getCompositein interfaceModelLessDataHolder- Parameters:
compositePath- path of the composite to retrieve- Returns:
- the composite or
nullif not exists or is empty - Throws:
IllegalArgumentException- if the given composite path is null or emptyBadItemTypeException- if the stored value at the given path is not a composite
-
getValue
public <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException
Description copied from interface:ModelLessDataHolderRetrieves the value of the data at the given path The type of the value will be deduced from the stored data. In some cases, the type can be wrong. For example, it is impossible to know if a stored date is a date or a date time- Specified by:
getValuein interfaceModelLessDataHolder- Type Parameters:
T- type of the value to retrieve. Should match the given data type- Parameters:
dataPath- path of the data- Returns:
- the value of the data or
nullif not exists or is empty. The object returned may be of a generic class defined by the storage. For example, an url may be returned as a String. Use the 2 arguments version to ensure to get the right kind of Object. - Throws:
IllegalArgumentException- if the given data path is null or emptyUnknownTypeException- if there is no compatible type with the data at the given data pathNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one)
-
getValue
public <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException
Description copied from interface:ModelLessDataHolderRetrieves the value of the data at the given path if exists and is not empty, or the default value- Specified by:
getValuein interfaceModelLessDataHolder- Type Parameters:
T- type of the value to retrieve. Should match the given data type- Parameters:
dataPath- path of the datadefaultValue- default value- Returns:
- the value of the data,
nullif the data exists but is empty, or the given default value - Throws:
IllegalArgumentException- if the given data path is null or emptyUnknownTypeException- if there is no compatible type with the data at the given data pathNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one)
-
getValueOfType
public <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, BadItemTypeException
Description copied from interface:ModelLessDataHolderRetrieves the value of the data at the given path if exists and is not empty, or the default value- Specified by:
getValueOfTypein interfaceModelLessDataHolder- Type Parameters:
T- type of the value to retrieve. Should match the given data type- Parameters:
dataPath- path of the datadataTypeId- type identifier of the datadefaultValue- default value- Returns:
- the value of the data,
nullif the data exists but is empty, or the given default value - Throws:
IllegalArgumentException- if the given data path is null or emptyBadItemTypeException- if the given type doesn't match the type of the stored value at the given path
-
getValueOfType
public <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException
Description copied from interface:ModelLessDataHolderRetrieves the value of the data at the given path- Specified by:
getValueOfTypein interfaceModelLessDataHolder- Type Parameters:
T- type of the value to retrieve. Should match the given data type- Parameters:
dataPath- path of the datadataTypeId- type identifier of the data- Returns:
- the value of the data or
nullif not exists or is empty - Throws:
IllegalArgumentException- if the given data path is null or emptyUnknownTypeException- if the given type isn't available for this data holder's type extension pointBadItemTypeException- if the given type doesn't match the type of the stored value at the given pathBadDataPathCardinalityException- if the value of a part of the data path is multiple. Only the last part can be multiple
-
_getComposite
protected ModelLessComposite _getComposite(String name) throws BadItemTypeException
Retrieves the composite with the given name- Parameters:
name- name of the composite to retrieve- Returns:
- the composite
- Throws:
BadItemTypeException- if the value stored in the repository with the given name is not a composite
-
hasValue
public boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
Description copied from interface:ModelLessDataHolderChecks if there is a value for the data at the given path- Specified by:
hasValuein interfaceDataHolder- Specified by:
hasValuein interfaceModelLessDataHolder- Parameters:
dataPath- path of the data- Returns:
trueif there is value (even empty) for the data,falseotherwise- Throws:
IllegalArgumentException- if the given data path is null or emptyBadDataPathCardinalityException- if the value of a part of the data path is multiple. Only the last part can be multiple
-
hasNonEmptyValue
public boolean hasNonEmptyValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
Description copied from interface:ModelLessDataHolderChecks if there is a non empty value for the data at the given path- Specified by:
hasNonEmptyValuein interfaceDataHolder- Specified by:
hasNonEmptyValuein interfaceModelLessDataHolder- Parameters:
dataPath- path of the data- Returns:
trueif there is a non empty value for the data,falseotherwise- Throws:
IllegalArgumentException- if the given data path is null or emptyBadDataPathCardinalityException- if the value of a part of the data path is multiple. Only the last part can be multiple
-
_hasNonEmptyValue
protected static boolean _hasNonEmptyValue(ModelLessDataHolder dataHolder, String dataPath, RepositoryModelItemType dataType) throws IllegalArgumentException, BadDataPathCardinalityException
Checks if there is a non empty value for the data at the given path- Parameters:
dataHolder- the data holderdataPath- path of the datadataType- the type of the data- Returns:
trueif there is a non empty value for the data,falseotherwise- Throws:
IllegalArgumentException- if the given data path is null or emptyBadDataPathCardinalityException- if the value of a part of the data path is multiple. Only the last part can be multiple
-
isMultiple
public boolean isMultiple(String dataPath) throws IllegalArgumentException, UnknownDataException, NotUniqueTypeException, BadDataPathCardinalityException
Description copied from interface:ModelLessDataHolderChecks if the value of the data at the given path is multiple- Specified by:
isMultiplein interfaceModelLessDataHolder- Parameters:
dataPath- path of the data to check- Returns:
trueif the value of the data is multiple,falseotherwise- Throws:
IllegalArgumentException- if the given data path is null or emptyUnknownDataException- the data at the given path does not existNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one)BadDataPathCardinalityException- if the value of a part of the data path is multiple. Only the last part can be multiple
-
getType
public RepositoryModelItemType getType(String dataPath) throws IllegalArgumentException, UnknownTypeException, UnknownDataException, NotUniqueTypeException
Description copied from interface:ModelLessDataHolderRetrieves the type of the data at the given path- Specified by:
getTypein interfaceModelLessDataHolder- Parameters:
dataPath- path of the data- Returns:
- the type of the data
- Throws:
IllegalArgumentException- if the given data path is null or emptyUnknownTypeException- if there is no compatible type with the data at the given data path or if the data is a repeater entry but the composite type is not availableUnknownDataException- if there is no data stored at the given pathNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one)
-
_getType
private RepositoryModelItemType _getType(String dataName) throws UnknownTypeException, UnknownDataException, NotUniqueTypeException
-
_getParentValue
protected static ModelLessDataHolder _getParentValue(ModelLessDataHolder dataHolder, String dataPath) throws BadDataPathCardinalityException, BadItemTypeException
Retrieves the data holder, last parent segment of the given data path Example : call this method with a path like 'my-composite1/my-composite2/my-data' will retrieve the composite 'my-composite2' in the composite 'my-composite1'- Parameters:
dataHolder- the data holderdataPath- the data path- Returns:
- the parent data holder
- Throws:
BadDataPathCardinalityException- if the value of a part of the data path is multiple. Only the last part can be multipleBadItemTypeException- if the value at the given data path is not a composite
-
getDataNames
public Collection<String> getDataNames()
Description copied from interface:DataHolderRetrieves the names of data contained by this data holder Retrieves only the data at first level, does not check composite data- Specified by:
getDataNamesin interfaceDataHolder- Returns:
- the names of all data contained by this data holder
-
dataToSAX
public void dataToSAX(ContentHandler contentHandler, String dataPath, DataContext context) throws SAXException, IOException, UnknownTypeException, NotUniqueTypeException
Description copied from interface:DataHolderGenerates SAX events for the data at the given data path in the currentDataHolderDo not generate any event if there is no values at the given path- Specified by:
dataToSAXin interfaceDataHolder- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventsdataPath- the path of the data to SAXcontext- The context of the data to SAX- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O APIUnknownTypeExceptionNotUniqueTypeException
-
dataToSAX
public void dataToSAX(ContentHandler contentHandler, DataContext context) throws SAXException, IOException, UnknownTypeException, NotUniqueTypeException
Description copied from interface:ModelLessDataHolderGenerates SAX events for data contained in thisDataHolder- Specified by:
dataToSAXin interfaceModelLessDataHolder- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventscontext- The context of the data to SAX- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O APIUnknownTypeException- if there is no compatible type with the saxed valueNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one) with the saxed value
-
getRepositoryData
public RepositoryData getRepositoryData()
Description copied from interface:DataHolderRetrieves the repository data used by thisDataHolder- Specified by:
getRepositoryDatain interfaceDataHolder- Returns:
- the repository data used by this
DataHolder
-
getParentDataHolder
public Optional<? extends ModelLessDataHolder> getParentDataHolder()
Description copied from interface:DataHolderRetrieves the optional parent of the currentDataHolderThere can be no parent if the currentDataHolderis the root- Specified by:
getParentDataHolderin interfaceDataHolder- Specified by:
getParentDataHolderin interfaceModelLessDataHolder- Returns:
- the parent of the current
DataHolder
-
getRootDataHolder
public ModelLessDataHolder getRootDataHolder()
Description copied from interface:DataHolderRetrieves theDataHolderthat is the root of the current one- Specified by:
getRootDataHolderin interfaceDataHolder- Specified by:
getRootDataHolderin interfaceModelLessDataHolder- Returns:
- the root
DataHolder
-
-