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.forms.binding;
18:
19: import org.apache.cocoon.forms.formmodel.Struct;
20: import org.apache.cocoon.forms.formmodel.Widget;
21:
22: import org.apache.commons.jxpath.JXPathContext;
23:
24: /**
25: * StructJXPathBinding provides an implementation of a {@link Binding}
26: * that narrows the context towards provided childbindings.
27: * <p>NOTES:
28: * <ol>
29: * <li>This Binding assumes that the provided widget-id points to a widget
30: * that contains other widgets.</li>
31: * </ol>
32: *
33: * @version $Id: StructJXPathBinding.java 450255 2006-09-26 23:48:43Z vgritsenko $
34: */
35: public class StructJXPathBinding extends ContextJXPathBinding {
36:
37: private final String widgetId;
38:
39: /**
40: * Constructs StructJXPathBinding
41: * @param widgetId
42: * @param xpath
43: * @param childBindings
44: */
45: public StructJXPathBinding(
46: JXPathBindingBuilderBase.CommonAttributes commonAtts,
47: String widgetId, String xpath,
48: JXPathBindingBase[] childBindings) {
49: super (commonAtts, xpath, childBindings);
50: this .widgetId = widgetId;
51: }
52:
53: public String getId() {
54: return widgetId;
55: }
56:
57: /**
58: * Narrows the scope on the form-model to the member widget-field, and
59: * narrows the scope on the object-model to the member xpath-context
60: * before continuing the binding over the child-bindings.
61: */
62: public void doLoad(Widget frmModel, JXPathContext jxpc)
63: throws BindingException {
64: Struct structWidget = (Struct) selectWidget(frmModel,
65: this .widgetId);
66: super .doLoad(structWidget, jxpc);
67: }
68:
69: /**
70: * Narrows the scope on the form-model to the member widget-field, and
71: * narrows the scope on the object-model to the member xpath-context
72: * before continuing the binding over the child-bindings.
73: */
74: public void doSave(Widget frmModel, JXPathContext jxpc)
75: throws BindingException {
76: Struct structWidget = (Struct) selectWidget(frmModel,
77: this .widgetId);
78: super .doSave(structWidget, jxpc);
79: }
80:
81: public String toString() {
82: return "StructJXPathBinding [widget=" + this .widgetId
83: + ", xpath=" + getXPath() + "]";
84: }
85: }
|