FileDocCategorySizeDatePackage
PropertyAccessorFactory.javaAPI DocHibernate 3.2.55674Mon Oct 24 03:45:38 BST 2005org.hibernate.property

PropertyAccessorFactory

public final class PropertyAccessorFactory extends Object
A factory for building/retrieving PropertyAccessor instances.
author
Gavin King
author
Steve Ebersole

Fields Summary
private static final PropertyAccessor
BASIC_PROPERTY_ACCESSOR
private static final PropertyAccessor
DIRECT_PROPERTY_ACCESSOR
private static final PropertyAccessor
MAP_ACCESSOR
private static final PropertyAccessor
NOOP_ACCESSOR
private static final PropertyAccessor
EMBEDDED_PROPERTY_ACCESSOR
Constructors Summary
private PropertyAccessorFactory()

Methods Summary
public static PropertyAccessorgetDom4jPropertyAccessor(java.lang.String nodeName, org.hibernate.type.Type type, org.hibernate.engine.SessionFactoryImplementor factory)

		//TODO: need some caching scheme? really comes down to decision 
		//      regarding amount of state (if any) kept on PropertyAccessors
		return new Dom4jAccessor( nodeName, type, factory );
	
public static PropertyAccessorgetDynamicMapPropertyAccessor()

		return MAP_ACCESSOR;
	
private static PropertyAccessorgetPojoPropertyAccessor(java.lang.String pojoAccessorStrategy)
Retreives a PropertyAccessor specific for a PojoRepresentation with the given access strategy.

param
pojoAccessorStrategy The access strategy.
return
An appropriate accessor.

		if ( StringHelper.isEmpty( pojoAccessorStrategy ) || "property".equals( pojoAccessorStrategy ) ) {
			return BASIC_PROPERTY_ACCESSOR;
		}
		else if ( "field".equals( pojoAccessorStrategy ) ) {
			return DIRECT_PROPERTY_ACCESSOR;
		}
		else if ( "embedded".equals( pojoAccessorStrategy ) ) {
			return EMBEDDED_PROPERTY_ACCESSOR;
		}
		else if ( "noop".equals(pojoAccessorStrategy) ) {
			return NOOP_ACCESSOR;
		}
		else {
			return resolveCustomAccessor( pojoAccessorStrategy );
		}
	
public static PropertyAccessorgetPropertyAccessor(org.hibernate.mapping.Property property, org.hibernate.EntityMode mode)
Retrieves a PropertyAccessor instance based on the given property definition and entity mode.

param
property The property for which to retrieve an accessor.
param
mode The mode for the resulting entity.
return
An appropriate accessor.
throws
MappingException


	//TODO: ideally we need the construction of PropertyAccessor to take the following:
	//      1) EntityMode
	//      2) EntityMode-specific data (i.e., the classname for pojo entities)
	//      3) Property-specific data based on the EntityMode (i.e., property-name or dom4j-node-name)
	// The easiest way, with the introduction of the new runtime-metamodel classes, would be the
	// the following predicates:
	//      1) PropertyAccessorFactory.getPropertyAccessor() takes references to both a
	//          org.hibernate.metadata.EntityModeMetadata and org.hibernate.metadata.Property
	//      2) What is now termed a "PropertyAccessor" stores any values needed from those two
	//          pieces of information
	//      3) Code can then simply call PropertyAccess.getGetter() with no parameters; likewise with
	//          PropertyAccessor.getSetter()

                                              
	         
		//TODO: this is temporary in that the end result will probably not take a Property reference per-se.
	    if ( null == mode || EntityMode.POJO.equals( mode ) ) {
		    return getPojoPropertyAccessor( property.getPropertyAccessorName() );
	    }
	    else if ( EntityMode.MAP.equals( mode ) ) {
		    return getDynamicMapPropertyAccessor();
	    }
	    else if ( EntityMode.DOM4J.equals( mode ) ) {
	    	//TODO: passing null here, because this method is not really used for DOM4J at the moment
	    	//      but it is still a bug, if we don't get rid of this!
		    return getDom4jPropertyAccessor( property.getAccessorPropertyName( mode ), property.getType(), null );
	    }
	    else {
		    throw new MappingException( "Unknown entity mode [" + mode + "]" );
	    }
	
public static PropertyAccessorgetPropertyAccessor(java.lang.Class optionalClass, java.lang.String type)

		if ( type==null ) type = optionalClass==null || optionalClass==Map.class ? "map" : "property";
		return getPropertyAccessor(type);
	
public static PropertyAccessorgetPropertyAccessor(java.lang.String type)

		if ( type==null || "property".equals(type) ) return BASIC_PROPERTY_ACCESSOR;
		if ( "field".equals(type) ) return DIRECT_PROPERTY_ACCESSOR;
		if ( "map".equals(type) ) return MAP_ACCESSOR;
		if ( "embedded".equals(type) ) return EMBEDDED_PROPERTY_ACCESSOR;
		if ( "noop".equals(type)) return NOOP_ACCESSOR;
		
		return resolveCustomAccessor(type);
	
private static PropertyAccessorresolveCustomAccessor(java.lang.String accessorName)

		Class accessorClass;
		try {
			accessorClass = ReflectHelper.classForName(accessorName);
		}
		catch (ClassNotFoundException cnfe) {
			throw new MappingException("could not find PropertyAccessor class: " + accessorName, cnfe);
		}
		try {
			return (PropertyAccessor) accessorClass.newInstance();
		}
		catch (Exception e) {
			throw new MappingException("could not instantiate PropertyAccessor class: " + accessorName, e);
		}