KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > binding > ComposedJXPathBindingBase


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.woody.binding;
17
18 import java.util.HashMap JavaDoc;
19
20 import org.apache.avalon.framework.logger.Logger;
21 import org.apache.cocoon.woody.formmodel.Widget;
22 import org.apache.commons.jxpath.JXPathContext;
23
24 /**
25  * ComposedJXPathBindingBase provides a helper base class for subclassing
26  * into specific {@link JXPathBindingBase} implementations that have nested
27  * child-bindings.
28  *
29  * @version CVS $Id: ComposedJXPathBindingBase.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public class ComposedJXPathBindingBase extends JXPathBindingBase {
32     private final JXPathBindingBase[] subBindings;
33
34     /**
35      * Constructs ComposedJXPathBindingBase
36      *
37      * @param childBindings sets the array of childBindings
38      */

39     protected ComposedJXPathBindingBase(JXPathBindingBuilderBase.CommonAttributes commonAtts, JXPathBindingBase[] childBindings) {
40         super(commonAtts);
41         this.subBindings = childBindings;
42         if (this.subBindings != null) {
43             for (int i = 0; i < this.subBindings.length; i++) {
44                 this.subBindings[i].setParent(this);
45             }
46         }
47     }
48
49     /**
50      * Receives the logger to use for logging activity, and hands it over to
51      * the nested children.
52      */

53     public void enableLogging(Logger logger) {
54         super.enableLogging(logger);
55         if (this.subBindings != null) {
56             for (int i = 0; i < this.subBindings.length; i++) {
57                 this.subBindings[i].enableLogging(logger);
58             }
59         }
60     }
61
62     /**
63      * Gets a binding class by id.
64      * @param id Id of binding class to get.
65      */

66     public Binding getClass(String JavaDoc id) {
67         if (classes == null) {
68             classes = new HashMap JavaDoc();
69             if (this.subBindings != null) {
70                 for (int i = 0; i < this.subBindings.length; i++) {
71                     Binding binding = this.subBindings[i];
72                     String JavaDoc bindingId = binding.getId();
73                     if (bindingId != null)
74                       classes.put(bindingId, binding);
75                 }
76             }
77         }
78         return super.getClass(id);
79     }
80
81     /**
82      * Returns child bindings.
83      */

84     public JXPathBindingBase[] getChildBindings() {
85         return subBindings;
86     }
87
88     /**
89      * Actively performs the binding from the ObjectModel to the Woody-form
90      * by passing the task onto it's children.
91      */

92     public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
93         if (this.subBindings != null) {
94             int size = this.subBindings.length;
95             for (int i = 0; i < size; i++) {
96                 this.subBindings[i].loadFormFromModel(frmModel, jxpc);
97             }
98         }
99     }
100
101     /**
102      * Actively performs the binding from the Woody-form to the ObjectModel
103      * by passing the task onto it's children.
104      */

105     public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
106         if (this.subBindings != null) {
107             int size = this.subBindings.length;
108             for (int i = 0; i < size; i++) {
109                 this.subBindings[i].saveFormToModel(frmModel, jxpc);
110             }
111         }
112     }
113 }
114
Popular Tags