blob: a10642e9ad170334e6d53598a35e2f9379459ebd [file] [log] [blame]
/**
* Copyright (c) 2009, 2019 Mia-Software and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Gregoire DUPE (Mia-Software) - initial API and implementation
*/
package org.eclipse.modisco.infra.facet.validation;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.validation.AbstractModelConstraint;
import org.eclipse.emf.validation.EMFEventType;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.modisco.infra.facet.Facet;
import org.eclipse.modisco.infra.facet.FacetSet;
/**
* @deprecated Replaced by EMF Facet
*/
@Deprecated
public class NonEmptyName extends AbstractModelConstraint {
@Override
public IStatus validate(final IValidationContext ctx) {
EObject eObj = ctx.getTarget();
EMFEventType eType = ctx.getEventType();
// In the case of batch mode.
if (eType == EMFEventType.NULL) {
String name = null;
if (eObj instanceof FacetSet) {
name = ((FacetSet) eObj).getName();
} else if (eObj instanceof Facet) {
name = ((Facet) eObj).getName();
} else if (eObj instanceof EStructuralFeature) {
name = ((EStructuralFeature) eObj).getName();
}
if (name == null || name.length() == 0) {
return ctx.createFailureStatus(eObj.eClass().getName());
}
}
return ctx.createSuccessStatus();
}
}