All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.facade.def.element.HookDefinition Maven / Gradle / Ivy

/**
 * Copyright (C) 2006  Bull S. A. S.
 * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation
 * version 2.1 of the License.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA  02110-1301, USA.
 **/
package org.ow2.bonita.facade.def.element;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Hook definition within Activity element.
 */

public interface HookDefinition extends Serializable {

  /**
   * Hook events used into Bonita V3 (mapping to hook events for Bonita V4).
   */
  public static enum V3Event {
    beforeTerminate, afterTerminate, beforeStart, aftertStart, onCancel, onReady;

    public static final Event getV4FromV3HookEventName(final V3Event event, final boolean automaticActivity) {
      if (automaticActivity) {
        return AUTOMATIC_MAPPING.get(event);
      }
      return MANUAL_MAPPING.get(event);
    }

    private static final Map AUTOMATIC_MAPPING;
    private static final Map MANUAL_MAPPING;
    static {
      Map tmp = new HashMap();
      // automatic MAPPING
      tmp.put(beforeTerminate, Event.automaticOnEnter);
      tmp.put(afterTerminate, Event.automaticOnEnter);
      AUTOMATIC_MAPPING = Collections.unmodifiableMap(tmp);

      tmp = new HashMap();
      tmp.put(beforeTerminate, Event.taskOnFinish);
      tmp.put(afterTerminate, Event.taskOnFinish);
      tmp.put(beforeStart, Event.taskOnStart);
      tmp.put(aftertStart, Event.taskOnStart);
      //tmp.put(onCancel, Event.taskOnCancel);
      tmp.put(onReady,  Event.taskOnReady);
      MANUAL_MAPPING = Collections.unmodifiableMap(tmp);
    }
  }

  /**
   * Hook events for Bonita V4.
   */
  public static enum Event {
    taskOnReady, taskOnStart, taskOnFinish, taskOnCancel, taskOnSuspend, taskOnResume, automaticOnEnter;

    public static final List TASK_EVENTS;
    static {
      final List tmp = new ArrayList(Arrays.asList(Event.values()));
      tmp.remove(automaticOnEnter);
      TASK_EVENTS = Collections.unmodifiableList(tmp);
    }

    // return task:onReady, automatic:onEnter,
    // instead of standard taskOnReady, automaticOnEnter,...
    public String toString() {
      final StringBuilder result = new StringBuilder(super.toString());
      int i = 0;
      char c = '$';
      while (i < result.length()) {
        c = result.charAt(i);
        if (Character.isUpperCase(c)) {
          break;
        }
        i++;
      }
      if (i < result.length()) {
        result.insert(i, ':');
        result.setCharAt(i + 1, Character.toLowerCase(c));
      }
      return result.toString();
    }
  }

  String getClassName();
  Event getEvent();
  boolean isThrowingException();
  Map getParameters();

}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy