Dave,
We do plan on eventually supporting java objects directly via. a syntax like class="java:coldfusion.server.ServiceFactory.DataSourceService" but it's just not there yet. In the meantime, you can use a factory-bean as a workaround. Write a simple cfc like this (untested):
<cfcomponent name="JavaObjectFactory">
<cffunction name="createJavaObject" returntype="any">
<cfargument name="className" type="string"/>
<cfreturn createObject("java",arguments.className)/>
</cffunction>
</cfcomponent>
You can then use that CFC to register java classes in CS like this:
<bean id="javaObjectFactory" class="path.to.JavaObjectFactory"/>
<bean id="datasourceService"
factory-bean="javaObjectFactory"
factory-method="createJavaObject">
<constructor-arg name="className">
<value>coldfusion.server.ServiceFactory.DataSourceService</value>
</constructor-arg>
</bean>
You can then use the "datasourceService" bean like any other bean in CS. Obviously if you wanted to handle arguments passed to the constructor of your java object it would be a little more work, but not too bad. This also would meet your need of transparency to the client... the CS beanFactory could care less whether it returns a CFC or Java Object (or string, or array, or struct) when you call getBean(...)
Hope that helps....
thanks,
Dave Ross
P.S. my brother's name is Merrill. Kinda weird.
On 9/4/06, Dave Merrill <[EMAIL PROTECTED]> wrote:
I should also mention that one of the goals behind our current (very basic)
ObjectFactory was to allow the returned objects to be either java or cfcs,
without the calling code's knowledge. Code just asks for an object by its
registered name, and if it's implemented as a cfc today and java tomorrow,
nothing changes.
I'd love to use ColdSpring instead, for its many more advanced capabilities,
but this cf/java transparency is a key longer-term strategy.
Dave Merrill
> Can anyone suggest a way to inject a cfc with a java object, like this:
>
> -----
> <bean id="datasourceService"
> class="coldfusion.server.ServiceFactory.DataSourceService" />
>
> then
>
> <bean id="model" class="cf_tests.coldspring.model">
> <constructor-arg name="datasourceService">
> <ref bean="datasourceService" />
> </constructor-arg>
> </bean>
> -----
>
> Apparently ColdSpring assumes that all objects it creates are CFCs, so it
> uses createOject('component', '...'); that's in
> beans.BeanDefinition.getBeanInstance().
>
> Is there another approach that doesn't run into this? If not, has anyone
> thought about what it would take to modify ColdSpring to make it possible?
>
> Dave Merrill
>
>
>
>
