1 19 package org.apache.cayenne.reflect; 20 21 import java.util.Iterator ; 22 23 import org.apache.cayenne.map.ObjEntity; 24 25 31 public class LazyClassDescriptorDecorator implements ClassDescriptor { 32 33 protected ClassDescriptor descriptor; 34 protected ClassDescriptorMap descriptorMap; 35 protected String entityName; 36 37 public LazyClassDescriptorDecorator(ClassDescriptorMap descriptorMap, 38 String entityName) { 39 this.descriptorMap = descriptorMap; 40 this.entityName = entityName; 41 } 42 43 47 protected void checkDescriptorInitialized() { 48 if (descriptor == null) { 49 descriptor = descriptorMap.createDescriptor(entityName); 50 } 51 } 52 53 57 public ClassDescriptor getDescriptor() { 58 checkDescriptorInitialized(); 59 return descriptor; 60 } 61 62 public Object createObject() { 63 checkDescriptorInitialized(); 64 return descriptor.createObject(); 65 } 66 67 public Property getDeclaredProperty(String propertyName) { 68 checkDescriptorInitialized(); 69 return descriptor.getDeclaredProperty(propertyName); 70 } 71 72 public ObjEntity getEntity() { 73 checkDescriptorInitialized(); 74 return descriptor.getEntity(); 75 } 76 77 public Class getObjectClass() { 78 checkDescriptorInitialized(); 79 return descriptor.getObjectClass(); 80 } 81 82 86 public Iterator getProperties() { 87 checkDescriptorInitialized(); 88 return descriptor.getProperties(); 89 } 90 91 public Iterator getIdProperties() { 92 checkDescriptorInitialized(); 93 return descriptor.getIdProperties(); 94 } 95 96 public Property getProperty(String propertyName) { 97 checkDescriptorInitialized(); 98 return descriptor.getProperty(propertyName); 99 } 100 101 public ClassDescriptor getSubclassDescriptor(Class objectClass) { 102 checkDescriptorInitialized(); 103 return descriptor.getSubclassDescriptor(objectClass); 104 } 105 106 public ClassDescriptor getSuperclassDescriptor() { 107 checkDescriptorInitialized(); 108 return descriptor.getSuperclassDescriptor(); 109 } 110 111 public void injectValueHolders(Object object) throws PropertyException { 112 checkDescriptorInitialized(); 113 descriptor.injectValueHolders(object); 114 } 115 116 public boolean isFault(Object object) { 117 checkDescriptorInitialized(); 118 return descriptor.isFault(object); 119 } 120 121 public void shallowMerge(Object from, Object to) throws PropertyException { 122 checkDescriptorInitialized(); 123 descriptor.shallowMerge(from, to); 124 } 125 126 public boolean visitDeclaredProperties(PropertyVisitor visitor) { 127 checkDescriptorInitialized(); 128 return descriptor.visitDeclaredProperties(visitor); 129 } 130 131 public boolean visitProperties(PropertyVisitor visitor) { 132 checkDescriptorInitialized(); 133 return descriptor.visitProperties(visitor); 134 } 135 136 public boolean visitAllProperties(PropertyVisitor visitor) { 137 checkDescriptorInitialized(); 138 return descriptor.visitAllProperties(visitor); 139 } 140 } 141 | Popular Tags |