All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nz.co.gregs.properties.PropertyContainer Maven / Gradle / Ivy

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nz.co.gregs.properties;

import java.util.List;

/**
 *
 * @author gregorygraham
 */
public class PropertyContainer {
	private transient PropertyContainerInstance wrapper;
	private final PropertyContainerWrapperFactory wrapperFactory;

	public PropertyContainer(PropertyContainerWrapperFactory factory) {
		wrapperFactory=factory;
	}

	/**
	 * Gets a wrapper for the underlying property (field or method) given the
	 * property's object reference.
	 *
	 * 

* For example the following code snippet will get a property wrapper for the * {@literal name} field: *

	 * Customer customer = ...;
	 * getPropertyWrapperOf(customer.name);
	 * 
* * @param obj a object in a field or bean of the PropertyContainer * @return the PropertyWrapper associated with the Object suppled or NULL. */ public Property getPropertyOf(Object obj) throws InstantiationException, IllegalAccessException { List props = getWrapper().getPropertyWrappers(); Object maybeTheObj; for (Property prop : props) { maybeTheObj = prop.rawJavaValue(); if (maybeTheObj == obj) { return prop; } } return null; } protected PropertyContainerInstance getWrapper() throws InstantiationException, IllegalAccessException { if (wrapper == null) { wrapper = wrapperFactory.instanceWrapperFor(this); } return wrapper; } /** * Returns the PropertyWrappers used internally to maintain the relationship * between fields and columns * * @return non-null list of property wrappers, empty if none */ public List getPropertyWrappers() throws InstantiationException, IllegalAccessException { return getWrapper().getPropertyDefinitions(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy