KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > samples > loanbroker > esb > transformers > CreditProfileXmlToCreditProfile


1 /*
2  * $Id: CreditProfileXmlToCreditProfile.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.samples.loanbroker.esb.transformers;
12
13 import org.dom4j.Document;
14 import org.dom4j.DocumentException;
15 import org.dom4j.DocumentHelper;
16 import org.mule.samples.loanbroker.esb.message.CreditProfile;
17 import org.mule.transformers.AbstractTransformer;
18 import org.mule.umo.transformer.TransformerException;
19
20 public class CreditProfileXmlToCreditProfile extends AbstractTransformer
21 {
22     /**
23      * Serial version
24      */

25     private static final long serialVersionUID = -8349744705446470225L;
26
27     public CreditProfileXmlToCreditProfile()
28     {
29         registerSourceType(String JavaDoc.class);
30         registerSourceType(Document.class);
31         setReturnClass(CreditProfile.class);
32     }
33
34     public Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
35     {
36         Document doc = null;
37         if (src instanceof Document)
38         {
39             doc = (Document)src;
40         }
41         else
42         {
43             try
44             {
45                 doc = DocumentHelper.parseText(src.toString());
46             }
47             catch (DocumentException e)
48             {
49                 throw new TransformerException(this, e);
50             }
51         }
52         String JavaDoc history = doc.valueOf("/credit-profile/customer-history");
53         String JavaDoc score = doc.valueOf("/credit-profile/credit-score");
54         CreditProfile cp = new CreditProfile();
55         cp.setCreditHistory(Integer.valueOf(history).intValue());
56         cp.setCreditScore(Integer.valueOf(score).intValue());
57         return cp;
58     }
59 }
60
Popular Tags