Coverage Report - org.mule.config.spring.handlers.AbstractPojoNamespaceHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractPojoNamespaceHandler
0%
0/16
0%
0/6
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.config.spring.handlers;
 8  
 
 9  
 import org.mule.config.spring.parsers.generic.OrphanDefinitionParser;
 10  
 import org.mule.config.spring.parsers.specific.InvokerMessageProcessorDefinitionParser;
 11  
 import org.mule.config.spring.util.ParamReader;
 12  
 
 13  
 import java.io.IOException;
 14  
 import java.lang.reflect.Method;
 15  
 
 16  
 /**
 17  
  * Turns a POJO into a config element and a set of method tags which map to
 18  
  * MessageProcessors.
 19  
  */
 20  0
 public abstract class AbstractPojoNamespaceHandler extends AbstractMuleNamespaceHandler
 21  
 {
 22  
     public void registerPojo(String configElementName, Class<?> cls)
 23  
     {
 24  
         // register a generic configuration element
 25  0
         OrphanDefinitionParser parser = new OrphanDefinitionParser(cls, true);
 26  0
         parser.addIgnored("name");
 27  0
         registerMuleBeanDefinitionParser(configElementName, parser);
 28  
 
 29  
         // register invoker parser for each non setter
 30  
         try
 31  
         {
 32  0
             ParamReader paramReader = new ParamReader(cls); // use the parameter
 33  
             // names from our class
 34  0
             for (Method m : cls.getDeclaredMethods())
 35  
             {
 36  
                 // don't create parsers for setters
 37  0
                 if (!m.getName().startsWith("set"))
 38  
                 {
 39  0
                     String[] parameterNames = paramReader.getParameterNames(m);
 40  
 
 41  0
                     registerMuleBeanDefinitionParser(splitCamelCase(m.getName()),
 42  
                         new InvokerMessageProcessorDefinitionParser("messageProcessor", cls, m.getName(),
 43  
                             parameterNames));
 44  
                 }
 45  
             }
 46  
         }
 47  0
         catch (IOException e)
 48  
         {
 49  0
             throw new RuntimeException(e);
 50  0
         }
 51  0
     }
 52  
 
 53  
     protected static String splitCamelCase(String s)
 54  
     {
 55  0
         if (s.contains("get"))
 56  
         {
 57  0
             s = s.substring(3);
 58  
         }
 59  0
         return s.replaceAll(
 60  
             String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z][0-9])", "(?<=[^A-Z])(?=[A-Z])",
 61  
                 "(?<=[A-Za-z0-9])(?=[^A-Za-z0-9])"), "-").toLowerCase();
 62  
     }
 63  
     
 64  
 }