You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Will Glass-Husain <wg...@forio.com> on 2004/05/03 00:19:40 UTC

Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Matt,

Thanks for the note - appreciate the pragmatic comment.

Are there any other changes or new capabilities you'd find useful in a data
resource loader?

Best,
WILL

----- Original Message ----- 
From: "Matt Raible" <li...@raibledesigns.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Thursday, April 29, 2004 7:10 PM
Subject: Re: Create a DataSourceResourceLoader that can be wired to the
datasource with IoC


> I don't care how things are done, but Will's patch (and a subsequent
> modification in Spring) made this DataSource-use-outside-of-JNDI work
> quite nicely.  I don't car as much about architecture as you guys - I
> just want to get something that works.
>
> Matt
>
> On Apr 29, 2004, at 5:30 PM, Will Glass-Husain wrote:
>
> > Hi Geir,
> >
> > Not sure what your specific objection is.  My proposed patch adds some
> > flexibility to the resource loaders by allowing an instance to be
> > passed in
> > instead of just the class name.  There's already a precedent for this
> > (the
> > loggers).  And it's entirely backwards compatible.  With the addition
> > of a
> > setter to the DataSourceResourceLoader it solves the problem.  (Matt's
> > tested and applied the patch:, although I warned him it was at his own
> > risk).
> >
> > I'm open to your suggested alternative (have the Spring developer use
> > the
> > Application attributes to pass the DataSource to a custom loader) but
> > I'm
> > not familiar enough with Spring to know if this is feasible.  As we'd
> > framed
> > it earlier, the request is to configure the resource loader and
> > Velocity
> > with a live DataSource by using with either Property settings or
> > bean-type
> > setters.   This would be a different route.  Matt, can you weigh in on
> > Geir's idea?
> >
> > Best,
> >
> > WILL
> >
> > ----- Original Message -----
> > From: "Geir Magnusson Jr" <ge...@4quarters.com>
> > To: "Velocity Developers List" <ve...@jakarta.apache.org>
> > Sent: Thursday, April 29, 2004 4:12 PM
> > Subject: Re: Create a DataSourceResourceLoader that can be wired to the
> > datasource with IoC
> >
> >
> >> I'm a little suspicious, as we have a facility for an application to
> >> pass whatever they want to down into components - application
> >> attributes.  The original driving case was (I think) to send something
> >> to a loader.
> >>
> >> For example, it's how the webapp resource loader gets and uses the
> >> servlet context.
> >>
> >> So I'd rather see us fix the DatasourceResourceLoader....
> >>
> >> On Apr 27, 2004, at 2:38 PM, Will Glass-Husain wrote:
> >>
> >>> Hi,
> >>>
> >>> I'd like to address this issue.  Any comments on my suggested
> >>> approach?
> >>> Specifically, I thought we could allow RuntimeInstance to take a live
> >>> instance of a resource loader as a property as an alternative to a
> >>> class
> >>> name.  I've recently discovered that Velocity accepts loggers passed
> >>> in this
> >>> way.
> >>>
> >>> from: EventHandlingTestCase.java
> >>>
> >>>   Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, this );
> >>>   Velocity.init();
> >>>
> >>> The basic idea is that the developer instantiates a resource loader,
> >>> configures it with a JNDI name and then passes it to Velocity.
> >>>
> >>> Inversion of Control and Spring are hot topics now in the Java / open
> >>> source
> >>> community, I think it'd be nice to modify the tool to be compatible.
> >>> Matt
> >>> Raible's an ardent Spring user, so we can get immediate feedback.
> >>>
> >>> Any comments or suggestions before I write this patch?
> >>>
> >>> WILLL
> >>>
> >>>
> >>>
> >>>
> >>> ----- Original Message -----
> >>> From: <bu...@apache.org>
> >>> To: <ve...@jakarta.apache.org>
> >>> Sent: Monday, April 26, 2004 8:54 PM
> >>> Subject: DO NOT REPLY [Bug 28611] New: - Create a
> >>> DataSourceResourceLoader
> >>> that can be wired to the datasource with IoC
> >>>
> >>>
> >>>> DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
> >>>> RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
> >>>> <http://issues.apache.org/bugzilla/show_bug.cgi?id=28611>.
> >>>> ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
> >>>> INSERTED IN THE BUG DATABASE.
> >>>>
> >>>> http://issues.apache.org/bugzilla/show_bug.cgi?id=28611
> >>>>
> >>>> Create a DataSourceResourceLoader that can be wired to the
> >>>> datasource
> >>>> with
> >>> IoC
> >>>>
> >>>>            Summary: Create a DataSourceResourceLoader that can be
> >>>> wired to
> >>>>                     the datasource with IoC
> >>>>            Product: Velocity
> >>>>            Version: 1.4
> >>>>           Platform: Other
> >>>>         OS/Version: Other
> >>>>             Status: NEW
> >>>>           Severity: Enhancement
> >>>>           Priority: Other
> >>>>          Component: Source
> >>>>         AssignedTo: velocity-dev@jakarta.apache.org
> >>>>         ReportedBy: matt@raibledesigns.com
> >>>>
> >>>>
> >>>> I'd like to create a ResourceLoader similar to
> >>>> DataSourceResourceLoader,
> >>> except that I'd like to set
> >>>> the DataSource via IoC (in Spring).  The main reason for this is so
> >>>> my
> >>> database-loading of templates
> >>>> does not depend on a JNDI connection.
> >>>>
> >>>> The main problem is how to manage a ResourceLoader with Spring and
> >>>> then
> >>> set it declaratively on its
> >>>> VelocityEngine - rather than via properties.
> >>>>
> >>>> <suggested patch from Will Glass-Husain>
> >>>> Does this mean that you'd need to pass in an instance of a resource
> >>> manager
> >>>> (initialized with the datasource) to VelocityEngine, rather than
> >>>> just
> >>>> set
> >>>> the class name as a property? (MR - Yes)
> >>>>
> >>>> As I understand the source code, this doesn't seem possible.  But I
> >>>> think
> >>> a
> >>>> patch wouldn't be difficult.  (a change to
> >>>> RuntimeInstance.initializeResourceManager) to look for an instance
> >>>> of
> >>>> the
> >>>> class as well as the class name.  Something similar to
> >>>> LogManager.createLogSystem which accepts as a property the class
> >>>> name
> >>>> of a
> >>>> class that implements LogSystem, or an instance of the class itself.
> >>>> </suggested patch>
> >>>>
> >>>> -------------------------------------------------------------------- 
> >>>> -
> >>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> >>>> For additional commands, e-mail:
> >>>> velocity-dev-help@jakarta.apache.org
> >>>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >>>
> >>>
> >> -- 
> >> Geir Magnusson Jr                                   203-247-1713(m)
> >> geir@4quarters.com
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Will Glass-Husain <wg...@forio.com>.
Thanks for sharing that.  Let us know if you have other useful tips...

WILL

On 4/24/06, Arvind Srinivasan <as...@worldbank.org> wrote:
>
> Will Glass-Husain <wglass <at> forio.com> writes:
>
> >
> > Matt,
> >
> > Thanks for the note - appreciate the pragmatic comment.
> >
> > Are there any other changes or new capabilities you'd find useful in a data
> > resource loader?
> >
> > Best,
> > WILL
> >
>
> After all the research based on Matt's and Will's work - i still had problems
> getting DatasourceResourceLoader to work with spring.
>
> The thing that seemed to happen was - The dataSource object seemed to be 'set'
> alright, but then subsequently new instance of 'DataSourceResourceLoader' gets
> initialized despite have a singleton attribute set to true...
>
> So finally took a different approach to get it work...Documenting here, so
> that anyone that may stumble across might find it helpful.
>
> <!-- spring configuraiton-->
> <bean id="velocityEngine" singleton="true"
> class="org.springframework.ui.velocity.VelocityEngineFactoryBean" >
>                <property name="velocityProperties">
>                        <props>
>                                 <prop key="resource.loader">ds</prop>
>                                 <prop
> key="ds.resource.loader.class">org.apache.velocity.runtime.resource.loader.Data
> SourceResourceLoader</prop>
>                                 <prop
> key="ds.resource.loader.resource.table">tb_velocity_template</prop>
>                                 <prop
> key="ds.resource.loader.resource.keycolumn">id_template</prop>
>                                 <prop
> key="ds.resource.loader.resource.templatecolumn">template_definition</prop>
>                                 <prop
> key="ds.resource.loader.resource.timestampcolumn">template_timestamp</prop>
>                                 <prop
> key="ds.resource.loader.resource.datasource">java:comp/env/jdbc/sampdb</prop>
>                        </props>
>                </property>
>
> <!--Datasource configration in Tomcat 5.5-->
> /conf/Catalina/<<host>>/<<appcontext>>.xml
>
> <Context path="/xxx" docBase="xxx" debug="1" reloadable="true">
>  <Resource name="jdbc/sampdb" auth="Container"
>    type="javax.sql.DataSource"
>    driverClassName="com.mysql.jdbc.Driver"
>    url="jdbc:mysql://localhost:3306/blogs" username="admin"
>    password="xxx" maxActive="20" maxIdle="10" maxWait="-1" />
> </Context>
>
> --
> Arvind
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>


--
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Arvind Srinivasan <as...@worldbank.org>.
Will Glass-Husain <wglass <at> forio.com> writes:

> 
> Matt,
> 
> Thanks for the note - appreciate the pragmatic comment.
> 
> Are there any other changes or new capabilities you'd find useful in a data
> resource loader?
> 
> Best,
> WILL
> 

After all the research based on Matt's and Will's work - i still had problems 
getting DatasourceResourceLoader to work with spring.

The thing that seemed to happen was - The dataSource object seemed to be 'set' 
alright, but then subsequently new instance of 'DataSourceResourceLoader' gets 
initialized despite have a singleton attribute set to true...

So finally took a different approach to get it work...Documenting here, so 
that anyone that may stumble across might find it helpful.

<!-- spring configuraiton-->
<bean id="velocityEngine" singleton="true" 
class="org.springframework.ui.velocity.VelocityEngineFactoryBean" >
		<property name="velocityProperties">
			<props>
				 <prop key="resource.loader">ds</prop>
				 <prop 
key="ds.resource.loader.class">org.apache.velocity.runtime.resource.loader.Data
SourceResourceLoader</prop>
				 <prop 
key="ds.resource.loader.resource.table">tb_velocity_template</prop>
				 <prop 
key="ds.resource.loader.resource.keycolumn">id_template</prop>
				 <prop 
key="ds.resource.loader.resource.templatecolumn">template_definition</prop>
				 <prop 
key="ds.resource.loader.resource.timestampcolumn">template_timestamp</prop>
				 <prop 
key="ds.resource.loader.resource.datasource">java:comp/env/jdbc/sampdb</prop>
			</props>
		</property> 

<!--Datasource configration in Tomcat 5.5-->
/conf/Catalina/<<host>>/<<appcontext>>.xml

<Context path="/xxx" docBase="xxx" debug="1" reloadable="true">
  <Resource name="jdbc/sampdb" auth="Container"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/blogs" username="admin"
    password="xxx" maxActive="20" maxIdle="10" maxWait="-1" />
</Context>

--
Arvind


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On May 3, 2004, at 2:08 AM, Matt Raible wrote:

> The only other one I can think that might be usefull is a URL
> ResourceLoader (it might already exists, I haven't checked).

It exists, but not in core...  in whiteboard or contrib, I think.  It's 
been around for a while and people that need it find it useful.


>   This would
> allow for templates to be stored on an intranet or a website with high
> availability.  I probably wouldn't use it, but it *sounds* good. ;-)
>
> Thanks,
>
> Matt
>
>> -----Original Message-----
>> From: Will Glass-Husain [mailto:wglass@forio.com]
>> Sent: Sunday, May 02, 2004 4:20 PM
>> To: Velocity Developers List; Matt Raible
>> Cc: Matt Raible
>> Subject: Re: Create a DataSourceResourceLoader that can be
>> wired to the datasource with IoC
>>
>>
>> Matt,
>>
>> Thanks for the note - appreciate the pragmatic comment.
>>
>> Are there any other changes or new capabilities you'd find
>> useful in a data resource loader?
>>
>> Best,
>> WILL
>>
>> ----- Original Message -----
>> From: "Matt Raible" <li...@raibledesigns.com>
>> To: "Velocity Developers List" <ve...@jakarta.apache.org>
>> Sent: Thursday, April 29, 2004 7:10 PM
>> Subject: Re: Create a DataSourceResourceLoader that can be
>> wired to the datasource with IoC
>>
>>
>>> I don't care how things are done, but Will's patch (and a
>> subsequent
>>> modification in Spring) made this
>> DataSource-use-outside-of-JNDI work
>>> quite nicely.  I don't car as much about architecture as
>> you guys - I
>>> just want to get something that works.
>>>
>>> Matt
>>>
>>> On Apr 29, 2004, at 5:30 PM, Will Glass-Husain wrote:
>>>
>>>> Hi Geir,
>>>>
>>>> Not sure what your specific objection is.  My proposed patch adds
>>>> some flexibility to the resource loaders by allowing an
>> instance to
>>>> be passed in instead of just the class name.  There's already a
>>>> precedent for this (the
>>>> loggers).  And it's entirely backwards compatible.  With
>> the addition
>>>> of a
>>>> setter to the DataSourceResourceLoader it solves the
>> problem.  (Matt's
>>>> tested and applied the patch:, although I warned him it
>> was at his own
>>>> risk).
>>>>
>>>> I'm open to your suggested alternative (have the Spring developer
>>>> use the Application attributes to pass the DataSource to a custom
>>>> loader) but I'm
>>>> not familiar enough with Spring to know if this is
>> feasible.  As we'd
>>>> framed
>>>> it earlier, the request is to configure the resource loader and
>>>> Velocity
>>>> with a live DataSource by using with either Property settings or
>>>> bean-type
>>>> setters.   This would be a different route.  Matt, can
>> you weigh in on
>>>> Geir's idea?
>>>>
>>>> Best,
>>>>
>>>> WILL
>>>>
>>>> ----- Original Message -----
>>>> From: "Geir Magnusson Jr" <ge...@4quarters.com>
>>>> To: "Velocity Developers List" <ve...@jakarta.apache.org>
>>>> Sent: Thursday, April 29, 2004 4:12 PM
>>>> Subject: Re: Create a DataSourceResourceLoader that can
>> be wired to
>>>> the datasource with IoC
>>>>
>>>>
>>>>> I'm a little suspicious, as we have a facility for an
>> application
>>>>> to pass whatever they want to down into components - application
>>>>> attributes.  The original driving case was (I think) to send
>>>>> something to a loader.
>>>>>
>>>>> For example, it's how the webapp resource loader gets
>> and uses the
>>>>> servlet context.
>>>>>
>>>>> So I'd rather see us fix the DatasourceResourceLoader....
>>>>>
>>>>> On Apr 27, 2004, at 2:38 PM, Will Glass-Husain wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'd like to address this issue.  Any comments on my suggested
>>>>>> approach? Specifically, I thought we could allow
>> RuntimeInstance
>>>>>> to take a live instance of a resource loader as a
>> property as an
>>>>>> alternative to a class
>>>>>> name.  I've recently discovered that Velocity accepts
>> loggers passed
>>>>>> in this
>>>>>> way.
>>>>>>
>>>>>> from: EventHandlingTestCase.java
>>>>>>
>>>>>>   Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, this );
>>>>>>   Velocity.init();
>>>>>>
>>>>>> The basic idea is that the developer instantiates a resource
>>>>>> loader, configures it with a JNDI name and then passes it to
>>>>>> Velocity.
>>>>>>
>>>>>> Inversion of Control and Spring are hot topics now in
>> the Java /
>>>>>> open source community, I think it'd be nice to modify
>> the tool to
>>>>>> be compatible. Matt
>>>>>> Raible's an ardent Spring user, so we can get immediate
>> feedback.
>>>>>>
>>>>>> Any comments or suggestions before I write this patch?
>>>>>>
>>>>>> WILLL
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ----- Original Message -----
>>>>>> From: <bu...@apache.org>
>>>>>> To: <ve...@jakarta.apache.org>
>>>>>> Sent: Monday, April 26, 2004 8:54 PM
>>>>>> Subject: DO NOT REPLY [Bug 28611] New: - Create a
>>>>>> DataSourceResourceLoader that can be wired to the
>> datasource with
>>>>>> IoC
>>>>>>
>>>>>>
>>>>>>> DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED
>>>>>>> COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
>>>>>>> <http://issues.apache.org/bugzilla/show_bug.cgi?id=28611>.
>>>>>>> ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED
>> AND INSERTED
>>>>>>> IN THE BUG DATABASE.
>>>>>>>
>>>>>>> http://issues.apache.org/bugzilla/show_bug.cgi?id=28611
>>>>>>>
>>>>>>> Create a DataSourceResourceLoader that can be wired to the
>>>>>>> datasource with
>>>>>> IoC
>>>>>>>
>>>>>>>            Summary: Create a DataSourceResourceLoader
>> that can be
>>>>>>> wired to
>>>>>>>                     the datasource with IoC
>>>>>>>            Product: Velocity
>>>>>>>            Version: 1.4
>>>>>>>           Platform: Other
>>>>>>>         OS/Version: Other
>>>>>>>             Status: NEW
>>>>>>>           Severity: Enhancement
>>>>>>>           Priority: Other
>>>>>>>          Component: Source
>>>>>>>         AssignedTo: velocity-dev@jakarta.apache.org
>>>>>>>         ReportedBy: matt@raibledesigns.com
>>>>>>>
>>>>>>>
>>>>>>> I'd like to create a ResourceLoader similar to
>>>>>>> DataSourceResourceLoader,
>>>>>> except that I'd like to set
>>>>>>> the DataSource via IoC (in Spring).  The main reason
>> for this is
>>>>>>> so my
>>>>>> database-loading of templates
>>>>>>> does not depend on a JNDI connection.
>>>>>>>
>>>>>>> The main problem is how to manage a ResourceLoader with Spring
>>>>>>> and then
>>>>>> set it declaratively on its
>>>>>>> VelocityEngine - rather than via properties.
>>>>>>>
>>>>>>> <suggested patch from Will Glass-Husain>
>>>>>>> Does this mean that you'd need to pass in an instance of a
>>>>>>> resource
>>>>>> manager
>>>>>>> (initialized with the datasource) to VelocityEngine,
>> rather than
>>>>>>> just set
>>>>>>> the class name as a property? (MR - Yes)
>>>>>>>
>>>>>>> As I understand the source code, this doesn't seem
>> possible.  But
>>>>>>> I think
>>>>>> a
>>>>>>> patch wouldn't be difficult.  (a change to
>>>>>>> RuntimeInstance.initializeResourceManager) to look for an
>>>>>>> instance of the
>>>>>>> class as well as the class name.  Something similar to
>>>>>>> LogManager.createLogSystem which accepts as a property
>> the class
>>>>>>> name
>>>>>>> of a
>>>>>>> class that implements LogSystem, or an instance of the
>> class itself.
>>>>>>> </suggested patch>
>>>>>>>
>>>>>>>
>> -----------------------------------------------------------------
>>>>>>> ---
>>>>>>> -
>>>>>>> To unsubscribe, e-mail:
>> velocity-dev-unsubscribe@jakarta.apache.org
>>>>>>> For additional commands, e-mail:
>>>>>>> velocity-dev-help@jakarta.apache.org
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>> ------------------------------------------------------------------
>>>>>> ---
>>>>>> To unsubscribe, e-mail:
>> velocity-dev-unsubscribe@jakarta.apache.org
>>>>>> For additional commands, e-mail:
>> velocity-dev-help@jakarta.apache.org
>>>>>>
>>>>>>
>>>>> -- 
>>>>> Geir Magnusson Jr
>> 203-247-1713(m)
>>>>> geir@4quarters.com
>>>>>
>>>>>
>>>>>
>> -------------------------------------------------------------------
>>>>> --
>>>>> To unsubscribe, e-mail:
>> velocity-dev-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail:
>> velocity-dev-help@jakarta.apache.org
>>>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:
>> velocity-dev-help@jakarta.apache.org
>>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


RE: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Matt Raible <li...@raibledesigns.com>.
The only other one I can think that might be usefull is a URL
ResourceLoader (it might already exists, I haven't checked).  This would
allow for templates to be stored on an intranet or a website with high
availability.  I probably wouldn't use it, but it *sounds* good. ;-)

Thanks,

Matt

> -----Original Message-----
> From: Will Glass-Husain [mailto:wglass@forio.com] 
> Sent: Sunday, May 02, 2004 4:20 PM
> To: Velocity Developers List; Matt Raible
> Cc: Matt Raible
> Subject: Re: Create a DataSourceResourceLoader that can be 
> wired to the datasource with IoC
> 
> 
> Matt,
> 
> Thanks for the note - appreciate the pragmatic comment.
> 
> Are there any other changes or new capabilities you'd find 
> useful in a data resource loader?
> 
> Best,
> WILL
> 
> ----- Original Message ----- 
> From: "Matt Raible" <li...@raibledesigns.com>
> To: "Velocity Developers List" <ve...@jakarta.apache.org>
> Sent: Thursday, April 29, 2004 7:10 PM
> Subject: Re: Create a DataSourceResourceLoader that can be 
> wired to the datasource with IoC
> 
> 
> > I don't care how things are done, but Will's patch (and a 
> subsequent 
> > modification in Spring) made this 
> DataSource-use-outside-of-JNDI work 
> > quite nicely.  I don't car as much about architecture as 
> you guys - I 
> > just want to get something that works.
> >
> > Matt
> >
> > On Apr 29, 2004, at 5:30 PM, Will Glass-Husain wrote:
> >
> > > Hi Geir,
> > >
> > > Not sure what your specific objection is.  My proposed patch adds 
> > > some flexibility to the resource loaders by allowing an 
> instance to 
> > > be passed in instead of just the class name.  There's already a 
> > > precedent for this (the
> > > loggers).  And it's entirely backwards compatible.  With 
> the addition
> > > of a
> > > setter to the DataSourceResourceLoader it solves the 
> problem.  (Matt's
> > > tested and applied the patch:, although I warned him it 
> was at his own
> > > risk).
> > >
> > > I'm open to your suggested alternative (have the Spring developer 
> > > use the Application attributes to pass the DataSource to a custom 
> > > loader) but I'm
> > > not familiar enough with Spring to know if this is 
> feasible.  As we'd
> > > framed
> > > it earlier, the request is to configure the resource loader and
> > > Velocity
> > > with a live DataSource by using with either Property settings or
> > > bean-type
> > > setters.   This would be a different route.  Matt, can 
> you weigh in on
> > > Geir's idea?
> > >
> > > Best,
> > >
> > > WILL
> > >
> > > ----- Original Message -----
> > > From: "Geir Magnusson Jr" <ge...@4quarters.com>
> > > To: "Velocity Developers List" <ve...@jakarta.apache.org>
> > > Sent: Thursday, April 29, 2004 4:12 PM
> > > Subject: Re: Create a DataSourceResourceLoader that can 
> be wired to 
> > > the datasource with IoC
> > >
> > >
> > >> I'm a little suspicious, as we have a facility for an 
> application 
> > >> to pass whatever they want to down into components - application 
> > >> attributes.  The original driving case was (I think) to send 
> > >> something to a loader.
> > >>
> > >> For example, it's how the webapp resource loader gets 
> and uses the 
> > >> servlet context.
> > >>
> > >> So I'd rather see us fix the DatasourceResourceLoader....
> > >>
> > >> On Apr 27, 2004, at 2:38 PM, Will Glass-Husain wrote:
> > >>
> > >>> Hi,
> > >>>
> > >>> I'd like to address this issue.  Any comments on my suggested 
> > >>> approach? Specifically, I thought we could allow 
> RuntimeInstance 
> > >>> to take a live instance of a resource loader as a 
> property as an 
> > >>> alternative to a class
> > >>> name.  I've recently discovered that Velocity accepts 
> loggers passed
> > >>> in this
> > >>> way.
> > >>>
> > >>> from: EventHandlingTestCase.java
> > >>>
> > >>>   Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, this );
> > >>>   Velocity.init();
> > >>>
> > >>> The basic idea is that the developer instantiates a resource 
> > >>> loader, configures it with a JNDI name and then passes it to 
> > >>> Velocity.
> > >>>
> > >>> Inversion of Control and Spring are hot topics now in 
> the Java / 
> > >>> open source community, I think it'd be nice to modify 
> the tool to 
> > >>> be compatible. Matt
> > >>> Raible's an ardent Spring user, so we can get immediate 
> feedback.
> > >>>
> > >>> Any comments or suggestions before I write this patch?
> > >>>
> > >>> WILLL
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> ----- Original Message -----
> > >>> From: <bu...@apache.org>
> > >>> To: <ve...@jakarta.apache.org>
> > >>> Sent: Monday, April 26, 2004 8:54 PM
> > >>> Subject: DO NOT REPLY [Bug 28611] New: - Create a 
> > >>> DataSourceResourceLoader that can be wired to the 
> datasource with 
> > >>> IoC
> > >>>
> > >>>
> > >>>> DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED 
> > >>>> COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT 
> > >>>> <http://issues.apache.org/bugzilla/show_bug.cgi?id=28611>.
> > >>>> ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED 
> AND INSERTED 
> > >>>> IN THE BUG DATABASE.
> > >>>>
> > >>>> http://issues.apache.org/bugzilla/show_bug.cgi?id=28611
> > >>>>
> > >>>> Create a DataSourceResourceLoader that can be wired to the 
> > >>>> datasource with
> > >>> IoC
> > >>>>
> > >>>>            Summary: Create a DataSourceResourceLoader 
> that can be 
> > >>>> wired to
> > >>>>                     the datasource with IoC
> > >>>>            Product: Velocity
> > >>>>            Version: 1.4
> > >>>>           Platform: Other
> > >>>>         OS/Version: Other
> > >>>>             Status: NEW
> > >>>>           Severity: Enhancement
> > >>>>           Priority: Other
> > >>>>          Component: Source
> > >>>>         AssignedTo: velocity-dev@jakarta.apache.org
> > >>>>         ReportedBy: matt@raibledesigns.com
> > >>>>
> > >>>>
> > >>>> I'd like to create a ResourceLoader similar to 
> > >>>> DataSourceResourceLoader,
> > >>> except that I'd like to set
> > >>>> the DataSource via IoC (in Spring).  The main reason 
> for this is 
> > >>>> so my
> > >>> database-loading of templates
> > >>>> does not depend on a JNDI connection.
> > >>>>
> > >>>> The main problem is how to manage a ResourceLoader with Spring 
> > >>>> and then
> > >>> set it declaratively on its
> > >>>> VelocityEngine - rather than via properties.
> > >>>>
> > >>>> <suggested patch from Will Glass-Husain>
> > >>>> Does this mean that you'd need to pass in an instance of a 
> > >>>> resource
> > >>> manager
> > >>>> (initialized with the datasource) to VelocityEngine, 
> rather than 
> > >>>> just set
> > >>>> the class name as a property? (MR - Yes)
> > >>>>
> > >>>> As I understand the source code, this doesn't seem 
> possible.  But 
> > >>>> I think
> > >>> a
> > >>>> patch wouldn't be difficult.  (a change to
> > >>>> RuntimeInstance.initializeResourceManager) to look for an 
> > >>>> instance of the
> > >>>> class as well as the class name.  Something similar to
> > >>>> LogManager.createLogSystem which accepts as a property 
> the class
> > >>>> name
> > >>>> of a
> > >>>> class that implements LogSystem, or an instance of the 
> class itself.
> > >>>> </suggested patch>
> > >>>>
> > >>>> 
> -----------------------------------------------------------------
> > >>>> ---
> > >>>> -
> > >>>> To unsubscribe, e-mail: 
> velocity-dev-unsubscribe@jakarta.apache.org
> > >>>> For additional commands, e-mail:
> > >>>> velocity-dev-help@jakarta.apache.org
> > >>>>
> > >>>
> > >>>
> > >>> 
> ------------------------------------------------------------------
> > >>> ---
> > >>> To unsubscribe, e-mail: 
> velocity-dev-unsubscribe@jakarta.apache.org
> > >>> For additional commands, e-mail: 
> velocity-dev-help@jakarta.apache.org
> > >>>
> > >>>
> > >> -- 
> > >> Geir Magnusson Jr                                   
> 203-247-1713(m)
> > >> geir@4quarters.com
> > >>
> > >>
> > >> 
> -------------------------------------------------------------------
> > >> --
> > >> To unsubscribe, e-mail: 
> velocity-dev-unsubscribe@jakarta.apache.org
> > >> For additional commands, e-mail: 
> velocity-dev-help@jakarta.apache.org
> > >>
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: 
> velocity-dev-help@jakarta.apache.org
> >
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On May 3, 2004, at 6:37 AM, Konstantin Priblouda wrote:

>
> --- Will Glass-Husain <wg...@forio.com> wrote:
>> Matt,
>>
>> Thanks for the note - appreciate the pragmatic
>> comment.
>>
>> Are there any other changes or new capabilities
>> you'd find useful in a data
>> resource loader?
>>
>> Best,
>> WILL
>
> Though I'm not Matt...

And you don't play him on TV?

>
> I would find context-awearness really usefull.
> ( for resource loaders )  - In my content management
> system content is itself template, which shall be
> rendered through velocity ( index entries, decision
> what media to embedd, link formatting etc. )
> And only convenietn mean to create velocity template
> out of stream is resource loader. And unfortunately
> this resource loader is not aware of execution context
> - only application properites
> ( ok , I can put some glue stuff in those app
> propeties and use servlet filter to establish
> reference and such... I'm already doing this, and I'm
> not happy because my portal alerteady containes a lot
> of filters, and they are really sourceof errors  )
>
> Instead I would favor access to context for resource
> loaders - so it can pull everything it needs out of my
> pico container :)

There are some big problems here because resource management isn't 
"render context" oriented, it's global.  Generally speaking, any number 
of requests can ask for the same template and use that template with 
unique contexts for each requests rendering. (Thinking in web terms of 
requests).

Add to that the complexity of arbitrary requests at render time using 
#parse() and you have a problem.

One solution I can think of is to have a custom resource loader and an 
application attribute in which you can register a context with a unique 
template 'name', and have your resource loader use the app attribute to 
recover the execution context based on that name.

Thinking out loud, your code does something like

	MyThingy myThingy = new MyThingy();

	ve.setApplicationAttribute("org.Konstantin.Priblouda.thingy", 
myThingy);

at startup, and then at runtime, for each rendering :

	ContextWrapper cw = new ContextWrapper(templateName, context);

	String fakeTemplateNamePrefix = myThingy.register(cw);

	Template t = ve.getTemplate(fakeTemplateNamePrefix + templateName);

your resource loader could do something like

     public synchronized InputStream getResourceStream(String 
templateName)
         throws ResourceNotFoundException
     {
		MyThingy t = 
rsvc.getApplicationAttribute("org.Konstantin.Priblouda.thingy");

		ContextWrapper myContext = t.getRegisteredContext(templateName);

		String realTemplateName = myContext.getRealTemplateName();

		return super.getResourceStream(realTemplateName);
	}

And to solve the problem of #parse(), you'd prepend the prefix to any 
real template name so that it would be unique in cache and this 
approach would work.

>
> Well, if we speak about dreams, it should be possible
> to bypass resource loader at all conveniently  - so I
> can create and execute template directly off-stream
> ( or do I miss something in velocity code? )

You can sort of do that.  You can use

VelocityEngine.evaluate(Context context, Writer writer,
                                     String logTag, Reader reader)
         throws ParseErrorException, MethodInvocationException,

to just render a stream.  You pay the overhead of parsing the stream to 
a template each time, but if your templates are request specific, it 
may not matter.

If it does, I have a similar

Template getTemplate(Reader)

that I use so you can do your own resource management.  But I've not 
put it in because I didn't think anyone else needed it...

geir

>
>
> regards,
>
> =====
> ----[ Konstantin Pribluda ( ko5tik ) ]----------------
> Zu Verstärkung meines Teams suche ich ab Sofort einen
> Softwareentwickler[In] für die Festanstellung.
> Arbeitsort: Mainz
> Skills:  Programieren, Kentnisse in OpenSource-Bereich
> ----[ http://www.pribluda.de ]------------------------
>
>
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Win a $20,000 Career Makeover at Yahoo! HotJobs
> http://hotjobs.sweepstakes.yahoo.com/careermakeover
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On May 3, 2004, at 10:27 AM, Will Glass-Husain wrote:

> Use my event handler patch and build a IncludeEventHandler.
>
> Then resources loaded in via #include or #parse can be selected as 
> needed
> according to the context.

that only solves one part of it, if the resource was #included or 
#parsed

>
> WILL
>
> ----- Original Message -----
> From: "Konstantin Priblouda" <kp...@yahoo.com>
> To: "Velocity Developers List" <ve...@jakarta.apache.org>
> Sent: Monday, May 03, 2004 3:37 AM
> Subject: Re: Create a DataSourceResourceLoader that can be wired to the
> datasource with IoC
>
>
>>
>> Instead I would favor access to context for resource
>> loaders - so it can pull everything it needs out of my
>> pico container :)
>>
>> Well, if we speak about dreams, it should be possible
>> to bypass resource loader at all conveniently  - so I
>> can create and execute template directly off-stream
>> ( or do I miss something in velocity code? )
>>
>>
>> regards,
>>
>> =====
>> ----[ Konstantin Pribluda ( ko5tik ) ]----------------
>> Zu Verstärkung meines Teams suche ich ab Sofort einen
>> Softwareentwickler[In] für die Festanstellung.
>> Arbeitsort: Mainz
>> Skills:  Programieren, Kentnisse in OpenSource-Bereich
>> ----[ http://www.pribluda.de ]------------------------
>>
>>
>>
>>
>> __________________________________
>> Do you Yahoo!?
>> Win a $20,000 Career Makeover at Yahoo! HotJobs
>> http://hotjobs.sweepstakes.yahoo.com/careermakeover
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Will Glass-Husain <wg...@forio.com>.
Use my event handler patch and build a IncludeEventHandler.

Then resources loaded in via #include or #parse can be selected as needed
according to the context.

WILL

----- Original Message ----- 
From: "Konstantin Priblouda" <kp...@yahoo.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Monday, May 03, 2004 3:37 AM
Subject: Re: Create a DataSourceResourceLoader that can be wired to the
datasource with IoC


>
> Instead I would favor access to context for resource
> loaders - so it can pull everything it needs out of my
> pico container :)
>
> Well, if we speak about dreams, it should be possible
> to bypass resource loader at all conveniently  - so I
> can create and execute template directly off-stream
> ( or do I miss something in velocity code? )
>
>
> regards,
>
> =====
> ----[ Konstantin Pribluda ( ko5tik ) ]----------------
> Zu Verstärkung meines Teams suche ich ab Sofort einen
> Softwareentwickler[In] für die Festanstellung.
> Arbeitsort: Mainz
> Skills:  Programieren, Kentnisse in OpenSource-Bereich
> ----[ http://www.pribluda.de ]------------------------
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Win a $20,000 Career Makeover at Yahoo! HotJobs
> http://hotjobs.sweepstakes.yahoo.com/careermakeover
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Create a DataSourceResourceLoader that can be wired to the datasource with IoC

Posted by Konstantin Priblouda <kp...@yahoo.com>.
--- Will Glass-Husain <wg...@forio.com> wrote:
> Matt,
> 
> Thanks for the note - appreciate the pragmatic
> comment.
> 
> Are there any other changes or new capabilities
> you'd find useful in a data
> resource loader?
> 
> Best,
> WILL

Though I'm not Matt...

I would find context-awearness really usefull. 
( for resource loaders )  - In my content management
system content is itself template, which shall be
rendered through velocity ( index entries, decision
what media to embedd, link formatting etc. ) 
And only convenietn mean to create velocity template
out of stream is resource loader. And unfortunately
this resource loader is not aware of execution context
- only application properites
( ok , I can put some glue stuff in those app 
propeties and use servlet filter to establish
reference and such... I'm already doing this, and I'm
not happy because my portal alerteady containes a lot
of filters, and they are really sourceof errors  ) 

Instead I would favor access to context for resource
loaders - so it can pull everything it needs out of my
pico container :) 

Well, if we speak about dreams, it should be possible
to bypass resource loader at all conveniently  - so I
can create and execute template directly off-stream
( or do I miss something in velocity code? )


regards,

=====
----[ Konstantin Pribluda ( ko5tik ) ]----------------
Zu Verst�rkung meines Teams suche ich ab Sofort einen
Softwareentwickler[In] f�r die Festanstellung. 
Arbeitsort: Mainz 
Skills:  Programieren, Kentnisse in OpenSource-Bereich
----[ http://www.pribluda.de ]------------------------


	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org