1 25 package org.ofbiz.service.config; 26 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import javolution.util.FastList; 31 32 import org.ofbiz.base.config.GenericConfigException; 33 import org.ofbiz.base.config.ResourceLoader; 34 import org.ofbiz.base.util.Debug; 35 import org.ofbiz.base.util.UtilXml; 36 import org.w3c.dom.Document ; 37 import org.w3c.dom.Element ; 38 39 47 public class ServiceConfigUtil { 48 49 public static final String module = ServiceConfigUtil.class.getName(); 50 public static final String SERVICE_ENGINE_XML_FILENAME = "serviceengine.xml"; 51 52 public static Element getXmlRootElement() throws GenericConfigException { 53 return ResourceLoader.getXmlRootElement(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME); 54 } 55 56 public static Document getXmlDocument() throws GenericConfigException { 57 return ResourceLoader.getXmlDocument(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME); 58 } 59 60 public static Element getElement(String elementName) { 61 Element rootElement = null; 62 63 try { 64 rootElement = ServiceConfigUtil.getXmlRootElement(); 65 } catch (GenericConfigException e) { 66 Debug.logError(e, "Error getting Service Engine XML root element", module); 67 } 68 return UtilXml.firstChildElement(rootElement, elementName); 69 } 70 71 public static String getElementAttr(String elementName, String attrName) { 72 Element element = getElement(elementName); 73 74 if (element == null) return null; 75 return element.getAttribute(attrName); 76 } 77 78 public static String getSendPool() { 79 return getElementAttr("thread-pool", "send-to-pool"); 80 } 81 82 public static List getRunPools() { 83 List readPools = null; 84 85 Element threadPool = getElement("thread-pool"); 86 List readPoolElements = UtilXml.childElementList(threadPool, "run-from-pool"); 87 if (readPoolElements != null) { 88 readPools = FastList.newInstance(); 89 Iterator i = readPoolElements.iterator(); 90 91 while (i.hasNext()) { 92 Element e = (Element ) i.next(); 93 readPools.add(e.getAttribute("name")); 94 } 95 } 96 return readPools; 97 } 98 99 public static int getPurgeJobDays() { 100 String days = getElementAttr("thread-pool", "purge-job-days"); 101 int purgeDays = 0; 102 try { 103 purgeDays = Integer.parseInt(days); 104 } catch (NumberFormatException e) { 105 Debug.logError(e, "Cannot read the number of days to keep jobs; not purging", module); 106 purgeDays = 0; 107 } 108 return purgeDays; 109 } 110 111 public static int getFailedRetryMin() { 112 String minString = getElementAttr("thread-pool", "failed-retry-min"); 113 int retryMin = 30; 114 try { 115 retryMin = Integer.parseInt(minString); 116 } catch (NumberFormatException e) { 117 Debug.logError(e, "Unable to parse retry minutes; using default of 30", module); 118 retryMin = 30; 119 } 120 return retryMin; 121 } 122 } 123 | Popular Tags |