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

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

import java.io.File;
import java.util.Properties;

import org.enhydra.shark.api.RootError;
import org.enhydra.shark.api.client.wfmc.wapi.WAPI;
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.NameValue;
import org.enhydra.shark.api.client.wfservice.PackageAdministration;
import org.enhydra.shark.api.client.wfservice.SharkConnection;
import org.enhydra.shark.api.client.wfservice.SharkInterface;
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 com.lutris.util.Config;

/**
 * The main engine class. The client application first has to call one of the static
 * methods configure() (which will initialize shark), and then static getInstance() method
 * of this class to get one and only one instance of this class. After that, clients can
 * call other methods for getting appropriate interfaces.
 * 
 * @version 1.2
 * @author Sasa Bojanic
 * @author Vladimir Puskas
 */
public final class Shark implements SharkInterface {

   private static SharkInterface theEngine;

   private static String implClassName = "org.enhydra.shark.SharkEngineManager";

   private static Shark me;

   static {
      me = new Shark();
   }

   // ////////////////////////////////////////////////////////////////
   // Configuration methods
   // ////////////////////////////////////////////////////////////////
   public static void configure(Properties props) {
      try {
         _conf(props);
         // shark.configure(props);
      } catch (Exception e) {
         throw new RootError(e);
      }
   }

   public static void configure(String filePath) {
      try {
         _conf(filePath);
         // shark.configure(filePath);
      } catch (Exception e) {
         throw new RootError(e);
      }
   }

   public static void configure(File configFile) {
      try {
         _conf(configFile);
         // shark.configure(configFile);
      } catch (Exception e) {
         throw new RootError(e);
      }
   }

   public static void configure() {
      try {
         Class.forName(implClassName)
            .getMethod("configure", new Class[] {})
            .invoke(null, new Object[] {});
         // shark.configure();
      } catch (Exception e) {
         throw new RootError(e);
      }
   }
   
   public static void configure(Config config) {
      try {
         _conf(config);
         // shark.configure(config);
      } catch (Exception e) {
         throw new RootError(e);
      }
   }

   public static boolean isConfigured () {
      try {
         return ((Boolean)Class.forName(implClassName)
            .getMethod("isConfigured", new Class[] {})
            .invoke(null, new Object[] {})).booleanValue();
         // shark.configure();
      } catch (Exception e) {
         throw new RootError(e);
      }      
   }
   
   public static Shark getInstance() {
      if (null == theEngine)
         try {
            theEngine = (SharkInterface) Class.forName(implClassName)
               .getDeclaredMethod("getInstance", new Class[] {})
               .invoke(null, new Object[] {});
            // Class.forName(implClassName)
            // .getMethod("getInstance", new Class[]
            // {})
            // .invoke(null, new Object[] {});
         } catch (Exception e) {
            throw new RootError(e);
         }
      return me;
   }

   private static void _conf(Object configuration) throws Exception {
      Class.forName(implClassName).getMethod("configure", new Class[] {
         configuration.getClass()
      }).invoke(null, new Object[] {
         configuration
      });
   }

   private Shark() {
   }

   // ////////////////////////////////////////////////////////////////
   // SharkInterface API implementation
   // ////////////////////////////////////////////////////////////////
   public AdminMisc getAdminMisc() throws Exception {
      return theEngine.getAdminMisc();
   }

   public AdminMiscExt getAdminMiscExtension() throws Exception {
      return theEngine.getAdminMiscExtension();
   }

   public ExecutionAdministration getExecutionAdministration() throws Exception {
      return theEngine.getExecutionAdministration();
   }

   public ExecutionAdministrationExt getExecutionAdministrationExtension()
      throws Exception {
      return theEngine.getExecutionAdministrationExtension();
   }

   public PackageAdministration getPackageAdministration() throws Exception {
      return theEngine.getPackageAdministration();
   }

   public SharkConnection getSharkConnection() throws Exception {
      return theEngine.getSharkConnection();
   }

   public ActivityFilterBuilder getActivityFilterBuilder() throws Exception {
      return theEngine.getActivityFilterBuilder();
   }

   public AssignmentFilterBuilder getAssignmentFilterBuilder() throws Exception {
      return theEngine.getAssignmentFilterBuilder();
   }

   public EventAuditFilterBuilder getEventAuditFilterBuilder() throws Exception {
      return theEngine.getEventAuditFilterBuilder();
   }

   public ProcessFilterBuilder getProcessFilterBuilder() throws Exception {
      return theEngine.getProcessFilterBuilder();
   }

   public ProcessMgrFilterBuilder getProcessMgrFilterBuilder() throws Exception {
      return theEngine.getProcessMgrFilterBuilder();
   }

   public ResourceFilterBuilder getResourceFilterBuilder() throws Exception {
      return theEngine.getResourceFilterBuilder();
   }

   public XPDLBrowser getXPDLBrowser() throws Exception {
      return theEngine.getXPDLBrowser();
   }

   public XPILHandler getXPILHandler() throws Exception {
      return theEngine.getXPILHandler();
   }

   public NameValue[] getProperties() throws Exception {
      return theEngine.getProperties();
   }

   public WAPI getWAPIConnection() throws Exception {
      return theEngine.getWAPIConnection();
   }

   public Object getPlugIn(String name) throws Exception {
      return theEngine.getPlugIn(name);
   }

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