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; 011 012import javax.jmi.reflect.RefFeatured; 013 014import net.mdatools.modelant.core.util.Navigator; 015 016/** 017 * Clear the association or attribute value of a model element and return that updated model element. 018 * @author Rusi Popov (popovr@mdatools.net) 019 */ 020public class Clear extends NavigateObjectPath<RefFeatured> { 021 022 /** 023 * @see NavigateObjectPath 024 */ 025 public Clear(String path) { 026 super( path ); 027 } 028 029 030 /** 031 * @see NavigateObjectPath 032 */ 033 public Clear(String[] path) { 034 super( path ); 035 } 036 037 /** 038 * Nothing to do 039 * @see net.mdatools.modelant.core.operation.element.NavigateObjectPath#processEmptyPath(javax.jmi.reflect.RefFeatured) 040 */ 041 protected RefFeatured processEmptyPath(RefFeatured start) { 042 return start; 043 } 044 045 046 /** 047 * Clear an association *-to-one 048 * @see net.mdatools.modelant.core.operation.element.NavigateObjectPath#processLast(javax.jmi.reflect.RefFeatured, javax.jmi.reflect.RefFeatured, java.lang.String, javax.jmi.reflect.RefFeatured) 049 */ 050 protected RefFeatured processLast(RefFeatured start, 051 RefFeatured current, 052 String itemName, 053 RefFeatured associated) { 054 current.refSetValue( itemName, null ); 055 056 return current; 057 } 058 059 060 /** 061 * @see net.mdatools.modelant.core.operation.element.NavigateObjectPath#processLast(javax.jmi.reflect.RefFeatured, javax.jmi.reflect.RefFeatured, java.lang.String, java.lang.Object) 062 */ 063 protected RefFeatured processLast(RefFeatured start, RefFeatured current, String itemName, Object value) { 064 if ( value instanceof Collection ) { // clear association to many 065 ((Collection) value).clear(); 066 067 } else { // clearing an attribute 068 current.refSetValue( itemName, null ); 069 } 070 return current; 071 } 072}