KickJava   Java API By Example, From Geeks To Geeks.

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


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.AggregateField;
19 import org.apache.cocoon.forms.formmodel.Widget;
20 import org.apache.commons.jxpath.JXPathContext;
21
22 /**
23  * AggregateJXPathBinding 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  * @version $Id: AggregateJXPathBinding.java 289538 2005-09-16 13:46:22Z sylvain $
32  */

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

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

61     public void doLoad(Widget frmModel,
62             JXPathContext jxpc) throws BindingException {
63         AggregateField aggregate =
64             (AggregateField)selectWidget(frmModel, this.widgetId);
65         JXPathContext subContext =
66             jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
67         super.doLoad(aggregate, subContext);
68         aggregate.combineFields();
69         if (getLogger().isDebugEnabled()) {
70             getLogger().debug("Done loading " + toString());
71         }
72     }
73
74     /**
75      * Narrows the scope on the form-model to the member widget-field, and
76      * narrows the scope on the object-model to the member xpath-context
77      * before continuing the binding over the child-bindings.
78      */

79     public void doSave(Widget frmModel,
80             JXPathContext jxpc) throws BindingException {
81         AggregateField aggregate =
82             (AggregateField)selectWidget(frmModel, this.widgetId);
83         JXPathContext subContext =
84             jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
85         super.doSave(aggregate, subContext);
86         if (getLogger().isDebugEnabled()) {
87             getLogger().debug("Done saving " + toString());
88         }
89     }
90
91     public String JavaDoc toString() {
92         return "AggregateJXPathBinding [widget=" + this.widgetId +
93             ", xpath=" + this.xpath + "]";
94     }
95 }
96
Popular Tags