KickJava   Java API By Example, From Geeks To Geeks.

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


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.JXPathBindingBuilderBase.CommonAttributes;
19 import org.apache.cocoon.forms.formmodel.Widget;
20 import org.apache.commons.jxpath.JXPathContext;
21
22 /**
23  * CustomJXPathBinding
24  */

25 public class CustomJXPathBinding extends JXPathBindingBase {
26     
27     /**
28      * The id of the cforms widget
29      */

30     private final String JavaDoc widgetId;
31     
32     /**
33      * The path into the objectModel to select
34      */

35     private final String JavaDoc xpath;
36     
37     /**
38      * The actual custom provided binding
39      */

40     private final AbstractCustomBinding wrappedBinding;
41     
42     /**
43      * Constructs CustomJXPathBinding
44      *
45      * @param commonAtts common configuration attributes {@link org.apache.cocoon.forms.binding.JXPathBindingBuilderBase.CommonAttributes}
46      * @param widgetId id of the widget to bind to
47      * @param xpath jxpath expression to narrow down the context to before calling the wrapped Binding
48      * @param wrappedBinding the actual custom written Binding implementation of {@link Binding}
49      */

50     public CustomJXPathBinding(CommonAttributes commonAtts, String JavaDoc widgetId,
51                                String JavaDoc xpath, AbstractCustomBinding wrappedBinding) {
52         super(commonAtts);
53         this.widgetId = widgetId;
54         this.xpath = xpath;
55         this.wrappedBinding = wrappedBinding;
56     }
57     
58     public String JavaDoc getXPath() { return xpath; }
59     public String JavaDoc getId() { return widgetId; }
60     public AbstractCustomBinding getWrappedBinding() { return wrappedBinding; }
61     
62     /**
63      * Delegates the actual loading operation to the provided Custom Binding Class
64      * after narrowing down on the selected widget (@id) and context (@path)
65      *
66      * @param frmModel the narrowed widget-scope from the parent binding
67      * @param jxpc the narrowed jxpath context from the parent binding
68      * @throws BindingException when the wrapped CustomBinding fails
69      */

70     public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
71         Widget selectedWidget = selectWidget(frmModel, this.widgetId);
72         JXPathContext context = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
73         
74         this.wrappedBinding.loadFormFromModel(selectedWidget, context);
75     }
76
77     /**
78      * Delegates the actual saving operation to the provided Custom Binding Class
79      * after narrowing down on the selected widget (@id) and context (@path)
80      *
81      * @param frmModel the narrowed widget-scope from the parent binding
82      * @param jxpc the narrowed jxpath context from the parent binding
83      * @throws BindingException when the wrapped CustomBinding fails
84      */

85     public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
86         Widget selectedWidget = selectWidget(frmModel, this.widgetId);
87         JXPathContext context = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
88         
89         this.wrappedBinding.saveFormToModel(selectedWidget, context);
90     }
91     
92
93 }
94
Popular Tags