Reuseable application component to implement BPM

In BPM, I see there are 3 major elements 1) Approver Helper 2) BPM process model and 3) groovy script to update status.

I am thinking of creating a custom application component to apply some standard process workflow which will be built-in the application. For that here is what I see and questions:

for #1 action we can make it generic like follows:

 public void updateState(UUID entityId, String entityName, String state) {
    Transaction tx = persistence.getTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        MetaClass metaClass = metadata.getClassNN(entityName);
        Entity entity = em.find((Class<Entity>) metaClass.getJavaClass(), entityId);
        if (entity != null) {
            entity.setValue("state", state);
        }
        tx.commit();
    } finally {
        tx.end();
    }
}

#2: To my understanding a BPM process model could be used in different entity approvals if they are having similar process steps. Therefore, this can be reused across the application.

#3 groovy script: this is Entity dependent.

def em = persistence.getEntityManager() 
def contract = em.find(com.company.bpmdemo.entity.Contract.class, entityId)
contract.setState('Not valid') 

My question is how can we make this groovy script dynamic like step # 1 above so that it is not hard-coded for a particular Entity but suitable across many Entities? If that is so, may be a custom Application component could be created which will be reusable ?