1 19 package org.apache.cayenne.reflect.generic; 20 21 import org.apache.cayenne.DataObject; 22 import org.apache.cayenne.map.ObjAttribute; 23 import org.apache.cayenne.map.ObjEntity; 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.PersistentDescriptor; 30 import org.apache.cayenne.reflect.PersistentDescriptorFactory; 31 import org.apache.cayenne.reflect.PropertyException; 32 33 40 public class DataObjectDescriptorFactory extends PersistentDescriptorFactory { 41 42 public DataObjectDescriptorFactory(ClassDescriptorMap descriptorMap) { 43 super(descriptorMap); 44 } 45 46 protected ClassDescriptor getDescriptor(ObjEntity entity, Class entityClass) { 47 if (!DataObject.class.isAssignableFrom(entityClass)) { 48 return null; 49 } 50 51 return super.getDescriptor(entity, entityClass); 52 } 53 54 protected PersistentDescriptor createDescriptor() { 55 return new DataObjectDescriptor(); 56 } 57 58 protected void createAttributeProperty( 59 PersistentDescriptor descriptor, 60 ObjAttribute attribute) { 61 descriptor.addDeclaredProperty(new DataObjectAttributeProperty(attribute)); 62 } 63 64 protected void createToManyProperty( 65 PersistentDescriptor descriptor, 66 ObjRelationship relationship) { 67 68 ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship 69 .getTargetEntityName()); 70 descriptor.addDeclaredProperty(new DataObjectToManyProperty( 71 relationship, 72 targetDescriptor)); 73 } 74 75 protected void createToOneProperty( 76 PersistentDescriptor descriptor, 77 ObjRelationship relationship) { 78 79 ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship 80 .getTargetEntityName()); 81 descriptor.addDeclaredProperty(new DataObjectToOneProperty( 82 relationship, 83 targetDescriptor)); 84 } 85 86 protected Accessor createAccessor( 87 PersistentDescriptor descriptor, 88 String propertyName, 89 Class propertyType) throws PropertyException { 90 return new DataObjectAccessor(propertyName); 91 } 92 } 93 | Popular Tags |