Package org.jbpm.pvm

Source Code of org.jbpm.pvm.SignalDefinition

/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This 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; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.pvm;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jbpm.PvmException;

/** describes the signature of an external trigger.
*
* @author Tom Baeyens
*/
public class SignalDefinition implements Serializable {

  private static final long serialVersionUID = 1L;
 
  public static final SignalDefinition DEFAULT = new SignalDefinition();
 
  protected String name;
  protected String description;
  protected Map<String, Class<?>> parameterDefinitions;
  protected Map<String, Object> properties;
 
  public SignalDefinition() {
  }
 
  public SignalDefinition(String name) {
    this.name = name;
  }
 
  public static SetBuilder build() {
    return new SetBuilder();
  }
 
  public static class SetBuilder {
    Set<SignalDefinition> signalDefinitions = new HashSet<SignalDefinition>();
    SignalDefinition current;
    public SetBuilder defaultSignal() {
      current = new SignalDefinition();
      signalDefinitions.add(current);
      return this;
    }
    public SetBuilder signal(String name) {
      current = new SignalDefinition(name);
      signalDefinitions.add(current);
      return this;
    }
    public SetBuilder parameter(String parameterName, Class<?> parameterClass) {
      if (current==null) {
        throw new PvmException("no current signal definition");
      }
      if (current.parameterDefinitions==null) {
        current.parameterDefinitions = new HashMap<String, Class<?>>();
      }
      current.parameterDefinitions.put(parameterName, parameterClass);
      return this;
    }
    public SetBuilder property(String key, Object value) {
      if (current==null) {
        throw new PvmException("no current signal definition");
      }
      if (current.properties==null) {
        current.properties = new HashMap<String, Object>();
      }
      current.properties.put(key, value);
      return this;
    }
    /** extracts the set of signal definitions that was constructed */
    public Set<SignalDefinition> done() {
      return signalDefinitions;
    }
  }

  public static Set<String> getSignalNames(List<SignalDefinition> signalDefinitions) {
    if (signalDefinitions==null) {
      return null;
    }
    Set<String> signalNames = new HashSet<String>();
    for (SignalDefinition signalDefinition : signalDefinitions) {
      signalNames.add(signalDefinition.getName());
    }
    return signalNames;
  }

  /** the signal name that corresponds to the value of the signal
   * parameter in the {@link Execution#signal(String)} method. */
  public String getName() {
    return name;
  }
 
  /** the signal name that corresponds to the value of the signal
   * parameter in the {@link Execution#signal(String)} method. */
  public void setName(String name) {
    this.name = name;
  }
 
  /** a free text description */
  public String getDescription() {
    return description;
  }
 
  /** a free text description */
  public void setDescription(String description) {
    this.description = description;
  }
 
  /** specifies the type of java object of the parameters that must be
   * fed into this signal. */
  public Map<String, Class< ? >> getParameterDefinitions() {
    return parameterDefinitions;
  }
 
  /** specifies the type of java object of the parameters that must be
   * fed into this signal. Overwrites the full map. Null is allowed. */
  public void setParameterDefinitions(Map<String, Class< ? >> parameterDefinitions) {
    this.parameterDefinitions = parameterDefinitions;
  }
}
TOP

Related Classes of org.jbpm.pvm.SignalDefinition

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.