1 23 24 package org.apache.slide.projector.expression; 25 26 import java.util.Iterator ; 27 28 import org.jdom.Element; 29 30 34 public class ExpressionFactory { 35 public static Expression create(Element element) { 36 String name = element.getName(); 37 Expression expression = null; 38 if ( name.equals("and") ) { 39 expression = new AndExpression(); 40 } else if ( name.equals("or") ) { 41 expression = new OrExpression(); 42 } else if ( name.equals("true") ) { 43 expression = new TrueExpression(); 44 } else if ( name.equals("event") ) { 45 String method = element.getAttributeValue("method"); 46 expression = new EventExpression(method); 47 for ( Iterator i = element.getChildren().iterator(); i.hasNext(); ) { 48 Element child = (Element)i.next(); 49 String key = child.getAttributeValue("key"); 50 String value = child.getAttributeValue("value"); 51 ((EventExpression)expression).addProperty(key, value); 52 } 53 } 54 if ( expression instanceof EnclosingExpression ) { 55 for ( Iterator i = element.getChildren().iterator(); i.hasNext(); ) { 56 Element child = (Element)i.next(); 57 Expression nestedExpression = create(child); 58 ((EnclosingExpression)expression).addExpression(nestedExpression); 59 } 60 } 61 return expression; 62 } 63 } | Popular Tags |