1 28 29 package org.objectweb.openccm.uml.transformation.rules.xml; 30 31 import ispuml.mdaTransformation.TransformationException; 32 import ispuml.mdaTransformation.rules.xml.Rule; 33 34 import java.util.StringTokenizer ; 35 import javax.jmi.reflect.RefEnum; 36 37 43 public class CopyEnumeration extends Rule implements EnumerationRule { 44 45 46 private String srcLabels []; 47 48 49 private String dstLabels []; 50 51 57 private String [] parseLabels(String labels) { 58 StringTokenizer token = new StringTokenizer (labels, "|"); 59 String [] arrayLabels = new String [token.countTokens()]; 60 for (int i=0 ; token.hasMoreTokens() ; i++) { 61 arrayLabels[i] = token.nextToken(); 62 } 63 return arrayLabels; 64 } 65 66 70 public void setMappingSrcLabel(String srcLabel) { 71 srcLabels = parseLabels(srcLabel); 72 } 73 74 78 public void setMappingDstLabel(String dstLabel) { 79 dstLabels = parseLabels(dstLabel); 80 } 81 82 89 public String getEquivalentLabel(Object object) throws TransformationException { 90 RefEnum refEnum = (RefEnum) object; 91 if (srcLabels.length != dstLabels.length) 92 throw new TransformationException("The mapping is incorrect."); 93 for (int i=0 ; i<srcLabels.length ; i++) { 94 if (refEnum.toString().equals(srcLabels[i])) { 96 return dstLabels[i]; 97 } 98 } 99 throw new TransformationException("The equivalent of " + refEnum.toString() + " is not found."); 100 } 101 102 } 103 | Popular Tags |