Coverage Report - org.mule.module.ibeans.config.IBeanHolder
 
Classes in this File Line Coverage Branch Coverage Complexity
IBeanHolder
0%
0/18
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.ibeans.config;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.construct.FlowConstruct;
 12  
 import org.mule.module.ibeans.spi.MuleIBeansPlugin;
 13  
 
 14  
 import org.ibeans.impl.IBeansNotationHelper;
 15  
 import org.ibeans.impl.view.TextView;
 16  
 
 17  
 /**
 18  
  * Holds a reference to an iBeans class in the registry. An iBean instance can be created from this object as well as reporting
 19  
  * its usage and short ID.
 20  
  */
 21  
 public class IBeanHolder implements Comparable
 22  
 {
 23  
     private Class ibean;
 24  
     private String usage;
 25  
 
 26  
     public IBeanHolder(Class ibean)
 27  0
     {
 28  0
         this.ibean = ibean;
 29  0
     }
 30  
 
 31  
     public int compareTo(Object o)
 32  
     {
 33  0
         IBeanHolder to = (IBeanHolder) o;
 34  0
         return getId().compareTo(to.getId());
 35  
     }
 36  
 
 37  
     public Class getIbeanClass()
 38  
     {
 39  0
         return ibean;
 40  
     }
 41  
 
 42  
     public Object create(MuleContext muleContext, MuleIBeansPlugin plugin) throws MuleException
 43  
     {
 44  0
         final String name = String.format("%s.%d", ibean.getSimpleName(), System.identityHashCode(this));
 45  0
         IBeanFlowConstruct flow = new IBeanFlowConstruct(name, muleContext);
 46  0
         muleContext.getRegistry().registerObject(flow.getName(), flow, FlowConstruct.class);
 47  
 
 48  0
         IBeanBinding router = new IBeanBinding(flow, muleContext, plugin);
 49  0
         router.setInterface(ibean);
 50  0
         return router.createProxy(new Object());
 51  
     }
 52  
 
 53  
     public String getId()
 54  
     {
 55  0
         return IBeansNotationHelper.getIBeanShortID(ibean);
 56  
     }
 57  
 
 58  
     public String getUsage()
 59  
     {
 60  0
         if (usage == null)
 61  
         {
 62  0
             TextView view = new TextView();
 63  0
             usage = view.createView(ibean);
 64  
         }
 65  0
         return usage;
 66  
     }
 67  
 
 68  
     @Override
 69  
     public String toString()
 70  
     {
 71  0
         return "IBean: " + getId() + " : " + ibean.getName();
 72  
     }
 73  
 }