From 9c7044a957818f2e21e64c91bc23498953afce63 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 25 Jun 2020 15:00:04 +0200 Subject: [PATCH] [New] Added StrolchAgent.get..() short hand methods --- .../li/strolch/agent/api/StrolchAgent.java | 60 +++++++++++++++++++ .../strolch/agent/api/StrolchComponent.java | 10 ++++ 2 files changed, 70 insertions(+) diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java index 4d6189fa7..f2f6ef217 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java @@ -32,9 +32,16 @@ import java.util.concurrent.TimeUnit; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import li.strolch.agent.impl.ComponentContainerImpl; +import li.strolch.exception.StrolchException; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.privilege.base.PrivilegeException; +import li.strolch.privilege.model.Certificate; import li.strolch.runtime.configuration.ConfigurationParser; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.configuration.StrolchConfiguration; +import li.strolch.runtime.privilege.PrivilegeHandler; +import li.strolch.runtime.privilege.PrivilegedRunnable; +import li.strolch.runtime.privilege.PrivilegedRunnableWithResult; import li.strolch.utils.ExecutorPool; import li.strolch.utils.helper.StringHelper; import li.strolch.utils.helper.SystemHelper; @@ -82,6 +89,59 @@ public class StrolchAgent { return this.container; } + /** + * @see ComponentContainer#hasComponent(Class) + */ + public boolean hasComponent(Class clazz) { + return this.container.hasComponent(clazz); + } + + /** + * @see ComponentContainer#getComponent(Class) + */ + public T getComponent(Class clazz) throws IllegalArgumentException { + return this.container.getComponent(clazz); + } + + public PrivilegeHandler getPrivilegeHandler() throws IllegalArgumentException { + return this.container.getPrivilegeHandler(); + } + + /** + * @see ComponentContainer#getRealm(Certificate) + */ + public StrolchRealm getRealm(Certificate certificate) throws StrolchException { + return this.container.getRealm(certificate); + } + + /** + * @see StrolchRealm#openTx(Certificate, Class, boolean) + */ + public StrolchTransaction openTx(Certificate certificate, Class clazz, boolean readOnly) { + return this.container.getRealm(certificate).openTx(certificate, clazz, readOnly); + } + + /** + * @see StrolchRealm#openTx(Certificate, String, boolean) + */ + public StrolchTransaction openTx(Certificate certificate, String action, boolean readOnly) { + return this.container.getRealm(certificate).openTx(certificate, action, readOnly); + } + + /** + * @see ComponentContainer#runAsAgent(PrivilegedRunnable) + */ + public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception { + getPrivilegeHandler().runAsAgent(runnable); + } + + /** + * @see ComponentContainer#runAsAgentWithResult(PrivilegedRunnableWithResult) + */ + public T runAsAgentWithResult(PrivilegedRunnableWithResult runnable) throws PrivilegeException, Exception { + return getPrivilegeHandler().runAsAgentWithResult(runnable); + } + /** * @return the name of this application as is defined in the configuration */ diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java index ea6bc1515..8813c7caf 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java @@ -96,6 +96,16 @@ public class StrolchComponent { return this.state; } + /** + * Returns the reference to the agent for sub classes + * + * @return the reference to the agent + */ + public StrolchAgent getAgent() { + DBC.PRE.assertNotNull("container is null!", this.container); + return this.container.getAgent(); + } + /** * Returns the reference to the container for sub classes *