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.binding.JXPathBindingManager.Assistant;
20: import org.apache.cocoon.forms.util.DomHelper;
21:
22: import org.w3c.dom.Element;
23:
24: /**
25: * InsertBeanJXPathBindingBuilder provides a helper class for the Factory
26: * implemented in {@link JXPathBindingManager} that helps construct the
27: * actual {@link InsertBeanJXPathBinding} out of the configuration in the
28: * provided configElement which looks like:
29: * <pre><code>
30: * <fb:insert-bean classname="..child-bean-class.." addmethod="..method-to-add.."/>
31: * </code></pre>
32: * or if the add method creates the new instance itself:
33: * <pre><code>
34: * <fb:insert-bean addmethod="..method-to-add.."/>
35: * </code></pre>
36: *
37: * @version $Id: InsertBeanJXPathBindingBuilder.java 450255 2006-09-26 23:48:43Z vgritsenko $
38: */
39: public class InsertBeanJXPathBindingBuilder extends
40: JXPathBindingBuilderBase {
41:
42: /**
43: * Creates an instance of {@link InsertBeanJXPathBinding} configured
44: * with the nested template of the bindingElm.
45: */
46: public JXPathBindingBase buildBinding(Element bindingElm,
47: Assistant assistant) throws BindingException {
48:
49: try {
50: CommonAttributes commonAtts = JXPathBindingBuilderBase
51: .getCommonAttributes(bindingElm);
52:
53: String className = DomHelper.getAttribute(bindingElm,
54: "classname", null);
55: String addMethod = DomHelper.getAttribute(bindingElm,
56: "addmethod", null);
57:
58: // do inheritance
59: InsertBeanJXPathBinding otherBinding = (InsertBeanJXPathBinding) assistant
60: .getContext().getSuperBinding();
61: if (otherBinding != null) {
62: commonAtts = JXPathBindingBuilderBase
63: .mergeCommonAttributes(otherBinding
64: .getCommonAtts(), commonAtts);
65:
66: if (className == null) {
67: className = otherBinding.getClassName();
68: }
69: if (addMethod == null) {
70: addMethod = otherBinding.getAddMethodName();
71: }
72: }
73:
74: return new InsertBeanJXPathBinding(commonAtts, className,
75: addMethod);
76: } catch (BindingException e) {
77: throw e;
78: } catch (Exception e) {
79: throw new BindingException(
80: "Error building a insert-bean binding defined at "
81: + DomHelper.getLocation(bindingElm), e);
82: }
83: }
84: }
|