Commits

Anonymous committed 79ca7c2

Made conversion properties file reload if file reloading is set

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

  • Participants
  • Parent commits 07e56f6

Comments (0)

Files changed (1)

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

 package com.opensymphony.xwork.util;
 
 import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.util.FileManager;
 
 import ognl.*;
 
                     Map mapping = (Map) mappings.get(clazz);
 
                     if (mapping == null) {
-                        mapping = new HashMap();
-                        mappings.put(clazz, mapping);
-
-                        String className = clazz.getName();
-                        String resource = className.replace('.', '/') + "-conversion.properties";
-                        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
-
-                        if (is != null) {
-                            Properties props = new Properties();
-                            props.load(is);
-                            mapping.putAll(props);
-
-                            for (Iterator iterator = mapping.entrySet().iterator();
-                                 iterator.hasNext();) {
-                                Map.Entry entry = (Map.Entry) iterator.next();
-                                entry.setValue(createTypeConverter((String) entry.getValue()));
-                            }
-                        } else {
-                            noMapping.add(clazz);
-                        }
+                        mapping = buildConverterMapping(clazz);
+
+                    } else {
+                        mapping = conditionalReload(clazz, mapping);
                     }
 
                     tc = (TypeConverter) mapping.get(property);
         }
     }
 
+    private Map buildConverterMapping(Class clazz) throws Exception {
+        Map mapping = new HashMap();
+
+        String resource = buildConverterFilename(clazz);
+        InputStream is = FileManager.loadFile(resource,clazz);
+
+        if (is != null) {
+            Properties props = new Properties();
+            props.load(is);
+            mapping.putAll(props);
+
+            for (Iterator iterator = mapping.entrySet().iterator();
+                 iterator.hasNext();) {
+                Map.Entry entry = (Map.Entry) iterator.next();
+                entry.setValue(createTypeConverter((String) entry.getValue()));
+            }
+            mappings.put(clazz, mapping);
+        } else {
+            noMapping.add(clazz);
+        }
+        return mapping;
+    }
+
+    private String buildConverterFilename(Class clazz) {
+        String className = clazz.getName();
+        String resource = className.replace('.', '/') + "-conversion.properties";
+        return resource;
+    }
+
+    private Map conditionalReload(Class clazz, Map oldValues) throws Exception {
+        Map mapping = oldValues;
+        if (FileManager.isReloadingConfigs()) {
+            if (FileManager.fileNeedsReloading(buildConverterFilename(clazz))) {
+                mapping = buildConverterMapping(clazz);
+            }
+        }
+        return mapping;
+    }
+
     public TypeConverter lookup(String className) {
         TypeConverter result = (TypeConverter) defaultMappings.get(className);