KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.DomHelper;
19 import org.w3c.dom.Element JavaDoc;
20
21 /**
22  * An experimental simple repeater binding that will replace
23  * (i.e. delete then re-add all) its content.
24  * Based on SimpleRepeater code.
25  * <pre>
26  * &lt;fb:temp-repeater
27  * id="contacts"
28  * parent-path="contacts"&gt;
29  * &lt;<em>... child bindings ...</em>&gt;
30  * &lt;/fb:temp-repeater&gt;
31  * </pre>
32  *
33  * @version $Id: TempRepeaterJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
34  */

35 public class TempRepeaterJXPathBindingBuilder
36     extends JXPathBindingBuilderBase {
37
38     public JXPathBindingBase buildBinding(Element JavaDoc bindingElem,
39         JXPathBindingManager.Assistant assistant) throws BindingException {
40         try {
41             CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElem);
42
43             String JavaDoc repeaterId = DomHelper.getAttribute(bindingElem, "id", null);
44             String JavaDoc parentPath = DomHelper.getAttribute(bindingElem,
45                     "parent-path", null);
46             String JavaDoc rowPath = DomHelper.getAttribute(bindingElem, "row-path", null);
47             String JavaDoc rowPathInsert = DomHelper.getAttribute(bindingElem,
48                     "row-path-insert", rowPath);
49             boolean virtualRows = DomHelper.getAttributeAsBoolean(
50                     bindingElem, "virtual-rows", false);
51             boolean clearOnLoad = DomHelper.getAttributeAsBoolean(
52                     bindingElem, "clear-before-load", true);
53             boolean deleteIfEmpty = DomHelper.getAttributeAsBoolean(
54                     bindingElem, "delete-parent-if-empty", false);
55
56             JXPathBindingBase[] insertBindings = null;
57             JXPathBindingBase[] childBindings = null;
58             
59             // do inheritance
60
TempRepeaterJXPathBinding otherBinding = (TempRepeaterJXPathBinding)assistant.getContext().getSuperBinding();
61             if(otherBinding!=null) {
62                 childBindings = otherBinding.getChildBindings();
63                 insertBindings = otherBinding.getInsertChildBindings();
64                 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
65                 
66                 if(parentPath==null)
67                     parentPath = otherBinding.getRepeaterPath();
68                 if(repeaterId==null)
69                     repeaterId = otherBinding.getId();
70                 if(rowPath==null)
71                     rowPath = otherBinding.getRowPath();
72                 if(rowPathInsert==null)
73                     rowPathInsert = otherBinding.getRowPathInsert();
74                 if(!bindingElem.hasAttribute("virtual-rows"))
75                     clearOnLoad = otherBinding.getVirtualRows();
76                 if(!bindingElem.hasAttribute("clear-before-load"))
77                     clearOnLoad = otherBinding.getClearOnLoad();
78                 if(!bindingElem.hasAttribute("delete-parent-if-empty"))
79                     deleteIfEmpty = otherBinding.getDeleteIfEmpty();
80             }
81             
82             Element JavaDoc childWrapElement = DomHelper.getChildElement(
83                     bindingElem, BindingManager.NAMESPACE, "on-bind");
84             childBindings = assistant.makeChildBindings(childWrapElement,childBindings);
85
86             Element JavaDoc insertWrapElement = DomHelper.getChildElement(bindingElem,
87                     BindingManager.NAMESPACE, "on-insert-row");
88             
89             if (insertWrapElement != null) {
90                 insertBindings =
91                     assistant.makeChildBindings(insertWrapElement,insertBindings);
92             }
93             return new TempRepeaterJXPathBinding(commonAtts, repeaterId,
94                     parentPath, rowPath, rowPathInsert, virtualRows,
95                     clearOnLoad, deleteIfEmpty,
96                     new ComposedJXPathBindingBase(
97                             JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
98                             childBindings),
99                     new ComposedJXPathBindingBase(
100                             JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
101                             insertBindings));
102         } catch (BindingException e) {
103             throw e;
104         } catch (Exception JavaDoc e) {
105             throw new BindingException(
106                     "Error building temp-repeater binding defined at " +
107                     DomHelper.getLocation(bindingElem), e);
108         }
109     }
110 }
111
Popular Tags