1 package org.sapia.gumby.view.binding; 2 3 import org.apache.commons.jxpath.CompiledExpression; 4 import org.apache.commons.jxpath.JXPathContext; 5 import org.sapia.gumby.view.Binding; 6 import org.sapia.gumby.view.View; 7 import org.sapia.util.xml.confix.ConfigurationException; 8 import org.sapia.util.xml.confix.ObjectCreationCallback; 9 10 25 public abstract class AbstractJXPathBinding implements Binding, 26 ObjectCreationCallback { 27 28 protected String _id; 29 protected String _attribute; 30 protected CompiledExpression _expr; 31 32 public void setId(String id) { 33 _id = id; 34 } 35 36 public void setAttribute(String attr) { 37 _attribute = attr; 38 } 39 40 43 public String getId() { 44 return _id; 45 } 46 47 protected Object acquireWidget(View v) { 48 Object widg = v.get(getId()); 49 if(widg == null) 50 throw new IllegalArgumentException ("No object found for: " + getId()); 51 return widg; 52 } 53 54 57 public Object onCreate() throws ConfigurationException { 58 if(_attribute == null) { 59 throw new ConfigurationException("XPath expression not set"); 60 } 61 if(_id == null) { 62 throw new ConfigurationException("ID not set"); 63 } 64 65 _expr = JXPathContext.compile(_attribute); 66 return this; 67 } 68 } 69 | Popular Tags |