KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A simple repeater binding that will replace (i.e. delete then re-add all) its
23  * content.
24  * <pre>
25  * &lt;fb:simple-repeater
26  * id="contacts"
27  * parent-path="contacts"&gt;
28  * &lt;<em>... child bindings ...</em>&gt;
29  * &lt;/fb:simple-repeater&gt;
30  * </pre>
31  *
32  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
33  * @version $Id: SimpleRepeaterJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
34  */

35 public class SimpleRepeaterJXPathBindingBuilder
36     extends JXPathBindingBuilderBase {
37
38     public JXPathBindingBase buildBinding(Element JavaDoc bindingElem,
39         JXPathBindingManager.Assistant assistant) throws BindingException {
40         try {
41             CommonAttributes commonAtts =
42                 JXPathBindingBuilderBase.getCommonAttributes(bindingElem);
43
44             String JavaDoc repeaterId = DomHelper.getAttribute(bindingElem, "id", null);
45             String JavaDoc parentPath = DomHelper.getAttribute(
46                     bindingElem, "parent-path", null);
47             String JavaDoc rowPath = DomHelper.getAttribute(bindingElem, "row-path", null);
48             boolean clearOnLoad = DomHelper.getAttributeAsBoolean(
49                     bindingElem, "clear-before-load", true);
50             boolean deleteIfEmpty = DomHelper.getAttributeAsBoolean(
51                     bindingElem, "delete-parent-if-empty", false);
52
53             JXPathBindingBase[] childBindings = null;
54             
55             // do inheritance
56
SimpleRepeaterJXPathBinding otherBinding = (SimpleRepeaterJXPathBinding)assistant.getContext().getSuperBinding();
57             if(otherBinding!=null) {
58                 childBindings = otherBinding.getChildBindings();
59                 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
60                 
61                 if(parentPath==null)
62                     parentPath = otherBinding.getRepeaterPath();
63                 if(repeaterId==null)
64                     repeaterId = otherBinding.getId();
65                 if(rowPath==null)
66                     rowPath = otherBinding.getRowPath();
67                 if(!bindingElem.hasAttribute("clear-before-load"))
68                     clearOnLoad = otherBinding.getClearOnLoad();
69                 if(!bindingElem.hasAttribute("delete-parent-if-empty"))
70                     deleteIfEmpty = otherBinding.getDeleteIfEmpty();
71             }
72             
73             childBindings = assistant.makeChildBindings(bindingElem, childBindings);
74
75             return new SimpleRepeaterJXPathBinding(commonAtts, repeaterId,
76                     parentPath, rowPath, clearOnLoad, deleteIfEmpty,
77                     new ComposedJXPathBindingBase(
78                             JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
79                             childBindings));
80         } catch (BindingException e) {
81             throw e;
82         } catch (Exception JavaDoc e) {
83             throw new BindingException(
84                     "Error building repeater binding defined at " +
85                     DomHelper.getLocation(bindingElem), e);
86         }
87     }
88 }
89
Popular Tags