1 23 24 package org.apache.slide.projector.expression; 25 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 30 import org.apache.slide.projector.Projector; 31 import org.apache.slide.projector.engine.Job; 32 import org.apache.slide.projector.engine.Scheduler; 33 import org.apache.slide.projector.value.URIValue; 34 import org.apache.webdav.lib.Subscriber; 35 36 import de.zeigermann.xml.XMLStringWriter; 37 import de.zeigermann.xml.XMLWriter; 38 39 43 public class EventExpression implements Expression, Subscriber { 44 public final static String URI = "uri"; 45 public final static String DEPTH = "depth"; 46 47 private String method; 48 private Map properties = new HashMap (); 49 private boolean eval = false; 50 private Job job; 51 52 public EventExpression(String method) { 53 this.method = method; 54 } 55 56 public void addProperty(String key, String value) { 57 properties.put(key, value); 58 } 59 60 public Expression activate(Job job) { 61 EventExpression activatedExpression = new EventExpression(method); 62 activatedExpression.setJob(job); 63 activatedExpression.properties.putAll(properties); 64 String uri = (String )properties.get(URI); 65 int depth = 0; 66 String depthProperty = (String )properties.get(DEPTH); 67 if ( depthProperty != null ) { 68 depth = Integer.valueOf(depthProperty).intValue(); 69 } 70 Projector.getRepository().subscribe(method, new URIValue(uri), depth, activatedExpression, Projector.getCredentials()); 71 return activatedExpression; 72 } 73 74 public void setJob(Job job) { 75 this.job = job; 76 } 77 78 public boolean evaluate() { 79 return eval; 80 } 81 82 public void save(XMLStringWriter writer) { 83 if ( eval ) { 84 new TrueExpression().save(writer); 85 } else { 86 writer.writeStartTag(XMLWriter.createStartTag("event", "method", method)); 87 for ( Iterator i = properties.entrySet().iterator(); i.hasNext(); ) { 88 Map.Entry entry = (Map.Entry )i.next(); 89 writer.writeEmptyElement(XMLWriter.createEmptyTag("property", new String [] { "key", "value" }, new String [] { (String )entry.getKey(), (String )entry.getValue() })); 90 } 91 writer.writeEndTag(XMLWriter.createEndTag("event")); 92 } 93 } 94 95 public void notify(String uri, Map information) { 96 eval = true; 97 Projector.getRepository().unsubscribe(new URIValue((String )properties.get(URI)), this, Projector.getCredentials()); 98 Scheduler.getInstance().notify(job); 99 } 100 } | Popular Tags |