KickJava   Java API By Example, From Geeks To Geeks.

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


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.formmodel.Widget;
19 import org.apache.commons.jxpath.JXPathContext;
20
21 /**
22  * SetAttributeJXPathBinding provides an implementation of a {@link Binding}
23  * that sets a particular attribute to a fixed value upon save.
24  * <p>
25  * NOTES: <ol>
26  * <li>This Binding does not perform any actions when loading.</li>
27  * </ol>
28  *
29  * @version $Id: SetAttributeJXPathBinding.java 289538 2005-09-16 13:46:22Z sylvain $
30  */

31 public class SetAttributeJXPathBinding extends JXPathBindingBase {
32
33     private final String JavaDoc name;
34     private final String JavaDoc value;
35
36     /**
37      * Constructs SetAttributeJXPathBinding
38      */

39     public SetAttributeJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String JavaDoc attName, String JavaDoc attValue) {
40         super(commonAtts);
41         this.name = attName;
42         this.value = attValue;
43     }
44     
45     public String JavaDoc getId() { return name; }
46     public String JavaDoc getValue() { return value; }
47
48     /**
49      * Do-Nothing implementation.
50      */

51     public void doLoad(Widget frmModel, JXPathContext jxpc) {
52         //this does nothing in the loading of things
53
}
54
55     /**
56      * Sets the attribute value on the passed JXPathContext
57      */

58     public void doSave(Widget frmModel, JXPathContext jxpc) {
59         jxpc.setValue("@" + this.name, this.value);
60         if (getLogger().isDebugEnabled())
61             getLogger().debug("done saving " + toString());
62     }
63
64     public String JavaDoc toString() {
65         return "SetAttributeJXPathBinding [attName=" + this.name + ", attValue=" + this.value + "]";
66     }
67 }
68
Popular Tags