|
From: Guillaume P. <gpo...@gl...> - 2004-10-06 04:11:05
|
Concerning OGNL, I took at stab at it to see how hard it would be to integrate. My prototype seems to work correctly, with a few adjustments needed. Would you guys be interested in a contribution from me? My implementation requires modifications in two areas. First, the a <ognl> tag should be added in the DTD, available everywhere you can use the <value> tag. In the XmlBeanDefinitionParser, the <ognl> tag would be converted to an OGNL implementation of a new Expression interface that define a class to resolve the expression given a context/BeanFactory. Then, the BeanFactory implementation would need to be modified, when it resolve ManagedList, RuntimeBeanReference, a new check would be added for the Expression class, where the expression would be resolved from the context. However, I encountered a minor issue while creating my prototype. The resolution where the expression would be converted to a value is in AbstractAutowireCapableBeanFactory, which doesn't implement ListableBeanFactory. It causes a problem because OGNL ask for a Map as context, and it calls the keySet() method on it, thus the map passed to OGNL must be able to return all the bean names in the context. A quick fix is to cast the AbstractAutowireCapableBeanFactory instance to ListableBeanFactory, since all of Spring's concrete BeanFactory implements ListableBeanFactory anyway, but it's somewhat an hack, and if someone extend AbstractAutowireCapableBeanFactory and doesn't implement ListableBeanFactory, then the OGNL wouldn't work properly. I guess it's unlikely though. I've attached the patch to this email, with the prototype for OGNL. It's working, but it doesn't have any documenation, decent tests, etc. If you guys are interested in my code, I can polish it, document it, and add a better test coverage. Let me know what you think. Regards, Guillaume ----- Original Message ----- From: "Colin Sampaleanu" <col...@ex...> To: <spr...@li...> Sent: Monday, October 04, 2004 1:32 PM Subject: Re: [Springframework-developer] PropertyPathFactoryBean > Good stuff. It overlaps of course with the mythical OGNL or expression > support which keeps getting pushed back, but in the meantime provides some > of the benefits for pretty little extra code... > > > jürgen höller [werk3AT] wrote: > >>I've just added a PropertyPathFactoryBean, following this suggestion: >> >>http://opensource.atlassian.com/projects/spring/browse/SPR-343 >> >> >>Usage examples: >> >> // target bean to be referenced by name >> <bean id="tb" class="org.springframework.beans.TestBean" >> singleton="false"> >> <property name="age"><value>10</value></property> >> <property name="spouse"> >> <bean class="org.springframework.beans.TestBean"> >> <property name="age"><value>11</value></property> >> </bean> >> </property> >> </bean> >> >> // will result in 12, which is the value of property 'age' of the inner >> bean >> <bean id="propertyPath1" >> class="org.springframework.beans.factory.config.PropertyPathFactoryBean"> >> <property name="targetObject"> >> <bean class="org.springframework.beans.TestBean"> >> <property name="age"><value>12</value></property> >> </bean> >> </property> >> <property name="propertyPath"><value>age</value></property> >> </bean> >> >> // will result in 11, which is the value of property 'spouse.age' of bean >> 'tb' >> <bean id="propertyPath2" >> class="org.springframework.beans.factory.config.PropertyPathFactoryBean"> >> <property name="targetBeanName"><value>tb</value></property> >> <property name="propertyPath"><value>spouse.age</value></property> >> </bean> >> >> // will result in 10, which is the value of property 'age' of bean 'tb' >> <bean id="tb.age" >> class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/> >> >> >>The last one, interpreting the bean name as 'beanName.property' pattern, >>is quite concise... >> > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out > more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |