01: package net.xoetrope.optional.data;
02:
03: import java.awt.Component;
04:
05: import net.xoetrope.optional.data.sql.DatabaseFieldModel;
06: import net.xoetrope.optional.data.sql.DatabaseRowModel;
07: import net.xoetrope.optional.data.sql.DatabaseTableModel;
08: import net.xoetrope.optional.data.sql.DatabaseTableModelAdapter;
09: import net.xoetrope.xml.XmlElement;
10: import net.xoetrope.xui.XTextHolder;
11: import net.xoetrope.xui.data.XDataBinding;
12: import net.xoetrope.xui.data.XDataBindingFactory;
13: import net.xoetrope.xui.data.XModel;
14:
15: /**
16: * A factory for bindings from this package. This binding factory is implicitly
17: * registered as part of loading the XOptionalDataSource. The XuiBuilder class
18: * then uses the factory to create bindings for the supported component types.
19: * <p>Copyright Xoetrope Ltd. 2003-2004</p>
20: * $Revision: 1.2 $
21: */
22: public class XOptionalBindingFactory implements XDataBindingFactory {
23: /**
24: * Try to get a binding factory to construct the binding
25: * @param comp the target component
26: * @param model the source data model
27: * @param bindingNode the XML element defining the binding
28: * @return the new binding if one could be constructed
29: */
30: public XDataBinding getBinding(Component comp, XModel model,
31: XmlElement bindingNode) {
32: String className = comp.getClass().getName();
33: if ((className.indexOf("XComboBox") > 0)
34: && (model instanceof DatabaseTableModel)) {
35: DatabaseTableModel dataModel = (DatabaseTableModel) model;
36: DatabaseTableModelAdapter adapter = new DatabaseTableModelAdapter(
37: dataModel);
38:
39: String displayColumn = bindingNode.getAttribute("display");
40: String keyColumn = bindingNode.getAttribute("key");
41: // String select = bindingNode.getAttribute( "select" );
42: XListTableBinding binding = new XListTableBinding(comp,
43: adapter);
44:
45: binding.setSourcePath(bindingNode.getAttribute("source"));
46: binding.setOutputPath(XModel.prefixOutputPath(bindingNode
47: .getAttribute("output")));
48: binding.setDisplayColumn(bindingNode
49: .getAttribute("display"));
50: binding.setKeyColumn(bindingNode.getAttribute("key"));
51:
52: return binding;
53: } else if ((className.indexOf("XTable") > 0)
54: && (model instanceof DatabaseTableModel)) {
55: DatabaseTableModel dataModel = (DatabaseTableModel) model;
56: XTableTableBinding binding = new XTableTableBinding(comp,
57: dataModel);
58: binding.setOutputPath(XModel.prefixOutputPath(bindingNode
59: .getAttribute("output")));
60: return binding;
61: } else if ((comp instanceof XTextHolder)
62: && ((model instanceof DatabaseTableModel)
63: || (model instanceof DatabaseRowModel) || (model instanceof DatabaseFieldModel))) {
64: XTextTableBinding binding = new XTextTableBinding(comp,
65: bindingNode.getAttribute("source"), model);
66: return binding;
67: }
68: return null;
69: }
70: }
|