@Override public boolean accept(Type type, Class<? extends MetaElement> metaClass) { boolean hasAnnotation = ClassUtils.getRawType(type).getAnnotation(MappedSuperclass.class) != null; boolean hasType = metaClass == MetaElement.class || metaClass == MetaMappedSuperclass.class || metaClass == MetaJpaDataObject.class; return hasAnnotation && hasType; }
private MetaInformation newMetaInformation() { if (listMetaClass != null) { return ClassUtils.newInstance(listMetaClass); } else { return null; } }
private Method getGetter(Class<?> beanClass, String fieldName) throws NoSuchMethodException { Method getter = ClassUtils.findGetter(beanClass, fieldName); if(getter != null){ return getter; }else{ throw new RepositoryMethodException(String.format("Unable to find accessor method for %s.%s",beanClass.getName(),fieldName)); } }
@Override public boolean accept(Class<?> repositoryClass) { boolean legacyRepo = ResourceRepository.class.isAssignableFrom(repositoryClass); boolean interfaceRepo = ResourceRepositoryV2.class.isAssignableFrom(repositoryClass); boolean anontationRepo = ClassUtils.getAnnotation(repositoryClass, JsonApiResourceRepository.class).isPresent(); return legacyRepo || interfaceRepo || anontationRepo; }
private void initAccessors() { if (field == null || readMethod == null) { MetaDataObject parent = getParent(); Class<?> beanClass = parent.getImplementationClass(); String name = getName(); this.field = ClassUtils.findClassField(beanClass, name); this.readMethod = ClassUtils.findGetter(beanClass, name); PreconditionUtil.assertFalse("no getter or field found ", field == null && readMethod == null); Class<?> rawType = field != null ? field.getType() : readMethod.getReturnType(); writeMethod = ClassUtils.findSetter(beanClass, name, rawType); } }
private void assignMetaMethod() { if (metaMethod == null) { metaMethod = ClassUtils.findMethodWith(implementationClass, JsonApiMeta.class); } }
private Method getSetter(Object bean, String fieldName, Class<?> fieldType) throws NoSuchMethodException { Class<? extends Object> beanClass = bean.getClass(); Method setter = ClassUtils.findSetter(beanClass, fieldName, fieldType); if(setter != null){ return setter; }else{ throw new RepositoryMethodException(String.format("Unable to find accessor method for %s.%s",beanClass.getName(),fieldName)); } } }
private List<AnnotatedResourceField> getResourceFields(Class<?> resourceClass) { List<Field> classFields = ClassUtils.getClassFields(resourceClass); List<Method> classGetters = ClassUtils.getClassGetters(resourceClass); List<ResourceFieldWrapper> resourceClassFields = getFieldResourceFields(classFields); List<ResourceFieldWrapper> resourceGetterFields = getGetterResourceFields(classGetters); return getResourceFields(resourceClassFields, resourceGetterFields); }
private Field findField(Class<?> beanClass, String fieldName) { List<Field> classFields = ClassUtils.getClassFields(beanClass); for (Field field : classFields) { if (field.getName().equals(fieldName)) { return field; } } return null; }
private Method findGetter(Class<?> beanClass, String fieldName) { List<Method> classGetters = ClassUtils.getClassGetters(beanClass); for (Method getter : classGetters) { String getterFieldName = getGetterFieldName(getter); if (getterFieldName.equals(fieldName)) { return getter; } } return null; }
@Override public boolean accept(Class<?> repositoryClass) { return RelationshipRepository.class.isAssignableFrom(repositoryClass) || RelationshipRepositoryV2.class.isAssignableFrom(repositoryClass) || ClassUtils.getAnnotation(repositoryClass, JsonApiRelationshipRepository.class).isPresent(); }
private void assignLinksMethod() { if (linksMethod == null) { linksMethod = ClassUtils.findMethodWith(implementationClass, JsonApiLinks.class); } }
@Override public boolean accept(Type type, Class<? extends MetaElement> metaClass) { boolean hasAnnotation = ClassUtils.getRawType(type).getAnnotation(Entity.class) != null; boolean hasMetaType = metaClass == MetaElement.class || metaClass == MetaEntity.class || metaClass == MetaJpaDataObject.class; return hasAnnotation && hasMetaType; }
private LinksInformation newLinksInformation() { if (listLinksClass != null) { return ClassUtils.newInstance(listLinksClass); } else { return null; } }
@Override public <A extends Annotation> List<Object> getInstancesByAnnotation(Class<A> annotationClass) { BeanManager beanManager = CDI.current().getBeanManager(); Set<Bean<?>> beans = beanManager.getBeans(Object.class); List<Object> list = new ArrayList<>(); for (Bean<?> bean : beans) { Class<?> beanClass = bean.getBeanClass(); Optional<A> annotation = ClassUtils.getAnnotation(beanClass, annotationClass); if (annotation.isPresent()) { CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean); Object object = beanManager.getReference(bean, beanClass, creationalContext); list.add(object); } } return list; }
public void delete(ID id, QueryAdapter queryAdapter) { Class<JsonApiDelete> annotationType = JsonApiDelete.class; if (deleteMethod == null) { deleteMethod = ClassUtils.findMethodWith(implementationClass, annotationType); } invokeOperation(deleteMethod, annotationType, new Object[]{id}, queryAdapter); } }
@Override public boolean accept(Type type, Class<? extends MetaElement> metaClass) { boolean hasAnnotation = ClassUtils.getRawType(type).getAnnotation(Embeddable.class) != null; boolean hasType = metaClass == MetaElement.class || metaClass == MetaEmbeddable.class || metaClass == MetaJpaDataObject.class; return hasAnnotation && hasType; }
@Override public T buildResource(Resource body) { return (T) ClassUtils.newInstance(resourceClass); }
@Override public Class<?> getTargetAffiliation() { @SuppressWarnings("unchecked") final Optional<JsonApiRelationshipRepository> annotation = ClassUtils.getAnnotation( repositoryInstanceBuilder.getRepositoryClass(), JsonApiRelationshipRepository.class ); if (annotation.isPresent()) { return annotation.get().target(); } else { throw new IllegalArgumentException( String.format( "Class %s must be annotated with @JsonApiRelationshipRepository", repositoryInstanceBuilder.getClass().getName() ) ); } }
public void setRelation(T source, D_ID targetId, String fieldName, QueryAdapter queryAdapter) { Class<JsonApiSetRelation> annotationType = JsonApiSetRelation.class; if (setRelationMethod == null) { setRelationMethod = ClassUtils.findMethodWith(implementationClass, annotationType); } invokeOperation(setRelationMethod, annotationType, new Object[]{source, targetId, fieldName}, queryAdapter); }