OpenSAGA Core

Improve validating and use of ActionModel in Actions

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: OpenSAGA 3.0.0
  • Component/s: Refactoring
  • Labels:
    None

Description

We should replace the heterogeneous handling with a more generic solution:

@SuppressWarnings("unchecked")
protected <T extends ActionModel> T verifyActionModelClass(final ActionModel actionModel, final Class<T> clazz) {
    if (!clazz.isAssignableFrom(actionModel.getClass()))
    {
        throw new IllegalArgumentException("The expected action model is '" + clazz + "' but was '" +
            actionModel.getClass() + "'.");
    }

    return (T) actionModel;
}

So far this was realised like this:

if (!(actionModel instanceof StoreActionModel)) {
    throw new IllegalArgumentException("Store action model expected instead of " + actionModel); }

StoreActionModel storeActionModel = (StoreActionModel) actionModel;

Now we are able to use the verifyActionModelClass method of the AbstractAction, this should be replaced continously in all actions.

StoreActionModel storeActionModel = verifyActionModelClass(actionModel, StoreActionModel.class);

Activity

Hide
Christopher Klewes added a comment -

Added method, as from now the method should be used in all actions. The refactoring of the existing actions is still pending!

Show
Christopher Klewes added a comment - Added method, as from now the method should be used in all actions. The refactoring of the existing actions is still pending!

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: