|
From: Rod J. <rod...@in...> - 2003-11-01 16:12:53
|
Cameron, I see you've now found the alias mechanism. You can define an alias upfront in the bean definition. Interesting. The BeanDefinition was originally meant to be a SPI. In fact I wanted to make it package-protected at one point. A BeanFactory is a pretty simple thing, and whether or not it uses a BeanDefinition is really down to the implementation. If we make user code dependent on that it means that implementors of BeanFactory and ListableBeanFactory have an implicit contract, which worries me. However, I guess there are legitimate issues here. A BeanIdAware interface might be better; however, it would also need to consider aliases. I did once consider it, but was able to solve the problem in hand another way. Of course multiple prototype instances might have the same id, so it couldn't be used as an equality check. Juergen, what do you think? Regards, Rod ----- Original Message ----- From: "Cameron Braid" <ca...@da...> To: <spr...@li...> Sent: Saturday, November 01, 2003 12:40 PM Subject: Re: [Springframework-developer] Bean factory getting access to its bean id > I just wanted to add that I for the second part of my question > (obtaining the bean ID for the current bean) I would implement > BeanFactoryAware and iterate through all of the bean names, calling > getBean(name) and checking for object identity. > > Does it make sense to add the ID and aliases into the > AbstractBeanDefinition and then to create a BeanDefinitionAware > interface that allows the bean to become aware ? > > Thanks again, > > Cameron > > Cameron Braid wrote: > > > 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 > |