Coverage Report - org.mule.example.loanbroker.transformers.CreditProfileXmlToCreditProfile
 
Classes in this File Line Coverage Branch Coverage Complexity
CreditProfileXmlToCreditProfile
0%
0/18
0%
0/2
2.5
 
 1  
 /*
 2  
  * $Id: CreditProfileXmlToCreditProfile.java 10789 2008-02-12 20:04:43Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
 
 11  
 package org.mule.example.loanbroker.transformers;
 12  
 
 13  
 import org.mule.api.transformer.TransformerException;
 14  
 import org.mule.example.loanbroker.messages.CreditProfile;
 15  
 import org.mule.transformer.AbstractTransformer;
 16  
 
 17  
 import org.dom4j.Document;
 18  
 import org.dom4j.DocumentException;
 19  
 import org.dom4j.DocumentHelper;
 20  
 
 21  
 public class CreditProfileXmlToCreditProfile extends AbstractTransformer
 22  
 {
 23  
 
 24  
     public CreditProfileXmlToCreditProfile()
 25  0
     {
 26  0
         registerSourceType(String.class);
 27  0
         registerSourceType(Document.class);
 28  0
         setReturnClass(CreditProfile.class);
 29  0
     }
 30  
 
 31  
     public Object doTransform(Object src, String encoding) throws TransformerException
 32  
     {
 33  0
         Document doc = null;
 34  
 
 35  0
         if (src instanceof Document)
 36  
         {
 37  0
             doc = (Document)src;
 38  
         }
 39  
         else
 40  
         {
 41  
             try
 42  
             {
 43  0
                 doc = DocumentHelper.parseText(src.toString());
 44  
             }
 45  0
             catch (DocumentException e)
 46  
             {
 47  0
                 throw new TransformerException(this, e);
 48  0
             }
 49  
         }
 50  
 
 51  0
         String history = doc.valueOf("/credit-profile/customer-history");
 52  0
         String score = doc.valueOf("/credit-profile/credit-score");
 53  0
         CreditProfile cp = new CreditProfile();
 54  0
         cp.setCreditHistory(Integer.valueOf(history).intValue());
 55  0
         cp.setCreditScore(Integer.valueOf(score).intValue());
 56  0
         return cp;
 57  
     }
 58  
 
 59  
 }