Class DefaultModelLessDataHolder
java.lang.Object
org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder
- All Implemented Interfaces:
DataHolder
,ModelLessDataHolder
- Direct Known Subclasses:
DefaultModifiableModelLessDataHolder
Default implementation for data holder without model
-
Field Summary
Modifier and TypeFieldDescriptionprotected Optional<? extends ModelLessDataHolder>
Parent of the currentDataHolder
protected RepositoryData
Repository data to use to store data in the repositoryprotected ModelLessDataHolder
RootDataHolder
protected ModelItemTypeExtensionPoint
Extension point to use to get available element types -
Constructor Summary
ConstructorDescriptionDefaultModelLessDataHolder
(ModelItemTypeExtensionPoint typeExtensionPoint, RepositoryData repositoryData) Creates a default model free data holderDefaultModelLessDataHolder
(ModelItemTypeExtensionPoint typeExtensionPoint, RepositoryData repositoryData, Optional<? extends ModelLessDataHolder> parent, Optional<? extends ModelLessDataHolder> root) Creates a default model free data holder -
Method Summary
Modifier and TypeMethodDescriptionprotected 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'dataToJSON
(String dataPath, DataContext context) Convert the data at the given path into a JSON objectdataToJSON
(DataContext context) Convert the data contained in thisDataHolder
void
dataToSAX
(ContentHandler contentHandler, String dataPath, DataContext context) Generates SAX events for the data at the given data path in the currentDataHolder
Do not generate any event if there is no values at the given pathvoid
dataToSAX
(ContentHandler contentHandler, DataContext context) Generates SAX events for data contained in thisDataHolder
getComposite
(String compositePath) Retrieves the composite at the given pathRetrieves the names of data contained by this data holder Retrieves only the data at first level, does not check composite dataProvide the ModelItemTypeExtensionPoint linked with the DataHolderOptional<? extends ModelLessDataHolder>
Retrieves the optional parent of the currentDataHolder
There can be no parent if the currentDataHolder
is the rootRetrieves the repository data used by thisDataHolder
Retrieves theDataHolder
that is the root of the current oneRetrieves the type of the data at the given path<T> T
Retrieves the value of the data at the given path The type of the value will be deduced from the stored data.<T> T
Retrieves the value of the data at the given path if exists and is not empty, or the default value<T> T
getValueOfType
(String dataPath, String dataTypeId) Retrieves the value of the data at the given path<T> T
getValueOfType
(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 valueboolean
Checks if there is a non empty value for the data at the given pathboolean
Checks if there is a non empty value for the data at the given pathboolean
hasValueOrEmpty
(String dataPath) Checks if there is a value, even empty, for the data at the given pathboolean
isMultiple
(String dataPath) Checks if the value of the data at the given path is multipleboolean
isMultiple
(String dataPath, String dataTypeId) Checks if the value of the data at the given path is multipleMethods 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, dataToJSON, dataToSAX
Methods inherited from interface org.ametys.plugins.repository.data.holder.ModelLessDataHolder
dataToJSON, dataToSAX
-
Field Details
-
_typeExtensionPoint
Extension point to use to get available element types -
_repositoryData
Repository data to use to store data in the repository -
_parent
Parent of the currentDataHolder
-
_root
RootDataHolder
-
-
Constructor Details
-
DefaultModelLessDataHolder
public DefaultModelLessDataHolder(ModelItemTypeExtensionPoint 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(ModelItemTypeExtensionPoint 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 createdDataHolder
is the rootDataHolder
root
- the rootDataHolder
repositoryData
- the repository data to use
-
-
Method Details
-
getComposite
public ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Retrieves the composite at the given path- Specified by:
getComposite
in interfaceDataHolder
- Specified by:
getComposite
in interfaceModelLessDataHolder
- Parameters:
compositePath
- path of the composite to retrieve- Returns:
- the composite or
null
if 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 compositeBadDataPathCardinalityException
- if the value of a part of the data path is multiple. Only the last part can be multiple
-
getValue
public <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadItemTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Retrieves 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:
getValue
in 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
null
if 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)BadItemTypeException
- if value at the sub data path of the given one is not a compositeBadDataPathCardinalityException
- if the value of a part of the data path is multiple. Only the last part can be multiple
-
getValue
public <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadItemTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Retrieves the value of the data at the given path if exists and is not empty, or the default value- Specified by:
getValue
in 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,
null
if 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)BadItemTypeException
- if value at the sub data path of the given one is not a compositeBadDataPathCardinalityException
- if the value of a part of the data path is multiple. Only the last part can be multiple
-
getValueOfType
public <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Retrieves the value of the data at the given path if exists and is not empty, or the default value- Specified by:
getValueOfType
in 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,
null
if the data exists but is empty, or the given default value - 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
-
getValueOfType
public <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Retrieves the value of the data at the given path- Specified by:
getValueOfType
in 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
null
if 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
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:ModelLessDataHolder
Checks if there is a non empty value for the data at the given path- Specified by:
hasValue
in interfaceDataHolder
- Specified by:
hasValue
in interfaceModelLessDataHolder
- Parameters:
dataPath
- path of the data- Returns:
true
if there is a non empty value for the data,false
otherwise- 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
-
hasValue
public boolean hasValue(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Checks if there is a non empty value for the data at the given path- Specified by:
hasValue
in interfaceModelLessDataHolder
- Parameters:
dataPath
- path of the datadataTypeId
- type identifier of the data- Returns:
true
if there is a non empty value for the data,false
otherwise- 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 pointBadDataPathCardinalityException
- if the value of a part of the data path is multiple. Only the last part can be multiple
-
hasValueOrEmpty
public boolean hasValueOrEmpty(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Checks if there is a value, even empty, for the data at the given path- Specified by:
hasValueOrEmpty
in interfaceDataHolder
- Specified by:
hasValueOrEmpty
in interfaceModelLessDataHolder
- Parameters:
dataPath
- path of the data- Returns:
true
if there is value, even empty, for the data,false
otherwise- 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, UnknownTypeException, NotUniqueTypeException, BadItemTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Checks if the value of the data at the given path is multiple- Specified by:
isMultiple
in interfaceModelLessDataHolder
- Parameters:
dataPath
- path of the data to check- Returns:
true
if the value of the data is multiple,false
otherwise- Throws:
IllegalArgumentException
- if the given data path is null or emptyUnknownDataException
- the data at the given path does not existUnknownTypeException
- 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)BadItemTypeException
- if value at the sub data path of the given one is not a compositeBadDataPathCardinalityException
- 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, String dataTypeId) throws IllegalArgumentException, UnknownDataException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Checks if the value of the data at the given path is multiple- Specified by:
isMultiple
in interfaceModelLessDataHolder
- Parameters:
dataPath
- path of the data to checkdataTypeId
- type identifier of the data- Returns:
true
if the value of the data is multiple,false
otherwise- Throws:
IllegalArgumentException
- if the given data path is null or emptyUnknownDataException
- the data at the given path does not existUnknownTypeException
- if there is no compatible type with the data at the given data pathBadItemTypeException
- if value at the sub data path of the given one is not a compositeBadDataPathCardinalityException
- 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, UnknownDataException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException Description copied from interface:ModelLessDataHolder
Retrieves the type of the data at the given path- Specified by:
getType
in interfaceModelLessDataHolder
- Parameters:
dataPath
- path of the data- Returns:
- the type of the data
- Throws:
IllegalArgumentException
- if the given data path is null or emptyUnknownDataException
- if there is no data stored at the given pathUnknownTypeException
- 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 availableNotUniqueTypeException
- 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
-
_getParentValue
protected static ModelLessDataHolder _getParentValue(ModelLessDataHolder dataHolder, String dataPath) throws BadItemTypeException, BadDataPathCardinalityException 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:
BadItemTypeException
- if the value at the given data path is not a compositeBadDataPathCardinalityException
- if the value of a part of the data path is multiple. Only the last part can be multiple
-
getDataNames
Description copied from interface:DataHolder
Retrieves the names of data contained by this data holder Retrieves only the data at first level, does not check composite data- Specified by:
getDataNames
in interfaceDataHolder
- Returns:
- the names of all data contained by this data holder
-
dataToSAX
public void dataToSAX(ContentHandler contentHandler, String dataPath, DataContext context) throws SAXException, UnknownTypeException, NotUniqueTypeException Description copied from interface:DataHolder
Generates SAX events for the data at the given data path in the currentDataHolder
Do not generate any event if there is no values at the given path- Specified by:
dataToSAX
in interfaceDataHolder
- Parameters:
contentHandler
- theContentHandler
that 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 generationUnknownTypeException
NotUniqueTypeException
-
dataToSAX
public void dataToSAX(ContentHandler contentHandler, DataContext context) throws SAXException, UnknownTypeException, NotUniqueTypeException Description copied from interface:ModelLessDataHolder
Generates SAX events for data contained in thisDataHolder
- Specified by:
dataToSAX
in interfaceModelLessDataHolder
- Parameters:
contentHandler
- theContentHandler
that will receive the SAX eventscontext
- The context of the data to SAX- Throws:
SAXException
- if an error occurs during the SAX events generationUnknownTypeException
- 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
-
dataToJSON
public Object dataToJSON(String dataPath, DataContext context) throws UnknownTypeException, NotUniqueTypeException Description copied from interface:DataHolder
Convert the data at the given path into a JSON object- Specified by:
dataToJSON
in interfaceDataHolder
- Parameters:
dataPath
- the path of the data to convertcontext
- The context of the data to convert- Returns:
- The value as JSON
- Throws:
UnknownTypeException
NotUniqueTypeException
-
dataToJSON
public Map<String,Object> dataToJSON(DataContext context) throws UnknownTypeException, NotUniqueTypeException Description copied from interface:ModelLessDataHolder
Convert the data contained in thisDataHolder
- Specified by:
dataToJSON
in interfaceModelLessDataHolder
- Parameters:
context
- The context of the data to convert- Returns:
- The data of the current
DataHolder
as JSON - Throws:
UnknownTypeException
- if there is no compatible type with the value to convertNotUniqueTypeException
- if there are many compatible types (there is no way to determine which type is the good one) with the value to convert
-
getRepositoryData
Description copied from interface:DataHolder
Retrieves the repository data used by thisDataHolder
- Specified by:
getRepositoryData
in interfaceDataHolder
- Returns:
- the repository data used by this
DataHolder
-
getParentDataHolder
Description copied from interface:DataHolder
Retrieves the optional parent of the currentDataHolder
There can be no parent if the currentDataHolder
is the root- Specified by:
getParentDataHolder
in interfaceDataHolder
- Specified by:
getParentDataHolder
in interfaceModelLessDataHolder
- Returns:
- the parent of the current
DataHolder
-
getRootDataHolder
Description copied from interface:DataHolder
Retrieves theDataHolder
that is the root of the current one- Specified by:
getRootDataHolder
in interfaceDataHolder
- Specified by:
getRootDataHolder
in interfaceModelLessDataHolder
- Returns:
- the root
DataHolder
-
getModelItemTypeExtensionPoint
Description copied from interface:ModelLessDataHolder
Provide the ModelItemTypeExtensionPoint linked with the DataHolder- Specified by:
getModelItemTypeExtensionPoint
in interfaceModelLessDataHolder
- Returns:
- the extension point
-