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

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

import java.util.List;
import java.util.Map;

import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
import org.enhydra.shark.api.client.wfmodel.InvalidPerformer;
import org.enhydra.shark.api.client.wfmodel.WfEventAudit;
import org.enhydra.shark.api.client.wfmodel.WfProcess;
import org.enhydra.shark.api.client.wfmodel.WfProcessIterator;
import org.enhydra.shark.api.client.wfmodel.WfRequester;
import org.enhydra.shark.api.internal.security.SecurityManager;

/**
 * WfRequesterWrapper - Workflow Requester implementation.
 * 
 * @author Sasa Bojanic
 */
public class WfRequesterWrapper implements WfRequester {

   protected WMSessionHandle shandle;

   protected String resourceUsername;

   protected WfRequesterWrapper(WMSessionHandle shandle, String resUsername) {
      this.shandle = shandle;
      this.resourceUsername = resUsername;
   }

   /**
    * Gets the number of processes.
    */
   public int how_many_performer() throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfRequesterWrapper.how_many_performer");
      
      try {
         checkSecurity("how_many_performer", null);
         
         return SharkEngineManager.getInstance()
         .getInstancePersistenceManager()
            .getResourceRequestersProcessIds(shandle, resourceUsername)
         .size();
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp, "WfRequesterWrapper.how_many_performer", this);
      }
   }

   /**
    * Gets an iterator of processes.
    */
   public WfProcessIterator get_iterator_performer() throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfRequesterWrapper.get_iterator_performer");
      try {
         checkSecurity("get_iterator_performer", null);

         return SharkEngineManager.getInstance()
         .getObjectFactory()
         .createProcessIteratorWrapper(shandle, resourceUsername, true);
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp,
                                  "WfRequesterWrapper.get_iterator_performer",
                                  this);
      }
   }

   /**
    * Returns a list of processes.
    * 
    * @return List of WfProcess objects.
    */
   public WfProcess[] get_sequence_performer(int max_number) throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfRequesterWrapper.get_sequence_performer");
      try {
         checkSecurity("get_sequence_performer", null);

         List alist = SharkUtilities.createResourceRequesterPerformersWrapper(shandle,
                                                                              resourceUsername);
         if (max_number > alist.size() || max_number <= 0) {
            max_number = alist.size();
         }

         WfProcess[] ret = new WfProcess[max_number];
         alist.subList(0, max_number).toArray(ret);
         return ret;
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp,
                                  "WfRequesterWrapper.get_sequence_performer",
                                  this);
      }
   }

   /**
    * Checks if a WfProcess is associated with this requester object.
    * 
    * @return true if the process is found.
    */
   public boolean is_member_of_performer(WfProcess member) throws Exception {
      long tStamp = SharkUtilities.methodStart(shandle,"WfRequesterWrapper.is_member_of_performer");
      try {
         checkSecurity("is_member_of_performer", null);

         String procId = member.key();
         List ids = SharkEngineManager.getInstance()
            .getInstancePersistenceManager()
            .getResourceRequestersProcessIds(shandle, resourceUsername);
         return ids.contains(procId);
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp,
                                  "WfRequesterWrapper.is_member_of_performer",
                                  this);
      }
   }

   /**
    * Receives notice of event status changes.
    */
   public void receive_event(WfEventAudit event) throws Exception, InvalidPerformer {
      long tStamp = SharkUtilities.methodStart(shandle,"WfRequesterWrapper.receive_event");
      try {
      } finally {
         SharkUtilities.methodEnd(shandle,tStamp, "WfRequesterWrapper.receive_event", this);
      }
   }

   protected void checkSecurity(String methodName, Map d) throws Exception {
      SecurityManager sm = SharkEngineManager.getInstance().getSecurityManager();
      if (sm != null) {
         sm.check_requester(shandle, resourceUsername, methodName, d);
      }
   }

   
}
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.