2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.clay.component.chain.AssignValueChangeListenersCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
AssignValueChangeListenersCommand
100%
24/24
N/A
10
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 /*
 19  
  * $Id: AssignValueChangeListenersCommand.java 464373 2006-10-16 04:21:54Z rahul $
 20  
  */
 21  
 package org.apache.shale.clay.component.chain;
 22  
 
 23  
 import java.util.Iterator;
 24  
 
 25  
 import javax.faces.component.EditableValueHolder;
 26  
 import javax.faces.component.UIComponent;
 27  
 
 28  
 import org.apache.commons.chain.Catalog;
 29  
 import org.apache.commons.chain.Command;
 30  
 import org.apache.commons.chain.Context;
 31  
 import org.apache.commons.logging.Log;
 32  
 import org.apache.commons.logging.LogFactory;
 33  
 import org.apache.shale.clay.config.Globals;
 34  
 import org.apache.shale.clay.config.beans.ComponentBean;
 35  
 import org.apache.shale.clay.config.beans.ValueChangeListenerBean;
 36  
 
 37  
 /**
 38  
  * <p>
 39  
  * For each {@link org.apache.shale.clay.config.beans.ValueChangeListenerBean}
 40  
  * in the <code>valueChangeListeners</code> collection, the
 41  
  * {@link org.apache.shale.clay.component.chain.CreateValueChangeListenerCommand}
 42  
  * command will be invoked.
 43  
  * </p>
 44  
  */
 45  22
 public class AssignValueChangeListenersCommand extends AbstractCommand {
 46  
 
 47  
     /**
 48  
      * <p>
 49  
      * Common Logging utility.
 50  
      * </p>
 51  
      */
 52  
     private static Log log;
 53  
     static {
 54  2
         log = LogFactory.getLog(AssignValueChangeListenersCommand.class);
 55  1
     }
 56  
 
 57  
     /**
 58  
      * <p>
 59  
      * Uses the <code>Globals.ADD_VALUE_CHANGE_LISTENER_COMMAND_NAME</code>
 60  
      * command to create a <code>ValueChangeListener</code>.</p>
 61  
      *
 62  
      * @param context common chains
 63  
      * @return <code>true</code> if the chain is complete
 64  
      * @exception Exception propagated up to the top of the chain
 65  
      */
 66  
     public boolean execute(Context context) throws Exception {
 67  
 
 68  398
         boolean isFinal = false;
 69  
 
 70  398
         ClayContext clayContext = (ClayContext) context;
 71  398
         if (clayContext == null) {
 72  
             throw new NullPointerException(getMessages()
 73  
                     .getMessage("clay.null.clayContext"));
 74  
         }
 75  
 
 76  398
         UIComponent child = (UIComponent) clayContext.getChild();
 77  398
         if (child == null) {
 78  
             throw new NullPointerException(getMessages()
 79  
                     .getMessage("clay.null.childComponent"));
 80  
         }
 81  
 
 82  398
         ComponentBean displayElement = clayContext.getDisplayElement();
 83  398
         if (displayElement == null) {
 84  
             throw new NullPointerException(getMessages()
 85  
                     .getMessage("clay.null.componentBean"));
 86  
         }
 87  
 
 88  398
         if (displayElement.getValueChangeListeners().size() > 0) {
 89  2
             if (child instanceof EditableValueHolder) {
 90  
 
 91  2
                 Iterator vi = displayElement.getValueChangeListenerIterator();
 92  4
                 while (vi.hasNext()) {
 93  2
                     ValueChangeListenerBean valueChangeListener = (ValueChangeListenerBean) vi
 94  
                             .next();
 95  
 
 96  2
                     ClayContext subContext = (ClayContext) clayContext.clone();
 97  2
                     subContext.setDisplayElement(valueChangeListener);
 98  2
                     subContext.setParent(child);
 99  
 
 100  2
                     Catalog catalog = getCatalog();
 101  2
                     Command command = catalog
 102  
                             .getCommand(Globals.ADD_VALUE_CHANGE_LISTENER_COMMAND_NAME);
 103  2
                     command.execute(subContext);
 104  
 
 105  2
                 }
 106  2
             } else {
 107  
                 log.error(getMessages().getMessage(
 108  
                         "assign.valueChangeListener.error",
 109  
                         new Object[] { displayElement }));
 110  
             }
 111  
         }
 112  
 
 113  398
         return isFinal;
 114  
     }
 115  
 
 116  
 }