KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > binding > ValueJXPathBindingBuilder


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 org.apache.cocoon.woody.util.DomHelper;
19 import org.apache.cocoon.woody.Constants;
20 import org.apache.cocoon.woody.datatype.convertor.Convertor;
21 import org.apache.cocoon.i18n.I18nUtils;
22 import org.w3c.dom.Element JavaDoc;
23
24 import java.util.Locale JavaDoc;
25
26 /**
27  * ValueJXPathBindingBuilder provides a helper class for the Factory
28  * implemented in {@link JXPathBindingManager} that helps construct the
29  * actual {@link ValueJXPathBinding} out of the configuration in the
30  * provided configElement which looks like:
31  * <pre><code>
32  * &lt;wb:value id="<i>widget-id</i>" 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:value&gt;
38  * </code></pre>
39  *
40  * @version CVS $Id: ValueJXPathBindingBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
41  */

42 public class ValueJXPathBindingBuilder extends JXPathBindingBuilderBase {
43
44     /**
45      * Creates an instance of {@link ValueJXPathBinding} based on the attributes
46      * and nested configuration of the provided bindingElm.
47      */

48     public JXPathBindingBase buildBinding(Element JavaDoc bindingElm, JXPathBindingManager.Assistant assistant) throws BindingException {
49
50         try {
51             CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
52             String JavaDoc xpath = DomHelper.getAttribute(bindingElm, "path");
53             String JavaDoc widgetId = DomHelper.getAttribute(bindingElm, "id");
54
55             Element JavaDoc updateWrapElement =
56                 DomHelper.getChildElement(bindingElm, BindingManager.NAMESPACE, "on-update");
57             JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement);
58
59             Convertor convertor = null;
60             Locale JavaDoc convertorLocale = Locale.US;
61             Element JavaDoc convertorEl = DomHelper.getChildElement(bindingElm, Constants.WD_NS, "convertor");
62             if (convertorEl != null) {
63                 String JavaDoc datatype = DomHelper.getAttribute(convertorEl, "datatype");
64                 String JavaDoc localeStr = convertorEl.getAttribute("datatype");
65                 if (!localeStr.equals("")) {
66                     convertorLocale = I18nUtils.parseLocale(localeStr);
67                 }
68
69                 convertor = assistant.getDatatypeManager().createConvertor(datatype, convertorEl);
70             }
71
72             ValueJXPathBinding fieldBinding =
73                     new ValueJXPathBinding(commonAtts,
74                             widgetId, xpath, updateBindings, convertor, convertorLocale);
75
76             return fieldBinding;
77         } catch (BindingException e) {
78             throw e;
79         } catch (Exception JavaDoc e) {
80             throw new BindingException("Error building binding defined at " + DomHelper.getLocation(bindingElm), e);
81         }
82     }
83 }
84
Popular Tags