1 52 53 package freemarker.ext.beans; 54 55 import java.util.HashMap ; 56 import java.util.Map ; 57 58 import freemarker.template.TemplateHashModel; 59 import freemarker.template.TemplateModel; 60 import freemarker.template.TemplateModelException; 61 import freemarker.template.utility.ClassUtil; 62 63 72 final class StaticModels 73 implements 74 TemplateHashModel 75 { 76 private final BeansWrapper wrapper; 77 private final Map cache = new HashMap (); 78 79 StaticModels(BeansWrapper wrapper) 80 { 81 this.wrapper = wrapper; 82 } 83 84 88 public TemplateModel get(String key) 89 throws 90 TemplateModelException 91 { 92 synchronized(cache) 93 { 94 TemplateModel model = (TemplateModel)cache.get(key); 95 if(model == null) 96 { 97 try 98 { 99 Class clazz = ClassUtil.forName(key); 100 model = new StaticModel(clazz, wrapper); 101 wrapper.introspectClass(clazz); 105 } 106 catch(Exception e) 107 { 108 throw new TemplateModelException(e); 109 } 110 cache.put(key, model); 111 } 112 return model; 113 } 114 } 115 116 void clearCache() 117 { 118 synchronized(cache) 119 { 120 cache.clear(); 121 } 122 } 123 124 public boolean isEmpty() 125 { 126 return false; 127 } 128 } 129 | Popular Tags |