001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.binding;
018:
019: import org.apache.cocoon.forms.formmodel.AggregateField;
020: import org.apache.cocoon.forms.formmodel.Widget;
021:
022: import org.apache.commons.jxpath.JXPathContext;
023:
024: /**
025: * AggregateJXPathBinding provides an implementation of a {@link Binding}
026: * that narrows the context towards provided childbindings.
027: * <p>NOTES:
028: * <ol>
029: * <li>This Binding assumes that the provided widget-id points to a widget
030: * that contains other widgets.</li>
031: * </ol>
032: *
033: * @version $Id: AggregateJXPathBinding.java 517733 2007-03-13 15:37:22Z vgritsenko $
034: */
035: public class AggregateJXPathBinding extends ComposedJXPathBindingBase {
036:
037: private final String xpath;
038:
039: private final String widgetId;
040:
041: /**
042: * Constructs AggregateJXPathBinding
043: * @param widgetId
044: * @param xpath
045: * @param childBindings
046: */
047: public AggregateJXPathBinding(
048: JXPathBindingBuilderBase.CommonAttributes commonAtts,
049: String widgetId, String xpath,
050: JXPathBindingBase[] childBindings) {
051: super (commonAtts, childBindings);
052: this .widgetId = widgetId;
053: this .xpath = xpath;
054: }
055:
056: public String getXPath() {
057: return xpath;
058: }
059:
060: public String getId() {
061: return widgetId;
062: }
063:
064: /**
065: * Narrows the scope on the form-model to the member widget-field, and
066: * narrows the scope on the object-model to the member xpath-context
067: * before continuing the binding over the child-bindings.
068: */
069: public void doLoad(Widget frmModel, JXPathContext jxpc)
070: throws BindingException {
071: AggregateField aggregate = (AggregateField) selectWidget(
072: frmModel, this .widgetId);
073: JXPathContext subContext = jxpc.getRelativeContext(jxpc
074: .getPointer(this .xpath));
075: super .doLoad(aggregate, subContext);
076: aggregate.combineFields();
077: if (getLogger().isDebugEnabled()) {
078: getLogger().debug("Done loading " + this );
079: }
080: }
081:
082: /**
083: * Narrows the scope on the form-model to the member widget-field, and
084: * narrows the scope on the object-model to the member xpath-context
085: * before continuing the binding over the child-bindings.
086: */
087: public void doSave(Widget frmModel, JXPathContext jxpc)
088: throws BindingException {
089: AggregateField aggregate = (AggregateField) selectWidget(
090: frmModel, this .widgetId);
091: JXPathContext subContext = jxpc.getRelativeContext(jxpc
092: .getPointer(this .xpath));
093: super .doSave(aggregate, subContext);
094: if (getLogger().isDebugEnabled()) {
095: getLogger().debug("Done saving " + this );
096: }
097: }
098:
099: public String toString() {
100: return "AggregateJXPathBinding [widget=" + this .widgetId
101: + ", xpath=" + this .xpath + "]";
102: }
103: }
|