1 package org.hibernate.tuple; 3 4 import java.lang.reflect.Method ; 5 import java.util.Iterator ; 6 7 import org.hibernate.HibernateException; 8 import org.hibernate.engine.SessionFactoryImplementor; 9 import org.hibernate.mapping.Component; 10 import org.hibernate.mapping.Property; 11 import org.hibernate.property.Getter; 12 import org.hibernate.property.Setter; 13 14 17 public abstract class AbstractComponentTuplizer implements ComponentTuplizer { 18 19 protected final Getter[] getters; 20 protected final Setter[] setters; 21 protected final int propertySpan; 22 protected final Instantiator instantiator; 23 protected final boolean hasCustomAccessors; 24 25 protected abstract Instantiator buildInstantiator(Component component); 26 protected abstract Getter buildGetter(Component component, Property prop); 27 protected abstract Setter buildSetter(Component component, Property prop); 28 29 protected AbstractComponentTuplizer(Component component) { 30 31 propertySpan = component.getPropertySpan(); 32 33 getters = new Getter[propertySpan]; 34 setters = new Setter[propertySpan]; 35 Iterator iter = component.getPropertyIterator(); 36 boolean foundCustomAccessor=false; 37 int i=0; 38 while ( iter.hasNext() ) { 39 Property prop = (Property) iter.next(); 40 getters[i] = buildGetter(component, prop); 41 setters[i] = buildSetter(component, prop); 42 if ( !prop.isBasicPropertyAccessor() ) foundCustomAccessor = true; 43 i++; 44 } 45 hasCustomAccessors = foundCustomAccessor; 46 47 String [] getterNames = new String [propertySpan]; 48 String [] setterNames = new String [propertySpan]; 49 Class [] propTypes = new Class [propertySpan]; 50 for ( int j = 0; j < propertySpan; j++ ) { 51 getterNames[j] = getters[j].getMethodName(); 52 setterNames[j] = setters[j].getMethodName(); 53 propTypes[j] = getters[j].getReturnType(); 54 } 55 instantiator = buildInstantiator(component); 56 } 57 58 59 public Object getPropertyValue(Object component, int i) 60 throws HibernateException { 61 return getters[i].get( component ); 62 } 63 64 public Object [] getPropertyValues(Object component) throws HibernateException { 65 Object [] values = new Object [propertySpan]; 66 for ( int i = 0; i < propertySpan; i++ ) { 67 values[i] = getPropertyValue( component, i ); 68 } 69 return values; 70 } 71 72 public boolean isInstance(Object object) { 73 return instantiator.isInstance(object); 74 } 75 76 public void setPropertyValues(Object component, Object [] values) 77 throws HibernateException { 78 79 for ( int i = 0; i < propertySpan; i++ ) { 80 setters[i].set( component, values[i], null ); 81 } 82 83 } 84 85 88 public Object instantiate() throws HibernateException { 89 return instantiator.instantiate(); 90 } 91 92 public Object getParent(Object component) { 93 return null; 94 } 95 96 public boolean hasParentProperty() { 97 return false; 98 } 99 100 public boolean isMethodOf(Method method) { 101 return false; 102 } 103 104 public void setParent(Object component, Object parent, SessionFactoryImplementor factory) { 105 throw new UnsupportedOperationException (); 106 } 107 108 } 109 | Popular Tags |