1 19 package org.apache.cayenne.reflect.valueholder; 20 21 import java.util.List ; 22 23 import org.apache.cayenne.ValueHolder; 24 import org.apache.cayenne.map.ObjRelationship; 25 import org.apache.cayenne.reflect.Accessor; 26 import org.apache.cayenne.reflect.ClassDescriptor; 27 import org.apache.cayenne.reflect.ClassDescriptorFactory; 28 import org.apache.cayenne.reflect.ClassDescriptorMap; 29 import org.apache.cayenne.reflect.ListProperty; 30 import org.apache.cayenne.reflect.PersistentDescriptor; 31 import org.apache.cayenne.reflect.PersistentDescriptorFactory; 32 import org.apache.cayenne.reflect.Property; 33 34 41 public class ValueHolderDescriptorFactory extends PersistentDescriptorFactory { 42 43 public ValueHolderDescriptorFactory(ClassDescriptorMap descriptorMap) { 44 super(descriptorMap); 45 } 46 47 protected void createToManyProperty( 48 PersistentDescriptor descriptor, 49 ObjRelationship relationship) { 50 51 ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship 52 .getTargetEntityName()); 53 String reverseName = relationship.getReverseRelationshipName(); 54 55 Accessor accessor = createAccessor(descriptor, relationship.getName(), List .class); 56 descriptor.addDeclaredProperty(new ListProperty( 57 descriptor, 58 targetDescriptor, 59 accessor, 60 reverseName)); 61 } 62 63 protected void createToOneProperty( 64 PersistentDescriptor descriptor, 65 ObjRelationship relationship) { 66 ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship 67 .getTargetEntityName()); 68 String reverseName = relationship.getReverseRelationshipName(); 69 70 Accessor accessor = createAccessor( 71 descriptor, 72 relationship.getName(), 73 ValueHolder.class); 74 Property property = new ValueHolderProperty( 75 descriptor, 76 targetDescriptor, 77 accessor, 78 reverseName); 79 80 descriptor.addDeclaredProperty(property); 81 } 82 } 83 | Popular Tags |