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.Struct;
20: import org.apache.cocoon.woody.formmodel.Widget;
21: import org.apache.commons.jxpath.JXPathContext;
22:
23: /**
24: * StructJXPathBinding 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: * @author Timothy Larson
33: * @version CVS $Id: StructJXPathBinding.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public class StructJXPathBinding extends ComposedJXPathBindingBase {
36:
37: private final String xpath;
38:
39: private final String widgetId;
40:
41: /**
42: * Constructs StructJXPathBinding
43: * @param widgetId
44: * @param xpath
45: * @param childBindings
46: */
47: public StructJXPathBinding(
48: JXPathBindingBuilderBase.CommonAttributes commonAtts,
49: String widgetId, String xpath,
50: JXPathBindingBase[] childBindings) {
51: super (commonAtts, childBindings);
52: this .widgetId = widgetId;
53: this .xpath = xpath;
54: }
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, JXPathContext jxpc)
62: throws BindingException {
63: Struct structWidget = (Struct) getWidget(frmModel,
64: this .widgetId);
65: JXPathContext subContext = jxpc.getRelativeContext(jxpc
66: .getPointer(this .xpath));
67: super .doLoad(structWidget, subContext);
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: Struct structWidget = (Struct) frmModel
81: .getWidget(this .widgetId);
82: JXPathContext subContext = jxpc.getRelativeContext(jxpc
83: .getPointer(this .xpath));
84: super .doSave(structWidget, subContext);
85: if (getLogger().isDebugEnabled()) {
86: getLogger().debug("done saving " + toString());
87: }
88: }
89:
90: public String toString() {
91: return "StructJXPathBinding [widget=" + this .widgetId
92: + ", xpath=" + this .xpath + "]";
93: }
94: }
|