Author: adrianc Date: Sun Jun 2 12:19:02 2013 New Revision: 1488694 URL: http://svn.apache.org/r1488694 Log: Bug fix in new ServiceConfigUtil code - do not use cached DOM object when creating models.
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java?rev=1488694&r1=1488693&r2=1488694&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java Sun Jun 2 12:19:02 2013 @@ -19,6 +19,7 @@ package org.ofbiz.service.config; import java.io.Serializable; +import java.net.URL; import java.util.List; import java.util.Map; @@ -28,10 +29,12 @@ import javolution.util.FastMap; import org.ofbiz.base.config.GenericConfigException; import org.ofbiz.base.config.ResourceLoader; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilURL; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.service.config.model.ServiceConfig; import org.ofbiz.service.config.model.ServiceEngine; +import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -57,7 +60,7 @@ public final class ServiceConfigUtil { public static ServiceConfig getServiceConfig() throws GenericConfigException { ServiceConfig instance = serviceConfigCache.get("instance"); if (instance == null) { - Element serviceConfigElement = ResourceLoader.getXmlRootElement(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME); + Element serviceConfigElement = getXmlDocument().getDocumentElement(); instance = ServiceConfig.create(serviceConfigElement); serviceConfigCache.putIfAbsent("instance", instance); instance = serviceConfigCache.get("instance"); @@ -65,6 +68,18 @@ public final class ServiceConfigUtil { return instance; } + private static Document getXmlDocument() throws GenericConfigException { + URL confUrl = UtilURL.fromResource(SERVICE_ENGINE_XML_FILENAME); + if (confUrl == null) { + throw new GenericConfigException("Could not find the " + SERVICE_ENGINE_XML_FILENAME + " file on the classpath"); + } + try { + return UtilXml.readXmlDocument(confUrl, true, true); + } catch (Exception e) { + throw new GenericConfigException("Exception thrown while reading " + SERVICE_ENGINE_XML_FILENAME + ": ", e); + } + } + /** * Returns the specified <code>ServiceEngine</code> instance, or <code>null</code> * if the engine does not exist.