KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > command > TypeMatchMappingCommand


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: TypeMatchMappingCommand.java,v 1.2 2005/06/08 06:21:43 nickb Exp $
16  */

17 package org.eclipse.emf.mapping.command;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.emf.common.command.Command;
23 import org.eclipse.emf.edit.command.CommandParameter;
24 import org.eclipse.emf.mapping.Mapping;
25 import org.eclipse.emf.mapping.domain.MappingDomain;
26
27
28 public class TypeMatchMappingCommand extends MatchMappingCommand
29 {
30   /**
31    * This creates a command that creates a new child mappings for the given mapping
32    * by attempting to match by type input children with output children.
33    */

34   public static Command create(MappingDomain domain, Mapping mapping)
35   {
36     return domain.createCommand(TypeMatchMappingCommand.class, new CommandParameter(mapping));
37   }
38
39   public TypeMatchMappingCommand(MappingDomain domain, Mapping mapping)
40   {
41     super(domain, mapping);
42   }
43
44   protected boolean match(Object JavaDoc inputObject, Object JavaDoc outputObject, Collection JavaDoc mappedObjects)
45   {
46     if (mappedInputs.contains(inputObject) || !domain.getMappingRoot().getMappings(inputObject).isEmpty())
47     {
48       return false; // Type matching never matches inputs that are already mapped
49
}
50
51     Object JavaDoc inputType = domain.getTypeClassifier(inputObject);
52     if (inputType != null)
53     {
54       Object JavaDoc outputType = domain.getTypeClassifier(outputObject);
55       Object JavaDoc convertedInputType = domain.getOutputTypeClassifier(inputType);
56
57       if (outputType != null && outputType == convertedInputType)
58       {
59         mappedObjects.add(inputObject);
60         return true;
61       }
62     }
63
64     return false;
65   }
66
67 }
68
Popular Tags