Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2008, 2009, 2010 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry5.internal.transform;
 
 import java.util.List;
 
Provides the page activation context handlers. This worker must be scheduled before OnEventWorker in order for the added event handler methods to be properly picked up and processed.

 
 {
     public void transform(ClassTransformation transformationMutableComponentModel model)
     {
         List<TransformFieldfields = transformation.matchFieldsWithAnnotation(PageActivationContext.class);
 
         // In the future we may add rules for ordering the fields (new attribute on annotation?)
 
         if (fields.size() > 1)
             throw new RuntimeException(TransformMessages.illegalNumberOfPageActivationContextHandlers(fields));
 
         // So there's 0 or 1 of these
 
         for (TransformField field : fields)
         {
             transformField(transformationmodelfield);
         }
     }
 
     private void transformField(ClassTransformation transformationMutableComponentModel modelTransformField field)
     {
         PageActivationContext annotation = field.getAnnotation(PageActivationContext.class);
 
         FieldAccess access = field.getAccess();
 
         if (annotation.activate())
         {
             transformation.addComponentEventHandler(., 1,
                     "PageActivationContextWorker activate event handler",
                     createActivationHandler(field.getType(), access));
         }
 
         if (annotation.passivate())
         {
             transformation.addComponentEventHandler(., 0,
                     "PageActivationContextWorker passivate event handler"createPassivateHandler(access));
         }
 
         // We don't claim the field, and other workers may even replace it with a FieldValueConduit.
     }
 
     private static ComponentEventHandler createActivationHandler(final String fieldTypefinal FieldAccess access)
     {
         return new ComponentEventHandler()
         {
             public void handleEvent(Component instanceComponentEvent event)
             {
                 Object value = event.coerceContext(0, fieldType);
 
                 access.write(instancevalue);
             }
         };
     }
 
     private static ComponentEventHandler createPassivateHandler(final FieldAccess access)
     {
         return new ComponentEventHandler()
         {
             public void handleEvent(Component instanceComponentEvent event)
             {
                 Object value = access.read(instance);
 
                 event.storeResult(value);
            }
        };
    }
New to GrepCode? Check out our FAQ X