You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Dennis Riedel <de...@web.de> on 2005/08/01 16:06:40 UTC
Creating components - avalon component model
Hello
I want to write my own components and access them from other components
or classes within my application.
I followed the instructions how to create a component and accessed it
through FlowScript using cocoon.getComponent().
That worked. But when I try to get the component through the
ServiceManager in a class that implements Serviceable it doesn`t work.
It seems to hang when it comes to the line where
manager.lookup(MyComponentInterface.ROLE); tries to get the instance.
After that no code is executed, only the finally statement where I try
to release the component. But there it throws a NullPointerException.
Example:
MyComponentInterface component = null;
try {
System.out.println("This line is executed");
component = (MyComponentInterface)
manager.lookup(MyComponentInterface.ROLE);
System.out.println("This line is not executed");
}catch(ServiceException e) {
System.out.println("Nothing gets executed here.");
}finally {
System.out.println("Finally is executed but throws
NullPointerException when running next line");
manager.release(component);
}
Ok. NullPointer is normal because it was declared null at first.
But why does lookup work with FlowScripts getComponent() but not when
using classes and the ServiceManager?
Thanks for any ideas or help.
Dennis
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re[2]: Creating components - avalon component model
Posted by Jens Maukisch <co...@maukisch.net>.
Hi,
> Ok. Well, it seems that I have a lack of knowledge about this component
> stuff. I printed out the serviceManager variable and it is null.
> So why? How does my class get an instance of ServiceManager. Who must
> call service(ServiceManager serviceManager) on it?
the class must be the Component itself to get the ServiceManager
automatically if you implement Serviceable.
hth
--
* best regards
* Jens Maukisch
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Creating components - avalon component model
Posted by Dennis Riedel <de...@web.de>.
Ok. Well, it seems that I have a lack of knowledge about this component
stuff. I printed out the serviceManager variable and it is null.
So why? How does my class get an instance of ServiceManager. Who must
call service(ServiceManager serviceManager) on it?
####MyExampleClass
public class Example implements Serviceable {
private ServiceManager serviceManager = null;
public Example() {}
public Hashtable getParts() {
Collection partCollection = new ArrayList();
Hashtable parts = new Hashtable();
DataAccessorInt dataAccessor = null;
try {
System.out.println("Example: getParts() - try LookUp"+
serviceManager);
dataAccessor = (DataAccessorInt)
serviceManager.lookup(DataAccessorInt.ROLE);
System.out.println("Example: LookedUp...");
partCollection = dataAccessor.getAllParts();
...
return parts;
}catch(ServiceException e){
System.out.println("Example: "+e);
return parts;
}finally{
System.out.println("Example: Releasing component...");
if(dataAccessor != null) {
serviceManager.release(dataAccessor);
}
}
}
public void service(ServiceManager serviceManager) throws
ServiceException {
this.serviceManager = serviceManager;
}
}
###END MyExampleClass
Thx for any help.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org