if (Thread.currentThread().getContextClassLoader() != null) { try { factory = (AbstractWorkflowFactory) Thread.currentThread().getContextClassLoader().loadClass(clazz).newInstance(); } catch (ClassNotFoundException e) {  factory = (AbstractWorkflowFactory) Class.forName(clazz).newInstance(); } } else {  factory = (AbstractWorkflowFactory) Class.forName(clazz).newInstance(); }
factory = (AbstractWorkflowFactory) ClassLoaderUtil.loadClass(clazz, getClass()).newInstance();
    public void load(URL url) throws FactoryException {        InputStream is = getInputStream(url);        try {            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();            dbf.setNamespaceAware(true);            DocumentBuilder db = null;            try {                db = dbf.newDocumentBuilder();            } catch (ParserConfigurationException e) {                log.fatal("Could not load config file", e);            }            Document doc = db.parse(is);            Element root = (Element) doc.getElementsByTagName("osworkflow").item(0);            Element p = (Element) root.getElementsByTagName("persistence").item(0);            Element factoryElement = (Element) root.getElementsByTagName("factory").item(0);            persistenceClass = p.getAttribute("class");            NodeList args = p.getElementsByTagName("property");            //persistenceArgs = new HashMap();            for (int i = 0; i < args.getLength(); i++) {                Element e = (Element) args.item(i);                persistenceArgs.put(e.getAttribute("key"), e.getAttribute("value"));            }            if (factoryElement != null) {                String clazz = null;                try {                    clazz = factoryElement.getAttribute("class");                    if (clazz == null) {                        throw new FactoryException("factory does not specify a class attribute");                    }                    if (Thread.currentThread().getContextClassLoader() != null) {                        try {                            factory = (AbstractWorkflowFactory) Thread.currentThread().getContextClassLoader().loadClass(clazz).newInstance();                        } catch (ClassNotFoundException e) {                            //fall back to this class' classloader.                            factory = (AbstractWorkflowFactory) Class.forName(clazz).newInstance();                        }                    } else {                        //no context classloader, so use current one                        factory = (AbstractWorkflowFactory) Class.forName(clazz).newInstance();                    }                    Properties properties = new Properties();                    NodeList props = factoryElement.getElementsByTagName("property");                    for (int i = 0; i < props.getLength(); i++) {                        Element e = (Element) props.item(i);                        properties.setProperty(e.getAttribute("key"), e.getAttribute("value"));                    }                    factory.init(properties);                    factory.initDone();                } catch (FactoryException ex) {                    throw ex;                } catch (Exception ex) {                    throw new FactoryException("Error creating workflow factory " + clazz, ex);                }            }            initialized = true;        } catch (FactoryException e) {            throw e;        } catch (Exception e) {            throw new FactoryException("Error in workflow config", e);        }    }