KickJava   Java API By Example, From Geeks To Geeks.

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


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.binding.JXPathBindingManager.Assistant;
19 import org.apache.cocoon.forms.util.DomHelper;
20 import org.w3c.dom.Element JavaDoc;
21
22 /**
23  * InsertBeanJXPathBindingBuilder provides a helper class for the Factory
24  * implemented in {@link JXPathBindingManager} that helps construct the
25  * actual {@link InsertBeanJXPathBinding} out of the configuration in the
26  * provided configElement which looks like:
27  * <pre><code>
28  * &lt;fb:insert-bean classname="..child-bean-class.." addmethod="..method-to-add.."/&gt;
29  * </code></pre>
30  * or if the add method creates the new instance itself:
31  * <pre><code>
32  * &lt;fb:insert-bean addmethod="..method-to-add.."/&gt;
33  * </code></pre>
34  *
35  * @version $Id: InsertBeanJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
36  */

37 public class InsertBeanJXPathBindingBuilder extends JXPathBindingBuilderBase {
38
39     /**
40      * Creates an instance of {@link InsertBeanJXPathBinding} configured
41      * with the nested template of the bindingElm.
42      */

43     public JXPathBindingBase buildBinding(Element JavaDoc bindingElm, Assistant assistant) throws BindingException {
44
45         try {
46             CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
47
48             String JavaDoc className =
49                 DomHelper.getAttribute(bindingElm, "classname", null);
50             String JavaDoc addMethod =
51                 DomHelper.getAttribute(bindingElm, "addmethod",null);
52
53 // do inheritance
54
InsertBeanJXPathBinding otherBinding = (InsertBeanJXPathBinding)assistant.getContext().getSuperBinding();
55             if(otherBinding!=null) {
56                 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
57                 
58                 if(className==null)
59                     className = otherBinding.getClassName();
60                 if(addMethod==null)
61                     addMethod = otherBinding.getAddMethodName();
62             }
63             
64             return new InsertBeanJXPathBinding(commonAtts, className, addMethod);
65         } catch (BindingException e) {
66             throw e;
67         } catch (Exception JavaDoc e) {
68             throw new BindingException("Error building a insert-bean binding defined at " + DomHelper.getLocation(bindingElm), e);
69         }
70     }
71 }
72
Popular Tags