KickJava   Java API By Example, From Geeks To Geeks.

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


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.Struct;
19 import org.apache.cocoon.woody.formmodel.Widget;
20 import org.apache.commons.jxpath.JXPathContext;
21
22 /**
23  * StructJXPathBinding 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 widget
28  * that contains other widgets.</li>
29  * </ol>
30  *
31  * @author Timothy Larson
32  * @version CVS $Id: StructJXPathBinding.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  */

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

46     public StructJXPathBinding(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     /**
53      * Narrows the scope on the form-model to the member widget-field, and
54      * narrows the scope on the object-model to the member xpath-context
55      * before continuing the binding over the child-bindings.
56      */

57     public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
58         Struct structWidget = (Struct)getWidget(frmModel, this.widgetId);
59         JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
60         super.doLoad(structWidget, subContext);
61         if (getLogger().isDebugEnabled()) {
62             getLogger().debug("done loading " + toString());
63         }
64     }
65
66     /**
67      * Narrows the scope on the form-model to the member widget-field, and
68      * narrows the scope on the object-model to the member xpath-context
69      * before continuing the binding over the child-bindings.
70      */

71     public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
72         Struct structWidget = (Struct)frmModel.getWidget(this.widgetId);
73         JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
74         super.doSave(structWidget, subContext);
75         if (getLogger().isDebugEnabled()) {
76             getLogger().debug("done saving " + toString());
77         }
78     }
79
80     public String JavaDoc toString() {
81         return "StructJXPathBinding [widget=" + this.widgetId + ", xpath=" + this.xpath + "]";
82     }
83 }
84
Popular Tags