On 06.08.2008 02:30, Robin Rigby wrote:

I am looking for the Java equivalent of the JavaScript
var parser =
cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
and the same for SourceResolver. Sitemap components seem to get them from an Avalon ServiceManager and I found a thread suggesting to copy from ContainerTestCase. Is there not a simpler way?

Hi Robin,

you need indeed a ServiceManager to retrieve the components as follows:

DOMParser domParser;
try {
  domParser = serviceManager.lookup(DOMParser.Role);
  // do something with the DOMParser
} catch (ServiceException e) {
  ...
} finally {
  serviceManager.release(domParser);
}

It depends on your use case if you can release the DOMParser instance immediately in the finally block or want to keep it and release it for example in a recycle method.

And: The Java code needs access to a Service Manager what means more or less that it has to be a Avalon component itself.

Joerg


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to