Coverage Report - org.seasar.cubby.dxo.impl.FormDxoImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
FormDxoImpl
100%
22/22
100%
4/4
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 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.cubby.dxo.impl;
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.seasar.cubby.dxo.FormDxo;
 22  
 import org.seasar.extension.dxo.annotation.AnnotationReader;
 23  
 import org.seasar.extension.dxo.annotation.AnnotationReaderFactory;
 24  
 import org.seasar.extension.dxo.command.DxoCommand;
 25  
 import org.seasar.extension.dxo.converter.ConverterFactory;
 26  
 import org.seasar.framework.container.annotation.tiger.InitMethod;
 27  
 import org.seasar.framework.util.ClassUtil;
 28  
 
 29  
 /**
 30  
  * 
 31  
  * @author baba
 32  
  *
 33  
  */
 34  38
 public class FormDxoImpl implements FormDxo {
 35  
 
 36  
         private ConverterFactory converterFactory;
 37  
 
 38  
         private AnnotationReaderFactory annotationReaderFactory;
 39  
 
 40  
         private DxoCommand objectArrayMapToBeanDxoCommand;
 41  
 
 42  
         private DxoCommand beanToStringArrayMapDxoCommand;
 43  
 
 44  
         public void setConverterFactory(final ConverterFactory converterFactory) {
 45  38
                 this.converterFactory = converterFactory;
 46  38
         }
 47  
 
 48  
         public void setAnnotationReaderFactory(
 49  
                         final AnnotationReaderFactory annotationReaderFactory) {
 50  38
                 this.annotationReaderFactory = annotationReaderFactory;
 51  38
         }
 52  
 
 53  
         @InitMethod
 54  
         public void initialize() {
 55  38
                 final Class<?> targetClass = this.getClass();
 56  
 
 57  38
                 final Method objectArrayMapToBeanConvertMethod = ClassUtil.getMethod(
 58  
                                 targetClass, "convert", new Class<?>[] { Map.class,
 59  
                                                 Object.class });
 60  38
                 this.objectArrayMapToBeanDxoCommand = createObjectArrayMapToBeanDxoCommand(
 61  
                                 targetClass, objectArrayMapToBeanConvertMethod);
 62  
 
 63  38
                 final Method beanToStringArrayMapConvertMethod = ClassUtil.getMethod(
 64  
                                 targetClass, "convert", new Class<?>[] { Object.class,
 65  
                                                 Map.class });
 66  38
                 this.beanToStringArrayMapDxoCommand = createBeanToStringArrayMapDxoCommand(
 67  
                                 targetClass, beanToStringArrayMapConvertMethod);
 68  38
         }
 69  
 
 70  
         public void convert(final Map<String, Object[]> src, final Object dest) {
 71  6
                 if (src != null) {
 72  5
                         objectArrayMapToBeanDxoCommand.execute(new Object[] { src, dest });
 73  
                 }
 74  6
         }
 75  
 
 76  
         public void convert(final Object src, final Map<String, String[]> dest) {
 77  5
                 if (src != null) {
 78  4
                         beanToStringArrayMapDxoCommand.execute(new Object[] { src, dest });
 79  
                 }
 80  5
         }
 81  
 
 82  
         @SuppressWarnings("unchecked")
 83  
         public DxoCommand createObjectArrayMapToBeanDxoCommand(
 84  
                         final Class dxoClass, final Method method) {
 85  38
                 final AnnotationReader annotationReader = annotationReaderFactory
 86  
                                 .getAnnotationReader();
 87  38
                 return new ObjectArrayMapToBeanDxoCommand(dxoClass, method,
 88  
                                 converterFactory, annotationReader, Object.class);
 89  
         }
 90  
 
 91  
         @SuppressWarnings("unchecked")
 92  
         public DxoCommand createBeanToStringArrayMapDxoCommand(
 93  
                         final Class dxoClass, final Method method) {
 94  38
                 final AnnotationReader annotationReader = annotationReaderFactory
 95  
                                 .getAnnotationReader();
 96  38
                 final String expression = annotationReader.getConversionRule(dxoClass,
 97  
                                 method);
 98  38
                 return new BeanToStringArrayMapDxoCommand(dxoClass, method,
 99  
                                 converterFactory, annotationReader, expression);
 100  
         }
 101  
 
 102  
 }