Jim Marino wrote:
>>> - As a user what steps do I need to take to provide custom data
>>> values for config properties? In a previous post, I listed an example
>>> of a concrete "Foo" class
>>>
<snip>a lot</snip>

I added support to the StAX version that allows you to specify a custom
parser for the content of any <v:name> element. It works by allowing you
to specify a "factory" attribute on the element which is the name of a
class to which we will pass the stax stream.

So if your XML contained:
  <properties>
    <propFoo factory='com.example.FooFactory'>
       <name>Hello</name>
    </propFoo>
  </properties>

we would create a new FooFactory, pass it the stream and use the result
to create the instance to inject into the component.

As a user, all you need to do is write the factory and include that with
your application. The implementation can use any XML binding technology
that can read from a StAX stream.

You can see an example in
https://svn.apache.org/repos/asf/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentLoaderTestCase.java

I also added a factory that converts simple element text into a instance
of the Property's type as follows:
* if the property is a String, use the element text
* if the property type has a static valueOf(String) method,
  call that and use the result
* if the property type has a constructor taking a single
  String parameter, use that to instantiate a value
* if there is a PropertyEditor available for the type,
  use that to construct a value from the element text
* bail...

This gives support for most common Java types including primitives,
Numbers, String, URLs, Date (albeit in a funky form) etc.

I would have based this on the XML Schema simple type but that
information is not stored in the Property configuration model. Once we
get that in there then it would be simple to modify this for a xml->java
type conversion.

--
Jeremy

Reply via email to