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tDQoJQW55IGRhbW4gZm9vbCBjYW4gd3JpdGUgY29kZSB0aGF0IGEgY29tcHV0ZXIgY2Fu IHVuZGVyc3RhbmQuLi4NCglUaGUgdHJpY2sgaXMgdG8gd3JpdGUgY29kZSB0aGF0IGh1bWFucyBj YW4gdW5kZXJzdGFuZC4NCglbTWFydGluIEZvd2xlciBodHRwOi8vd3d3Lm1hcnRpbmZvd2xlci5j b20vZGlzdHJpYnV0ZWRDb21wdXRpbmcvcmVmYWN0b3JpbmcucGRmXQ0KCQ0KCQ0KCQ0KCQ0KCQ0K CS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0N CglUaGlzIFNGLm5ldCBlbWFpbCBpcyBzcG9uc29yZWQgYnk6IFNGLm5ldCBHaXZlYmFjayBQcm9n cmFtLg0KCURvZXMgU291cmNlRm9yZ2UubmV0IGhlbHAgeW91IGJlIG1vcmUgcHJvZHVjdGl2ZT8g IERvZXMgaXQNCgloZWxwIHlvdSBjcmVhdGUgYmV0dGVyIGNvZGU/ICAgU0hBUkUgVEhFIExPVkUs IGFuZCBoZWxwIHVzIGhlbHANCglZT1UhICBDbGljayBIZXJlOiBodHRwOi8vc291cmNlZm9yZ2Uu bmV0L2RvbmF0ZS8NCglfX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fXw0KCVNwcmluZ2ZyYW1ld29yay1kZXZlbG9wZXIgbWFpbGluZyBsaXN0DQoJU3ByaW5nZnJh bWV3b3JrLWRldmVsb3BlckBsaXN0cy5zb3VyY2Vmb3JnZS5uZXQNCglodHRwczovL2xpc3RzLnNv dXJjZWZvcmdlLm5ldC9saXN0cy9saXN0aW5mby9zcHJpbmdmcmFtZXdvcmstZGV2ZWxvcGVyDQoJ DQoNCg== |
|
From: Rod J. <rod...@in...> - 2003-11-01 16:15:39
|
Sounds reasonable. Thanks Juergen. Please disregard my previous email... Regards, Rod ----- Original Message ----- From: "jürgen höller [werk3AT]" <jue...@we...> To: <spr...@li...> Sent: Saturday, November 01, 2003 4:05 PM Subject: Re: [Springframework-developer] Bean factory getting access to its bean id > Cameron, > > Good points. I've repeatedly considered relaxing that XML id requirement myself, BTW, to ease BeanNameUrlHandlerMapping-mapped controllers definitions with Spring's web MVC. > > So I've just implemented the following changes: > > - There's a BeanNameAware interface now, with a setBeanName method that gets called on initialization. BTW, the BeanFactory interface calls the canonical name "name" and alias names "aliases", while the XML bean definition format adopts the XML style of an id attribute, allowing for multiple aliases via a delimited "name" attribute. > > - The "id" attribute is no longer required in the XML bean definition format. If no id is specified, the first name in the "name" attribute will be used as canonical name (all others as aliases). If no id and no name specified, an exception will get thrown. Note that you need to use the generic <ref bean=".../> syntax to reference any bean name, as the more restrictive <ref local="..."/> will be validated against local XML ids. In general, if you don't need to rely on XML id validation, always use <ref bean="..."/>. > > - Spring already had a PropertiesFactoryBean class for making a properties file in the class path available as Properties bean in the bean factory. I've reworked this to also support local properties via a "properties" bean property (to be filled via "<props>" in the XML case). It can also merge properties from a file with locally defined ones. You should be able to use that instead of your own PropertiesFactoryBean implementation. There's also a ResourcePropertiesFactoryBean that loads a properties file as application context resource (via ApplicationContext.getResourceByPath). > > If noone objects, I will commit these changes to CVS tomorrow. I guess the "id" relaxation is debatable, but I'm strongly for it as my colleagues at werk3AT tend to use BeanNameUrlHandlerMapping a lot and have repeatedly complained about the need for an additional id attribute. Cameron faces a similar use case for WebWork actions; we should ease such stuff, even if XML ids are still recommended for normal beans. > > Juergen > > > -----Ursprüngliche Nachricht----- > Von: Cameron Braid [mailto:ca...@da...] > Gesendet: Sa 01.11.2003 13:20 > An: spr...@li... > Cc: > Betreff: [[W3-SPAM]] - [Springframework-developer] Bean factory getting access to its bean id - Email found in subject > > > > Is there any way that I can allow a bean factory to find out its id > attribute from the applicationContext.xml > > i.e. I am trying to get a grip on how spring works, and therefore I am > trying to write a little integration layer to make spring an action > factory for xwork, to allow me to use spring components and > interceptors. I want to try and avoid repetition of configuration > wherever possible. > > I have it at the stage where I have a bean declaration like this : > > <bean id="defaultActionTransactionAttributes" > class="com.datacodex.spring.beans.PropertiesFactoryBean"> > <property name="properties"> > <props> > <prop key="execute">PROPAGATION_REQUIRED</prop> > </props> > </property> > </bean> > > <bean id="admin.SpringAdminAction" class="WebworkActionFactoryBean"> > <property > name="action"><value>/admin/SpringAdminAction</value></property> > <property name="transactionManager"><ref > local="transactionManager"/></property> > <property name="transactionAttributes"><ref > local="defaultActionTransactionAttributes"/></property> > </bean> > > I would like to be able to access the id="admin.SpringAdminAction" value > (or the bean name attribute) from within the WebworkActionFactoryBean > therefore removing the need to have the extra 'action' property > <property name="action"><value>/admin/SpringAdminAction</value></property>. > > Idealy I would like to use the /admin/SpringAdminAction as the bean id > to make mapping from WebWork seamless, and without needing the > conversion to '.' style. > Therefore - is there any way that the bean id can be changed to allow > any valid xml string ? Currently I am receiving an exception, from the > xml validator. Can the id atttribuet be changed to be a > > [22:12:29]INFO [XmlBeanFactory] Loading XmlBeanFactory from InputStream > [[ReadStream com.caucho.vfs.FileReadStream@190a0d6]] > [22:12:29]ERROR[ContextLoader] Failed to initialize beans in application > context: Line 44 in XML document is invalid; nested exception is: > org.xml.sax.SAXParseException: Attribute value > "/admin/SpringAdminAction" of type ID must be a name. > org.xml.sax.SAXParseException: Attribute value > "/admin/SpringAdminAction" of type ID must be a name. > at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) > at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) > at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:76) > > The dtd states that it myst be a valid XML ID, and to use the optional > name attribute if you want an illegal name. Though this will require > two identifyers for the bean, which I think is pointless. Does the ID > have to be mandatory. Can't a validation be implemented in java to > check that atleast the name or the id is supplied ? Then the same for > the <!ATTLIST ref local IDREF #IMPLIED> this could be a CDATA with java > based validation. > > Cheers, > > Cameron > > -- > Any damn fool can write code that a computer can understand... > The trick is to write code that humans can understand. > [Martin Fowler http://www.martinfowler.com/distributedComputing/refactoring.pdf] > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > NHum>xmjzyDPrqz{~{zzu~zqz~{z |
|
From: Cameron B. <ca...@da...> - 2003-11-02 03:13:58
|
Thanks .. see inline response. jürgen höller [werk3AT] wrote: >Cameron, > >Good points. I've repeatedly considered relaxing that XML id requirement myself, BTW, to ease BeanNameUrlHandlerMapping-mapped controllers definitions with Spring's web MVC. > >So I've just implemented the following changes: > >- There's a BeanNameAware interface now, with a setBeanName method that gets called on initialization. BTW, the BeanFactory interface calls the canonical name "name" and alias names "aliases", while the XML bean definition format adopts the XML style of an id attribute, allowing for multiple aliases via a delimited "name" attribute. > > > Sounds good. >- The "id" attribute is no longer required in the XML bean definition format. If no id is specified, the first name in the "name" attribute will be used as canonical name (all others as aliases). If no id and no name specified, an exception will get thrown. Note that you need to use the generic <ref bean=".../> syntax to reference any bean name, as the more restrictive <ref local="..."/> will be validated against local XML ids. In general, if you don't need to rely on XML id validation, always use <ref bean="..."/>. > > > Excellent. >- Spring already had a PropertiesFactoryBean class for making a properties file in the class path available as Properties bean in the bean factory. I've reworked this to also support local properties via a "properties" bean property (to be filled via "<props>" in the XML case). It can also merge properties from a file with locally defined ones. You should be able to use that instead of your own PropertiesFactoryBean implementation. There's also a ResourcePropertiesFactoryBean that loads a properties file as application context resource (via ApplicationContext.getResourceByPath). > > > Thanks, that is a better idea. >If noone objects, I will commit these changes to CVS tomorrow. I guess the "id" relaxation is debatable, but I'm strongly for it as my colleagues at werk3AT tend to use BeanNameUrlHandlerMapping a lot and have repeatedly complained about the need for an additional id attribute. Cameron faces a similar use case for WebWork actions; we should ease such stuff, even if XML ids are still recommended for normal beans. > > > I could live with it either way. Though I thaink that the ID should be optional since it isn't required in all cases. >Juergen > > > -----Ursprüngliche Nachricht----- > Von: Cameron Braid [mailto:ca...@da...] > Gesendet: Sa 01.11.2003 13:20 > An: spr...@li... > Cc: > Betreff: [[W3-SPAM]] - [Springframework-developer] Bean factory getting access to its bean id - Email found in subject > > > > Is there any way that I can allow a bean factory to find out its id > attribute from the applicationContext.xml > > i.e. I am trying to get a grip on how spring works, and therefore I am > trying to write a little integration layer to make spring an action > factory for xwork, to allow me to use spring components and > interceptors. I want to try and avoid repetition of configuration > wherever possible. > > I have it at the stage where I have a bean declaration like this : > > <bean id="defaultActionTransactionAttributes" > class="com.datacodex.spring.beans.PropertiesFactoryBean"> > <property name="properties"> > <props> > <prop key="execute">PROPAGATION_REQUIRED</prop> > </props> > </property> > </bean> > > <bean id="admin.SpringAdminAction" class="WebworkActionFactoryBean"> > <property > name="action"><value>/admin/SpringAdminAction</value></property> > <property name="transactionManager"><ref > local="transactionManager"/></property> > <property name="transactionAttributes"><ref > local="defaultActionTransactionAttributes"/></property> > </bean> > > I would like to be able to access the id="admin.SpringAdminAction" value > (or the bean name attribute) from within the WebworkActionFactoryBean > therefore removing the need to have the extra 'action' property > <property name="action"><value>/admin/SpringAdminAction</value></property>. > > Idealy I would like to use the /admin/SpringAdminAction as the bean id > to make mapping from WebWork seamless, and without needing the > conversion to '.' style. > Therefore - is there any way that the bean id can be changed to allow > any valid xml string ? Currently I am receiving an exception, from the > xml validator. Can the id atttribuet be changed to be a > > [22:12:29]INFO [XmlBeanFactory] Loading XmlBeanFactory from InputStream > [[ReadStream com.caucho.vfs.FileReadStream@190a0d6]] > [22:12:29]ERROR[ContextLoader] Failed to initialize beans in application > context: Line 44 in XML document is invalid; nested exception is: > org.xml.sax.SAXParseException: Attribute value > "/admin/SpringAdminAction" of type ID must be a name. > org.xml.sax.SAXParseException: Attribute value > "/admin/SpringAdminAction" of type ID must be a name. > at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) > at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) > at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:76) > > The dtd states that it myst be a valid XML ID, and to use the optional > name attribute if you want an illegal name. Though this will require > two identifyers for the bean, which I think is pointless. Does the ID > have to be mandatory. Can't a validation be implemented in java to > check that atleast the name or the id is supplied ? Then the same for > the <!ATTLIST ref local IDREF #IMPLIED> this could be a CDATA with java > based validation. > > Cheers, > > Cameron > > -- > Any damn fool can write code that a computer can understand... > The trick is to write code that humans can understand. > [Martin Fowler http://www.martinfowler.com/distributedComputing/refactoring.pdf] > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > >N?HY隊X???'???u??w?+?m?$>? ????????xZ+????*.m騭?k?ۜ?+?????^??????jכz?^??y!?DD????݅?i??^??P)brAޭ?m??????q???z?ݢv?{?)?~??{ >+?ׯzZ)z???X??X??*k?x????u?ޖ?^?X???(??~??zw???i????l???q???z???l?X??)ߣ?)?)?~??{ >+?ׯzZ)er== > -- Any damn fool can write code that a computer can understand... The trick is to write code that humans can understand. [Martin Fowler http://www.martinfowler.com/distributedComputing/refactoring.pdf] |
|
From: Cameron B. <ca...@da...> - 2003-11-05 11:59:07
|
I've just checkout this code.
The bean/@id attribute relaxing is fantastic thanks!
I can now use the Spring Framework as an Action Factory for
Xwork/WebWork with no duplcation of configuration, using spring to
define business related interceptors : components, transactions,
security and webwork to provide web/view oriented interceptors :
request-params, validation
xwork.xml snippet :
<package name="admin" namespace="/admin" extends="default">
<action name="update" class="com.project.AdminUpdateAction"
method="txUpdate">
<result name="redirect">read.action?id=${id}</result>
</action>
</package>
applicationContext.xml snippet :
<bean name="/admin/update"
class="com.datacodex.spring.webwork.WebworkActionFactoryBean">
<property name="sessionFactory"><ref
local="sessionFactory"/></property>
<property name="transactionManager"><ref
local="transactionManager"/></property>
<property name="transactionAttributes"><ref
local="defaultActionTransactionAttributes"/></property>
</bean>
very simple, neat and clean !
Thanks guys for your fantastic framework.
Cameron.
jürgen höller [werk3AT] wrote:
>Cameron,
>
>Good points. I've repeatedly considered relaxing that XML id requirement myself, BTW, to ease BeanNameUrlHandlerMapping-mapped controllers definitions with Spring's web MVC.
>
>So I've just implemented the following changes:
>
>- There's a BeanNameAware interface now, with a setBeanName method that gets called on initialization. BTW, the BeanFactory interface calls the canonical name "name" and alias names "aliases", while the XML bean definition format adopts the XML style of an id attribute, allowing for multiple aliases via a delimited "name" attribute.
>
>- The "id" attribute is no longer required in the XML bean definition format. If no id is specified, the first name in the "name" attribute will be used as canonical name (all others as aliases). If no id and no name specified, an exception will get thrown. Note that you need to use the generic <ref bean=".../> syntax to reference any bean name, as the more restrictive <ref local="..."/> will be validated against local XML ids. In general, if you don't need to rely on XML id validation, always use <ref bean="..."/>.
>
>- Spring already had a PropertiesFactoryBean class for making a properties file in the class path available as Properties bean in the bean factory. I've reworked this to also support local properties via a "properties" bean property (to be filled via "<props>" in the XML case). It can also merge properties from a file with locally defined ones. You should be able to use that instead of your own PropertiesFactoryBean implementation. There's also a ResourcePropertiesFactoryBean that loads a properties file as application context resource (via ApplicationContext.getResourceByPath).
>
>If noone objects, I will commit these changes to CVS tomorrow. I guess the "id" relaxation is debatable, but I'm strongly for it as my colleagues at werk3AT tend to use BeanNameUrlHandlerMapping a lot and have repeatedly complained about the need for an additional id attribute. Cameron faces a similar use case for WebWork actions; we should ease such stuff, even if XML ids are still recommended for normal beans.
>
>Juergen
>
>
> -----Ursprüngliche Nachricht-----
> Von: Cameron Braid [mailto:ca...@da...]
> Gesendet: Sa 01.11.2003 13:20
> An: spr...@li...
> Cc:
> Betreff: [[W3-SPAM]] - [Springframework-developer] Bean factory getting access to its bean id - Email found in subject
>
>
>
> Is there any way that I can allow a bean factory to find out its id
> attribute from the applicationContext.xml
>
> i.e. I am trying to get a grip on how spring works, and therefore I am
> trying to write a little integration layer to make spring an action
> factory for xwork, to allow me to use spring components and
> interceptors. I want to try and avoid repetition of configuration
> wherever possible.
>
> I have it at the stage where I have a bean declaration like this :
>
> <bean id="defaultActionTransactionAttributes"
> class="com.datacodex.spring.beans.PropertiesFactoryBean">
> <property name="properties">
> <props>
> <prop key="execute">PROPAGATION_REQUIRED</prop>
> </props>
> </property>
> </bean>
>
> <bean id="admin.SpringAdminAction" class="WebworkActionFactoryBean">
> <property
> name="action"><value>/admin/SpringAdminAction</value></property>
> <property name="transactionManager"><ref
> local="transactionManager"/></property>
> <property name="transactionAttributes"><ref
> local="defaultActionTransactionAttributes"/></property>
> </bean>
>
> I would like to be able to access the id="admin.SpringAdminAction" value
> (or the bean name attribute) from within the WebworkActionFactoryBean
> therefore removing the need to have the extra 'action' property
> <property name="action"><value>/admin/SpringAdminAction</value></property>.
>
> Idealy I would like to use the /admin/SpringAdminAction as the bean id
> to make mapping from WebWork seamless, and without needing the
> conversion to '.' style.
> Therefore - is there any way that the bean id can be changed to allow
> any valid xml string ? Currently I am receiving an exception, from the
> xml validator. Can the id atttribuet be changed to be a
>
> [22:12:29]INFO [XmlBeanFactory] Loading XmlBeanFactory from InputStream
> [[ReadStream com.caucho.vfs.FileReadStream@190a0d6]]
> [22:12:29]ERROR[ContextLoader] Failed to initialize beans in application
> context: Line 44 in XML document is invalid; nested exception is:
> org.xml.sax.SAXParseException: Attribute value
> "/admin/SpringAdminAction" of type ID must be a name.
> org.xml.sax.SAXParseException: Attribute value
> "/admin/SpringAdminAction" of type ID must be a name.
> at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
> at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
> at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:76)
>
> The dtd states that it myst be a valid XML ID, and to use the optional
> name attribute if you want an illegal name. Though this will require
> two identifyers for the bean, which I think is pointless. Does the ID
> have to be mandatory. Can't a validation be implemented in java to
> check that atleast the name or the id is supplied ? Then the same for
> the <!ATTLIST ref local IDREF #IMPLIED> this could be a CDATA with java
> based validation.
>
> Cheers,
>
> Cameron
>
> --
> Any damn fool can write code that a computer can understand...
> The trick is to write code that humans can understand.
> [Martin Fowler http://www.martinfowler.com/distributedComputing/refactoring.pdf]
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>N?HY隊X???'???u??w?+?m?$>? ????????xZ+????*.m騭?k?ۜ?+?????^??????jכz?^??y!?DD????݅?i??^??P)brAޭ?m??????q???z?ݢv?{?)?~??{
>+?ׯzZ)z???X??X??*k?x????u?ޖ?^?X???(??~??zw???i????l???q???z???l?X??)ߣ?)?)?~??{
>+?ׯzZ)er==
>
--
Any damn fool can write code that a computer can understand...
The trick is to write code that humans can understand.
[Martin Fowler http://www.martinfowler.com/distributedComputing/refactoring.pdf]
|