public class DocumentModelResolver extends AbstractObjectResolver 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_ONLY
Since 10.2 
 | 
static String | 
STORE_PATH_ONLY
Since 10.2 
 | 
static String | 
STORE_REPO_AND_ID  | 
static String | 
STORE_REPO_AND_PATH  | 
parameters, validationVALIDATION_PARAMETER_KEY| 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. 
 | 
Object | 
fetch(Object value,
     Object context)
Provides the entity referenced by a value, in the given context. 
 | 
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. 
 | 
Serializable | 
getReference(Object entity)
Generates a reference to an entity. 
 | 
protected void | 
resolve(Object value,
       Object context,
       BiConsumer<CoreSession,DocumentRef> resolver)
Resolves the value (in the context) into a session and docRef, and passes them to the resolver. 
 | 
boolean | 
validate(Object value)
Validates some value references an existing entity. 
 | 
boolean | 
validate(Object value,
        Object context)
Validates some value references an existing entity, in the given context 
 | 
checkConfig, getParametersclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetParameterspublic static final String NAME
public static final String PARAM_STORE
public static final String STORE_REPO_AND_PATH
public static final String STORE_PATH_ONLY
public static final String STORE_REPO_AND_ID
public static final String STORE_ID_ONLY
public DocumentModelResolver()
public DocumentModelResolver.MODE getMode()
public List<Class<?>> getManagedClasses()
ObjectResolvergetManagedClasses in interface ObjectResolverpublic void configure(Map<String,String> parameters) throws IllegalStateException
ObjectResolverconfigure in interface ObjectResolverconfigure in class AbstractObjectResolverparameters - 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()
ObjectResolvergetName in interface ObjectResolverpublic boolean validate(Object value)
ObjectResolvervalidate in interface ObjectResolvervalidate in class AbstractObjectResolvervalue - The reference.public boolean validate(Object value, Object context)
ObjectResolvervalidate in interface ObjectResolvervalidate in class AbstractObjectResolvervalue - The reference.context - A resolver-specific context allowing resolution of the value.public Object fetch(Object value)
ObjectResolverfetch in interface ObjectResolvervalue - The reference.public Object fetch(Object value, Object context)
ObjectResolverfetch in interface ObjectResolvervalue - The reference.context - A resolver-specific context allowing resolution of the value.protected void resolve(Object value, Object context, BiConsumer<CoreSession,DocumentRef> resolver)
The resolver is not called if the value cannot be resolved.
public <T> T fetch(Class<T> type, Object value) throws IllegalStateException
ObjectResolverfetch in interface ObjectResolvervalue - The reference.IllegalStateException - If this resolver has not been configured.public Serializable getReference(Object entity) throws IllegalStateException
ObjectResolvergetReference in interface ObjectResolverentity - The entity.IllegalStateException - If this resolver has not been configured.public String getConstraintErrorMessage(Object invalidValue, Locale locale)
ObjectResolvergetConstraintErrorMessage in interface ObjectResolverinvalidValue - The invalid value that don't match any entity.locale - The language in which the message should be generated.Copyright © 2019 Nuxeo. All rights reserved.