1 23 24 package org.apache.slide.projector.expression; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.apache.slide.projector.engine.Job; 31 32 import de.zeigermann.xml.XMLStringWriter; 33 import de.zeigermann.xml.XMLWriter; 34 35 39 public class AndExpression implements EnclosingExpression { 40 private List nestedExpressions = new ArrayList (); 41 42 public Expression activate(Job job) { 43 AndExpression activatedExpression = new AndExpression(); 44 for ( Iterator i = nestedExpressions.iterator(); i.hasNext(); ) { 45 activatedExpression.addExpression(((Expression)i.next()).activate(job)); 46 } 47 return activatedExpression; 48 } 49 50 public void addExpression(Expression expression) { 51 nestedExpressions.add(expression); 52 } 53 54 public boolean evaluate() { 55 boolean eval = true; 56 for ( Iterator i = nestedExpressions.iterator(); i.hasNext(); ) { 57 Expression expression = (Expression)i.next(); 58 if ( !expression.evaluate()) { 59 eval = false; 60 } 61 } 62 return eval; 63 } 64 65 public void save(XMLStringWriter writer) { 66 writer.writeStartTag(XMLWriter.createStartTag("and")); 67 for ( Iterator i = nestedExpressions.iterator(); i.hasNext(); ) { 68 Expression expression = (Expression)i.next(); 69 expression.save(writer); 70 } 71 writer.writeEndTag(XMLWriter.createEndTag("and")); 72 } 73 } | Popular Tags |