Coverage Report - br.com.arsmachina.tapestrycrud.services.impl.TapestryCrudModuleServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
TapestryCrudModuleServiceImpl
0%
0/30
0%
0/18
0
 
 1  
 // Copyright 2008 Thiago H. de Paula Figueiredo
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package br.com.arsmachina.tapestrycrud.services.impl;
 16  
 
 17  
 import java.util.Collections;
 18  
 import java.util.Set;
 19  
 
 20  
 import org.apache.tapestry5.PrimaryKeyEncoder;
 21  
 
 22  
 import br.com.arsmachina.module.service.ModuleService;
 23  
 import br.com.arsmachina.tapestrycrud.encoder.ActivationContextEncoder;
 24  
 import br.com.arsmachina.tapestrycrud.encoder.Encoder;
 25  
 import br.com.arsmachina.tapestrycrud.encoder.LabelEncoder;
 26  
 import br.com.arsmachina.tapestrycrud.module.TapestryCrudModule;
 27  
 import br.com.arsmachina.tapestrycrud.services.TapestryCrudModuleService;
 28  
 
 29  
 /**
 30  
  * Default {@link ModuleService} implementation.
 31  
  * 
 32  
  * @author Thiago H. de Paula Figueiredo
 33  
  */
 34  
 public class TapestryCrudModuleServiceImpl implements TapestryCrudModuleService {
 35  
 
 36  
         final private Set<TapestryCrudModule> modules;
 37  
 
 38  
         /**
 39  
          * Single constructor of this class.
 40  
          * 
 41  
          * @param entityClasses a {@link Set} of {@link TapestryCrudModule}s. It cannot be null.
 42  
          */
 43  0
         public TapestryCrudModuleServiceImpl(Set<TapestryCrudModule> modules) {
 44  
 
 45  0
                 if (modules == null) {
 46  0
                         throw new IllegalArgumentException("Parameter modules cannot be null");
 47  
                 }
 48  
 
 49  0
                 this.modules = Collections.unmodifiableSet(modules);
 50  
 
 51  0
         }
 52  
 
 53  
         public Set<TapestryCrudModule> getModules() {
 54  0
                 return modules;
 55  
         }
 56  
 
 57  
         public <T> Class<? extends ActivationContextEncoder<T>> getActivationContextEncoderClass(
 58  
                         Class<T> entityClass) {
 59  
                 
 60  0
                 Class<? extends ActivationContextEncoder<T>> encoder = null;
 61  
                 
 62  0
                 for (TapestryCrudModule module : modules) {
 63  
                         
 64  0
                         encoder = module.getActivationContextEncoderClass(entityClass);
 65  
                         
 66  0
                         if (encoder != null) {
 67  0
                                 break;
 68  
                         }
 69  
                         
 70  
                 }
 71  
                 
 72  0
                 return encoder;
 73  
                 
 74  
         }
 75  
 
 76  
         public <T> Class<? extends Encoder<T, ?>> getEncoderClass(
 77  
                         Class<T> entityClass) {
 78  
                 
 79  0
                 Class<? extends Encoder<T, ?>> encoder = null;
 80  
                 
 81  0
                 for (TapestryCrudModule module : modules) {
 82  
                         
 83  0
                         encoder = module.getEncoderClass(entityClass);
 84  
                         
 85  0
                         if (encoder != null) {
 86  0
                                 break;
 87  
                         }
 88  
                         
 89  
                 }
 90  
                 
 91  0
                 return encoder;
 92  
                 
 93  
         }
 94  
 
 95  
         public <T> Class<? extends LabelEncoder<T>> getLabelEncoderClass(Class<T> entityClass) {
 96  
                 
 97  0
                 Class<? extends LabelEncoder<T>> encoder = null;
 98  
                 
 99  0
                 for (TapestryCrudModule module : modules) {
 100  
                         
 101  0
                         encoder = module.getLabelEncoderClass(entityClass);
 102  
                         
 103  0
                         if (encoder != null) {
 104  0
                                 break;
 105  
                         }
 106  
                         
 107  
                 }
 108  
                 
 109  0
                 return encoder;
 110  
 
 111  
                 
 112  
         }
 113  
 
 114  
         public <T> Class<? extends PrimaryKeyEncoder<?, T>> getPrimaryKeyEncoderClass(
 115  
                         Class<T> entityClass) {
 116  
 
 117  0
                 Class<? extends PrimaryKeyEncoder<?, T>> encoder = null;
 118  
                 
 119  0
                 for (TapestryCrudModule module : modules) {
 120  
                         
 121  0
                         encoder = module.getPrimaryKeyEncoderClass(entityClass);
 122  
                         
 123  0
                         if (encoder != null) {
 124  0
                                 break;
 125  
                         }
 126  
                         
 127  
                 }
 128  
                 
 129  0
                 return encoder;
 130  
 
 131  
         }
 132  
 
 133  
 }