Hi
I was looking for factory based API and I played a little bit around. The result is simple hand made implementation proving the idea I had in mind. I think, the result is in the nature very similar to Aslak's proposal. I am just not so happy with the class type approach.
What does the proposal show? It shows:
- No up() method. All the generic typos are gone.
- A factory class that creates all the standard nodes. A user type just the . (dot) and the IDE will show all possible options. Most of the time, there will be only one.
- A particular node can be instantiated decoupled from the descriptor instance.
- To provide conventient behavour is very simple to implement. I implementet a simple test case for this.
I didn't looked so far how the factory will be created and available for the user. I guess there will be one for a particular descriptor. So, this is left out at the moment.
First Example: Simple Demonstation
@Test
public void testFactory() throws Exception {
final ConnectorDescriptor jca10Generated = create();
final Factory factory = jca10Generated.getFactory();
jca10Generated
.description("It is a sample resource adapter")
.setResourceadapter(factory.Resourceadapter()
.addConfigProperty(factory.ConfigProperty()
.configPropertyName("Input")
.configPropertyType("java.lang.String")
.configPropertyValue("test messages")));
}
Second Example: Detached Demonstation (technically the same but show that you can create a node instance separate)
@Test
public void testDetachedMode() throws Exception {
final ConnectorDescriptor jca10Generated = create();
final Factory factory = jca10Generated.getFactory();
final Resourceadapter resourceAdapter = factory.Resourceadapter();
final ConfigProperty property = factory.ConfigProperty()
.configPropertyName("Input")
.configPropertyType("java.lang.String")
.configPropertyValue("test messages");
jca10Generated
.description("It is a sample resource adapter")
.setResourceadapter(resourceAdapter.addConfigProperty(property));
}
Third Example: Convenient Behavour
@Test
public void testConvenientResourceAdapter() throws Exception {
final ConnectorDescriptor jca10Generated = create();
final Factory factory = jca10Generated.getFactory();
// this class just adds additional information. Can also be provided within a factory class
final ConvenientResourceAdapter resourceAdapter = new ConvenientResourceAdapter();
final ConfigProperty property = factory.ConfigProperty()
.configPropertyName("Input")
.configPropertyType("java.lang.String")
.configPropertyValue("test messages");
jca10Generated
.description("It is a sample resource adapter")
.setResourceadapter(resourceAdapter.addConfigProperty(property));
String generatedRaXml = jca10Generated.exportAsString();
System.out.println(generatedRaXml);
}
The output is then:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<connector attr="val">
<description>It is a sample resource adapter</description>
<my-node my-attribute="great">my-text</my-node>
<resourceadapter>
<config-property>
<config-property-name>Input</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>test messages</config-property-value>
</config-property>
</resourceadapter>
</connector>
For single node assigment I propose: set<NodeName> e.g. setResourceadapter(..)
For adding an instance to a list I propose: add<NodeName> e.g. addConfigProperty(property)
You can find the implementation here: https://github.com/rbattenfeld/descriptors/tree/prototype
I am sending a pull request as Andrew mentioned in the reboot thread but I am not sure if that is correct:-)
Would be great to push this project further.
Regards,
Ralf
Comments