KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.DomHelper;
19 import org.w3c.dom.Element JavaDoc;
20
21 /**
22  * SetAttributeJXPathBindingBuilder provides a helper class for the Factory
23  * implemented in {@link JXPathBindingManager} that helps construct the
24  * actual {@link SetAttributeJXPathBinding} out of the configuration in the
25  * provided configElement which looks like:
26  * <pre><code>
27  * &lt;fb:set-attribute name="<i>attribute-name to set to</i>"
28  * value="<i>attribute-value</i>"/&gt;
29  * </code></pre>
30  *
31  * @version $Id: SetAttributeJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
32  */

33 public class SetAttributeJXPathBindingBuilder
34     extends JXPathBindingBuilderBase {
35
36
37     /**
38      * Creates an instance of {@link SetAttributeJXPathBinding} according to
39      * the attributes of the provided bindingElm.
40      */

41     public JXPathBindingBase buildBinding(Element JavaDoc bindingElm,
42         JXPathBindingManager.Assistant assistant) throws BindingException {
43
44         try {
45             CommonAttributes commonAtts =
46                 JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
47
48             String JavaDoc attName = DomHelper.getAttribute(bindingElm, "name", null);
49             String JavaDoc attValue = DomHelper.getAttribute(bindingElm, "value", null);
50
51             // do inheritance
52
SetAttributeJXPathBinding otherBinding = (SetAttributeJXPathBinding)assistant.getContext().getSuperBinding();
53             if(otherBinding!=null) {
54                 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
55                 
56                 if(attName==null)
57                     attName = otherBinding.getId();
58                 if(attValue==null)
59                     attValue = otherBinding.getValue();
60             }
61             
62             SetAttributeJXPathBinding attBinding =
63                 new SetAttributeJXPathBinding(commonAtts, attName, attValue);
64             return attBinding;
65         } catch (BindingException e) {
66             throw e;
67         } catch (Exception JavaDoc e) {
68             throw new BindingException(
69                     "Error building set-attribute binding defined at " +
70                     DomHelper.getLocation(bindingElm), e);
71         }
72     }
73 }
74
Popular Tags