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.binding.library.Library;
020: import org.apache.cocoon.forms.formmodel.Form;
021: import org.apache.cocoon.forms.formmodel.Widget;
022:
023: import org.apache.commons.jxpath.JXPathContext;
024:
025: /**
026: * AbstractCustomBinding
027: * @version $Id: AbstractCustomBinding.java 450255 2006-09-26 23:48:43Z vgritsenko $
028: */
029: public abstract class AbstractCustomBinding implements Binding {
030:
031: //TODO: following stuff should be removed after we cleaned out the Binding interface
032: private Binding parent;
033: private String id;
034: private String xpath;
035:
036: public void setXpath(String path) {
037: this .xpath = path;
038: }
039:
040: public String getXpath() {
041: return xpath;
042: }
043:
044: /**
045: * Sets parent binding.
046: */
047: public void setParent(Binding binding) {
048: this .parent = binding;
049: }
050:
051: /**
052: * Returns binding definition id.
053: */
054: public String getId() {
055: return this .id;
056: }
057:
058: public Binding getClass(String id) {
059: return this .parent.getClass(id);
060: }
061:
062: //TODO: end of stuff to clean out over time
063: //below is the real useful stuff...
064:
065: public boolean isValid() {
066: return false; // pessimistic
067: }
068:
069: // needed for the Binding interface, should never need to be used in a subclass
070: public Library getEnclosingLibrary() {
071: return null;
072: }
073:
074: public void setEnclosingLibrary(Library lib) {
075: }
076:
077: /**
078: * Binding service method called upon loading.
079: * This will delegate to the overloaded version specific for this base-class.
080: * {@link #doLoad(Widget, JXPathContext)}
081: *
082: * @param frmModel
083: * @param objModel
084: * @throws BindingException
085: */
086: public final void loadFormFromModel(Widget frmModel, Object objModel)
087: throws BindingException {
088: if (frmModel instanceof Form) {
089: ((Form) frmModel).informStartLoadingModel();
090: }
091: try {
092: doLoad(frmModel, (JXPathContext) objModel);
093: } catch (Exception e) {
094: throw new BindingException(
095: "Error executing custom binding", e);
096: }
097: if (frmModel instanceof Form) {
098: ((Form) frmModel).informEndLoadingModel();
099: }
100: }
101:
102: /**
103: * Binding service method called upon saving.
104: * This will delegate to the overloaded version specific for this base-class.
105: * {@link #doSave(Widget, JXPathContext)}
106: *
107: * @param frmModel
108: * @param objModel
109: * @throws BindingException
110: */
111: public final void saveFormToModel(Widget frmModel, Object objModel)
112: throws BindingException {
113: if (frmModel instanceof Form) {
114: ((Form) frmModel).informStartSavingModel();
115: }
116: try {
117: doSave(frmModel, (JXPathContext) objModel);
118: } catch (Exception e) {
119: throw new BindingException(
120: "Error executing custom binding", e);
121: }
122: if (frmModel instanceof Form) {
123: ((Form) frmModel).informEndSavingModel();
124: }
125: }
126:
127: /**
128: * @param frmModel
129: * @param context
130: */
131: protected abstract void doLoad(Widget frmModel,
132: JXPathContext context) throws Exception;
133:
134: protected abstract void doSave(Widget frmModel,
135: JXPathContext context) throws Exception;
136: }
|