You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lionel Crine <cr...@4dconcept.fr> on 2005/02/11 15:58:05 UTC

Creating a global object for my application ?

Hi,

Here is my puzzle :
I'd like to initialize an object (to access a database) only when a user 
get his connection granted.
And then, I want to release the object when the session is finished.

Obviously, The created object should handle multiple users.


Is there any aboject defined in Cocoon as a component or should I make 
it myself ?


Thanks in advance.
Lionel



-- 
Lionel CRINE
Ingénieur Systèmes documentaires
Société : 4DConcept
22 rue Etienne de Jouy 78353 JOUY EN JOSAS
Tel : 01.34.58.70.70 Fax : 01.39.46.06.90


Re: Resource re-use between sitemaps

Posted by Geert Josten <Ge...@daidalos.nl>.
Hi Colin,

Luca Garulli wrote:
> AFAIK you cannot call resources defined in the parent sitemap.

Besides this, map:call is not allowed withing map:pipeline. It has to be wrapped in a map:match.

> You should try to use XPatch or write an ant target that build the
> final sitemap merging all sub-sitemaps ;-)

You can also rewrite the resource to a match that is inside an 'internal-only' pipeline.

For instance:

Parent sitemap:

<map:match pattern="common-resource">
   <!-- generate, transform and serialize or simply 'read' your html -->
</map:match>

Sub sitemap:

<map:match pattern="call-resource">
   <map:read src="cocoon://path-to-parent-sitemap/common-resource" />
</map:match>

Cheers,
Geert

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Resource re-use between sitemaps

Posted by Luca Garulli <l....@gmail.com>.
AFAIK you cannot call resources defined in the parent sitemap.

You should try to use XPatch or write an ant target that build the
final sitemap merging all sub-sitemaps ;-)

bye,
Luca Garulli
www.Pro-Netics.com (member of Orixo.com - The XML business alliance)
OrienTechnologies.com - Light ODBMS, All in one JDO solution

On Fri, 11 Feb 2005 15:14:00 -0000, Colin Eberhardt
<co...@tecsphere.com> wrote:
> Dear All,
> 
> I am creating a few cocoon applications which have common patterns. I
> have created a common sitemap and a number of sub-sitemaps. The
> sub-sitemaps are able to access all the components defined in the common
> sitemap, however if I try to call a resource which is defined in the
> common sitemap cocoon complains that it is unable to find the specified
> resource.
> 
> Here is a very simple example of what I am trying to achieve...
> 
> Here is the base sitemaps:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
>         <map:components>
>                 <map:generators default="file"/>
>                 <map:transformers default="xslt"/>
>                 <map:serializers default="html"/>
>                 <map:readers default="resource"/>
>                 <map:matchers default="wildcard"/>
>         </map:components>
>         <map:resources>
>                 <map:resource name="common-resource">
>                         <map:generate src="test.html" type="file" />
>                         <map:serialize type="html" />
>                 </map:resource>
>         </map:resources>
>         <map:pipelines>
>                 <map:pipeline>
>                         <map:mount check-reload="yes"
> src="subsitemap.xmap" uri-prefix=""/>
>                 </map:pipeline>
>         </map:pipelines>
> </map:sitemap>
> 
> And here is the sitemap which it references:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
>         <map:components>
>                 <map:generators default="file"/>
>                 <map:transformers default="xslt"/>
>                 <map:serializers default="html"/>
>                 <map:readers default="resource"/>
>                 <map:matchers default="wildcard"/>
>         </map:components>
>         <map:pipelines>
>                 <map:pipeline>
>                         <map:call resource="common-resource"/>
>                 </map:pipeline>
>         </map:pipelines>
> </map:sitemap>
> 
> However, the call to the resource named "common-resource" fails.
> 
> What am I doing wrong, or are resources not re-useable!
> 
> Colin Eberhardt
> Software Engineer
> eMail: colin.eberhardt@tecsphere.com
> 
> TecSphere Ltd
> Centre for Advanced Industry
> Coble Dene, Royal Quays
> Newcastle upon Tyne NE29 6DE
> United Kingdom
> 
> Direct Dial: +44 (191) 270 31 13
> Fax: +44 (191) 270 31 09
> http://www.tecsphere.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Resource re-use between sitemaps

Posted by Colin Eberhardt <co...@tecsphere.com>.
Dear All,

I am creating a few cocoon applications which have common patterns. I
have created a common sitemap and a number of sub-sitemaps. The
sub-sitemaps are able to access all the components defined in the common
sitemap, however if I try to call a resource which is defined in the
common sitemap cocoon complains that it is unable to find the specified
resource.

Here is a very simple example of what I am trying to achieve...


Here is the base sitemaps:

<?xml version="1.0" encoding="ISO-8859-1"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
	<map:components>
		<map:generators default="file"/>
		<map:transformers default="xslt"/>
		<map:serializers default="html"/>
		<map:readers default="resource"/>
		<map:matchers default="wildcard"/>
	</map:components>
	<map:resources>
		<map:resource name="common-resource">
			<map:generate src="test.html" type="file" />
			<map:serialize type="html" />
	    	</map:resource>
	</map:resources>
	<map:pipelines>
		<map:pipeline>		
			<map:mount check-reload="yes"
src="subsitemap.xmap" uri-prefix=""/>
		</map:pipeline>		
	</map:pipelines>
</map:sitemap>

And here is the sitemap which it references:

<?xml version="1.0" encoding="ISO-8859-1"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
	<map:components>
		<map:generators default="file"/>
		<map:transformers default="xslt"/>
		<map:serializers default="html"/>
		<map:readers default="resource"/>
		<map:matchers default="wildcard"/>
	</map:components>	
	<map:pipelines>
		<map:pipeline>
			<map:call resource="common-resource"/>
		</map:pipeline>		
	</map:pipelines>
</map:sitemap>


However, the call to the resource named "common-resource" fails.

What am I doing wrong, or are resources not re-useable!

Colin Eberhardt
Software Engineer
eMail: colin.eberhardt@tecsphere.com

TecSphere Ltd
Centre for Advanced Industry
Coble Dene, Royal Quays
Newcastle upon Tyne NE29 6DE
United Kingdom

Direct Dial: +44 (191) 270 31 13
Fax: +44 (191) 270 31 09
http://www.tecsphere.com




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Creating a global object for my application ?

Posted by Adam Ratcliffe <ad...@prema.co.nz>.
Hi Lionel

I have a class AbstractDB, an Avalon component, that manages the lifecycle
of a connection.
It implements these Avalon interfaces: Initializable, Disposable,
Recyclable, Serviceable.

In initialize() I look up the datasource:

            ServiceSelector selector = (ServiceSelector)
this.serviceManager.lookup(DataSourceComponent.ROLE
                    + "Selector");
            this.datasource = (DataSourceComponent)
selector.select(this.dataSourceName);
            serviceManager.release(selector);

The method used to retrieve the connection looks like this:

            try {
                connection = datasource.getConnection();
                if (this.logger.isDebugEnabled())
                    this.logger.debug("Connection created: " +
this.connection.hashCode());
            } catch (Exception e) {
                throw new Exception("Could not create SQL connection using
datasource '" + this.dataSourceName + "'!",
                        e);
            }

In recycle() I close the connection, and in dispose I release the
datasource:

        if (datasource != null) {
            serviceManager.release(datasource);
        }

Is this something like you had in mind?

HTH
Adam

> -----Original Message-----
> From: Lionel Crine [mailto:crine@4dconcept.fr]
> Sent: Saturday, 12 February 2005 3:58 a.m.
> To: users@cocoon.apache.org
> Subject: Creating a global object for my application ?
>
>
> Hi,
>
> Here is my puzzle :
> I'd like to initialize an object (to access a database) only when a user
> get his connection granted.
> And then, I want to release the object when the session is finished.
>
> Obviously, The created object should handle multiple users.
>
>
> Is there any aboject defined in Cocoon as a component or should I make
> it myself ?
>
>
> Thanks in advance.
> Lionel
>
>
>
> --
> Lionel CRINE
> Ingénieur Systèmes documentaires
> Société : 4DConcept
> 22 rue Etienne de Jouy 78353 JOUY EN JOSAS
> Tel : 01.34.58.70.70 Fax : 01.39.46.06.90
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org