Coverage Report - org.mule.config.transformer.AnnotatedTransformerObjectProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
AnnotatedTransformerObjectProcessor
0%
0/21
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: AnnotatedTransformerObjectProcessor.java 20321 2010-11-24 15:21:24Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.config.transformer;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.annotations.ContainsTransformerMethods;
 15  
 import org.mule.api.annotations.Transformer;
 16  
 import org.mule.api.context.MuleContextAware;
 17  
 import org.mule.api.registry.PreInitProcessor;
 18  
 import org.mule.util.annotation.AnnotationMetaData;
 19  
 import org.mule.util.annotation.AnnotationUtils;
 20  
 
 21  
 import java.lang.reflect.Method;
 22  
 import java.util.List;
 23  
 
 24  
 /**
 25  
  * Will check all method level annotations to see if there are any {@link org.mule.api.annotations.Transformer} annotations present.
 26  
  * For each method annotated with {@link org.mule.api.annotations.Transformer} a Mule transformer will be created.  When the
 27  
  * transformer is used, the method will get invoked
 28  
  *
 29  
  * @see org.mule.api.annotations.Transformer
 30  
  */
 31  
 public class AnnotatedTransformerObjectProcessor implements PreInitProcessor, MuleContextAware
 32  
 {
 33  
 
 34  
     private MuleContext muleContext;
 35  
 
 36  
     public AnnotatedTransformerObjectProcessor()
 37  0
     {
 38  0
     }
 39  
 
 40  
     public AnnotatedTransformerObjectProcessor(MuleContext muleContext)
 41  0
     {
 42  0
         setMuleContext(muleContext);
 43  0
     }
 44  
 
 45  
     public void setMuleContext(MuleContext context)
 46  
     {
 47  0
         this.muleContext = context;
 48  0
     }
 49  
 
 50  
     public Object process(Object object)
 51  
     {
 52  0
         Class<? extends Object> clazz = object.getClass();
 53  0
         if (clazz.getAnnotation(ContainsTransformerMethods.class) == null)
 54  
         {
 55  0
             return object;
 56  
         }
 57  0
         List<AnnotationMetaData> annos = AnnotationUtils.getMethodAnnotations(clazz, Transformer.class);
 58  
 
 59  0
         if (annos.size() == 0)
 60  
         {
 61  0
             return object;
 62  
         }
 63  0
         for (AnnotationMetaData data : annos)
 64  
         {
 65  
             try
 66  
             {
 67  0
                 Transformer anno = (Transformer) data.getAnnotation();
 68  0
                 AnnotatedTransformerProxy trans = new AnnotatedTransformerProxy(
 69  
                         anno.priorityWeighting(),
 70  
                         object, (Method) data.getMember(), anno.sourceTypes(),
 71  
                         null /*anno.sourceMimeType()*/, null /*anno.resultMimeType()*/);
 72  
 
 73  0
                 muleContext.getRegistry().registerTransformer(trans);
 74  
             }
 75  0
             catch (MuleException e)
 76  
             {
 77  0
                 throw new RuntimeException(e);
 78  0
             }
 79  
         }
 80  0
         return object;
 81  
     }
 82  
 }