Am Tue, 24 Aug 2004 13:29:01 +0200 schrieb Steinkamp Andre <[EMAIL PROTECTED]>:

MyComponent now can get the dep1 and dep2 from the ServiceManager, but what if i want a user to edit the block.xml and not the source code and the .xinfo files? so he can add a new Component from MyService and declare a new dependency with key="dep3". but in the service method from MyComponent this dependency will never be fulfilled. so there is no chance to style it variable!?

Ah, OK, now I see what you want to do. You can't use Serviceable anymore in that case. Look at the dynamics tutorial or simply at the following code, where I dynamically resolve a renderer that renders an e-mail body. Some notes: rendererPaths is taken from the configuration, container is taken from the context (key: urn:composition:containment.model type: org.apache.avalon.composition.model.ContainmentModel). My mail client will unfortunately break the formatting of the code for those using clients that don't support format=flowed.


rendererPath = rendererPaths[i].trim();
if ( log.isDebugEnabled() ) {
log.debug("resolving renderer: "+rendererPath);
}
ReferenceDescriptor rdesc = new ReferenceDescriptor(BodyRenderer.class.getName(),
new Version(1, 0, 0));
DeploymentModel model = container.getModel(rendererPath);
if ( model == null ) {
throw new MailerException("Configuration error: No component found at path "+rendererPath);
}
if ( ! model.isaCandidate(rdesc) ) {
throw new MailerException("Configuration error: Component at path "+rendererPath+" doesn't match "+rdesc);
}
BodyRenderer renderer = null;
try {
try {
renderer = (BodyRenderer)model.resolve();
if ( log.isDebugEnabled() ) {
log.debug("Renderer "+rendererPath+" resolved to "+renderer);
}
}
catch ( Exception exc ) {
throw new MailerException("Unable to resolve component at path "+rendererPath, exc);
}
// body rendering, mail sending, etc.
}
finally {
if ( renderer != null ) {
if ( log.isDebugEnabled() ) {
log.debug("Releasing renderer: "+rendererPath+" ("+renderer+")");
}
model.release(renderer);
}
}



cu & HTH, Raffi

--
The difference between theory and practice is that in theory, there is no difference, but in practice, there is.



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



Reply via email to