|
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] |