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: import org.apache.cocoon.util.Deprecation;
21:
22: import org.w3c.dom.Element;
23:
24: /**
25: * StructJXPathBindingBuilder provides a helper class for the Factory
26: * implemented in {@link JXPathBindingManager} that helps construct the
27: * actual {@link StructJXPathBinding} out of the configuration in the
28: * provided configElement which looks like:
29: * <pre><code>
30: * <fb:struct id="<i>widget-id</i>" path="<i>xpath-expression</i>"
31: * direction="<i>load|save</i>" lenient="<i>true|false</i>" >
32: * <fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>" />
33: * </fb:struct>
34: * </code></pre>
35: *
36: * @version $Id: StructJXPathBindingBuilder.java 517733 2007-03-13 15:37:22Z vgritsenko $
37: */
38: public class StructJXPathBindingBuilder extends
39: JXPathBindingBuilderBase {
40:
41: public JXPathBindingBase buildBinding(Element bindingElm,
42: JXPathBindingManager.Assistant assistant)
43: throws BindingException {
44: Deprecation.logger
45: .info("'fb:struct' is deprecated and replaced by 'fb:group' at "
46: + DomHelper.getLocation(bindingElm));
47: try {
48: String widgetId = DomHelper.getAttribute(bindingElm, "id");
49: CommonAttributes commonAtts = JXPathBindingBuilderBase
50: .getCommonAttributes(bindingElm);
51: String xpath = DomHelper.getAttribute(bindingElm, "path");
52:
53: JXPathBindingBase[] childBindings = new JXPathBindingBase[0];
54:
55: // do inheritance
56: StructJXPathBinding otherBinding = (StructJXPathBinding) assistant
57: .getContext().getSuperBinding();
58: if (otherBinding != null) {
59: childBindings = otherBinding.getChildBindings();
60: commonAtts = JXPathBindingBuilderBase
61: .mergeCommonAttributes(otherBinding
62: .getCommonAtts(), commonAtts);
63:
64: // FIXME Never happens
65: if (xpath == null)
66: xpath = otherBinding.getXPath();
67: // FIXME Never happens
68: if (widgetId == null)
69: widgetId = otherBinding.getId();
70: }
71:
72: childBindings = assistant.makeChildBindings(bindingElm,
73: childBindings);
74:
75: return new StructJXPathBinding(commonAtts, widgetId, xpath,
76: childBindings);
77: } catch (BindingException e) {
78: throw e;
79: } catch (Exception e) {
80: throw new BindingException("Error building struct binding",
81: e, DomHelper.getLocationObject(bindingElm));
82: }
83: }
84: }
|