01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.binding;
18:
19: import org.apache.cocoon.woody.formmodel.AggregateField;
20: import org.apache.cocoon.woody.formmodel.Widget;
21: import org.apache.commons.jxpath.JXPathContext;
22:
23: /**
24: * AggregateJXPathBinding provides an implementation of a {@link Binding}
25: * that narrows the context towards provided childbindings.
26: * <p>
27: * NOTES: <ol>
28: * <li>This Binding assumes that the provided widget-id points to a widget
29: * that contains other widgets.</li>
30: * </ol>
31: *
32: * @version CVS $Id: AggregateJXPathBinding.java 433543 2006-08-22 06:22:54Z crossley $
33: */
34: public class AggregateJXPathBinding extends ComposedJXPathBindingBase {
35:
36: private final String xpath;
37:
38: private final String widgetId;
39:
40: /**
41: * Constructs AggregateJXPathBinding
42: * @param widgetId
43: * @param xpath
44: * @param childBindings
45: */
46: public AggregateJXPathBinding(
47: JXPathBindingBuilderBase.CommonAttributes commonAtts,
48: String widgetId, String xpath,
49: JXPathBindingBase[] childBindings) {
50: super (commonAtts, childBindings);
51: this .widgetId = widgetId;
52: this .xpath = xpath;
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)
61: throws BindingException {
62: AggregateField aggregate = (AggregateField) frmModel
63: .getWidget(this .widgetId);
64: JXPathContext subContext = jxpc.getRelativeContext(jxpc
65: .getPointer(this .xpath));
66: super .doLoad(aggregate, subContext);
67: aggregate.combineFields();
68: if (getLogger().isDebugEnabled()) {
69: getLogger().debug("Done loading " + toString());
70: }
71: }
72:
73: /**
74: * Narrows the scope on the form-model to the member widget-field, and
75: * narrows the scope on the object-model to the member xpath-context
76: * before continuing the binding over the child-bindings.
77: */
78: public void doSave(Widget frmModel, JXPathContext jxpc)
79: throws BindingException {
80: AggregateField aggregate = (AggregateField) frmModel
81: .getWidget(this .widgetId);
82: JXPathContext subContext = jxpc.getRelativeContext(jxpc
83: .getPointer(this .xpath));
84: super .doSave(aggregate, subContext);
85: if (getLogger().isDebugEnabled()) {
86: getLogger().debug("Done saving " + toString());
87: }
88: }
89:
90: public String toString() {
91: return "AggregateJXPathBinding [widget=" + this .widgetId
92: + ", xpath=" + this .xpath + "]";
93: }
94: }
|