1 28 29 package org.objectweb.openccm.uml.transformation.engine; 30 31 import ispuml.mdaTransformation.EngineContext; 32 import ispuml.mdaTransformation.MappingRuleEngine; 33 import ispuml.mdaTransformation.RuleContext; 34 import ispuml.mdaTransformation.TransformationException; 35 36 import java.util.ArrayList ; 37 import java.util.Collection ; 38 import java.util.Iterator ; 39 import java.util.List ; 40 41 45 public class MappingRuleEngineWithCollection extends MappingRuleEngine { 46 47 55 protected Object transformCollection(Object bean, RuleContext request, String rulesetName, String ruleName) 56 throws TransformationException { 57 if (!(bean instanceof Collection )) 58 throw new TransformationException("Object to transform should denote a Collection."); 59 60 if (request.getCurrentRuleContext().getRule() instanceof ispuml.mdaTransformation.rules.xml.MultiParamXmlRule) { 61 ispuml.mdaTransformation.rules.xml.MultiParamXmlRule rule = (ispuml.mdaTransformation.rules.xml.MultiParamXmlRule)request.getCurrentRuleContext().getRule(); 62 ispuml.mdaTransformation.rules.Parameters parameters = rule.getSrcParameterNames(); 63 if (parameters != null && parameters.size() > 1) { 64 return transform(bean, request, rulesetName, ruleName); 65 } 66 } 67 68 Collection collection = (Collection ) bean; 69 Iterator iter = collection.iterator(); 70 List results = new ArrayList (); 71 while (iter.hasNext()) { 72 Object curBean = iter.next(); 73 if (curBean != null) { 74 if (Collection .class.isAssignableFrom(curBean.getClass())) { 75 List list = (List ) transformCollection(curBean, request, rulesetName, ruleName); 76 results.addAll(list); 77 } else { 78 Object res = transform(curBean, request, rulesetName, ruleName); 79 if (res != null) 80 results.add(res); 81 } 82 } } 85 return results; 86 } 87 88 91 public EngineContext getContext() { 92 EngineContext context = super.getContext(); 93 if (context.getAttribute("CR") == null) 94 context.putAttribute("CR", "\n"); 95 return context; 96 } 97 98 } 99 | Popular Tags |