[Minor] Added simpler constructor to Command class

This commit is contained in:
Robert von Burg 2018-11-17 16:49:47 +01:00
parent fefa23b62c
commit 09bcdfd772
1 changed files with 77 additions and 69 deletions

View File

@ -15,9 +15,6 @@
*/
package li.strolch.service.api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchComponent;
import li.strolch.model.PolicyContainer;
@ -33,11 +30,13 @@ import li.strolch.privilege.model.Restrictable;
import li.strolch.runtime.StrolchConstants;
import li.strolch.runtime.privilege.PrivilegedRunnable;
import li.strolch.runtime.privilege.PrivilegedRunnableWithResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <p>
* Implementation of the Command Pattern to create re-usable components which are performed during
* {@link StrolchTransaction StrolchTransactions} as part of the execution of {@link Service Services}
* Implementation of the Command Pattern to create re-usable components which are performed during {@link
* StrolchTransaction StrolchTransactions} as part of the execution of {@link Service Services}
* </p>
*
* <p>
@ -54,11 +53,23 @@ public abstract class Command implements Restrictable {
private final StrolchTransaction tx;
/**
* Instantiate a new {@link Command}
* Instantiate a new command
*
* @param tx
* the transaction
*/
public Command(StrolchTransaction tx) {
this.container = tx.getContainer();
this.tx = tx;
}
/**
* Instantiate a new command
*
* @param container
* the {@link ComponentContainer} to access components at runtime
* the {@link ComponentContainer} to access components at runtime
* @param tx
* the transaction
*/
public Command(ComponentContainer container, StrolchTransaction tx) {
this.container = container;
@ -66,16 +77,15 @@ public abstract class Command implements Restrictable {
}
/**
* Allows the concrete {@link Command} implementation access to {@link StrolchComponent StrolchComponents} at
* runtime
* Allows the concrete command implementation access to {@link StrolchComponent StrolchComponents} at runtime
*
* @param clazz
* the type of component to be returned
* the type of component to be returned
*
* @return the component with the given {@link Class} which is registered on the {@link ComponentContainer}
*
* @throws IllegalArgumentException
* if the component with the given class does not exist
* if the component with the given class does not exist
*/
protected <V> V getComponent(Class<V> clazz) throws IllegalArgumentException {
return this.container.getComponent(clazz);
@ -92,10 +102,8 @@ public abstract class Command implements Restrictable {
* Returns a {@link StrolchPolicy} instance from the given parameters
*
* @param policyClass
* the policy type to return. The simple name of the class determines the type of Policy to return.
* @param policyDefs
* the policy defs from which to get the policy by using the simple name of the policy class to determine
* the type of policy to return
* the policy type to return. The simple name of the class determines the type of Policy to return.
* @param policyContainer the container
*
* @return the policy
*/
@ -112,9 +120,9 @@ public abstract class Command implements Restrictable {
* Performs the given {@link SystemAction} as a system user with the given username
*
* @param username
* the name of the system user to perform the action as
* the name of the system user to perform the action as
* @param action
* the action to perform
* the action to perform
*
* @throws PrivilegeException
*/
@ -126,9 +134,9 @@ public abstract class Command implements Restrictable {
* Performs the given {@link SystemAction} as a system user with the given username
*
* @param username
* the name of the system user to perform the action as
* the name of the system user to perform the action as
* @param action
* the action to perform
* the action to perform
*
* @return the result
*
@ -142,9 +150,9 @@ public abstract class Command implements Restrictable {
* Performs the given {@link PrivilegedRunnable} as a system user with the given username
*
* @param username
* the name of the system user to perform the action as
* the name of the system user to perform the action as
* @param runnable
* the runnable to perform
* the runnable to perform
*
* @throws PrivilegeException
*/
@ -156,9 +164,9 @@ public abstract class Command implements Restrictable {
* Performs the given {@link PrivilegedRunnableWithResult} as a system user with the given username
*
* @param username
* the name of the system user to perform the action as
* the name of the system user to perform the action as
* @param runnable
* the runnable to perform
* the runnable to perform
*
* @return the result
*
@ -172,9 +180,9 @@ public abstract class Command implements Restrictable {
* Performs the given {@link SystemAction} as the privileged system user {@link StrolchConstants#SYSTEM_USER_AGENT}
*
* @param username
* the name of the system user to perform the action as
* the name of the system user to perform the action as
* @param action
* the action to perform
* the action to perform
*
* @throws PrivilegeException
*/
@ -186,9 +194,9 @@ public abstract class Command implements Restrictable {
* Performs the given {@link SystemAction} as the privileged system user {@link StrolchConstants#SYSTEM_USER_AGENT}
*
* @param username
* the name of the system user to perform the action as
* the name of the system user to perform the action as
* @param action
* the action to perform
* the action to perform
*
* @return the result
*
@ -199,11 +207,11 @@ public abstract class Command implements Restrictable {
}
/**
* Performs the given {@link PrivilegedRunnable} as the privileged system user
* {@link StrolchConstants#SYSTEM_USER_AGENT}
* Performs the given {@link PrivilegedRunnable} as the privileged system user {@link
* StrolchConstants#SYSTEM_USER_AGENT}
*
* @param action
* the action to perform
* the action to perform
*
* @throws PrivilegeException
*/
@ -212,11 +220,11 @@ public abstract class Command implements Restrictable {
}
/**
* Performs the given {@link PrivilegedRunnableWithResult} as the privileged system user
* {@link StrolchConstants#SYSTEM_USER_AGENT}
* Performs the given {@link PrivilegedRunnableWithResult} as the privileged system user {@link
* StrolchConstants#SYSTEM_USER_AGENT}
*
* @param action
* the action to perform
* the action to perform
*
* @return the result
*
@ -264,8 +272,8 @@ public abstract class Command implements Restrictable {
*
* <p>
* <b>Note:</b> Do not call this method directly, this method is called by the {@link StrolchTransaction} when the
* transaction is committed. Add this {@link Command} to the transaction by calling
* {@link StrolchTransaction#addCommand(Command)}
* transaction is committed. Add this {@link Command} to the transaction by calling {@link
* StrolchTransaction#addCommand(Command)}
* </p>
*/
public abstract void doCommand();