KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > 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.woody.binding;
17
18 import org.apache.cocoon.woody.formmodel.Union;
19 import org.apache.cocoon.woody.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  * @author Timothy Larson
32  * @version CVS $Id: CaseJXPathBinding.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  */

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

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

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

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