1 15 package org.apache.tapestry.services.impl; 16 17 import java.util.Collections ; 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.hivemind.ClassResolver; 22 import org.apache.hivemind.service.ClassFactory; 23 import org.apache.tapestry.enhance.EnhancedClassValidator; 24 import org.apache.tapestry.enhance.EnhancementOperationImpl; 25 import org.apache.tapestry.enhance.EnhancementWorker; 26 import org.apache.tapestry.event.ResetEventListener; 27 import org.apache.tapestry.services.ComponentConstructor; 28 import org.apache.tapestry.services.ComponentConstructorFactory; 29 import org.apache.tapestry.spec.IComponentSpecification; 30 31 38 public class ComponentConstructorFactoryImpl implements ComponentConstructorFactory, 39 ResetEventListener 40 { 41 private ClassFactory _classFactory; 42 43 private ClassResolver _classResolver; 44 45 private EnhancedClassValidator _validator; 46 47 private EnhancementWorker _chain; 48 49 53 54 private Map _cachedConstructors = Collections.synchronizedMap(new HashMap ()); 55 56 public void resetEventDidOccur() 57 { 58 _cachedConstructors.clear(); 59 } 60 61 public ComponentConstructor getComponentConstructor(IComponentSpecification specification, 62 String className) 63 { 64 ComponentConstructor result = (ComponentConstructor) _cachedConstructors.get(specification); 65 66 if (result == null) 67 { 68 Class baseClass = _classResolver.findClass(className); 69 70 EnhancementOperationImpl eo = new EnhancementOperationImpl(_classResolver, 71 specification, baseClass, _classFactory); 72 73 76 _chain.performEnhancement(eo, specification); 77 78 result = eo.getConstructor(); 79 80 85 _validator.validate(baseClass, result.getComponentClass(), specification); 86 87 _cachedConstructors.put(specification, result); 88 } 89 90 return result; 91 } 92 93 public void setClassFactory(ClassFactory classFactory) 94 { 95 _classFactory = classFactory; 96 } 97 98 public void setClassResolver(ClassResolver classResolver) 99 { 100 _classResolver = classResolver; 101 } 102 103 public void setValidator(EnhancedClassValidator validator) 104 { 105 _validator = validator; 106 } 107 108 public void setChain(EnhancementWorker chain) 109 { 110 _chain = chain; 111 } 112 } | Popular Tags |