Hi Konstantin,

Am 30.01.2015 um 14:48 schrieb Konstantin Kolinko:
2015-01-30 13:51 GMT+03:00  <rj...@apache.org>:
Author: rjung
Date: Fri Jan 30 10:51:01 2015
New Revision: 1655982

URL: http://svn.apache.org/r1655982
Log:
Enhance our naming BeanFactory.

If a bean property exists which the Introspector
presents us with a type that we don't have a
string conversion for, but the bean actually
has a method to set the property from a string,
allow to provide this information to the
BeanFactory.

New attribute "forceString" taking a comma separated
list of items as values. Each item is either a bean
property name (e.g. "foo") meaning that there is a
setter function "setFoo(String)" for that property.
Or the item is of the form "foo=method" meaning that
property "foo" can be set by calling "method(String)".

This should make writing a custom bean factory
obsolete in quite a few cases.


Maybe do this without any configuration?

It is our own code in org.apache.naming.factory.BeanFactory that
performs the value assignment. There is a case that happens when the
property cannot be assigned,

[[[
                                 throw new NamingException
                                     ("String conversion for property "
+ propName +
                                      " of type '" + propType.getName() +
                                      "' not available");
]]]

1) We can look for a java.beans.PropertyEditor
(PropertyEditorManager.findEditor())

I have to look into that.

2) We can look for setter(String) method, like your new code does.

But would it be safe to simply use such a setter? We are now outside of the beans specifcation. The property was found but it has a different type. There is a second method with the same name as the property setter but taking a string as argument. I'm not sure if automagically calling such alternative setters would be OK or whether it should be an explicit choice of admin or webapp developer how to cope with that situation. The name suggests it would set the property but we can't be sure.

Your code allows to use any arbitrary method as a setter. I think that
if a custom name is needed, one can just rename the XML attribute one
is using for the property.

You mean if we find an attribute for which we don't find a property, we would look for a method of the same name with a string arg and then call it? That sounds OK for me, because the user kind of told us to do it and it would make the name=method syntax obsolete.

Thanks for review and improvement suggestions!

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to