WfProcessMgrIteratorWrapper.java :  » Workflow-Engines » shark » org » enhydra » shark » Java Open Source

Java Open Source » Workflow Engines » shark 
shark » org » enhydra » shark » WfProcessMgrIteratorWrapper.java
package org.enhydra.shark;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
import org.enhydra.shark.api.client.wfmodel.WfProcessMgr;
import org.enhydra.shark.api.client.wfmodel.process_mgr_stateType;
import org.enhydra.shark.api.client.wfservice.WfProcessMgrIterator;
import org.enhydra.shark.api.common.SharkConstants;
import org.enhydra.shark.api.internal.instancepersistence.ProcessMgrPersistenceObject;
import org.enhydra.shark.api.internal.scripting.Evaluator;

/**
 * Iterator for engine's process managers. The following names may be used for
 * expressions: packageId, processDefinitionId, name, category, createdTime_ms, version,
 * enabled.
 * 
 * @author Sasa Bojanic
 */
public class WfProcessMgrIteratorWrapper extends BaseIteratorWrapper implements
                                                                    WfProcessMgrIterator {

   protected WfProcessMgrIteratorWrapper(WMSessionHandle shandle) throws Exception {
      super(shandle);
   }

   public WfProcessMgr get_next_object() throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfProcessMgrIteratorWrapper.get_next_object");

      try {
         checkSecurity("get_next_object", null);

         return (WfProcessMgr) super.getNextObject();
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp,
                                  "WfProcessMgrIteratorWrapper.get_next_object",
                                  this);
      }
   }

   public WfProcessMgr get_previous_object() throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfProcessMgrIteratorWrapper.get_previous_object");
      try {
         checkSecurity("get_previous_object", null);

         return (WfProcessMgr) super.getPreviousObject();
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp,
                                  "WfProcessMgrIteratorWrapper.get_previous_object",
                                  this);
      }
   }

   public WfProcessMgr[] get_next_n_sequence(int max_number) throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfProcessMgrIteratorWrapper.get_next_n_sequence");

      try {
         checkSecurity("get_next_n_sequence", null);

         WfProcessMgr[] ret = null;
         List l = super.getNextNSequence(max_number);
         ret = new WfProcessMgr[l.size()];
         l.toArray(ret);
         return ret;
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp,
                                  "WfProcessMgrIteratorWrapper.get_next_n_sequence",
                                  this);
      }

   }

   public WfProcessMgr[] get_previous_n_sequence(int max_number) throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfProcessMgrIteratorWrapper.get_previous_n_sequence");

      try {
         checkSecurity("get_previous_n_sequence", null);

         WfProcessMgr[] ret = null;
         List l = super.getPreviousNSequence(max_number);
         ret = new WfProcessMgr[l.size()];
         l.toArray(ret);
         return ret;
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp,
                                  "WfProcessMgrIteratorWrapper.get_previous_n_sequence",
                                  this);
      }

   }

   protected void fillObjectList() throws Exception {
      if (objectList != null)
         return;

      List mgrs = new ArrayList();
      List l = SharkEngineManager.getInstance()
         .getInstancePersistenceManager()
         .getProcessMgrsWhere(shandle, sqlWhere, startAt, limit);

      Evaluator evaluator = SharkEngineManager.getInstance()
         .getScriptingManager()
         .getEvaluator(shandle,queryGrammar);

      for (int i = 0; i < l.size(); i++) {
         ProcessMgrPersistenceObject po = (ProcessMgrPersistenceObject) l.get(i);
         boolean toAdd = true;
         if (eval) {
            Map context = new HashMap();
            context.put("name", po.getName());

            if (ignoreUsedContext
                || (!ignoreUsedContext && 0 <= usedContext.indexOf(SharkConstants.MGR_CATEGORY))) {
               String cat = SharkUtilities.getWorkflowProcess(shandle,
                                                              po.getPackageId(),
                                                              po.getVersion(),
                                                              po.getProcessDefinitionId())
                  .getAccessLevel();
               context.put(SharkConstants.MGR_CATEGORY, cat);
            }
            if (ignoreUsedContext
                || (!ignoreUsedContext && 0 <= usedContext.indexOf(SharkConstants.MGR_VERSION))) {
               context.put(SharkConstants.MGR_VERSION, po.getVersion());
            }
            if (ignoreUsedContext
                || (!ignoreUsedContext && 0 <= usedContext.indexOf(SharkConstants.MGR_CREATED_TIME_MS))) {
               context.put(SharkConstants.MGR_CREATED_TIME_MS, new Long(po.getCreated()));
            }
            if (ignoreUsedContext
                || (!ignoreUsedContext && 0 <= usedContext.indexOf(SharkConstants.MGR_PACKAGE_ID))) {
               context.put(SharkConstants.MGR_PACKAGE_ID, po.getPackageId());
            }
            if (ignoreUsedContext
                || (!ignoreUsedContext && 0 <= usedContext.indexOf(SharkConstants.MGR_PROCESS_DEFINITION_ID))) {
               context.put(SharkConstants.MGR_PROCESS_DEFINITION_ID,
                           po.getProcessDefinitionId());
            }
            if (ignoreUsedContext
                || (!ignoreUsedContext && 0 <= usedContext.indexOf(SharkConstants.MGR_ENABLED))) {
               context.put(SharkConstants.MGR_ENABLED,
                           new Boolean(po.getState() == process_mgr_stateType._enabled));
            }
            toAdd = evaluator.evaluateCondition(shandle, null, null, queryExpression, context);
         }
         if (toAdd) {
            mgrs.add(SharkEngineManager.getInstance()
               .getObjectFactory()
               .createProcessMgrWrapper(shandle, po.getName()));
         }
      }
      setObjectList(mgrs);
   }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.