Clover coverage report - Maven Clover report
Coverage timestamp: Thu Oct 11 2007 08:41:48 CEST
file stats: LOC: 103   Methods: 3
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BusinessObjectFactory.java 87.5% 79.4% 100% 82.2%
coverage coverage
 1    /*
 2    * Copyright (C) 2007 Eric MIGNOT - mignots.eric@free.fr
 3    *
 4    * This library is free software; you can redistribute it and/or
 5    * modify it under the terms of the GNU Lesser General Public
 6    * License as published by the Free Software Foundation; either
 7    * version 2.1 of the License, or (at your option) any later version.
 8    *
 9    * This library is distributed in the hope that it will be useful,
 10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12    * Lesser General Public License for more details.
 13    *
 14    * You should have received a copy of the GNU Lesser General Public
 15    * License along with this library; if not, write to the Free Software
 16    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17    */
 18    package org.ericmignot.modeler.helpers.data;
 19   
 20    import java.io.UnsupportedEncodingException;
 21    import java.net.URLDecoder;
 22   
 23    import org.ericmignot.modeler.data.BusinessObject;
 24    import org.ericmignot.modeler.data.Model;
 25    import org.ericmignot.modeler.util.xml.XMLHelper;
 26    import org.w3c.dom.Element;
 27    import org.w3c.dom.NodeList;
 28   
 29    public class BusinessObjectFactory {
 30   
 31    /**
 32    * Singleton
 33    */
 34    private static BusinessObjectFactory uniqueInstance;
 35  105 public static BusinessObjectFactory getInstance()
 36    {
 37  105 if (BusinessObjectFactory.uniqueInstance == null)
 38    {
 39  1 BusinessObjectFactory.uniqueInstance = new BusinessObjectFactory();
 40    }
 41  105 return BusinessObjectFactory.uniqueInstance;
 42    }
 43   
 44    /**
 45    *
 46    * @param bo the businessObject XML representation
 47    * @return the instance of the new BusinessObject
 48    */
 49  17 public BusinessObject createBusinessObject(String xml, Model model)
 50    {
 51  17 Element bo = XMLHelper.getFirstElementByName(xml, "BusinessObject");
 52  17 return this.createBusinessObject(bo, model);
 53    }
 54   
 55  106 public BusinessObject createBusinessObject(Element bo, Model model)
 56    {
 57  106 BusinessObject toReturn =null;
 58   
 59  106 String className = bo.getAttributes().getNamedItem("class").getNodeValue();
 60  106 try {
 61  106 toReturn = (BusinessObject) Class.forName(className).newInstance();
 62    } catch (InstantiationException e) {
 63  0 e.printStackTrace();
 64  0 return null;
 65    } catch (IllegalAccessException e) {
 66  0 e.printStackTrace();
 67  0 return null;
 68    } catch (ClassNotFoundException e) {
 69  0 e.printStackTrace();
 70  0 return null;
 71    }
 72   
 73  106 NodeList paramList = bo.getElementsByTagName("Param");
 74  106 for (int j = 0; j < paramList.getLength(); j++)
 75    {
 76  381 Element param = (Element) paramList.item(j);
 77  381 String paramName = param.getAttributes().getNamedItem("Name").getNodeValue();
 78  381 String paramValue = param.getAttributes().getNamedItem("Value").getNodeValue();
 79  381 try {
 80  381 paramValue = URLDecoder.decode(paramValue, "utf-8");
 81    } catch (UnsupportedEncodingException e) {
 82  0 e.printStackTrace();
 83    }
 84  381 toReturn.setFieldValue(paramName, paramValue);
 85    }
 86   
 87  106 NodeList referenceList = bo.getElementsByTagName("Reference");
 88  106 for (int j = 0; j < referenceList.getLength(); j++)
 89    {
 90  70 Element reference = (Element) referenceList.item(j);
 91  70 String type = reference.getAttributes().getNamedItem("Type").getNodeValue();
 92  70 String Id = reference.getAttributes().getNamedItem("Id").getNodeValue();
 93  70 BusinessObject referenceValue = model.getBusinessObjectById(type, Long.parseLong(Id));
 94  70 if (referenceValue != null)
 95    {
 96  70 String referenceName = reference.getAttributes().getNamedItem("Name").getNodeValue();
 97  70 toReturn.setReference(referenceName, referenceValue);
 98    }
 99    }
 100   
 101  106 return toReturn;
 102    }
 103    }