KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > binding > AbstractCustomBinding


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.binding;
17
18 import org.apache.cocoon.forms.binding.library.Library;
19 import org.apache.cocoon.forms.formmodel.Widget;
20 import org.apache.commons.jxpath.JXPathContext;
21
22 /**
23  * AbstractCustomBinding
24  */

25 public abstract class AbstractCustomBinding implements Binding {
26
27     //TODO: following stuff should be removed after we cleaned out the Binding interface
28
private Binding parent;
29     private String JavaDoc id;
30
31     /**
32      * Sets parent binding.
33      */

34     public void setParent(Binding binding) {
35         this.parent = binding;
36     }
37     /**
38      * Returns binding definition id.
39      */

40     public String JavaDoc getId() {
41         return this.id;
42     }
43     public Binding getClass(String JavaDoc id) {
44         return this.parent.getClass(id);
45     }
46     //TODO: end of stuff to clean out over time
47
//below is the real useful stuff...
48

49     public boolean isValid() {
50         return false; // pessimistic
51
}
52     public Library getLocalLibrary() {
53         return null;
54     }
55     
56     /**
57      * Binding service method called upon loading.
58      * This will delegate to the overloaded version specific for this base-class.
59      * {@link #doLoad(Widget, JXPathContext)}
60      *
61      * @param frmModel
62      * @param objModel
63      * @throws BindingException
64      */

65     public final void loadFormFromModel(Widget frmModel, Object JavaDoc objModel) throws BindingException {
66         try {
67             doLoad(frmModel, (JXPathContext)objModel);
68         } catch (Exception JavaDoc e) {
69             throw new BindingException("Error executing custom binding", e);
70         }
71     }
72
73     /**
74      * Binding service method called upon saving.
75      * This will delegate to the overloaded version specific for this base-class.
76      * {@link #doSave(Widget, JXPathContext)}
77      *
78      * @param frmModel
79      * @param objModel
80      * @throws BindingException
81      */

82     public final void saveFormToModel(Widget frmModel, Object JavaDoc objModel) throws BindingException {
83         try {
84             doSave(frmModel, (JXPathContext)objModel);
85         } catch (Exception JavaDoc e) {
86             throw new BindingException("Error executing custom binding", e);
87         }
88     }
89     
90     /**
91      *
92      * @param frmModel
93      * @param context
94      */

95     protected abstract void doLoad(Widget frmModel, JXPathContext context) throws Exception JavaDoc;
96     protected abstract void doSave(Widget frmModel, JXPathContext context) throws Exception JavaDoc;
97 }
98
Popular Tags