1 17 package org.eclipse.emf.mapping.command; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.eclipse.emf.common.command.Command; 26 import org.eclipse.emf.edit.command.CommandParameter; 27 import org.eclipse.emf.mapping.Mapping; 28 import org.eclipse.emf.mapping.domain.MappingDomain; 29 30 31 public class NameMatchMappingCommand extends MatchMappingCommand 32 { 33 37 public static Command create(MappingDomain domain, Mapping mapping) 38 { 39 return domain.createCommand(NameMatchMappingCommand.class, new CommandParameter(mapping)); 40 } 41 42 public NameMatchMappingCommand(MappingDomain domain, Mapping mapping) 43 { 44 super(domain, mapping); 45 } 46 47 protected boolean match(Object inputObject, Object outputObject, Collection mappedObjects) 48 { 49 String inputName = domain.getName(inputObject); 50 String outputName = domain.getName(outputObject); 51 52 if (inputName != null && outputName != null) 53 { 54 List parsedInputName = domain.parseInputName(inputName); 55 List parsedOutputName = domain.parseOutputName(outputName); 56 57 if (concatName(parsedInputName).equalsIgnoreCase(concatName(parsedOutputName))) 58 { 59 mappedObjects.add(inputObject); 60 } 61 } 81 82 boolean multipleMatchesAllowed = (domain.getMappingEnablementFlags() & MappingDomain.ENABLE_MULTIPLE_INPUTS) != 0; 83 return !multipleMatchesAllowed; } 85 86 protected String concatName(List parsedName) 87 { 88 String result = ""; 89 for (Iterator nameIter = parsedName.iterator(); nameIter.hasNext(); ) 90 { 91 result += nameIter.next(); 92 } 93 return result; 94 } 95 96 public void execute() 97 { 98 super.execute(); 99 100 for (Iterator commands = new ArrayList (commandList).iterator(); commands.hasNext(); ) 103 { 104 Command command = (Command)commands.next(); 105 appendAndExecute(NameMatchMappingCommand.create(domain, (Mapping)command.getResult().iterator().next())); 106 } 107 } 108 109 } 110 | Popular Tags |