@Test public void testElementFactory() throws NoSuchFieldException, FormException { PropertyElementFactory tested = new PropertyElementFactory(); Element methodElement = tested.create(MethodTestBean.class.getDeclaredField("name")); Element fieldElement = tested.create(FieldTestBean.class.getDeclaredField("name")); Assert.assertEquals(PropertyMethodElement.class, methodElement.getClass()); Assert.assertEquals(PropertyFieldElement.class, fieldElement.getClass()); }
@Override public Element create(Field field) throws FormException { Element element = null; if (field.getDeclaringClass().isAnnotationPresent(Accessor.class) && (Accessor.AccessType.METHOD == field.getDeclaringClass().getAnnotation(Accessor.class).value())) { try { Method propertyGetter = ReflectionUtils.getPropertyGetter(field); if (Property.class.isAssignableFrom(propertyGetter.getReturnType())) { element = new PropertyMethodElement(field); } else { element = new ReadOnlyPropertyMethodElement(field); } } catch (NoSuchMethodException e) { logger.log(Level.INFO, "No property getter found for " + field); throw new FormException(e); } } else { if (Property.class.isAssignableFrom(field.getType())) { element = new PropertyFieldElement(field); } else if (ReadOnlyProperty.class.isAssignableFrom(field.getType())) { element = new ReadOnlyPropertyFieldElement(field); } } return element; }
PropertyElementFactory implements ElementFactory { @Override public Element create(Field field) throws FormException { Element element = null; if (field.getDeclaringClass().isAnnotationPresent(Accessor.class) && (Accessor.AccessType.METHOD == field.getDeclaringClass().getAnnotation(Accessor.class).value())) { try { Method propertyGetter = ReflectionUtils.getPropertyGetter(field); if (Property.class.isAssignableFrom(propertyGetter.getReturnType())) { element = new PropertyMethodElement(field); } else { element = new ReadOnlyPropertyMethodElement(field); } } catch (NoSuchMethodException e) { logger.log(Level.INFO, "No property getter found for " + field); throw new FormException(e); } } else { if (Property.class.isAssignableFrom(field.getType())) { element = new PropertyFieldElement(field); } else if (ReadOnlyProperty.class.isAssignableFrom(field.getType())) { element = new ReadOnlyPropertyFieldElement(field); } } return element; } }
PropertyElementFactory implements ElementFactory { @Override public Element create(Field field) throws FormException { Element element = null; if (field.getDeclaringClass().isAnnotationPresent(Accessor.class) && (Accessor.AccessType.METHOD == field.getDeclaringClass().getAnnotation(Accessor.class).value())) { try { Method propertyGetter = ReflectionUtils.getPropertyGetter(field); if (Property.class.isAssignableFrom(propertyGetter.getReturnType())) { element = new PropertyMethodElement(field); } else { element = new ReadOnlyPropertyMethodElement(field); } } catch (NoSuchMethodException e) { logger.log(Level.INFO, "No property getter found for " + field); throw new FormException(e); } } else { if (Property.class.isAssignableFrom(field.getType())) { element = new PropertyFieldElement(field); } else if (ReadOnlyProperty.class.isAssignableFrom(field.getType())) { element = new ReadOnlyPropertyFieldElement(field); } } return element; }  }
PropertyElementFactory implements ElementFactory { @Override public Element create(Field field) throws FormException { Element element = null; if (field.getDeclaringClass().isAnnotationPresent(Accessor.class) && (Accessor.AccessType.METHOD == field.getDeclaringClass().getAnnotation(Accessor.class).value())) { try { Method propertyGetter = ReflectionUtils.getPropertyGetter(field); if (Property.class.isAssignableFrom(propertyGetter.getReturnType())) { element = new PropertyMethodElement(field); } else { element = new ReadOnlyPropertyMethodElement(field); } } catch (NoSuchMethodException e) { logger.log(Level.INFO, "No property getter found for " + field); throw new FormException(e); } } else { if (Property.class.isAssignableFrom(field.getType())) { element = new PropertyFieldElement(field); } else if (ReadOnlyProperty.class.isAssignableFrom(field.getType())) { element = new ReadOnlyPropertyFieldElement(field); } } return element; }  @Override Element create(Field field); }
PropertyElementFactory implements ElementFactory { @Override public Element create(Field field) throws FormException { Element element = null; if (field.getDeclaringClass().isAnnotationPresent(Accessor.class) && (Accessor.AccessType.METHOD == field.getDeclaringClass().getAnnotation(Accessor.class).value())) { try { Method propertyGetter = ReflectionUtils.getPropertyGetter(field); if (Property.class.isAssignableFrom(propertyGetter.getReturnType())) { element = new PropertyMethodElement(field); } else { element = new ReadOnlyPropertyMethodElement(field); } } catch (NoSuchMethodException e) { logger.log(Level.INFO, "No property getter found for " + field); throw new FormException(e); } } else { if (Property.class.isAssignableFrom(field.getType())) { element = new PropertyFieldElement(field); } else if (ReadOnlyProperty.class.isAssignableFrom(field.getType())) { element = new ReadOnlyPropertyFieldElement(field); } } return element; }  @Override Element create(Field field);  }