KickJava   Java API By Example, From Geeks To Geeks.

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


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  * UniqueFieldJXPathBindingBuilder provides a helper class for the Factory
28  * implemented in {@link JXPathBindingManager} that helps construct the
29  * actual {@link UniqueFieldJXPathBinding} out of the configuration in the
30  * provided configElement which looks like:
31  * <pre><code>
32  * &lt;wb:unique-field id="<i>widget-id</i>" path="<i>xpath-expression</i>"&gt;
33  * &lt;!-- optional convertor of these field --&gt;
34  * &lt;wd:convertor&gt;
35  * &lt;!-- any convertor --&gt;
36  * &lt;/wd:convertor&gt;
37  * &lt;/wb:unique-field&gt;
38  * </code></pre>
39  *
40  * @version CVS $Id: UniqueFieldJXPathBindingBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
41  */

42 public class UniqueFieldJXPathBindingBuilder extends JXPathBindingBuilderBase {
43
44     /**
45      * Creates an instance of {@link UniqueFieldJXPathBinding} 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 widgetId = DomHelper.getAttribute(bindingElm, "id");
53             String JavaDoc xpath = DomHelper.getAttribute(bindingElm, "path");
54
55             Convertor convertor = null;
56             Locale JavaDoc convertorLocale = Locale.US;
57             Element JavaDoc convertorEl = DomHelper.getChildElement(bindingElm, Constants.WD_NS, "convertor");
58             if (convertorEl != null) {
59                 String JavaDoc datatype = DomHelper.getAttribute(convertorEl, "datatype");
60                 String JavaDoc localeStr = convertorEl.getAttribute("datatype");
61                 if (!localeStr.equals("")) {
62                     convertorLocale = I18nUtils.parseLocale(localeStr);
63                 }
64                 convertor = assistant.getDatatypeManager().createConvertor(datatype, convertorEl);
65             }
66
67             UniqueFieldJXPathBinding fieldBinding =
68                     new UniqueFieldJXPathBinding(commonAtts,
69                             widgetId, xpath, convertor, convertorLocale);
70
71             return fieldBinding;
72         } catch (BindingException e) {
73             throw e;
74         } catch (Exception JavaDoc e) {
75             throw new BindingException("Error building binding defined at " + DomHelper.getLocation(bindingElm), e);
76         }
77     }
78 }
79
Popular Tags