public class EntityDictionary extends Object
Include.type()
Modifier and Type | Field and Description |
---|---|
protected CopyOnWriteArrayList<Class<?>> |
bindEntityRoots |
protected ConcurrentHashMap<String,Class<?>> |
bindJsonApiToEntity |
protected com.google.common.collect.BiMap<String,Class<? extends Check>> |
checkNames |
protected ConcurrentHashMap<Class<?>,EntityBinding> |
entityBindings |
protected Injector |
injector |
protected ConcurrentHashMap<Class<?>,List<Class<?>>> |
subclassingEntities |
Constructor and Description |
---|
EntityDictionary(Map<String,Class<? extends Check>> checks)
Instantiate a new EntityDictionary with the provided set of checks.
|
EntityDictionary(Map<String,Class<? extends Check>> checks,
Injector injector)
Instantiate a new EntityDictionary with the provided set of checks and an injection function.
|
Modifier and Type | Method and Description |
---|---|
void |
bindEntity(Class<?> cls)
Add given Entity bean to dictionary.
|
<T> void |
bindInitializer(Initializer<T> initializer,
Class<T> cls)
Bind a particular initializer to a class.
|
void |
bindTrigger(Class<?> entityClass,
Class<? extends Annotation> annotationClass,
LifeCycleHook callback)
Binds a lifecycle hook to a particular entity class.
|
void |
bindTrigger(Class<?> entityClass,
Class<? extends Annotation> annotationClass,
LifeCycleHook callback,
boolean allowMultipleInvocations)
Binds a lifecycle hook to a particular entity class.
|
void |
bindTrigger(Class<?> entityClass,
Class<? extends Annotation> annotationClass,
String fieldOrMethodName,
LifeCycleHook callback)
Binds a lifecycle hook to a particular field or method in an entity.
|
boolean |
cascadeDeletes(Class<?> targetClass,
String fieldName)
Returns true if the relationship cascades deletes and false otherwise.
|
boolean |
entityHasChecksForPermission(Class<?> resourceClass,
Class<? extends Annotation> annotationClass)
Determine if a given (entity class, permission) pair have any permissions defined.
|
static Method |
findMethod(Class<?> entityClass,
String name,
Class<?>... paramClass)
Find an arbitrary method.
|
AccessibleObject |
getAccessibleObject(Class<?> targetClass,
String fieldName)
Retrieve the accessible object for a field.
|
AccessibleObject |
getAccessibleObject(Object target,
String fieldName)
Retrieve the accessible object for a field from a target object.
|
javax.persistence.AccessType |
getAccessType(Class<?> entityClass)
Returns whether the entire entity uses Field or Property level access.
|
List<String> |
getAllFields(Class<?> entityClass)
Get a list of all fields including both relationships and attributes.
|
List<String> |
getAllFields(Object entity)
Get a list of all fields including both relationships and attributes.
|
<A extends Annotation> |
getAnnotation(Class<?> recordClass,
Class<A> annotationClass)
Return annotation from class, parents or package.
|
<A extends Annotation> |
getAnnotation(PersistentResource record,
Class<A> annotationClass)
Return annotation from class, parents or package.
|
<A extends Annotation> |
getAttributeOrRelationAnnotation(Class<?> entityClass,
Class<A> annotationClass,
String identifier)
Return a single annotation from field or accessor method.
|
<A extends Annotation> |
getAttributeOrRelationAnnotations(Class<?> entityClass,
Class<A> annotationClass,
String identifier)
Return multiple annotations from field or accessor method.
|
List<String> |
getAttributes(Class<?> entityClass)
Get the list of attribute names for an entity.
|
List<String> |
getAttributes(Object entity)
Get the list of attribute names for an entity.
|
Set<Class<?>> |
getBindings()
Get all bindings.
|
Class<? extends Check> |
getCheck(String checkIdentifier)
Returns the check mapped to a particular identifier.
|
String |
getCheckIdentifier(Class<? extends Check> checkClass)
Returns the friendly named mapped to this given check.
|
Map<String,Class<? extends Check>> |
getCheckMappings()
Get the check mappings.
|
List<String> |
getElideBoundRelationships(Class<?> entityClass)
Get a list of elide-bound relationships.
|
List<String> |
getElideBoundRelationships(Object entity)
Get a list of elide-bound relationships.
|
protected EntityBinding |
getEntityBinding(Class<?> entityClass) |
Class<?> |
getEntityClass(String entityName)
Returns the binding class for a given entity name.
|
String |
getEntityFor(Class<?> entityClass)
Returns the Entity name for a given binding class.
|
Set<String> |
getFieldsOfType(Class<?> targetClass,
Class<?> targetType)
Retrieve fields from an object containing a particular type.
|
static Annotation |
getFirstAnnotation(Class<?> entityClass,
List<Class<? extends Annotation>> annotationClassList)
Return first matching annotation from class, parents or package.
|
String |
getId(Object value)
Gets id.
|
Collection<Annotation> |
getIdAnnotations(Object value)
Returns annotations applied to the ID field.
|
String |
getIdFieldName(Class<?> entityClass)
Returns the name of the id field.
|
Class<?> |
getIdType(Class<?> entityClass)
Returns type of id field.
|
String |
getJsonAliasFor(Class<?> entityClass)
Returns the Include name for a given binding class.
|
String |
getNameFromAlias(Class<?> entityClass,
String alias)
Get the true field/method name from an alias.
|
String |
getNameFromAlias(Object entity,
String alias)
Get the true field/method name from an alias.
|
Class<?> |
getParameterizedType(Class<?> entityClass,
String identifier)
Retrieve the parameterized type for the given field.
|
Class<?> |
getParameterizedType(Class<?> entityClass,
String identifier,
int paramIndex)
Retrieve the parameterized type for the given field.
|
Class<?> |
getParameterizedType(Object entity,
String identifier)
Retrieve the parameterized type for the given field.
|
Class<?> |
getParameterizedType(Object entity,
String identifier,
int paramIndex)
Retrieve the parameterized type for the given field.
|
org.antlr.v4.runtime.tree.ParseTree |
getPermissionsForClass(Class<?> resourceClass,
Class<? extends Annotation> annotationClass)
Gets the specified permission definition (if any) at the class level.
|
org.antlr.v4.runtime.tree.ParseTree |
getPermissionsForField(Class<?> resourceClass,
String field,
Class<? extends Annotation> annotationClass)
Gets the specified permission definition (if any) at the class level.
|
String |
getRelationInverse(Class<?> cls,
String relation)
If a relationship is bidirectional, returns the name of the peer relationship in the peer entity.
|
List<String> |
getRelationships(Class<?> entityClass)
Get the list of relationship names for an entity.
|
List<String> |
getRelationships(Object entity)
Get the list of relationship names for an entity.
|
RelationshipType |
getRelationshipType(Class<?> cls,
String relation)
Get the type of relationship from a relation.
|
RelationshipType |
getRelationshipType(Object entity,
String relation)
Get the type of relationship from a relation.
|
static String |
getSimpleName(Class<?> cls)
Cache the simple name of the provided class.
|
List<Class<?>> |
getSubclassingEntities(Class entityClass)
Get a list of inherited entities from a particular entity.
|
List<Class<?>> |
getSubclassingEntities(String entityName)
Get a list of inherited entities from a particular entity.
|
List<String> |
getSubclassingEntityNames(Class entityClass)
Get inherited entity names for a particular entity.
|
List<String> |
getSubclassingEntityNames(String entityName)
Get inherited entity names for a particular entity.
|
List<Class<?>> |
getSuperClassEntities(Class entityClass)
Fetch all entity classes that provided entity inherits from (i.e.
|
List<Class<?>> |
getSuperClassEntities(String entityName)
Fetch all entity classes that the provided entity inherits from (i.e.
|
List<String> |
getSuperClassEntityNames(Class entityClass)
Fetch all entity names that the provided entity inherits from (i.e.
|
List<String> |
getSuperClassEntityNames(String entityName)
Fetch all entity names that the provided entity inherits from (i.e.
|
<A extends Annotation> |
getTriggers(Class<?> cls,
Class<A> annotationClass) |
<A extends Annotation> |
getTriggers(Class<?> cls,
Class<A> annotationClass,
String fieldName) |
Class<?> |
getType(Class<?> entityClass,
String identifier)
Get a type for a field on an entity.
|
Class<?> |
getType(Object entity,
String identifier)
Get a type for a field on an entity.
|
boolean |
hasBinding(Class<?> cls)
Returns whether or not a class is already bound.
|
<T> void |
initializeEntity(T entity)
Initialize an entity.
|
boolean |
isAttribute(Class<?> entityClass,
String attributeName) |
boolean |
isComputed(Class<?> entityClass,
String fieldName) |
boolean |
isMappedInterface(Class<?> interfaceClass) |
boolean |
isMethodRequestScopeable(Class<?> entityClass,
Method method)
Determine whether or not a method is request scopeable.
|
boolean |
isMethodRequestScopeable(Object entity,
Method method)
Determine whether or not a method is request scopeable.
|
boolean |
isRelation(Class<?> entityClass,
String relationName) |
boolean |
isRoot(Class<?> entityClass)
Is root.
|
boolean |
isShareable(Class<?> entityClass)
Returns whether or not an entity is shareable.
|
Class<?> |
lookupEntityClass(Class<?> objClass)
Follow for this class or super-class for Entity annotation.
|
<T> List<T> |
walkEntityGraph(Set<Class<?>> entities,
Function<Class<?>,T> transform)
Walks the entity graph and performs a transform function on each element.
|
protected final ConcurrentHashMap<String,Class<?>> bindJsonApiToEntity
protected final ConcurrentHashMap<Class<?>,EntityBinding> entityBindings
protected final CopyOnWriteArrayList<Class<?>> bindEntityRoots
protected final ConcurrentHashMap<Class<?>,List<Class<?>>> subclassingEntities
protected final com.google.common.collect.BiMap<String,Class<? extends Check>> checkNames
protected final Injector injector
public EntityDictionary(Map<String,Class<? extends Check>> checks)
com.yahoo.elide.security.checks.prefab
are mapped to Prefab.CONTAINER.CHECK
(e.g. @ReadPermission(expression="Prefab.Role.All")
or @ReadPermission(expression="Prefab.Common.UpdateOnCreate")
)checks
- a map that links the identifiers used in the permission expression strings
to their implementing classespublic EntityDictionary(Map<String,Class<? extends Check>> checks, Injector injector)
com.yahoo.elide.security.checks.prefab
are mapped
to Prefab.CONTAINER.CHECK
* (e.g. @ReadPermission(expression="Prefab.Role.All")
or @ReadPermission(expression="Prefab.Common.UpdateOnCreate")
)checks
- a map that links the identifiers used in the permission expression strings
to their implementing classesinjector
- a function typically associated with a dependency injection framework that will
initialize Elide models.public static String getSimpleName(Class<?> cls)
cls
- the Class
object to be checkedpublic static Method findMethod(Class<?> entityClass, String name, Class<?>... paramClass) throws NoSuchMethodException
entityClass
- the entity classname
- the nameparamClass
- the param classNoSuchMethodException
- the no such method exceptionprotected EntityBinding getEntityBinding(Class<?> entityClass)
public boolean isMappedInterface(Class<?> interfaceClass)
public Class<?> getEntityClass(String entityName)
entityName
- entity namepublic String getJsonAliasFor(Class<?> entityClass)
entityClass
- the entity classInclude
public String getEntityFor(Class<?> entityClass)
entityClass
- the entity classEntity
public boolean entityHasChecksForPermission(Class<?> resourceClass, Class<? extends Annotation> annotationClass)
resourceClass
- the entity classannotationClass
- the permission annotationtrue
if that permission is defined anywhere within the classpublic org.antlr.v4.runtime.tree.ParseTree getPermissionsForClass(Class<?> resourceClass, Class<? extends Annotation> annotationClass)
resourceClass
- the entity to checkannotationClass
- the permission to look forParseTree
expressing the permissions, if one exists
or null
if the permission is not specified at a class levelpublic org.antlr.v4.runtime.tree.ParseTree getPermissionsForField(Class<?> resourceClass, String field, Class<? extends Annotation> annotationClass)
resourceClass
- the entity to checkfield
- the field to inspectannotationClass
- the permission to look forParseTree
expressing the permissions, if one exists
or null
if the permission is not specified on that fieldpublic Class<? extends Check> getCheck(String checkIdentifier)
checkIdentifier
- the name from the expression stringCheck
mapped to the identifier or null
if the given identifer is unmappedpublic List<String> getSubclassingEntityNames(String entityName)
entityName
- Json alias name for entitypublic List<String> getSubclassingEntityNames(Class entityClass)
entityClass
- Entity classpublic List<Class<?>> getSubclassingEntities(String entityName)
entityName
- Json alias name for entitypublic List<Class<?>> getSubclassingEntities(Class entityClass)
entityClass
- Entity classpublic List<String> getSuperClassEntityNames(String entityName)
entityName
- Json alias name for entitypublic List<String> getSuperClassEntityNames(Class entityClass)
entityClass
- Entity classpublic List<Class<?>> getSuperClassEntities(String entityName)
entityName
- Json alias name for entitypublic List<Class<?>> getSuperClassEntities(Class entityClass)
entityClass
- Entity classpublic String getCheckIdentifier(Class<? extends Check> checkClass)
checkClass
- The class to lookuppublic String getIdFieldName(Class<?> entityClass)
entityClass
- Entity classpublic javax.persistence.AccessType getAccessType(Class<?> entityClass)
entityClass
- Entity Classpublic Map<String,Class<? extends Check>> getCheckMappings()
public List<String> getAttributes(Class<?> entityClass)
entityClass
- entity namepublic List<String> getAttributes(Object entity)
entity
- entity instancepublic List<String> getRelationships(Class<?> entityClass)
entityClass
- entity namepublic List<String> getRelationships(Object entity)
entity
- entity instancepublic List<String> getElideBoundRelationships(Class<?> entityClass)
entityClass
- Entity class to find relationships forpublic List<String> getElideBoundRelationships(Object entity)
entity
- Entity instance to find relationships forpublic boolean isMethodRequestScopeable(Object entity, Method method)
entity
- Entity instancemethod
- Method on entity to checkpublic boolean isMethodRequestScopeable(Class<?> entityClass, Method method)
entityClass
- Entity to checkmethod
- Method on entity to checkpublic List<String> getAllFields(Class<?> entityClass)
entityClass
- entity namepublic List<String> getAllFields(Object entity)
entity
- entitypublic RelationshipType getRelationshipType(Class<?> cls, String relation)
cls
- Entity classrelation
- Name of relationship fieldpublic String getRelationInverse(Class<?> cls, String relation)
cls
- the clsrelation
- the relationpublic RelationshipType getRelationshipType(Object entity, String relation)
entity
- Entity instancerelation
- Name of relationship fieldpublic Class<?> getType(Class<?> entityClass, String identifier)
entityClass
- Entity classidentifier
- Field to lookup typepublic Class<?> getType(Object entity, String identifier)
entity
- Entity instanceidentifier
- Field to lookup typepublic Class<?> getParameterizedType(Class<?> entityClass, String identifier)
entityClass
- the entity classidentifier
- the identifierpublic Class<?> getParameterizedType(Class<?> entityClass, String identifier, int paramIndex)
entityClass
- the entity classidentifier
- the identifierparamIndex
- the index of the parameterizationpublic Class<?> getParameterizedType(Object entity, String identifier)
entity
- Entity instanceidentifier
- Field to lookuppublic Class<?> getParameterizedType(Object entity, String identifier, int paramIndex)
entity
- Entity instanceidentifier
- Field to lookupparamIndex
- the index of the parameterizationpublic String getNameFromAlias(Class<?> entityClass, String alias)
entityClass
- Entity namealias
- Alias to convertpublic String getNameFromAlias(Object entity, String alias)
entity
- Entity instancealias
- Alias to convertpublic <T> void initializeEntity(T entity)
T
- the type parameterentity
- Entity to initializepublic <T> void bindInitializer(Initializer<T> initializer, Class<T> cls)
T
- the type parameterinitializer
- Initializer to use for classcls
- Class to bind initializationpublic boolean isShareable(Class<?> entityClass)
entityClass
- the entity type to check for the shareable permissionspublic void bindEntity(Class<?> cls)
cls
- Entity bean classpublic <A extends Annotation> A getAnnotation(PersistentResource record, Class<A> annotationClass)
A
- genericClassrecord
- the recordannotationClass
- the annotation classpublic <A extends Annotation> A getAnnotation(Class<?> recordClass, Class<A> annotationClass)
A
- genericClassrecordClass
- the record classannotationClass
- the annotation classpublic <A extends Annotation> Collection<LifeCycleHook> getTriggers(Class<?> cls, Class<A> annotationClass, String fieldName)
public <A extends Annotation> Collection<LifeCycleHook> getTriggers(Class<?> cls, Class<A> annotationClass)
public <A extends Annotation> A getAttributeOrRelationAnnotation(Class<?> entityClass, Class<A> annotationClass, String identifier)
A
- genericClassentityClass
- the entity classannotationClass
- given annotation typeidentifier
- the identifierpublic <A extends Annotation> A[] getAttributeOrRelationAnnotations(Class<?> entityClass, Class<A> annotationClass, String identifier)
A
- the type parameterentityClass
- the entity classannotationClass
- given annotation typeidentifier
- the identifierpublic static Annotation getFirstAnnotation(Class<?> entityClass, List<Class<? extends Annotation>> annotationClassList)
entityClass
- Entity class typeannotationClassList
- List of sought annotationspublic boolean isRoot(Class<?> entityClass)
entityClass
- the entity classpublic Class<?> getIdType(Class<?> entityClass)
entityClass
- the entity classpublic Collection<Annotation> getIdAnnotations(Object value)
value
- the valuepublic Class<?> lookupEntityClass(Class<?> objClass)
objClass
- provided classpublic AccessibleObject getAccessibleObject(Object target, String fieldName)
target
- the object to getfieldName
- the field name to get or invoke equivalent get methodpublic AccessibleObject getAccessibleObject(Class<?> targetClass, String fieldName)
targetClass
- the object to getfieldName
- the field name to get or invoke equivalent get methodpublic Set<String> getFieldsOfType(Class<?> targetClass, Class<?> targetType)
targetClass
- Class to search for fieldstargetType
- Type of fields to findpublic void bindTrigger(Class<?> entityClass, Class<? extends Annotation> annotationClass, String fieldOrMethodName, LifeCycleHook callback)
entityClass
- The entity that triggers the lifecycle hook.annotationClass
- (OnReadPostCommit, OnUpdatePreSecurity, etc)fieldOrMethodName
- The name of the field or methodcallback
- The callback function to invoke.public void bindTrigger(Class<?> entityClass, Class<? extends Annotation> annotationClass, LifeCycleHook callback, boolean allowMultipleInvocations)
allowMultipleInvocations
flag.entityClass
- The entity that triggers the lifecycle hook.annotationClass
- (OnReadPostCommit, OnUpdatePreSecurity, etc)callback
- The callback function to invoke.allowMultipleInvocations
- Should the same life cycle hook be invoked multiple times for multiple
CRUD actions on the same model.public void bindTrigger(Class<?> entityClass, Class<? extends Annotation> annotationClass, LifeCycleHook callback)
entityClass
- The entity that triggers the lifecycle hook.annotationClass
- (OnReadPostCommit, OnUpdatePreSecurity, etc)callback
- The callback function to invoke.public boolean cascadeDeletes(Class<?> targetClass, String fieldName)
targetClass
- The class which owns the relationship.fieldName
- The relationshippublic <T> List<T> walkEntityGraph(Set<Class<?>> entities, Function<Class<?>,T> transform)
T
- The result type.entities
- The roots of the entity graph.transform
- The function to transform each entity class into a result.public boolean hasBinding(Class<?> cls)
cls
- Copyright © 2015–2019 Yahoo! Inc.. All rights reserved.