
org.ow2.bonita.parsing.binding.TransitionBinding 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.parsing.binding;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ow2.bonita.pvm.internal.util.XmlUtil;
import org.ow2.bonita.pvm.internal.xml.Parse;
import org.ow2.bonita.pvm.internal.xml.Parser;
import org.ow2.bonita.facade.def.element.ConditionDefinition;
import org.ow2.bonita.facade.def.element.ConditionDefinition.Type;
import org.ow2.bonita.facade.def.element.impl.ConditionDefinitionImpl;
import org.ow2.bonita.facade.def.majorElement.TransitionDefinition;
import org.ow2.bonita.facade.def.majorElement.impl.TransitionDefinitionImpl;
import org.ow2.bonita.facade.uuid.PackageDefinitionUUID;
import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
import org.ow2.bonita.facade.uuid.TransitionDefinitionUUID;
import org.ow2.bonita.services.util.ServiceEnvTool;
import org.w3c.dom.Element;
/**
* @author Marc Blachon, Guillaume Porcher, Charles Souillard, Miguel Valdes, Pierre Vigneras
*/
public class TransitionBinding extends MajorElementBinding {
public TransitionBinding() {
super("Transition");
}
private static final Logger LOG = Logger.getLogger(PackageBinding.class.getName());
public Object parse(final Element transitionElement, final Parse parse, final Parser parser) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("parsing element = " + transitionElement);
}
final String id = getId(transitionElement);
final String name = getName(transitionElement);
final TransitionDefinitionUUID recordUUID =
ServiceEnvTool.getUUIDGenerator().getTransitionDefinitionUUID(
getObject(ProcessDefinitionUUID.class, parse),
id);
parse.pushObject(recordUUID);
final String description = getChildTextContent(transitionElement, "Description");
ConditionDefinition condition = null;
final Element conditionElement = XmlUtil.element(transitionElement, "Condition");
if (conditionElement != null) {
final String contentAsString = conditionElement.getTextContent();
if (contentAsString == null || "".equals(contentAsString.trim())) {
parse.addProblem("Condition is empty on transition " + id);
}
final Type type = getEnumValue(Type.class, XmlUtil.attribute(conditionElement, "Type"), null);
final List xpressionElements = XmlUtil.elements(conditionElement, "Xpression");
if (xpressionElements != null && !xpressionElements.isEmpty()) {
parse.addProblem("Element Xpression not supported on Condition element");
}
condition = new ConditionDefinitionImpl(contentAsString, type, null, null);
}
final String from = XmlUtil.attribute(transitionElement, "From");
if (from == null) {
parse.addProblem("From attribute is not defined on transition: " + id);
}
final String to = XmlUtil.attribute(transitionElement, "To");
if (to == null) {
parse.addProblem("To attribute is not defined on transition: " + id);
}
final TransitionDefinition transition = new TransitionDefinitionImpl(recordUUID, id,
getObject(PackageDefinitionUUID.class, parse), getObject(ProcessDefinitionUUID.class, parse),
condition, description, from, name, to);
parse.popObject();
return transition;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy