KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.cocoon.util.Deprecation;
20 import org.w3c.dom.Element JavaDoc;
21
22 /**
23  * StructJXPathBindingBuilder provides a helper class for the Factory
24  * implemented in {@link JXPathBindingManager} that helps construct the
25  * actual {@link StructJXPathBinding} out of the configuration in the
26  * provided configElement which looks like:
27  * <pre><code>
28  * &lt;fb:struct id="<i>widget-id</i>" path="<i>xpath-expression</i>"
29  * direction="<i>load|save</i>" lenient="<i>true|false</i>" &gt;
30  * &lt;fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>" />
31  * &lt;/fb:struct&gt;
32  * </code></pre>
33  *
34  * @version $Id: StructJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
35  */

36 public class StructJXPathBindingBuilder
37     extends JXPathBindingBuilderBase {
38
39     public JXPathBindingBase buildBinding(Element JavaDoc bindingElm, JXPathBindingManager.Assistant assistant)
40             throws BindingException {
41         Deprecation.logger.info("'fb:struct' is deprecated and replaced by 'fb:group' at " + DomHelper.getLocation(bindingElm));
42         try {
43             String JavaDoc widgetId = DomHelper.getAttribute(bindingElm, "id");
44             CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
45             String JavaDoc xpath = DomHelper.getAttribute(bindingElm, "path");
46
47             JXPathBindingBase[] childBindings = new JXPathBindingBase[0];
48
49 // do inheritance
50
StructJXPathBinding otherBinding = (StructJXPathBinding)assistant.getContext().getSuperBinding();
51             if(otherBinding!=null) {
52                 childBindings = otherBinding.getChildBindings();
53                 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
54                 
55                 if(xpath==null)
56                     xpath = otherBinding.getXPath();
57                 if(widgetId==null)
58                     widgetId = otherBinding.getId();
59             }
60             
61             childBindings = assistant.makeChildBindings(bindingElm,childBindings);
62             
63             StructJXPathBinding structBinding =
64                 new StructJXPathBinding(commonAtts, widgetId, xpath, childBindings);
65             return structBinding;
66         } catch (BindingException e) {
67             throw e;
68         } catch (Exception JavaDoc e) {
69             throw new BindingException("Error building struct binding defined at " + DomHelper.getLocation(bindingElm), e);
70         }
71     }
72 }
73
Popular Tags