You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jorg Heymans <jh...@domek.be> on 2003/10/30 16:24:45 UTC
Getting the componentmanager (was Re: access defaultsmetamodule variables
from java code)
Using cocoon 2.04, how can I retrieve the componentmanager from within a
transformer? Do i need to use the sourceresolver or something from setup()?
My knowledge on avalon components is poor, so i'm hoping someone can
enlighten me here .
tnx
Jorg
Reinhard Poetz wrote:
> From: Jorg Heymans
>
>
>>Hi,
>>
>>I asked a similar question a few months ago without any luck.
>>This issue
>>has now raised its head again :
>>
>>
>>Does the objectmodel allow to access variables from the
>>defaultsmetamodule in java code (eg transformers,
>>generators...)? I would like to have a global defined in here
>>that I can use in the
>>sitemap AND in code, without having to pass it as a parameter
>>all the time.
>>
>>Basically , I'm hoping to avoid following each time my
>>transformer is used :
>>
>><map:transform type="mycustom" >
>> <map:parameter name="dir"
>>value="{defaults:directory}"/> </map:transform>
>>
>>One could argue that if i need this, then there is something
>>wrong with
>>my design. Or maybe i shouldn't use cocoon.xconf as a plain
>>properties
>>file and put this stuff in plain properties?
>
>
> I'm not sure IIUC what you want to do, but you can call InputModules
> from within your transformer too using the ComponentManager.
>
> HTH
>
> --
> Reinhard
>
>
> ---------------------------------------------------------------------
> 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
Re: Getting the componentmanager (was Re: access defaultsmetamodule
variables from java code)
Posted by Jorg Heymans <jh...@domek.be>.
this is a valid alternative. I used this to get to the variables from a
serializer.
wiki updated to reflect this.
Stephan Coboos wrote:
> Hello,
>
> better you should use the interface Serviceable to get the ServiceManager,
> not the ComponentManager (is deprecated?). The interface Component is just a
> marker interface (no definitions) and has only the affect for mark a
> component. The ServiceManager handles now all java objects not only Objects
> of type Component.
>
> A short example:
>
> ...
> ...
> public myClass extends ... implements Serviceable {
>
> ServiceManager manager;
>
> public void service(ServiceManager manager) {
>
> this.manager = manager;
> }
>
> public aMethod() {
>
> MyObject object = (MyObject)this.manager.lookup(MyObject.ROLE);
> }
> }
>
> Regards
> Stephan
>
> ----- Original Message -----
> From: "Jorg Heymans" <jh...@domek.be>
> To: <us...@cocoon.apache.org>
> Sent: Thursday, October 30, 2003 5:43 PM
> Subject: Re: Getting the componentmanager (was Re: access defaultsmetamodule
> variables from java code)
>
>
>
>>Nearly there :)
>>
>>My transformer is extending AbstractDOMTransformer so i already have
>>access to this manager object.
>>
>>So would i do:
>>Component c = manager.lookup(
>>"org.apache.cocoon.components.modules.input.DefaultsMetaModule");
>>
>>the Component seems like a class without any methods.. so maybe do some
>>casting here?
>>
>>
>>Jorg
>>Reinhard Poetz wrote:
>>
>>>From: Jorg Heymans
>>>
>>>
>>>
>>>>Using cocoon 2.04, how can I retrieve the componentmanager
>>>
>>>>from within a
>>>
>>>>transformer? Do i need to use the sourceresolver or something
>>>
>>>>from setup()? My knowledge on avalon components is poor, so
>>>
>>>>i'm hoping someone can enlighten me here .
>>>
>>>
>>>Use the Composable interface in your component and implement the method
>>>compose:
>>>
>>> public void compose(ComponentManager manager) throws
>>>ComponentException {
>>> this.manager = manager;
>>> }
>>>
>>>HTH
>>>
>>>--
>>>Reinhard
>>>
>>>
>>>---------------------------------------------------------------------
>>>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
>>
>
>
>
> ---------------------------------------------------------------------
> 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
Re: Getting the componentmanager (was Re: access defaultsmetamodule variables from java code)
Posted by Stephan Coboos <cr...@gmx.net>.
Hello,
better you should use the interface Serviceable to get the ServiceManager,
not the ComponentManager (is deprecated?). The interface Component is just a
marker interface (no definitions) and has only the affect for mark a
component. The ServiceManager handles now all java objects not only Objects
of type Component.
A short example:
...
...
public myClass extends ... implements Serviceable {
ServiceManager manager;
public void service(ServiceManager manager) {
this.manager = manager;
}
public aMethod() {
MyObject object = (MyObject)this.manager.lookup(MyObject.ROLE);
}
}
Regards
Stephan
----- Original Message -----
From: "Jorg Heymans" <jh...@domek.be>
To: <us...@cocoon.apache.org>
Sent: Thursday, October 30, 2003 5:43 PM
Subject: Re: Getting the componentmanager (was Re: access defaultsmetamodule
variables from java code)
> Nearly there :)
>
> My transformer is extending AbstractDOMTransformer so i already have
> access to this manager object.
>
> So would i do:
> Component c = manager.lookup(
> "org.apache.cocoon.components.modules.input.DefaultsMetaModule");
>
> the Component seems like a class without any methods.. so maybe do some
> casting here?
>
>
> Jorg
> Reinhard Poetz wrote:
> > From: Jorg Heymans
> >
> >
> >>Using cocoon 2.04, how can I retrieve the componentmanager
> >>from within a
> >>transformer? Do i need to use the sourceresolver or something
> >>from setup()? My knowledge on avalon components is poor, so
> >>i'm hoping someone can enlighten me here .
> >
> >
> > Use the Composable interface in your component and implement the method
> > compose:
> >
> > public void compose(ComponentManager manager) throws
> > ComponentException {
> > this.manager = manager;
> > }
> >
> > HTH
> >
> > --
> > Reinhard
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Getting the componentmanager (was Re: access defaultsmetamodule
variables from java code)
Posted by Joerg Heinicke <jh...@virbus.de>.
On 30.10.2003 17:43, Jorg Heymans wrote:
> Nearly there :)
>
> My transformer is extending AbstractDOMTransformer so i already have
> access to this manager object.
>
> So would i do:
> Component c = manager.lookup(
> "org.apache.cocoon.components.modules.input.DefaultsMetaModule");
>
> the Component seems like a class without any methods.. so maybe do some
> casting here?
Simply cast it to org.apache.cocoon.components.modules.input.InputModule.
You can also have a look into the modular database actions.
Joerg
> Reinhard Poetz wrote:
>
>> From: Jorg Heymans
>>
>>
>>> Using cocoon 2.04, how can I retrieve the componentmanager from
>>> within a transformer? Do i need to use the sourceresolver or
>>> something from setup()? My knowledge on avalon components is poor, so
>>> i'm hoping someone can enlighten me here .
>>
>>
>>
>> Use the Composable interface in your component and implement the method
>> compose:
>> public void compose(ComponentManager manager) throws
>> ComponentException {
>> this.manager = manager;
>> }
>>
>> HTH
>>
>> --
>> Reinhard
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Getting the componentmanager (was Re: access defaultsmetamodule
variables from java code)
Posted by Jorg Heymans <jh...@domek.be>.
done, it's in FAQ
Reinhard Poetz wrote:
> From: Jorg Heymans
>
>
>>k-tsching !!
>>
>>works now :) I want to wiki this up, how can i add a new page
>>to the wiki?
>
>
> simply by adding a new link with a non-existing page. after saving you
> get a question mark instead of the link (because it doesn't exist) and
> then after clicking it you can edit the new page.
>
> --
> Reinhard
>
>
> ---------------------------------------------------------------------
> 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
RE: Getting the componentmanager (was Re: access defaultsmetamodule variables from java code)
Posted by Reinhard Poetz <re...@apache.org>.
From: Jorg Heymans
>
> k-tsching !!
>
> works now :) I want to wiki this up, how can i add a new page
> to the wiki?
simply by adding a new link with a non-existing page. after saving you
get a question mark instead of the link (because it doesn't exist) and
then after clicking it you can edit the new page.
--
Reinhard
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Getting the componentmanager (was Re: access defaultsmetamodule
variables from java code)
Posted by Jorg Heymans <jh...@domek.be>.
k-tsching !!
works now :) I want to wiki this up, how can i add a new page to the wiki?
many thanks Reinhard!
Jorg
Reinhard Poetz wrote:
> From: Jorg Heymans
>
>
>>InputModule d = (InputModule)manager.lookup(
>>"org.apache.cocoon.components.modules.input.InputModuleSelector");
>>-> this one bums out with a null exception object
>
>
> try this:
>
> try {
> this.selector = (ComponentSelector)this.manager.lookup(InputModule.ROLE
> + "Selector");
> } catch(ComponentException ce) {
> throw new PatternException("Cannot access input modules selector", ce);
> }
>
> // Get the module
> InputModule module;
> try {
> module = (InputModule)this.selector.select(moduleName);
> } catch(ComponentException ce) {
> throw new PatternException("Cannot get InputModule named '" +
> moduleName +
> "' in expression '" + this.originalExpr + "'", ce);
> }
>
> (for further details have a look at the class
> org.apache.cocoon.components.treeprocessor.variables.PreparedVariableRes
> olver)
>
> HTH
>
> --
> Reinhard
>
>
> ---------------------------------------------------------------------
> 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
RE: Getting the componentmanager (was Re: access defaultsmetamodule variables from java code)
Posted by Reinhard Poetz <re...@apache.org>.
From: Jorg Heymans
> InputModule d = (InputModule)manager.lookup(
> "org.apache.cocoon.components.modules.input.InputModuleSelector");
> -> this one bums out with a null exception object
try this:
try {
this.selector = (ComponentSelector)this.manager.lookup(InputModule.ROLE
+ "Selector");
} catch(ComponentException ce) {
throw new PatternException("Cannot access input modules selector", ce);
}
// Get the module
InputModule module;
try {
module = (InputModule)this.selector.select(moduleName);
} catch(ComponentException ce) {
throw new PatternException("Cannot get InputModule named '" +
moduleName +
"' in expression '" + this.originalExpr + "'", ce);
}
(for further details have a look at the class
org.apache.cocoon.components.treeprocessor.variables.PreparedVariableRes
olver)
HTH
--
Reinhard
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Getting the componentmanager (was Re: access defaultsmetamodule
variables from java code)
Posted by Jorg Heymans <jh...@domek.be>.
ok tried the following without success ("could not find component
exception") in the setup method of my transformer.
DefaultsMetaModule d =
(DefaultsMetaModule) manager.lookup(InputModule.ROLE);
DefaultsMetaModule d =
(DefaultsMetaModule)
manager.lookup("org.apache.cocoon.components.modules.input.DefaultsMetaModule");
InputModule d = (InputModule)manager.lookup(
"org.apache.cocoon.components.modules.input.InputModule");
InputModule d = (InputModule)manager.lookup(
"org.apache.cocoon.components.modules.input.InputModuleSelector");
-> this one bums out with a null exception object
Then for getting the actual attribute i use
logger.debug((String)d.getAttribute("VIDEO-SERVER", null, objectModel));
Reinhard Poetz wrote:
> From: Jorg Heymans
>
>
>>Nearly there :)
>>
>>My transformer is extending AbstractDOMTransformer so i already have
>>access to this manager object.
>>
>>So would i do:
>>Component c = manager.lookup(
>>"org.apache.cocoon.components.modules.input.DefaultsMetaModule");
>>
>>the Component seems like a class without any methods.. so
>>maybe do some
>>casting here?
>
>
> You have to lookup the InputModuleSelector and NOT a concret
> implementation. A selector offers a select method which returns the
> object instance you request. There are many examples in the Cocoon
> codebase that show you concret selector implementations.
>
> --
> Reinhard
>
>
> ---------------------------------------------------------------------
> 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
RE: Getting the componentmanager (was Re: access defaultsmetamodule variables from java code)
Posted by Reinhard Poetz <re...@apache.org>.
From: Jorg Heymans
> Nearly there :)
>
> My transformer is extending AbstractDOMTransformer so i already have
> access to this manager object.
>
> So would i do:
> Component c = manager.lookup(
> "org.apache.cocoon.components.modules.input.DefaultsMetaModule");
>
> the Component seems like a class without any methods.. so
> maybe do some
> casting here?
You have to lookup the InputModuleSelector and NOT a concret
implementation. A selector offers a select method which returns the
object instance you request. There are many examples in the Cocoon
codebase that show you concret selector implementations.
--
Reinhard
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Getting the componentmanager (was Re: access defaultsmetamodule
variables from java code)
Posted by Jorg Heymans <jh...@domek.be>.
Nearly there :)
My transformer is extending AbstractDOMTransformer so i already have
access to this manager object.
So would i do:
Component c = manager.lookup(
"org.apache.cocoon.components.modules.input.DefaultsMetaModule");
the Component seems like a class without any methods.. so maybe do some
casting here?
Jorg
Reinhard Poetz wrote:
> From: Jorg Heymans
>
>
>>Using cocoon 2.04, how can I retrieve the componentmanager
>>from within a
>>transformer? Do i need to use the sourceresolver or something
>>from setup()? My knowledge on avalon components is poor, so
>>i'm hoping someone can enlighten me here .
>
>
> Use the Composable interface in your component and implement the method
> compose:
>
> public void compose(ComponentManager manager) throws
> ComponentException {
> this.manager = manager;
> }
>
> HTH
>
> --
> Reinhard
>
>
> ---------------------------------------------------------------------
> 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
RE: Getting the componentmanager (was Re: access defaultsmetamodule variables from java code)
Posted by Reinhard Poetz <re...@apache.org>.
From: Jorg Heymans
> Using cocoon 2.04, how can I retrieve the componentmanager
> from within a
> transformer? Do i need to use the sourceresolver or something
> from setup()? My knowledge on avalon components is poor, so
> i'm hoping someone can enlighten me here .
Use the Composable interface in your component and implement the method
compose:
public void compose(ComponentManager manager) throws
ComponentException {
this.manager = manager;
}
HTH
--
Reinhard
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org