[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Property replacement
adrian@jboss.org
do-not-reply at jboss.com
Wed Jan 24 09:13:46 EST 2007
None of the property editors should be doing system property replacement.
The best way to fix this and maintain backwards compatibility is the following
diff in ValueConvertor.
| [ejort at warjort plugins]$ svn diff ValueConvertor.java
| Index: ValueConvertor.java
| ===================================================================
| --- ValueConvertor.java (revision 59913)
| +++ ValueConvertor.java (working copy)
| @@ -31,6 +31,7 @@
| import org.jboss.reflect.plugins.introspection.ReflectionUtils;
| import org.jboss.reflect.spi.ProgressionConvertor;
| import org.jboss.reflect.spi.ProgressionConvertorFactory;
| +import org.jboss.util.StringPropertyReplacer;
| import org.jboss.util.propertyeditor.PropertyEditors;
|
| /**
| @@ -69,15 +70,37 @@
| * @return the value or null if there is no editor
| * @throws Throwable for any error
| */
| - @SuppressWarnings("unchecked")
| public static Object convertValue(Class<? extends Object> clazz, Object value) throws Throwable
| {
| + return convertValue(clazz, value, false);
| + }
| +
| + /**
| + * Convert a value
| + *
| + * @param clazz the class
| + * @param value the value
| + * @param replaceProperties whether to replace system properties
| + * @return the value or null if there is no editor
| + * @throws Throwable for any error
| + */
| + @SuppressWarnings("unchecked")
| + public static Object convertValue(Class<? extends Object> clazz, Object value, boolean replaceProperties) throws Throwable
| + {
| if (clazz == null)
| throw new IllegalArgumentException("Null class");
| if (value == null)
| return null;
|
| Class<? extends Object> valueClass = value.getClass();
| +
| + // If we have a string replace any system properties when requested
| + if (replaceProperties && valueClass == String.class)
| + {
| + String string = (String) value;
| + value = StringPropertyReplacer.replaceProperties(string);
| + }
| +
| if (clazz.isAssignableFrom(valueClass))
| return value;
|
Then add the following new method to TypeInfo
that invokes the alternative method in ValueConvertor
| /**
| * Convert a value
| *
| * @param value the original value
| * @param replaceProperties whether to replace properties
| * @return the converted value
| * @throws Throwable for any error
| */
| Object convertValue(Object value, boolean replaceProperties) throws Throwable;
|
The StringValueMetaData should be invoking this new method.
Finally, it would be good if StringValueMetaData also had an additional
parameter to turn off string property replace (like the JMX stuff does)
e.g. (but also for other places that take a "value")
| <!-- This property is not replaced -->
| <property name="blah" replace="false">${hello}</property>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4005799#4005799
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4005799
More information about the jboss-dev-forums
mailing list