001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.woody.binding;
018:
019: import java.util.HashMap;
020:
021: import org.apache.avalon.framework.logger.Logger;
022: import org.apache.cocoon.woody.formmodel.Widget;
023: import org.apache.commons.jxpath.JXPathContext;
024:
025: /**
026: * ComposedJXPathBindingBase provides a helper base class for subclassing
027: * into specific {@link JXPathBindingBase} implementations that have nested
028: * child-bindings.
029: *
030: * @version CVS $Id: ComposedJXPathBindingBase.java 433543 2006-08-22 06:22:54Z crossley $
031: */
032: public class ComposedJXPathBindingBase extends JXPathBindingBase {
033: private final JXPathBindingBase[] subBindings;
034:
035: /**
036: * Constructs ComposedJXPathBindingBase
037: *
038: * @param childBindings sets the array of childBindings
039: */
040: protected ComposedJXPathBindingBase(
041: JXPathBindingBuilderBase.CommonAttributes commonAtts,
042: JXPathBindingBase[] childBindings) {
043: super (commonAtts);
044: this .subBindings = childBindings;
045: if (this .subBindings != null) {
046: for (int i = 0; i < this .subBindings.length; i++) {
047: this .subBindings[i].setParent(this );
048: }
049: }
050: }
051:
052: /**
053: * Receives the logger to use for logging activity, and hands it over to
054: * the nested children.
055: */
056: public void enableLogging(Logger logger) {
057: super .enableLogging(logger);
058: if (this .subBindings != null) {
059: for (int i = 0; i < this .subBindings.length; i++) {
060: this .subBindings[i].enableLogging(logger);
061: }
062: }
063: }
064:
065: /**
066: * Gets a binding class by id.
067: * @param id Id of binding class to get.
068: */
069: public Binding getClass(String id) {
070: if (classes == null) {
071: classes = new HashMap();
072: if (this .subBindings != null) {
073: for (int i = 0; i < this .subBindings.length; i++) {
074: Binding binding = this .subBindings[i];
075: String bindingId = binding.getId();
076: if (bindingId != null)
077: classes.put(bindingId, binding);
078: }
079: }
080: }
081: return super .getClass(id);
082: }
083:
084: /**
085: * Returns child bindings.
086: */
087: public JXPathBindingBase[] getChildBindings() {
088: return subBindings;
089: }
090:
091: /**
092: * Actively performs the binding from the ObjectModel to the Woody-form
093: * by passing the task onto it's children.
094: */
095: public void doLoad(Widget frmModel, JXPathContext jxpc)
096: throws BindingException {
097: if (this .subBindings != null) {
098: int size = this .subBindings.length;
099: for (int i = 0; i < size; i++) {
100: this .subBindings[i].loadFormFromModel(frmModel, jxpc);
101: }
102: }
103: }
104:
105: /**
106: * Actively performs the binding from the Woody-form to the ObjectModel
107: * by passing the task onto it's children.
108: */
109: public void doSave(Widget frmModel, JXPathContext jxpc)
110: throws BindingException {
111: if (this .subBindings != null) {
112: int size = this .subBindings.length;
113: for (int i = 0; i < size; i++) {
114: this.subBindings[i].saveFormToModel(frmModel, jxpc);
115: }
116: }
117: }
118: }
|