public class DocumentModelResolver extends Object implements ObjectResolver
ObjectResolver
allows to manage integrity for fields containing DocumentModel
references (id or
path).
Resolved references must be either a path or an id, default mode is id. Storing path keep link with place in the Document hierarchy no matter which Document is referenced. Storing id track the Document no matter where the Document is stored.
All references, id or path, are prefixed with the document expected repository name. For example :
The fetch(Object)
method returns DocumentModel
. The fetch(Class, Object)
returns
DocumentModel
or specific document adapter.
To use it, put the following code in your schema XSD :
<!-- default resolver is an id based resolver -->
<xs:simpleType name="favoriteDocument1">
<xs:restriction base="xs:string" ref:resolver="documentResolver" />
</xs:simpleType>
<!-- store id -->
<xs:simpleType name="favoriteDocument2">
<xs:restriction base="xs:string" ref:resolver="documentResolver" ref:store="id" />
</xs:simpleType>
<!-- store path -->
<xs:simpleType name="bestDocumentRepositoryPlace">
<xs:restriction base="xs:string" ref:resolver="documentResolver" ref:store="path" />
</xs:simpleType>
Modifier and Type | Class and Description |
---|---|
static class |
DocumentModelResolver.MODE |
protected static class |
DocumentModelResolver.REF |
ObjectResolver.Helper
Modifier and Type | Field and Description |
---|---|
static String |
NAME |
static String |
PARAM_STORE |
static String |
STORE_ID_REF |
static String |
STORE_PATH_REF |
Constructor and Description |
---|
DocumentModelResolver() |
Modifier and Type | Method and Description |
---|---|
void |
configure(Map<String,String> parameters)
Configure this resolver.
|
<T> T |
fetch(Class<T> type,
Object value)
Provides the entity referenced by a value, return the entity as expected type.
|
Object |
fetch(Object value)
Provides the entity referenced by a value.
|
String |
getConstraintErrorMessage(Object invalidValue,
Locale locale)
Provides an error message to display when some invalid value does not match existing entity.
|
List<Class<?>> |
getManagedClasses()
Returns the resolved object types.
|
DocumentModelResolver.MODE |
getMode() |
String |
getName()
Provides this resolver name.
|
Map<String,Serializable> |
getParameters()
Provides this resolver parameters.
|
Serializable |
getReference(Object entity)
Generates a reference to an entity.
|
boolean |
validate(Object value)
Validates some value references an existing entity.
|
public static final String NAME
public static final String PARAM_STORE
public static final String STORE_PATH_REF
public static final String STORE_ID_REF
public DocumentModelResolver()
public DocumentModelResolver.MODE getMode()
public List<Class<?>> getManagedClasses()
ObjectResolver
getManagedClasses
in interface ObjectResolver
public void configure(Map<String,String> parameters) throws IllegalStateException
ObjectResolver
configure
in interface ObjectResolver
parameters
- A map of parameter whose keys are parameter names and map value are corresponding values.IllegalStateException
- If this resolver is already configured.public String getName()
ObjectResolver
getName
in interface ObjectResolver
public Map<String,Serializable> getParameters()
ObjectResolver
getParameters
in interface ObjectResolver
public boolean validate(Object value) throws IllegalStateException
ObjectResolver
validate
in interface ObjectResolver
value
- The reference.IllegalStateException
- If this resolver has not been configured.public Object fetch(Object value) throws IllegalStateException
ObjectResolver
fetch
in interface ObjectResolver
value
- The reference.IllegalStateException
- If this resolver has not been configured.public <T> T fetch(Class<T> type, Object value) throws IllegalStateException
ObjectResolver
fetch
in interface ObjectResolver
value
- The reference.IllegalStateException
- If this resolver has not been configured.public Serializable getReference(Object entity) throws IllegalStateException
ObjectResolver
getReference
in interface ObjectResolver
entity
- The entity.IllegalStateException
- If this resolver has not been configured.public String getConstraintErrorMessage(Object invalidValue, Locale locale)
ObjectResolver
getConstraintErrorMessage
in interface ObjectResolver
invalidValue
- The invalid value that don't match any entity.locale
- The language in which the message should be generated.Copyright © 2018 Nuxeo. All rights reserved.