Java Code Examples for com.openpojo.reflection.PojoClass#getPojoFieldsAnnotatedWith()
The following examples show how to use
com.openpojo.reflection.PojoClass#getPojoFieldsAnnotatedWith() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BusinessPojoHelper.java From openpojo with Apache License 2.0 | 6 votes |
/** * Get all business keys declared on a class and the parent super classes. * * @param clazz * The class to introspect. * @return The list of fields that are annotated with @BusinessKey, will return an empty list if none are found. */ public static List<BusinessKeyField> getBusinessKeyFields(final Class<?> clazz) { List<BusinessKeyField> businessKeyFields = cache.get(clazz.getName()); if (businessKeyFields != null) { return businessKeyFields; } businessKeyFields = new LinkedList<BusinessKeyField>(); PojoClass pojoClass = PojoClassFactory.getPojoClass(clazz); while (pojoClass != null) { for (PojoField pojoField : pojoClass.getPojoFieldsAnnotatedWith(BusinessKey.class)) { businessKeyFields.add(new DefaultBusinessKeyField(pojoField)); } pojoClass = pojoClass.getSuperClass(); } cache.add(clazz.getName(), businessKeyFields); return businessKeyFields; }
Example 2
Source File: InstanceFactory.java From openpojo with Apache License 2.0 | 4 votes |
private static void initializeBusinessKeys(PojoClass pojoClass, Object instance) { for (PojoField field : pojoClass.getPojoFieldsAnnotatedWith(BusinessKey.class)) { if (field.get(instance) == null || field.isPrimitive()) field.set(instance, RandomFactory.getRandomValue(field)); } }
Example 3
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 3 votes |
@Test public void testGetPojoFieldsAnnotatedWith() { PojoClass pojoClass = getPojoClassImplForClass(AClassWithAnnotatedFields.class); Affirm.affirmEquals("Expected 4 fields", 4, pojoClass.getPojoFields().size()); List<PojoField> annotatedPojoFields = pojoClass.getPojoFieldsAnnotatedWith(SomeAnnotation.class); Affirm.affirmEquals("Expected 2 annotated fields", 2, annotatedPojoFields.size()); }