[New] injecting ComponentContainer into Services at execution time
This commit is contained in:
parent
66920308d0
commit
19c7a120ca
|
@ -17,18 +17,33 @@ package li.strolch.service;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import li.strolch.runtime.agent.api.ComponentContainer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractService<T extends ServiceArgument, U extends ServiceResult> implements Service<T, U> {
|
public abstract class AbstractService<T extends ServiceArgument, U extends ServiceResult> implements Service<T, U> {
|
||||||
|
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class);
|
protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class);
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private ComponentContainer container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the container
|
||||||
|
*/
|
||||||
|
protected ComponentContainer getContainer() {
|
||||||
|
return this.container;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContainer(ComponentContainer container) {
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final U doService(T argument) {
|
public final U doService(T argument) {
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,13 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa
|
||||||
super(container, componentName);
|
super(container, componentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(ComponentConfiguration configuration) {
|
||||||
|
if (getContainer().hasComponent(StrolchPrivilegeHandler.class))
|
||||||
|
this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class);
|
||||||
|
super.initialize(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <U extends ServiceResult> U doService(Certificate certificate, Service<ServiceArgument, U> service) {
|
public <U extends ServiceResult> U doService(Certificate certificate, Service<ServiceArgument, U> service) {
|
||||||
return doService(certificate, service, null);
|
return doService(certificate, service, null);
|
||||||
|
@ -67,6 +74,7 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// then perform the service
|
// then perform the service
|
||||||
|
service.setContainer(getContainer());
|
||||||
U serviceResult = service.doService(argument);
|
U serviceResult = service.doService(argument);
|
||||||
|
|
||||||
// log the result
|
// log the result
|
||||||
|
@ -90,11 +98,4 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa
|
||||||
throw new StrolchException(msg, e);
|
throw new StrolchException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(ComponentConfiguration configuration) {
|
|
||||||
if (getContainer().hasComponent(StrolchPrivilegeHandler.class))
|
|
||||||
this.privilegeHandler = getContainer().getComponent(StrolchPrivilegeHandler.class);
|
|
||||||
super.initialize(configuration);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,15 @@ package li.strolch.service;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import li.strolch.runtime.agent.api.ComponentContainer;
|
||||||
import ch.eitchnet.privilege.model.Restrictable;
|
import ch.eitchnet.privilege.model.Restrictable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface Service<T extends ServiceArgument, U extends ServiceResult> extends Serializable, Restrictable {
|
public interface Service<T extends ServiceArgument, U extends ServiceResult> extends Serializable, Restrictable {
|
||||||
|
|
||||||
public U doService(T argument);
|
public U doService(T argument);
|
||||||
|
|
||||||
|
public void setContainer(ComponentContainer container);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue