public void setEntity(Object entity, Type entityType) { this.originalEntity = this.entity = entity; this.entityType = entityType; if (this.entity instanceof GenericEntity) { final GenericEntity ge = (GenericEntity) this.entity; this.entity = ge.getEntity(); this.entityType = ge.getType(); } }
public void setEntity(Object entity) { if (entity == null) { this.entity = null; this.genericType = null; this.entityClass = null; } else if (entity instanceof GenericEntity) { GenericEntity ge = (GenericEntity) entity; this.entity = ge.getEntity(); this.genericType = ge.getType(); this.entityClass = ge.getRawType(); } else { this.entity = entity; this.entityClass = entity.getClass(); this.genericType = null; } }
protected MediaType resolveContentTypeByAccept(List<MediaType> accepts, Object entity) { if (accepts == null || accepts.size() == 0 || entity == null) { return MediaType.WILDCARD_TYPE; } Class clazz = entity.getClass(); Type type = null; if (entity instanceof GenericEntity) { GenericEntity gen = (GenericEntity) entity; clazz = gen.getRawType(); type = gen.getType(); } for (MediaType accept : accepts) { if (providerFactory.getMessageBodyWriter(clazz, type, null, accept) != null) { return accept; } } return MediaType.WILDCARD_TYPE; }
/** * To handle generic case where user do not know the type, here we will be looking for a type and * then generate EntityResource<E> * * @param entity * @return EntityResource<E> */ public static <E> EntityResource<E> createEntityResource(E entity) { GenericEntity<E> ge = new GenericEntity<E>(entity) {}; Type t = com.temenos.interaction.core.command.CommandHelper.getEffectiveGenericType( ge.getType(), entity); if (ResourceTypeHelper.isType(ge.getRawType(), t, OEntity.class, OEntity.class)) { OEntity te = (OEntity) entity; String entityName = te != null && te.getEntityType() != null ? te.getEntityType().getName() : null; return com.temenos.interaction.core.command.CommandHelper.createEntityResource( entityName, entity, OEntity.class); } else if (ResourceTypeHelper.isType(ge.getRawType(), t, Entity.class, Entity.class)) { Entity te = (Entity) entity; String entityName = te != null ? te.getName() : null; return com.temenos.interaction.core.command.CommandHelper.createEntityResource( entityName, entity, Entity.class); } else { // Call the generic and lets see what happens return com.temenos.interaction.core.command.CommandHelper.createEntityResource(entity, null); } }