001/* 002 * Copyright c 2018 Rusi Popov, MDA Tools.net All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the terms of the 005 * Eclipse Public License v2.0 which accompanies this distribution, and is available at 006 * http://www.eclipse.org/legal/epl-v20.html 007 */ 008package net.mdatools.modelant.core.operation.element; 009 010import java.util.Collection; 011import java.util.Iterator; 012 013import javax.jmi.reflect.JmiException; 014import javax.jmi.reflect.RefBaseObject; 015 016import net.mdatools.modelant.core.api.Function; 017 018/** 019 * Verify the model element it is called for against the validation rules form the metamodel. 020 * Any violations are reported in the task log. 021 * @author Rusi Popov (popovr@mdatools.net) 022 */ 023public class Verify implements Function<RefBaseObject, String> { 024 025 /** 026 * This rule that validates the constraints defined in the target extent. Any violations are 027 * reported in the task log as errors. 028 */ 029 public String execute(RefBaseObject target) { 030 StringBuilder result; 031 Collection<JmiException> verificationResult; 032 Iterator<JmiException> exceptionIterator; 033 JmiException exception; 034 035 result = new StringBuilder(); 036 037 verificationResult = target.refVerifyConstraints( true ); // deep validation 038 exceptionIterator = verificationResult.iterator(); 039 while ( exceptionIterator.hasNext() ) { 040 exception = exceptionIterator.next(); 041 042 result.append(new PrintModelElement().execute( exception )); 043 } 044 return result.toString(); 045 } 046}