use of java.lang.reflect.AnnotatedElement in project cuba by cuba-platform.
the class DataContextImpl method setPropertyValue.
protected void setPropertyValue(Entity entity, MetaProperty property, @Nullable Object value, boolean checkEquals) {
if (!property.isReadOnly()) {
((AbstractInstance) entity).setValue(property.getName(), value, checkEquals);
} else {
AnnotatedElement annotatedElement = property.getAnnotatedElement();
if (annotatedElement instanceof Field) {
Field field = (Field) annotatedElement;
field.setAccessible(true);
try {
field.set(entity, value);
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to set property value", e);
}
}
}
}
use of java.lang.reflect.AnnotatedElement in project cuba by cuba-platform.
the class MetadataTools method isOwningSide.
/**
* Determine whether the given property is on the owning side of an association.
*/
public boolean isOwningSide(MetaProperty metaProperty) {
checkNotNullArgument(metaProperty, "metaProperty is null");
if (!metaProperty.getRange().isClass())
return false;
AnnotatedElement el = metaProperty.getAnnotatedElement();
for (Annotation annotation : el.getAnnotations()) {
if (annotation instanceof ManyToOne)
return true;
if (annotation instanceof OneToMany || annotation instanceof OneToOne)
return el.isAnnotationPresent(JoinColumn.class) || el.isAnnotationPresent(JoinTable.class);
if (annotation instanceof ManyToMany)
return el.isAnnotationPresent(JoinTable.class);
}
return false;
}
use of java.lang.reflect.AnnotatedElement in project cuba by cuba-platform.
the class MetadataLoader method postProcessProperty.
protected void postProcessProperty(MetaClass metaClass, MetaProperty metaProperty) {
// init inverse properties
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null && inverseProp.getInverse() == null) {
((MetaPropertyImpl) inverseProp).setInverse(metaProperty);
}
if (metaProperty.getRange() == null || !metaProperty.getRange().isClass())
return;
AnnotatedElement annotatedElement = metaProperty.getAnnotatedElement();
OnDelete onDelete = annotatedElement.getAnnotation(OnDelete.class);
if (onDelete != null) {
Map<String, Object> metaAnnotations = metaClass.getAnnotations();
MetaProperty[] properties = (MetaProperty[]) metaAnnotations.get(OnDelete.class.getName());
properties = ArrayUtils.add(properties, metaProperty);
metaAnnotations.put(OnDelete.class.getName(), properties);
}
OnDeleteInverse onDeleteInverse = annotatedElement.getAnnotation(OnDeleteInverse.class);
if (onDeleteInverse != null) {
Map<String, Object> metaAnnotations = metaProperty.getRange().asClass().getAnnotations();
MetaProperty[] properties = (MetaProperty[]) metaAnnotations.get(OnDeleteInverse.class.getName());
properties = ArrayUtils.add(properties, metaProperty);
metaAnnotations.put(OnDeleteInverse.class.getName(), properties);
}
}
use of java.lang.reflect.AnnotatedElement in project geronimo-xbean by apache.
the class MetaAnnotatedElement method getDeclaredMetaAnnotations.
private static Collection<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> clazz) {
Map<Class, Annotation> map = new HashMap<Class, Annotation>();
for (Annotation annotation : clazz.getDeclaredAnnotations()) {
map.put(annotation.annotationType(), annotation);
}
List<Annotation[]> groups = new ArrayList<Annotation[]>();
Class<? extends Annotation> metatype = getMetatype(clazz);
if (metatype != null) {
try {
Class<?> def = clazz.getClassLoader().loadClass(clazz.getName() + "$$");
List<AnnotatedElement> elements = new ArrayList<AnnotatedElement>();
elements.addAll(asList(def.getDeclaredFields()));
elements.addAll(asList(def.getDeclaredConstructors()));
elements.addAll(asList(def.getDeclaredMethods()));
for (Method method : def.getDeclaredMethods()) {
for (Annotation[] array : method.getParameterAnnotations()) {
groups.add(array);
}
}
for (Constructor constructor : def.getDeclaredConstructors()) {
for (Annotation[] array : constructor.getParameterAnnotations()) {
groups.add(array);
}
}
for (AnnotatedElement element : elements) {
groups.add(element.getDeclaredAnnotations());
}
for (Annotation[] annotations : groups) {
if (contains(annotations, clazz)) {
for (Annotation annotation : annotations) {
map.put(annotation.annotationType(), annotation);
}
}
}
} catch (ClassNotFoundException e) {
// inner class is optional
}
}
map.remove(Target.class);
map.remove(Retention.class);
map.remove(Documented.class);
map.remove(metatype);
map.remove(clazz);
return map.values();
}
use of java.lang.reflect.AnnotatedElement in project newts by OpenNMS.
the class MergeSort method createCmdLineParser.
private CmdLineParser createCmdLineParser() {
return new CmdLineParser(this) {
@SuppressWarnings("rawtypes")
@Override
public void addArgument(final Setter setter, Argument a) {
Setter newSetter = setter;
if (setter instanceof MethodSetter) {
newSetter = new Setter() {
@SuppressWarnings("unchecked")
@Override
public void addValue(Object value) throws CmdLineException {
setter.addValue(value);
}
@Override
public Class getType() {
return setter.getType();
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public FieldSetter asFieldSetter() {
return setter.asFieldSetter();
}
@Override
public AnnotatedElement asAnnotatedElement() {
return setter.asAnnotatedElement();
}
};
}
super.addArgument(newSetter, a);
}
};
}
Aggregations