001: /*
002: * $Id: ServiceConfigUtil.java,v 1.5 2003/11/05 22:41:55 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.service.config;
026:
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import java.util.List;
030:
031: import org.ofbiz.base.config.GenericConfigException;
032: import org.ofbiz.base.config.ResourceLoader;
033: import org.ofbiz.base.util.Debug;
034: import org.ofbiz.base.util.UtilXml;
035: import org.w3c.dom.Document;
036: import org.w3c.dom.Element;
037:
038: /**
039: * Misc. utility method for dealing with the serviceengine.xml file
040: *
041: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
042: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
043: * @version $Revision: 1.5 $
044: * @since 2.0
045: */
046: public class ServiceConfigUtil {
047:
048: public static final String module = ServiceConfigUtil.class
049: .getName();
050: public static final String SERVICE_ENGINE_XML_FILENAME = "serviceengine.xml";
051:
052: public static Element getXmlRootElement()
053: throws GenericConfigException {
054: return ResourceLoader
055: .getXmlRootElement(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME);
056: }
057:
058: public static Document getXmlDocument()
059: throws GenericConfigException {
060: return ResourceLoader
061: .getXmlDocument(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME);
062: }
063:
064: public static Element getElement(String elementName) {
065: Element rootElement = null;
066:
067: try {
068: rootElement = ServiceConfigUtil.getXmlRootElement();
069: } catch (GenericConfigException e) {
070: Debug.logError(e,
071: "Error getting Service Engine XML root element",
072: module);
073: }
074: return UtilXml.firstChildElement(rootElement, elementName);
075: }
076:
077: public static String getElementAttr(String elementName,
078: String attrName) {
079: Element element = getElement(elementName);
080:
081: if (element == null)
082: return null;
083: return element.getAttribute(attrName);
084: }
085:
086: public static String getSendPool() {
087: return getElementAttr("thread-pool", "send-to-pool");
088: }
089:
090: public static List getRunPools() {
091: List readPools = null;
092:
093: Element threadPool = getElement("thread-pool");
094: List readPoolElements = UtilXml.childElementList(threadPool,
095: "run-from-pool");
096: if (readPoolElements != null) {
097: readPools = new ArrayList();
098: Iterator i = readPoolElements.iterator();
099:
100: while (i.hasNext()) {
101: Element e = (Element) i.next();
102: readPools.add(e.getAttribute("name"));
103: }
104: }
105: return readPools;
106: }
107:
108: public static int getPurgeJobDays() {
109: String days = getElementAttr("thread-pool", "purge-job-days");
110: int purgeDays = 0;
111: try {
112: purgeDays = Integer.parseInt(days);
113: } catch (NumberFormatException e) {
114: Debug
115: .logError(
116: e,
117: "Cannot read the number of days to keep jobs; not purging",
118: module);
119: purgeDays = 0;
120: }
121: return purgeDays;
122: }
123:
124: public static int getFailedRetryMin() {
125: String minString = getElementAttr("thread-pool",
126: "failed-retry-min");
127: int retryMin = 30;
128: try {
129: retryMin = Integer.parseInt(minString);
130: } catch (NumberFormatException e) {
131: Debug
132: .logError(
133: e,
134: "Unable to parse retry minutes; using default of 30",
135: module);
136: retryMin = 30;
137: }
138: return retryMin;
139: }
140: }
|