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.model.topology; 009 010import java.util.ArrayList; 011import java.util.List; 012 013import javax.jmi.reflect.RefObject; 014 015import net.mdatools.modelant.core.api.match.MatchingCriteria; 016 017/** 018 * This class represents a list of criteria (like class or other list criteria) 019 * @author Rusi Popov (popovr@mdatools.net) 020 */ 021public class ExceptionCriteria implements MatchingCriteria { 022 023 /** 024 * Holds the nested matching criteria 025 */ 026 private final MatchingCriteria nested; 027 028 /** 029 * Holds the exceptions of the rules nested imposes 030 */ 031 private final ListCriteria exceptions = new ListCriteria(); 032 033 034 /** 035 * @param nested 036 */ 037 public ExceptionCriteria(MatchingCriteria nested) { 038 assert nested != null : "Expected a non-null criteria to wrap"; 039 this.nested = nested; 040 } 041 042 043 044 /** 045 * @see net.mdatools.modelant.core.api.match.MatchingCriteria#getAttributes(javax.jmi.reflect.RefObject) 046 */ 047 public List<String> getAttributes(RefObject forObject) { 048 List<String> result; 049 050 result = new ArrayList<String>( nested.getAttributes( forObject )); 051 result.removeAll( exceptions.getAttributes( forObject ) ); 052 053 return result; 054 } 055 056 057 /** 058 * @see net.mdatools.modelant.core.api.match.MatchingCriteria#getAssociations(javax.jmi.reflect.RefObject) 059 */ 060 public List<String> getAssociations(RefObject forObject) { 061 List<String> result; 062 063 result = new ArrayList<String>( nested.getAssociations( forObject )); 064 result.removeAll( exceptions.getAssociations( forObject ) ); 065 066 return result; 067 } 068 069 /** 070 * @param criteria 071 */ 072 public void add(MatchingCriteria criteria) { 073 assert criteria != null : "Expected non-null criteria"; 074 075 exceptions.add(criteria); 076 } 077 078 /** 079 * @see java.lang.Object#toString() 080 */ 081 public String toString() { 082 StringBuilder builder; 083 084 builder = new StringBuilder(); 085 builder.append( "ExceptionCriteria [" ); 086 builder.append( "nested=" ).append( nested ).append( ", " ); 087 builder.append( "exceptions=" ).append( exceptions ); 088 builder.append( "]" ); 089 return builder.toString(); 090 } 091}