Coverage Report - org.kuali.rice.kns.uif.util.ComponentIdBeanPostProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentIdBeanPostProcessor
0%
0/9
0%
0/6
2
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 1.0 (the
 5  
  * "License"); 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.opensource.org/licenses/ecl1.php
 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, WITHOUT
 12  
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13  
  * License for the specific language governing permissions and limitations under
 14  
  * the License.
 15  
  */
 16  
 package org.kuali.rice.kns.uif.util;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kns.uif.core.Component;
 20  
 import org.springframework.beans.BeansException;
 21  
 import org.springframework.beans.factory.config.BeanPostProcessor;
 22  
 
 23  
 /**
 24  
  * Sets the unique Id for a <code>Component</code> if not set
 25  
  * 
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  
 public class ComponentIdBeanPostProcessor implements BeanPostProcessor {
 29  
 
 30  0
     public ComponentIdBeanPostProcessor() {}
 31  
 
 32  
     /**
 33  
      * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
 34  
      *      java.lang.String)
 35  
      */
 36  
     @Override
 37  
     public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
 38  0
         return bean;
 39  
     }
 40  
 
 41  
     /**
 42  
      * Sets the unique Id for a <code>Component</code> if not set
 43  
      * 
 44  
      * <p>
 45  
      * Will use the bean name (if not the spring generated) or generate a
 46  
      * numeric identifier
 47  
      * </p>
 48  
      * 
 49  
      * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
 50  
      *      java.lang.String)
 51  
      * @see org.kuali.rice.kns.uif.core.Component#getDecorators
 52  
      */
 53  
     @Override
 54  
     public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
 55  0
         if (bean instanceof Component) {
 56  0
             Component component = (Component) bean;
 57  
 
 58  0
             if (StringUtils.isBlank(component.getId())) {
 59  0
                 if (!StringUtils.contains(beanName, "$")) {
 60  0
                     component.setId(beanName);
 61  
                 }
 62  
                 else {
 63  0
                     component.setId(ComponentFactory.getNextId());
 64  
                 }
 65  
             }
 66  
         }
 67  
 
 68  0
         return bean;
 69  
     }
 70  
 
 71  
 }