KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > gumby > view > binding > AbstractJXPathBinding


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 /**
11  * @author Yanick Duchesne
12  *
13  * <dl>
14  * <dt><b>Copyright: </b>
15  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
16  * Source Software </a>. All Rights Reserved.</dd>
17  * </dt>
18  * <dt><b>License: </b>
19  * <dd>Read the license.txt file of the jar or visit the <a
20  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
21  * OSS web site</dd>
22  * </dt>
23  * </dl>
24  */

25 public abstract class AbstractJXPathBinding implements Binding,
26     ObjectCreationCallback {
27
28   protected String JavaDoc _id;
29   protected String JavaDoc _attribute;
30   protected CompiledExpression _expr;
31
32   public void setId(String JavaDoc id) {
33     _id = id;
34   }
35
36   public void setAttribute(String JavaDoc attr) {
37     _attribute = attr;
38   }
39
40   /**
41    * @see org.sapia.gumby.view.Binding#getId()
42    */

43   public String JavaDoc getId() {
44     return _id;
45   }
46
47   protected Object JavaDoc acquireWidget(View v) {
48     Object JavaDoc widg = v.get(getId());
49     if(widg == null)
50       throw new IllegalArgumentException JavaDoc("No object found for: " + getId());
51     return widg;
52   }
53
54   /**
55    * @see org.sapia.util.xml.confix.ObjectCreationCallback#onCreate()
56    */

57   public Object JavaDoc 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