Coverage Report - org.seasar.teeda.core.config.faces.assembler.ConverterChildAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
ConverterChildAssembler
97%
31/32
75%
12/16
2.167
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.config.faces.assembler;
 17  
 
 18  
 import java.util.Collections;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.faces.application.Application;
 24  
 
 25  
 import org.seasar.framework.util.StringUtil;
 26  
 import org.seasar.teeda.core.application.ConfigurationSupport;
 27  
 import org.seasar.teeda.core.application.ConverterConfiguration;
 28  
 import org.seasar.teeda.core.config.faces.element.ConverterElement;
 29  
 import org.seasar.teeda.core.config.faces.element.PropertyElement;
 30  
 import org.seasar.teeda.core.util.ApplicationUtil;
 31  
 import org.seasar.teeda.core.util.IteratorUtil;
 32  
 
 33  
 public abstract class ConverterChildAssembler implements JsfAssembler {
 34  
 
 35  
     private Application application_;
 36  
 
 37  12
     private Map targetCovnerters_ = Collections.EMPTY_MAP;
 38  
 
 39  12
     public ConverterChildAssembler(Map targetConverters) {
 40  12
         application_ = ApplicationUtil.getApplicationFromFactory();
 41  12
         targetCovnerters_ = targetConverters;
 42  12
     }
 43  
 
 44  
     public void assemble() {
 45  12
         String converterKey = null;
 46  12
         ConverterElement converterElement = null;
 47  12
         for (Iterator itr = IteratorUtil.getEntryIterator(targetCovnerters_); itr
 48  20
                 .hasNext();) {
 49  8
             Map.Entry entry = (Map.Entry) itr.next();
 50  8
             converterKey = (String) entry.getKey();
 51  8
             converterElement = (ConverterElement) entry.getValue();
 52  8
             if (!StringUtil.isEmpty(converterKey) && converterElement != null) {
 53  7
                 setConverterConfiguration(converterKey, converterElement);
 54  7
                 doAssemble(converterKey, converterElement);
 55  
             }
 56  
         }
 57  12
     }
 58  
 
 59  
     protected void setConverterConfiguration(String converterKey,
 60  
             ConverterElement converterElement) {
 61  7
         if (converterElement == null) {
 62  0
             return;
 63  
         }
 64  7
         Application app = getApplication();
 65  7
         if (app instanceof ConfigurationSupport) {
 66  1
             List properties = converterElement.getPropertyElements();
 67  1
             ConfigurationSupport support = (ConfigurationSupport) app;
 68  1
             for (Iterator itr = IteratorUtil.getIterator(properties); itr
 69  2
                     .hasNext();) {
 70  1
                 PropertyElement property = (PropertyElement) itr.next();
 71  1
                 String propertyName = property.getPropertyName();
 72  1
                 String propertyClass = property.getPropertyClass();
 73  1
                 String defaultValue = property.getDefaultValue();
 74  1
                 if (!StringUtil.isEmpty(propertyName)
 75  
                         && !StringUtil.isEmpty(propertyClass)) {
 76  1
                     doAddConverterConfiguration(support, converterKey,
 77  
                             new ConverterConfiguration(propertyName,
 78  
                                     propertyClass, defaultValue));
 79  
                 }
 80  
             }
 81  
         }
 82  7
     }
 83  
 
 84  
     protected final Application getApplication() {
 85  14
         return application_;
 86  
     }
 87  
 
 88  
     protected abstract void doAssemble(String converterKey,
 89  
             ConverterElement converterElement);
 90  
 
 91  
     protected abstract void doAddConverterConfiguration(
 92  
             ConfigurationSupport support, String converterKey,
 93  
             ConverterConfiguration configuration);
 94  
 
 95  
 }