/** * Creates an accessor for the property of the embeddable class. */ protected Accessor createEmbeddableAccessor(EmbeddableDescriptor descriptor, String propertyName, Class<?> propertyType) { return new FieldAccessor(descriptor.getObjectClass(), propertyName, propertyType); }
/** * Recursively looks for a named field in a class hierarchy. */ protected Field lookupFieldInHierarchy(Class<?> beanClass, String fieldName) throws SecurityException, NoSuchFieldException { // TODO: support property names following other common naming patterns, such as // "_propertyName" try { return beanClass.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { Class<?> superClass = beanClass.getSuperclass(); if (superClass == null || superClass.getName().equals(Object.class.getName())) { throw e; } return lookupFieldInHierarchy(superClass, fieldName); } }
public FieldAccessor(Class<?> objectClass, String propertyName, Class<?> propertyType) { // sanity check if (objectClass == null) { throw new IllegalArgumentException("Null objectClass"); } if (propertyName == null) { throw new IllegalArgumentException("Null propertyName"); } this.propertyName = propertyName; this.field = prepareField(objectClass, propertyName, propertyType); this.nullValue = PropertyUtils.defaultNullValueForType(field.getType()); }
/** * Creates an accessor for the property. */ protected Accessor createAccessor(PersistentDescriptor descriptor, String propertyName, Class<?> propertyType) throws PropertyException { return new FieldAccessor(descriptor.getObjectClass(), propertyName, propertyType); }
field = lookupFieldInHierarchy(beanClass, propertyName);
public FieldEmbeddableDescriptor(Embeddable embeddable, String ownerProperty, String embeddedPropertyProperty) { this.embeddable = embeddable; try { this.embeddableClass = Class.forName(embeddable.getClassName(), true, Thread .currentThread() .getContextClassLoader()); } catch (ClassNotFoundException e) { throw new PropertyException("Class not found", e); } this.ownerAccessor = new FieldAccessor( embeddableClass, ownerProperty, Persistent.class); this.embeddedPropertyAccessor = new FieldAccessor( embeddableClass, embeddedPropertyProperty, String.class); }