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: * UnionJXPathBindingBuilder provides a helper class for the Factory
25: * implemented in {@link JXPathBindingManager} that helps construct the
26: * actual {@link UnionJXPathBinding} out of the configuration in the
27: * provided configElement which looks like:
28: * <pre><code>
29: * <fb:union id="<i>widget-id</i>" path="<i>xpath-expression</i>"
30: * direction="<i>load|save</i>" lenient="<i>true|false</i>" >
31: * <fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>" />
32: * </fb:union>
33: * </code></pre>
34: *
35: * @version $Id: UnionJXPathBindingBuilder.java 517733 2007-03-13 15:37:22Z vgritsenko $
36: */
37: public class UnionJXPathBindingBuilder 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: String xpath = DomHelper.getAttribute(bindingElm, "path",
48: null);
49:
50: JXPathBindingBase[] childBindings = new JXPathBindingBase[0];
51:
52: // do inheritance
53: UnionJXPathBinding otherBinding = (UnionJXPathBinding) assistant
54: .getContext().getSuperBinding();
55: if (otherBinding != null) {
56: childBindings = otherBinding.getChildBindings();
57: commonAtts = JXPathBindingBuilderBase
58: .mergeCommonAttributes(otherBinding
59: .getCommonAtts(), commonAtts);
60:
61: if (xpath == null) {
62: xpath = otherBinding.getXPath();
63: }
64: if (widgetId == null) {
65: widgetId = otherBinding.getId();
66: }
67: }
68:
69: childBindings = assistant.makeChildBindings(bindingElm,
70: childBindings);
71:
72: return new UnionJXPathBinding(commonAtts, widgetId, xpath,
73: childBindings);
74: } catch (BindingException e) {
75: throw e;
76: } catch (Exception e) {
77: throw new BindingException("Error building union binding",
78: e, DomHelper.getLocationObject(bindingElm));
79: }
80: }
81: }
|