cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "g[R]eK" <g...@bluebottle.com>
Subject Re: Instantiating a class on Cocoon startup
Date Mon, 01 Aug 2005 12:41:13 GMT
Christoph Hermann napisaƂ(a):

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hello,
>
>is there a way in Cocoon to load a class on cocoon startup?
>What i want to accomplish is like read some sort of configuration file
>and then hold these values in memory while cocoon is running.
>So i thought of building a xml file which is loaded through xmlbeans
>into a static var or so. Thath way i wouldn't have to load the
>configuration File on each request.
>Can anyone give me some hints on how to accomplish this?
>  
>
If you want your class to be loaded at startup you have to create 
interface like:
package your.package;

import org.apache.avalon.framework.component.Component;

public interface YourNiceIterface extends Component {
String ROLE = PersistenceFactory.class.getName();

//some methods
}

and then class:
public class YourNiceClass implements YourNiceInterface, Configurable, 
Serviceable, Initializable, Disposable, ThreadSafe {
//implement what you want
}

All these interfaces (excluding YourNiceInterface) are Avalon's 
interfaces and they are to tell that you need initialization 
(Initializable) of your component.
If you need some logging, then your class should derive from 
AbstractLogEnabled. If you need more details about intefaces, just ask.

Then you have to put in cocon.xconf something like this:
<component class="your.package.YourNiceClass" 
role="your.package.YourNiceInteface"/>

*BUT*, maybe you just need XMLFileModule[1]? ;-)
Or at least you should implement your own input module to easy obtain 
your configuration.

[1] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/components/modules/input/XMLFileModule.html

-- 
g[R]eK

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


Mime
View raw message