Coverage Report - br.com.arsmachina.tapestrycrud.services.impl.PrimaryKeyEncoderActivationContextEncoder
 
Classes in this File Line Coverage Branch Coverage Complexity
PrimaryKeyEncoderActivationContextEncoder
0%
0/10
0%
0/4
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.io.Serializable;
 18  
 
 19  
 import org.apache.tapestry5.EventContext;
 20  
 import org.apache.tapestry5.PrimaryKeyEncoder;
 21  
 
 22  
 import br.com.arsmachina.tapestrycrud.encoder.ActivationContextEncoder;
 23  
 
 24  
 /**
 25  
  * An {@link ActivationContextEncoder} implementation based in a {@link PrimaryKeyEncoder}.
 26  
  * 
 27  
  * @author Thiago H. de Paula Figueiredo
 28  
  * @param <T> the entity class related to this DAO.
 29  
  * @param <K> the type of the field that represents the entity class' primary key.
 30  
  */
 31  
 class PrimaryKeyEncoderActivationContextEncoder<T, K extends Serializable> implements
 32  
                 ActivationContextEncoder<T> {
 33  
 
 34  
         final private Class<K> primaryKeyType;
 35  
 
 36  
         final private PrimaryKeyEncoder<K, T> primaryKeyEncoder;
 37  
 
 38  
         /**
 39  
          * @param primaryKeyType
 40  
          */
 41  
         @SuppressWarnings("unchecked")
 42  0
         public PrimaryKeyEncoderActivationContextEncoder(PrimaryKeyEncoder<K, T> primaryKeyEncoder,
 43  
                         Class<K> primaryKeyType) {
 44  
 
 45  0
                 if (primaryKeyType == null) {
 46  0
                         throw new IllegalArgumentException("Parameter primaryKeyType cannot be null");
 47  
                 }
 48  
 
 49  0
                 if (primaryKeyEncoder == null) {
 50  0
                         throw new IllegalArgumentException("Parameter primaryKeyEncoder cannot be null");
 51  
                 }
 52  
 
 53  0
                 this.primaryKeyEncoder = primaryKeyEncoder;
 54  0
                 this.primaryKeyType = primaryKeyType;
 55  
 
 56  0
         }
 57  
 
 58  
         /**
 59  
          * @see br.com.arsmachina.tapestrycrud.encoder.ActivationContextEncoder#toActivationContext(java.lang.Object)
 60  
          */
 61  
         public Object toActivationContext(T object) {
 62  0
                 return primaryKeyEncoder.toKey(object);
 63  
         }
 64  
 
 65  
         /**
 66  
          * @see br.com.arsmachina.tapestrycrud.encoder.ActivationContextEncoder#toObject(org.apache.tapestry5.EventContext)
 67  
          */
 68  
         public T toObject(EventContext value) {
 69  0
                 return primaryKeyEncoder.toValue(value.get(primaryKeyType, 0));
 70  
         }
 71  
 
 72  
 }