KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > binding > CaseJXPathBinding


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.binding;
17
18 import org.apache.cocoon.forms.formmodel.Union;
19 import org.apache.cocoon.forms.formmodel.Widget;
20 import org.apache.commons.jxpath.JXPathContext;
21
22 /**
23  * CaseJXPathBinding provides an implementation of a {@link Binding}
24  * that narrows the context towards provided childbindings.
25  * <p>
26  * NOTES: <ol>
27  * <li>This Binding assumes that the provided widget-id points to a
28  * case of a union.</li>
29  * </ol>
30  *
31  * @version $Id: CaseJXPathBinding.java 289538 2005-09-16 13:46:22Z sylvain $
32  */

33 public class CaseJXPathBinding extends ComposedJXPathBindingBase {
34
35     private final String JavaDoc xpath;
36
37     private final String JavaDoc widgetId;
38
39     /**
40      * Constructs CaseJXPathBinding
41      * @param commonAtts
42      * @param widgetId
43      * @param xpath
44      * @param childBindings
45      */

46     public CaseJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String JavaDoc widgetId, String JavaDoc xpath, JXPathBindingBase[] childBindings) {
47         super(commonAtts, childBindings);
48         this.widgetId = widgetId;
49         this.xpath = xpath;
50     }
51
52     public String JavaDoc getXPath() { return xpath; }
53     public String JavaDoc getId() { return widgetId; }
54
55     /**
56      * Narrows the scope on the form-model to the member widget-field, and
57      * narrows the scope on the object-model to the member xpath-context
58      * before continuing the binding over the child-bindings.
59      */

60     public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
61         Union unionWidget = (Union)frmModel;
62         if (widgetId.equals(unionWidget.getValue())) {
63             // JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
64
Binding[] subBindings = getChildBindings();
65             if (subBindings != null) {
66                 int size = subBindings.length;
67                 for (int i = 0; i < size; i++) {
68                     subBindings[i].loadFormFromModel(unionWidget, jxpc);
69                 }
70             }
71             if (getLogger().isDebugEnabled()) {
72                 getLogger().debug("done loading " + toString());
73             }
74         }
75     }
76
77     /**
78      * Narrows the scope on the form-model to the member widget-field, and
79      * narrows the scope on the object-model to the member xpath-context
80      * before continuing the binding over the child-bindings.
81      */

82     public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
83         Union unionWidget = (Union)frmModel;
84         if (widgetId.equals(unionWidget.getValue())) {
85             // JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
86
Binding[] subBindings = getChildBindings();
87             if (subBindings != null) {
88                 int size = subBindings.length;
89                 for (int i = 0; i < size; i++) {
90                     subBindings[i].saveFormToModel(unionWidget, jxpc);
91                 }
92             }
93             if (getLogger().isDebugEnabled()) {
94                 getLogger().debug("done saving " + toString());
95             }
96         }
97     }
98
99     public String JavaDoc toString() {
100         return "CaseJXPathBinding [widget=" + this.widgetId + ", xpath=" + this.xpath + "]";
101     }
102 }
103
Popular Tags