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.avalon.framework.service.ServiceException;
020: import org.apache.avalon.framework.service.ServiceManager;
021: import org.apache.avalon.framework.service.Serviceable;
022:
023: import org.apache.cocoon.forms.binding.JXPathBindingBuilderBase.CommonAttributes;
024: import org.apache.cocoon.forms.formmodel.Widget;
025:
026: import org.apache.commons.jxpath.JXPathContext;
027:
028: /**
029: * CustomJXPathBinding
030: */
031: public class CustomJXPathBinding extends JXPathBindingBase implements
032: Serviceable {
033:
034: /**
035: * The id of the cforms widget
036: */
037: private final String widgetId;
038:
039: /**
040: * The path into the objectModel to select
041: */
042: private final String xpath;
043:
044: /**
045: * The actual custom provided binding
046: */
047: private final AbstractCustomBinding wrappedBinding;
048:
049: /**
050: * Constructs CustomJXPathBinding
051: *
052: * @param commonAtts common configuration attributes {@link org.apache.cocoon.forms.binding.JXPathBindingBuilderBase.CommonAttributes}
053: * @param widgetId id of the widget to bind to
054: * @param xpath jxpath expression to narrow down the context to before calling the wrapped Binding
055: * @param wrappedBinding the actual custom written Binding implementation of {@link Binding}
056: */
057: public CustomJXPathBinding(CommonAttributes commonAtts,
058: String widgetId, String xpath,
059: AbstractCustomBinding wrappedBinding) {
060: super (commonAtts);
061: this .widgetId = widgetId;
062: this .xpath = xpath;
063: this .wrappedBinding = wrappedBinding;
064: wrappedBinding.setXpath(xpath);
065: }
066:
067: public String getXPath() {
068: return xpath;
069: }
070:
071: public String getId() {
072: return widgetId;
073: }
074:
075: public AbstractCustomBinding getWrappedBinding() {
076: return wrappedBinding;
077: }
078:
079: /**
080: * Delegates the actual loading operation to the provided Custom Binding Class
081: * after narrowing down on the selected widget (@id) and context (@path)
082: *
083: * @param frmModel the narrowed widget-scope from the parent binding
084: * @param jxpc the narrowed jxpath context from the parent binding
085: * @throws BindingException when the wrapped CustomBinding fails
086: */
087: public void doLoad(Widget frmModel, JXPathContext jxpc)
088: throws BindingException {
089: Widget selectedWidget = selectWidget(frmModel, this .widgetId);
090: this .wrappedBinding.loadFormFromModel(selectedWidget, jxpc);
091: }
092:
093: /**
094: * Delegates the actual saving operation to the provided Custom Binding Class
095: * after narrowing down on the selected widget (@id) and context (@path)
096: *
097: * @param frmModel the narrowed widget-scope from the parent binding
098: * @param jxpc the narrowed jxpath context from the parent binding
099: * @throws BindingException when the wrapped CustomBinding fails
100: */
101: public void doSave(Widget frmModel, JXPathContext jxpc)
102: throws BindingException {
103: Widget selectedWidget = selectWidget(frmModel, this .widgetId);
104: this .wrappedBinding.saveFormToModel(selectedWidget, jxpc);
105: }
106:
107: /**
108: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
109: */
110: public void service(ServiceManager manager) throws ServiceException {
111: if (wrappedBinding instanceof Serviceable) {
112: ((Serviceable) wrappedBinding).service(manager);
113: }
114: }
115: }
|