| /******************************************************************************* |
| * Copyright (c) 2011, 2012, 2013, 2014 Red Hat, Inc. |
| * All rights reserved. |
| * This program is made available under the terms of the |
| * Eclipse Public License v1.0 which accompanies this distribution, |
| * and is available at http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Red Hat, Inc. - initial API and implementation |
| * |
| * @author Bob Brodt |
| ******************************************************************************/ |
| |
| package org.eclipse.bpmn2.modeler.core.validation.validators; |
| |
| import java.util.List; |
| |
| import org.eclipse.bpmn2.EndEvent; |
| import org.eclipse.bpmn2.Event; |
| import org.eclipse.bpmn2.EventDefinition; |
| import org.eclipse.bpmn2.StartEvent; |
| import org.eclipse.core.runtime.Assert; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.emf.validation.IValidationContext; |
| |
| /** |
| * |
| */ |
| public class EventValidator extends AbstractBpmn2ElementValidator<Event> { |
| |
| /** |
| * Construct a BPMN2 Element Validator from a Validation Context. |
| * |
| * @param ctx |
| */ |
| public EventValidator(IValidationContext ctx) { |
| super(ctx); |
| } |
| |
| /** |
| * Construct a BPMN2 Element Validator with the given Validator as the parent. |
| * The parent is responsible for collecting all of the validation Status objects |
| * and reporting them back to the Validation Constraint. |
| * |
| * @param parent a parent Validator class |
| */ |
| @SuppressWarnings("rawtypes") |
| public EventValidator(AbstractBpmn2ElementValidator parent) { |
| super(parent); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.validation.validators.AbstractBpmn2ElementValidator#validate(org.eclipse.bpmn2.BaseElement) |
| */ |
| @Override |
| public IStatus validate(Event object) { |
| if (ProcessValidator.isContainingProcessExecutable(object)) { |
| EStructuralFeature feature = object.eClass().getEStructuralFeature("eventDefinitions"); //$NON-NLS-1$ |
| Assert.isNotNull(feature); |
| List<EventDefinition> eventdefs = (List<EventDefinition>) object.eGet(feature); |
| if (eventdefs.size()==0) { |
| if (!(object instanceof StartEvent || object instanceof EndEvent)) |
| addMissingFeatureStatus(object,"eventDefinitions",Status.ERROR); //$NON-NLS-1$ |
| } |
| // Note that Event Definitions will be validated by the EventDefinitionsValidator |
| } |
| return getResult(); |
| } |
| |
| } |
| |