01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.binding;
18:
19: import org.apache.cocoon.forms.util.DomHelper;
20:
21: import org.w3c.dom.Element;
22:
23: /**
24: * ClassJXPathBindingBuilder provides a helper class for the Factory
25: * implemented in {@link JXPathBindingManager} that helps construct the
26: * actual {@link ClassJXPathBinding} out of the configuration in the
27: * provided configElement which looks like:
28: * <pre><code>
29: * <fb:class id="<i>widget-id</i>">
30: * <fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>"
31: * direction="<i>load|save</i>" lenient="<i>true|false</i>"/>
32: * </fb:class>
33: * </code></pre>
34: *
35: * @version $Id: ClassJXPathBindingBuilder.java 517733 2007-03-13 15:37:22Z vgritsenko $
36: */
37: public class ClassJXPathBindingBuilder extends JXPathBindingBuilderBase {
38:
39: public JXPathBindingBase buildBinding(Element bindingElm,
40: JXPathBindingManager.Assistant assistant)
41: throws BindingException {
42: try {
43: String widgetId = DomHelper.getAttribute(bindingElm, "id",
44: null);
45: CommonAttributes commonAtts = JXPathBindingBuilderBase
46: .getCommonAttributes(bindingElm);
47:
48: JXPathBindingBase[] childBindings = new JXPathBindingBase[0];
49:
50: // do inheritance
51: ClassJXPathBinding otherBinding = (ClassJXPathBinding) assistant
52: .getContext().getSuperBinding();
53: if (otherBinding != null) {
54: childBindings = otherBinding.getChildBindings();
55: commonAtts = JXPathBindingBuilderBase
56: .mergeCommonAttributes(otherBinding
57: .getCommonAtts(), commonAtts);
58:
59: if (widgetId == null) {
60: widgetId = otherBinding.getId();
61: }
62: }
63:
64: childBindings = assistant.makeChildBindings(bindingElm,
65: childBindings);
66:
67: return new ClassJXPathBinding(commonAtts, widgetId,
68: childBindings);
69: } catch (BindingException e) {
70: throw e;
71: } catch (Exception e) {
72: throw new BindingException("Error building class binding",
73: e, DomHelper.getLocationObject(bindingElm));
74: }
75: }
76: }
|