|
From: Bryant H. <bry...@ho...> - 2007-10-05 15:59:27
|
Hello,
I seem to remember a some what similar question to this a few weeks =
back. So I have a BeanPostProcessor that I've written that applies some =
additional attributes to arbitrary objects. I'd like to use the =
extensible XML support in Spring to be able to do something like the =
following:
<bean id=3D"..." class=3D"...">
<myns:newtag attr1=3D"..." attr2=3D"..." />
<myns:newtag attr1=3D"..." />
</bean>
Basically inserting a new tag within the bean definition that is similar =
to the <property /> tag in terms of min/maxoccurs. Each one creating a =
BeanPostProcessor that will apply its changes to the bean it is defined =
within. Now I've looked over the tutorials and I've seen two types of =
extensions.
One is adding an attribute from an alternate namespace e.g.
<bean id=3D"..." class=3D"... myns:extra-attr />
This involves writing a Decorator that has access to the bean definition =
and holder, but won't work for me because my tag can be applied multiple =
times with different attributes of its own.
The other using a namespace extension where a <bean> tag would already =
be allowed e.g.
<bean id=3D"..." class=3D"...">
<property name=3D"prop">
<myns:newtag ... />
</property>
</bean>
I can see how this works because the bean definition created via my =
parser just gets set directly into the property. In my case I don't =
need or have a property that I can hang my new bean definition off of. =
It's just a BeanPostProcessor that I want to create behind the scenes. =
In fact, the only reason I want to embed it inside the bean definition =
is because I'd like to imply that this tag applies to this bean =
(otherwise I'll need to provide the name of the bean so that my post =
processor can ignore other beans).
So I can see how I'd write an extension as follows:
<bean id=3D"some.id" class=3D"..." />
<myns:newtag bean=3D"some.id" attr1=3D"..." attr2=3D"..." />
<myns:newtag bean=3D"some.id" attr1=3D"..." />
The above example would be straight forward to implement based on the =
examples but the fact that I have to tie it to my original bean =
definition (by specifying bean=3D"some.id") is what I was trying to get =
around by embedding the tag within the bean definition itself.
Any suggestions on how I can do this? If I just embed my namespaces XML =
inside of a bean definition will it get invoked and if so, will it add =
my bean to the bean factory or does it need a property do hang it off =
of?
Thanks,
Bryant |