KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > 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.woody.binding;
17
18 import org.apache.cocoon.woody.formmodel.AggregateField;
19 import org.apache.cocoon.woody.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 CVS $Id: AggregateJXPathBinding.java 30932 2004-07-29 17:35:38Z vgritsenko $
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     /**
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,
59             JXPathContext jxpc) throws BindingException {
60         AggregateField aggregate =
61             (AggregateField)frmModel.getWidget(this.widgetId);
62         JXPathContext subContext =
63             jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
64         super.doLoad(aggregate, subContext);
65         aggregate.combineFields();
66         if (getLogger().isDebugEnabled()) {
67             getLogger().debug("Done loading " + toString());
68         }
69     }
70
71     /**
72      * Narrows the scope on the form-model to the member widget-field, and
73      * narrows the scope on the object-model to the member xpath-context
74      * before continuing the binding over the child-bindings.
75      */

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