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

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

import java.lang.reflect.Method;
import java.util.Map;

import org.enhydra.shark.api.client.wfmc.wapi.WAPI;
import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
import org.enhydra.shark.api.client.wfmodel.WfActivity;
import org.enhydra.shark.api.client.wfmodel.WfActivityIterator;
import org.enhydra.shark.api.client.wfmodel.WfAssignment;
import org.enhydra.shark.api.client.wfmodel.WfAssignmentIterator;
import org.enhydra.shark.api.client.wfmodel.WfEventAuditIterator;
import org.enhydra.shark.api.client.wfmodel.WfProcess;
import org.enhydra.shark.api.client.wfmodel.WfProcessIterator;
import org.enhydra.shark.api.client.wfmodel.WfProcessMgr;
import org.enhydra.shark.api.client.wfmodel.WfRequester;
import org.enhydra.shark.api.client.wfmodel.WfResource;
import org.enhydra.shark.api.client.wfservice.AdminMisc;
import org.enhydra.shark.api.client.wfservice.AdminMiscExt;
import org.enhydra.shark.api.client.wfservice.ExecutionAdministration;
import org.enhydra.shark.api.client.wfservice.ExecutionAdministrationExt;
import org.enhydra.shark.api.client.wfservice.PackageAdministration;
import org.enhydra.shark.api.client.wfservice.SharkConnection;
import org.enhydra.shark.api.client.wfservice.WfProcessMgrIterator;
import org.enhydra.shark.api.client.wfservice.WfResourceIterator;
import org.enhydra.shark.api.client.wfservice.XPDLBrowser;
import org.enhydra.shark.api.client.xpil.XPILHandler;
import org.enhydra.shark.api.common.ActivityFilterBuilder;
import org.enhydra.shark.api.common.AssignmentFilterBuilder;
import org.enhydra.shark.api.common.EventAuditFilterBuilder;
import org.enhydra.shark.api.common.ProcessFilterBuilder;
import org.enhydra.shark.api.common.ProcessMgrFilterBuilder;
import org.enhydra.shark.api.common.ResourceFilterBuilder;
import org.enhydra.shark.api.internal.eventaudit.AssignmentEventAuditPersistenceObject;
import org.enhydra.shark.api.internal.eventaudit.CreateProcessEventAuditPersistenceObject;
import org.enhydra.shark.api.internal.eventaudit.DataEventAuditPersistenceObject;
import org.enhydra.shark.api.internal.eventaudit.StateEventAuditPersistenceObject;
import org.enhydra.shark.api.internal.instancepersistence.ActivityPersistenceObject;
import org.enhydra.shark.api.internal.instancepersistence.AssignmentPersistenceObject;
import org.enhydra.shark.api.internal.instancepersistence.ProcessMgrPersistenceObject;
import org.enhydra.shark.api.internal.instancepersistence.ProcessPersistenceObject;
import org.enhydra.shark.api.internal.instancepersistence.ResourcePersistenceObject;
import org.enhydra.shark.api.internal.working.ObjectFactory;
import org.enhydra.shark.api.internal.working.WfActivityInternal;
import org.enhydra.shark.api.internal.working.WfAssignmentEventAuditInternal;
import org.enhydra.shark.api.internal.working.WfAssignmentInternal;
import org.enhydra.shark.api.internal.working.WfCreateProcessEventAuditInternal;
import org.enhydra.shark.api.internal.working.WfDataEventAuditInternal;
import org.enhydra.shark.api.internal.working.WfExecutionObjectInternal;
import org.enhydra.shark.api.internal.working.WfProcessInternal;
import org.enhydra.shark.api.internal.working.WfProcessMgrInternal;
import org.enhydra.shark.api.internal.working.WfRequesterInternal;
import org.enhydra.shark.api.internal.working.WfResourceInternal;
import org.enhydra.shark.api.internal.working.WfStateEventAuditInternal;

/**
 * Factory for generating Shark core objects.
 * 
 * @author Sasa Bojanic
 * @version 1.0
 */
public class SharkObjectFactory implements ObjectFactory {

   protected SharkObjectFactory() {
   }

   // main objects
   public WfProcessMgrInternal createProcessMgr(WMSessionHandle shandle,
                                                String packageId,
                                                String version,
                                                String procDefId) throws Exception {

      return new WfProcessMgrImpl(shandle, packageId, version, procDefId);
   }

   public WfProcessMgrInternal createProcessMgr(ProcessMgrPersistenceObject po)
      throws Exception {
      return new WfProcessMgrImpl(po);
   }

   public WfProcessMgr createProcessMgrWrapper(WMSessionHandle shandle, String name)
      throws Exception {

      return new WfProcessMgrWrapper(shandle, name);
   }

   public WfProcessInternal createProcess(WMSessionHandle shandle,
                                          WfProcessMgrInternal manager,
                                          WfRequesterInternal requester,
                                          String key) throws Exception {

      return new WfProcessImpl(shandle, manager, requester, key);
   }

   public WfProcessInternal createProcess(ProcessPersistenceObject po)
      throws Exception {
      return new WfProcessImpl(po);
   }

   public WfProcess createProcessWrapper(WMSessionHandle shandle,
                                         String mgrName,
                                         String procId) {

      return new WfProcessWrapper(shandle, mgrName, procId);
   }

   public WfRequesterInternal createDefaultRequester(WMSessionHandle shandle,
                                                     String resUsername,
                                                     WfRequester extRequester) {
      return new WfDefaultRequester(shandle, resUsername, extRequester);
   }

   public WfRequester createRequesterWrapper(WMSessionHandle shandle, String resUsername) {

      return new WfRequesterWrapper(shandle, resUsername);
   }

   public WfActivityInternal createActivity(WMSessionHandle shandle,
                                            WfProcessInternal process,
                                            String key,
                                            // String activitySetDefId,
                                            String activityDefId,
                                            WfActivityInternal blockActivity)
      throws Exception {

      return new WfActivityImpl(shandle, process, key, activityDefId, blockActivity);
   }

   public WfActivityInternal createActivity(ActivityPersistenceObject po,
                                            WfProcessInternal process) throws Exception {
      return new WfActivityImpl(po, process);
   }

   public WfActivity createActivityWrapper(WMSessionHandle shandle,
                                           String mgrName,
                                           String procId,
                                           String actId) {

      return new WfActivityWrapper(shandle, mgrName, procId, actId);
   }

   public WfAssignmentInternal createAssignment(WMSessionHandle shandle,
                                                WfActivityInternal activity,
                                                WfResourceInternal resource)
      throws Exception {

      return new WfAssignmentImpl(shandle, activity, resource);
   }

   public WfAssignmentInternal createAssignment(AssignmentPersistenceObject po,
                                                WfResourceInternal res) throws Exception {
      return new WfAssignmentImpl(po, res);
   }

   public WfAssignment createAssignmentWrapper(WMSessionHandle shandle,
                                               String mgrName,
                                               String procId,
                                               String actId,
                                               String username) {

      return new WfAssignmentWrapper(shandle, mgrName, procId, actId, username);
   }

   public WfResourceInternal createResource(WMSessionHandle shandle, String resourceKey)
      throws Exception {

      return new WfResourceImpl(shandle, resourceKey);
   }

   public WfResourceInternal createResource(ResourcePersistenceObject po)
      throws Exception {
      return new WfResourceImpl(po);
   }

   public WfResource createResourceWrapper(WMSessionHandle shandle, String username) {

      return new WfResourceWrapper(shandle, username);
   }

   // event audits
   public WfAssignmentEventAuditInternal createAssignmentEventAuditWrapper(WMSessionHandle shandle,
                                                                           WfActivityInternal activity,
                                                                           WfResourceInternal oldRes,
                                                                           WfResourceInternal newRes,
                                                                           boolean isAccepted)
      throws Exception {

      return new WfAssignmentEventAuditWrapper(shandle,
                                               activity,
                                               oldRes,
                                               newRes,
                                               isAccepted);
   }

   public WfAssignmentEventAuditInternal createAssignmentEventAuditWrapper(WMSessionHandle shandle,
                                                                           AssignmentEventAuditPersistenceObject po)
      throws Exception {

      return new WfAssignmentEventAuditWrapper(shandle, po);
   }

   public WfCreateProcessEventAuditInternal createCreateProcessEventAuditWrapper(WMSessionHandle shandle,
                                                                                 WfProcessInternal process,
                                                                                 WfRequesterInternal requester)
      throws Exception {

      return new WfCreateProcessEventAuditWrapper(shandle, process, requester);
   }

   public WfCreateProcessEventAuditInternal createCreateProcessEventAuditWrapper(WMSessionHandle shandle,
                                                                                 CreateProcessEventAuditPersistenceObject po)
      throws Exception {

      return new WfCreateProcessEventAuditWrapper(shandle, po);
   }

   public WfDataEventAuditInternal createDataEventAuditWrapper(WMSessionHandle shandle,
                                                               WfExecutionObjectInternal object,
                                                               String eventType,
                                                               Map oldData,
                                                               Map newData)
      throws Exception {

      return new WfDataEventAuditWrapper(shandle, object, eventType, oldData, newData);
   }

   public WfDataEventAuditInternal createDataEventAuditWrapper(WMSessionHandle shandle,
                                                               DataEventAuditPersistenceObject po)
      throws Exception {

      return new WfDataEventAuditWrapper(shandle, po);
   }

   public WfStateEventAuditInternal createStateEventAuditWrapper(WMSessionHandle shandle,
                                                                 WfExecutionObjectInternal object,
                                                                 String eventType,
                                                                 String oldState,
                                                                 String newState)
      throws Exception {

      return new WfStateEventAuditWrapper(shandle, object, eventType, oldState, newState);
   }

   public WfStateEventAuditInternal createStateEventAuditWrapper(WMSessionHandle shandle,
                                                                 StateEventAuditPersistenceObject po)
      throws Exception {

      return new WfStateEventAuditWrapper(shandle, po);
   }

   // iterators
   public WfProcessMgrIterator createProcessMgrIteratorWrapper(WMSessionHandle shandle)
      throws Exception {

      return new WfProcessMgrIteratorWrapper(shandle);
   }

   public WfProcessIterator createProcessIteratorWrapper(WMSessionHandle shandle,
                                                         String mgrName) throws Exception {

      return new WfProcessIteratorWrapper(shandle, mgrName);
   }

   public WfProcessIterator createProcessIteratorWrapper(WMSessionHandle shandle,
                                                         String procId,
                                                         String actId) throws Exception {

      return new WfProcessIteratorWrapper(shandle, procId, actId);
   }

   public WfProcessIterator createProcessIteratorWrapper(WMSessionHandle shandle,
                                                         String username,
                                                         boolean ext) throws Exception {

      return new WfProcessIteratorWrapper(shandle, username, true);
   }

   public WfActivityIterator createActivityIteratorWrapper(WMSessionHandle shandle,
                                                           String procId)
      throws Exception {

      return new WfActivityIteratorWrapper(shandle, procId);
   }

   public WfAssignmentIterator createAssignmentIteratorWrapper(WMSessionHandle shandle,
                                                               String procId,
                                                               String actId)
      throws Exception {

      return new WfAssignmentIteratorWrapper(shandle, procId, actId);
   }

   public WfAssignmentIterator createAssignmentIteratorWrapper(WMSessionHandle shandle,
                                                               String username)
      throws Exception {

      return new WfAssignmentIteratorWrapper(shandle, username);
   }

   public WfResourceIterator createResourceIteratorWrapper(WMSessionHandle shandle)
      throws Exception {

      return new WfResourceIteratorWrapper(shandle);
   }

   public WfEventAuditIterator createEventAuditIteratorWrapper(WMSessionHandle shandle,
                                                               String procId)
      throws Exception {

      return new WfEventAuditIteratorWrapper(shandle, procId);
   }

   public WfEventAuditIterator createEventAuditIteratorWrapper(WMSessionHandle shandle,
                                                               String procId,
                                                               String actId)
      throws Exception {

      return new WfEventAuditIteratorWrapper(shandle, procId, actId);
   }

   public AdminMisc createAdminMisc() {
      return AdminMiscImpl.getInstance();
   }

   public AdminMiscExt createAdminMiscExt() {
      try {
         Class cls=Class.forName("org.enhydra.shark.AdminMiscExtImpl");
         Method m=cls.getMethod("getInstance", null);
         AdminMiscExt ame=(AdminMiscExt)m.invoke(null, null);
         return ame;
      } catch (Exception ex) {         
      }
      throw new RuntimeException("Community version does not provide implementation of AdminMiscExt interface!");
   }

   public ExecutionAdministration createExecutionAdministration() {
      return ExecutionAdmin.getInstance();
   }

   public ExecutionAdministrationExt createExecutionAdministrationExt() {
      try {
         Class cls=Class.forName("org.enhydra.shark.ExecutionAdminExt");
         Method m=cls.getMethod("getInstance", null);
         ExecutionAdministrationExt eae=(ExecutionAdministrationExt)m.invoke(null, null);
         return eae;
      } catch (Exception ex) {         
      }
      throw new RuntimeException("Community version does not provide implementation of ExecutionAdministrationExt interface!");
   }

   public PackageAdministration createPackageAdministration() {
      return PackageAdmin.getInstance();
   }

   public SharkConnection createSharkConnection() {
      return new SharkConnectionImpl();
   }

   public ActivityFilterBuilder createActivityFilterBuilder() {
      return ActivityFilterBuilderDODS.getInstance();
   }

   public AssignmentFilterBuilder createAssignmentFilterBuilder() {
      return AssignmentFilterBuilderDODS.getInstance();
   }

   public EventAuditFilterBuilder createEventAuditFilterBuilder() {
      throw new RuntimeException("Not implemented yet!");
   }

   public ProcessFilterBuilder createProcessFilterBuilder() {
      return ProcessFilterBuilderDODS.getInstance();
   }

   public ProcessMgrFilterBuilder createProcessMgrFilterBuilder() {
      return ProcessMgrFilterBuilderDODS.getInstance();

   }

   public ResourceFilterBuilder createResourceFilterBuilder() {
      return ResourceFilterBuilderDODS.getInstance();
   }

   public XPDLBrowser createXPDLBrowser() {
      return XPDLBrowserImpl.getInstance();
   }

   public XPILHandler createXPILHandler() {
      return XPILHandlerImpl.getInstance();
   }

   public WAPI createWAPI() {
      return WAPIImpl.getInstance();
   }
}
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.