Coverage Report - org.mule.module.ibeans.config.IntegrationBeanAnnotatedObjectProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegrationBeanAnnotatedObjectProcessor
0%
0/32
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: IntegrationBeanAnnotatedObjectProcessor.java 19952 2010-10-15 18:39:57Z aperepel $
 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.module.ibeans.config;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.MuleRuntimeException;
 15  
 import org.mule.api.construct.FlowConstruct;
 16  
 import org.mule.api.context.MuleContextAware;
 17  
 import org.mule.api.registry.InjectProcessor;
 18  
 import org.mule.module.ibeans.spi.MuleIBeansPlugin;
 19  
 import org.mule.util.annotation.AnnotationMetaData;
 20  
 import org.mule.util.annotation.AnnotationUtils;
 21  
 
 22  
 import java.lang.reflect.Field;
 23  
 import java.util.Set;
 24  
 
 25  
 import org.ibeans.annotation.IntegrationBean;
 26  
 
 27  
 public class IntegrationBeanAnnotatedObjectProcessor implements InjectProcessor, MuleContextAware
 28  
 {
 29  
     private MuleContext muleContext;
 30  
     private MuleIBeansPlugin plugin;
 31  
 
 32  
     public IntegrationBeanAnnotatedObjectProcessor()
 33  0
     {
 34  0
     }
 35  
 
 36  
     public IntegrationBeanAnnotatedObjectProcessor(MuleContext muleContext)
 37  
     {
 38  0
         this();
 39  0
         setMuleContext(muleContext);
 40  0
     }
 41  
 
 42  
     public void setMuleContext(MuleContext context)
 43  
     {
 44  0
         this.muleContext = context;
 45  0
         this.plugin = new MuleIBeansPlugin(context);
 46  0
     }
 47  
 
 48  
     public Object process(Object object)
 49  
     {
 50  0
         Set<AnnotationMetaData> annos = AnnotationUtils.getFieldAnnotationsForHeirarchy(object.getClass(), IntegrationBean.class);
 51  
 
 52  0
         for (AnnotationMetaData data : annos)
 53  
         {
 54  0
             Field field = (Field) data.getMember();
 55  0
             field.setAccessible(true);
 56  
             try
 57  
             {
 58  0
                 if (field.get(object) != null)
 59  
                 {
 60  0
                     continue;
 61  
                 }
 62  
             }
 63  0
             catch (IllegalAccessException e)
 64  
             {
 65  0
                 continue;
 66  0
             }
 67  0
             IBeanBinding binding = createBinding(field.getType().getSimpleName());
 68  0
             binding.setInterface(field.getType());
 69  0
             Object proxy = binding.createProxy(new Object());
 70  
             try
 71  
             {
 72  0
                 field.set(object, proxy);
 73  
             }
 74  0
             catch (IllegalAccessException e)
 75  
             {
 76  0
                 throw new RuntimeException("Failed to create IntegrationBean proxy for: " + field.getType(), e);
 77  0
             }
 78  0
         }
 79  0
         return object;
 80  
     }
 81  
 
 82  
     protected IBeanBinding createBinding(String name)
 83  
     {
 84  0
         IBeanFlowConstruct flow = new IBeanFlowConstruct(name + ".ibean", muleContext);
 85  
         try
 86  
         {
 87  0
             muleContext.getRegistry().registerObject(flow.getName(), flow, FlowConstruct.class);
 88  
         }
 89  0
         catch (MuleException e)
 90  
         {
 91  0
             throw new MuleRuntimeException(e);
 92  0
         }
 93  0
         return new IBeanBinding(flow, muleContext, plugin);
 94  
     }
 95  
 }