KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > 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.woody.binding;
17
18 import java.util.Locale JavaDoc;
19
20 import org.apache.cocoon.woody.Constants;
21 import org.apache.cocoon.woody.util.DomHelper;
22 import org.apache.cocoon.woody.datatype.convertor.Convertor;
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;wb: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;wb:on-update&gt;
35  * &lt;!-- any childbinding --&gt;
36  * &lt;/wb:on-update&gt;
37  * &lt;/wb:multi-value&gt;
38  * </code></pre>
39  *
40  * @version CVS $Id: MultiValueJXPathBindingBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
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");
53             String JavaDoc parentPath = DomHelper.getAttribute(bindingElem, "parent-path");
54             String JavaDoc rowPath = DomHelper.getAttribute(bindingElem, "row-path");
55
56             Element JavaDoc updateWrapElement =
57                 DomHelper.getChildElement(bindingElem, BindingManager.NAMESPACE, "on-update");
58             JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement);
59
60             Convertor convertor = null;
61             Locale JavaDoc convertorLocale = Locale.US;
62             Element JavaDoc convertorEl = DomHelper.getChildElement(bindingElem, Constants.WD_NS, "convertor");
63             if (convertorEl != null) {
64                 String JavaDoc datatype = DomHelper.getAttribute(convertorEl, "datatype");
65                 String JavaDoc localeStr = convertorEl.getAttribute("datatype");
66                 if (!localeStr.equals("")) {
67                     convertorLocale = I18nUtils.parseLocale(localeStr);
68                 }
69
70                 convertor = assistant.getDatatypeManager().createConvertor(datatype, convertorEl);
71             }
72
73             return new MultiValueJXPathBinding( commonAtts, multiValueId, parentPath, rowPath,
74                                                 updateBindings, convertor, convertorLocale);
75         } catch (BindingException e) {
76             throw e;
77         } catch (Exception JavaDoc e) {
78             throw new BindingException("Error building multi value binding defined at " + DomHelper.getLocation(bindingElem), e);
79         }
80     }
81 }
82
Popular Tags