Commits

plightbo  committed 8e68db7

cache BeanInfo objects (MAN these are slow)

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@367e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 045f528

Comments (0)

Files changed (1)

File src/java/com/opensymphony/xwork/util/OgnlUtil.java

 
     private static final Log log = LogFactory.getLog(OgnlUtil.class);
     private static HashMap expressions = new HashMap();
+    private static HashMap beanInfoCache = new HashMap();
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         BeanInfo beanInfoTo;
 
         try {
-            beanInfoFrom = Introspector.getBeanInfo(from.getClass(), Object.class);
-            beanInfoTo = Introspector.getBeanInfo(to.getClass(), Object.class);
+            beanInfoFrom = getBeanInfo(from);
+            beanInfoTo = getBeanInfo(to);
         } catch (IntrospectionException e) {
             log.error("An error occured", e);
 
         }
     }
 
+    private static BeanInfo getBeanInfo(Object from) throws IntrospectionException {
+        BeanInfo beanInfo;
+        beanInfo = (BeanInfo) beanInfoCache.get(from.getClass());
+        if (beanInfo == null) {
+            beanInfo = Introspector.getBeanInfo(from.getClass(), Object.class);
+            beanInfoCache.put(from.getClass(), beanInfo);
+        }
+        return beanInfo;
+    }
+
     static void internalSetProperty(String name, Object value, Object o, Map context, boolean throwPropertyExceptions) {
         try {
             setValue(name, context, o, value);