
org.ow2.bonita.facade.runtime.var.Enumeration Maven / Gradle / Ivy
/**
* Copyright (C) 2007 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.runtime.var;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
import org.ow2.bonita.util.BonitaRuntimeException;
/**
* This class is used with get methods for managing variables of the QueryRuntimeAPI
* when the variables have been defined as Enumeration (DataField with EnumerationType type).
.
* It is also used to set Enumeration type variables (giving an object of this class to the methods:
* {@link org.ow2.bonita.facade.RuntimeAPI#setActivityInstanceVariable setActivityInstanceVariable}
* or {@link org.ow2.bonita.facade.RuntimeAPI#setProcessInstanceVariable setProcessInstanceVariable}
* or {@link org.ow2.bonita.facade.RuntimeAPI#setVariable setVariable}
* from the {@link org.ow2.bonita.facade.RuntimeAPI RuntimeAPI}.
*
* Here after an example of code for getting Enumeration objects.
*
* Object var = queryRuntimeAPI.getActivityInstanceVariable(instanceUUID, activityId, key);
* if (var instanceof Enumeration) {
* Enumeration enu = (Enumeration)var;
* } else {
* String str = (String)var;
* }
*
* @author Marc Blachon, Guillaume Porcher, Charles Souillard, Miguel Valdes, Pierre Vigneras
*/
public class Enumeration implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8365185099594417727L;
private Set possibleValues;
private String selectedValue;
protected Enumeration() {
}
/**
* Creates an Enumeration giving the list of possible values and the selected value.
* The selected value should be one of the possible values.
* @param possibleValues the list of possible values of the enumeration.
* @param selectedValue the selected value of the enumeration.
*/
public Enumeration(Set possibleValues, String selectedValue) {
this.possibleValues = possibleValues;
setSelectedValue(selectedValue);
}
/**
* Returns the collection of possible values.
* @return the collection of possible values.
*/
public Set getPossibleValues() {
return Collections.unmodifiableSet(this.possibleValues);
}
/**
* Returns the selected value.
* @return the selected value.
*/
public String getSelectedValue() {
return this.selectedValue;
}
/*
public void setPossibleValues(Set possibleValues) {
this.possibleValues = possibleValues;
}
*/
protected void setSelectedValue(String selectedValue) {
if (possibleValues == null) {
throw new BonitaRuntimeException("This enumeration is not defined to have a possible value.");
}
if (selectedValue != null) {
if (!possibleValues.contains(selectedValue)) {
throw new BonitaRuntimeException("Invalid enumeration value : "
+ selectedValue + " is not contained in possiblevalues : " + possibleValues);
}
}
this.selectedValue = selectedValue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy