KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Locale JavaDoc;
19
20 import org.apache.cocoon.forms.FormsConstants;
21 import org.apache.cocoon.forms.datatype.convertor.Convertor;
22 import org.apache.cocoon.forms.util.DomHelper;
23 import org.apache.cocoon.i18n.I18nUtils;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * A simple multi field binding that will replace (i.e. delete then re-add all) its
28  * content.
29  * <pre><code>
30  * &lt;fb:multi-value id="<i>widget-id</i>"
31  * parent-path="<i>xpath-expression</i>"
32  * row-path="<i>xpath-expression</i>"&gt;
33  * &lt;!-- optional child binding to be executed upon 'save' of changed value --&gt;
34  * &lt;fb:on-update&gt;
35  * &lt;!-- any childbinding --&gt;
36  * &lt;/fb:on-update&gt;
37  * &lt;/fb:multi-value&gt;
38  * </code></pre>
39  *
40  * @version $Id: MultiValueJXPathBindingBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
41  */

42 public class MultiValueJXPathBindingBuilder
43     extends JXPathBindingBuilderBase {
44
45     public JXPathBindingBase buildBinding(
46         Element JavaDoc bindingElem,
47         JXPathBindingManager.Assistant assistant) throws BindingException {
48
49         try {
50             CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElem);
51
52             String JavaDoc multiValueId = DomHelper.getAttribute(bindingElem, "id", null);
53             String JavaDoc parentPath = DomHelper.getAttribute(bindingElem, "parent-path", null);
54             String JavaDoc rowPath = DomHelper.getAttribute(bindingElem, "row-path", null);
55
56             
57             Convertor convertor = null;
58             Locale JavaDoc convertorLocale = Locale.US;
59             Element JavaDoc convertorEl = DomHelper.getChildElement(bindingElem, FormsConstants.DEFINITION_NS, "convertor");
60             if (convertorEl != null) {
61                 String JavaDoc datatype = DomHelper.getAttribute(convertorEl, "datatype", null);
62                 String JavaDoc localeStr = DomHelper.getAttribute(convertorEl, "locale", null);
63                 if (localeStr != null) {
64                     convertorLocale = I18nUtils.parseLocale(localeStr);
65                 }
66
67                 convertor = assistant.getDatatypeManager().createConvertor(datatype, convertorEl);
68             }
69             
70             MultiValueJXPathBinding existingBinding = (MultiValueJXPathBinding)assistant.getContext().getSuperBinding();
71             JXPathBindingBase[] existingBindings = new JXPathBindingBase[0];
72             if(existingBinding != null) {
73                 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(existingBinding.getCommonAtts(),commonAtts);
74                 existingBindings = existingBinding.getUpdateBinding().getChildBindings();
75                 
76                 if(multiValueId == null)
77                     multiValueId = existingBinding.getId();
78                 if(parentPath == null)
79                     parentPath = existingBinding.getMultiValuePath();
80                 if(rowPath == null)
81                     rowPath = existingBinding.getRowPath();
82                 
83                 if(convertor == null) {
84                     convertor = existingBinding.getConvertor();
85                     convertorLocale = existingBinding.getLocale();
86                 }
87             }
88             
89             Element JavaDoc updateWrapElement =
90                 DomHelper.getChildElement(bindingElem, BindingManager.NAMESPACE, "on-update");
91             JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement,existingBindings);
92
93
94             return new MultiValueJXPathBinding( commonAtts, multiValueId, parentPath, rowPath,
95                                                 updateBindings, convertor, convertorLocale);
96         } catch (BindingException e) {
97             throw e;
98         } catch (Exception JavaDoc e) {
99             throw new BindingException("Error building multi value binding defined at " + DomHelper.getLocation(bindingElem), e);
100         }
101     }
102 }
103
Popular Tags