KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > binding > NewJXPathBinding


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.Widget;
19 import org.apache.commons.jxpath.JXPathContext;
20
21 /**
22  * NewJXPathBinding provides an implementation of a {@link Binding}
23  * that references a class of bindings.
24  * <p>
25  * NOTES: <ol>
26  * <li>This Binding assumes that the provided widget-id points to a
27  * class that contains other widgets.</li>
28  * </ol>
29  *
30  * @author Timothy Larson
31  * @version CVS $Id: NewJXPathBinding.java 30932 2004-07-29 17:35:38Z vgritsenko $
32  */

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

45     public NewJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String JavaDoc widgetId, JXPathBindingBase[] childBindings) {
46         super(commonAtts, childBindings);
47         this.widgetId = widgetId;
48         this.classBinding = null;
49     }
50
51     private void resolve() {
52         classBinding = getClass(widgetId);
53     }
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         if (classBinding == null)
62             resolve();
63         if (classBinding instanceof ClassJXPathBinding) {
64             Binding[] subBindings = ((ComposedJXPathBindingBase)classBinding).getChildBindings();
65             if (subBindings != null) {
66                 int size = subBindings.length;
67                 for (int i = 0; i < size; i++) {
68                     subBindings[i].loadFormFromModel(frmModel, jxpc);
69                 }
70             }
71         } else {
72             classBinding.loadFormFromModel(frmModel, jxpc);
73         }
74     }
75
76     /**
77      * Narrows the scope on the form-model to the member widget-field, and
78      * narrows the scope on the object-model to the member xpath-context
79      * before continuing the binding over the child-bindings.
80      */

81     public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
82         if (classBinding == null)
83             resolve();
84         if (classBinding instanceof ClassJXPathBinding) {
85             Binding[] subBindings = ((ComposedJXPathBindingBase)classBinding).getChildBindings();
86             if (subBindings != null) {
87                 int size = subBindings.length;
88                 for (int i = 0; i < size; i++) {
89                     subBindings[i].saveFormToModel(frmModel, jxpc);
90                 }
91             }
92         } else {
93             classBinding.saveFormToModel(frmModel, jxpc);
94         }
95     }
96
97     public String JavaDoc toString() {
98         return "NewJXPathBinding [widget=" + this.widgetId + "]";
99     }
100 }
101
Popular Tags