KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > 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.forms.binding;
17
18 import java.util.Collections JavaDoc;
19 import java.util.HashMap JavaDoc;
20
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.cocoon.forms.formmodel.Widget;
23 import org.apache.commons.jxpath.JXPathContext;
24
25 /**
26  * ComposedJXPathBindingBase provides a helper base class for subclassing
27  * into specific {@link JXPathBindingBase} implementations that have nested
28  * child-bindings.
29  *
30  * @version $Id: ComposedJXPathBindingBase.java 289715 2005-09-17 10:05:05Z sylvain $
31  */

32 public class ComposedJXPathBindingBase extends JXPathBindingBase {
33     private final JXPathBindingBase[] subBindings;
34
35     public String JavaDoc getXPath() { return null; }
36     
37     /**
38      * Constructs ComposedJXPathBindingBase
39      *
40      * @param childBindings sets the array of childBindings
41      */

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

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

69     public Binding getClass(String JavaDoc id) {
70         if (classes == null) {
71             classes = new HashMap JavaDoc();
72             if (this.subBindings != null) {
73                 for (int i = 0; i < this.subBindings.length; i++) {
74                     Binding binding = this.subBindings[i];
75                     if (binding instanceof ClassJXPathBinding) {
76                         String JavaDoc bindingId = binding.getId();
77                         if (bindingId != null)
78                           classes.put(bindingId, binding);
79                     }
80                 }
81                 
82                 // Fee memory used by an empty map
83
if (classes.size() == 0) {
84                     classes = Collections.EMPTY_MAP;
85                 }
86             }
87         }
88         return super.getClass(id);
89     }
90
91     /**
92      * Returns child bindings.
93      */

94     public JXPathBindingBase[] getChildBindings() {
95         return subBindings;
96     }
97
98     /**
99      * Actively performs the binding from the ObjectModel to the CForms-form
100      * by passing the task onto it's children.
101      */

102     public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
103         if (this.subBindings != null) {
104             int size = this.subBindings.length;
105             for (int i = 0; i < size; i++) {
106                 this.subBindings[i].loadFormFromModel(frmModel, jxpc);
107             }
108         }
109     }
110
111     /**
112      * Actively performs the binding from the CForms-form to the ObjectModel
113      * by passing the task onto it's children.
114      */

115     public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
116         if (this.subBindings != null) {
117             int size = this.subBindings.length;
118             for (int i = 0; i < size; i++) {
119                 this.subBindings[i].saveFormToModel(frmModel, jxpc);
120             }
121         }
122     }
123 }
124
Popular Tags