Coverage Report - br.com.arsmachina.tapestrycrud.components.ActivationContextPageLink
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivationContextPageLink
0%
0/3
N/A
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.components;
 16  
 
 17  
 
 18  
 import org.apache.tapestry5.BindingConstants;
 19  
 import org.apache.tapestry5.annotations.Parameter;
 20  
 import org.apache.tapestry5.annotations.Property;
 21  
 import org.apache.tapestry5.annotations.SupportsInformalParameters;
 22  
 import org.apache.tapestry5.corelib.base.AbstractLink;
 23  
 import org.apache.tapestry5.ioc.annotations.Inject;
 24  
 
 25  
 import br.com.arsmachina.tapestrycrud.encoder.ActivationContextEncoder;
 26  
 import br.com.arsmachina.tapestrycrud.encoder.Encoder;
 27  
 import br.com.arsmachina.tapestrycrud.services.ActivationContextEncoderSource;
 28  
 
 29  
 /**
 30  
  * A replacement to {@link org.apache.tapestry5.corelib.components.PageLink} that, given an object
 31  
  * passed as parameter, uses the corresponding {@link Encoder} to get the context
 32  
  * {@link Encoder#toKey(Object) } activation value.
 33  
  * 
 34  
  * @author Thiago H. de Paula Figueiredo
 35  
  */
 36  
 @SupportsInformalParameters
 37  0
 public class ActivationContextPageLink extends AbstractLink {
 38  
 
 39  
         /**
 40  
          * The logical name of the page to link to.
 41  
          */
 42  
         @SuppressWarnings("unused")
 43  
         @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
 44  
         @Property
 45  
         private String page;
 46  
         
 47  
         /**
 48  
          * The object from which the activation context value will be extracted.
 49  
          */
 50  
         @Parameter(required = true)
 51  
         private Object object;
 52  
 
 53  
         @Inject
 54  
         private ActivationContextEncoderSource activationContextEncoderSource;
 55  
 
 56  
         @SuppressWarnings("unchecked")
 57  
         public Object getContext() {
 58  
 
 59  
                 ActivationContextEncoder encoder;
 60  0
                 encoder = activationContextEncoderSource.get(object.getClass());
 61  0
                 return encoder.toActivationContext(object);
 62  
                 
 63  
         }
 64  
 
 65  
 }