KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > service > config > ServiceConfigUtil


1 /*
2  * $Id: ServiceConfigUtil.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.service.config;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
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 JavaDoc;
37 import org.w3c.dom.Element JavaDoc;
38
39 /**
40  * Misc. utility method for dealing with the serviceengine.xml file
41  *
42  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
43  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
44  * @version $Rev: 5462 $
45  * @since 2.0
46  */

47 public class ServiceConfigUtil {
48     
49     public static final String JavaDoc module = ServiceConfigUtil.class.getName();
50     public static final String JavaDoc SERVICE_ENGINE_XML_FILENAME = "serviceengine.xml";
51
52     public static Element JavaDoc getXmlRootElement() throws GenericConfigException {
53         return ResourceLoader.getXmlRootElement(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME);
54     }
55
56     public static Document JavaDoc getXmlDocument() throws GenericConfigException {
57         return ResourceLoader.getXmlDocument(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME);
58     }
59
60     public static Element JavaDoc getElement(String JavaDoc elementName) {
61         Element JavaDoc 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 JavaDoc getElementAttr(String JavaDoc elementName, String JavaDoc attrName) {
72         Element JavaDoc element = getElement(elementName);
73
74         if (element == null) return null;
75         return element.getAttribute(attrName);
76     }
77
78     public static String JavaDoc getSendPool() {
79         return getElementAttr("thread-pool", "send-to-pool");
80     }
81     
82     public static List JavaDoc getRunPools() {
83         List JavaDoc readPools = null;
84         
85         Element JavaDoc threadPool = getElement("thread-pool");
86         List JavaDoc readPoolElements = UtilXml.childElementList(threadPool, "run-from-pool");
87         if (readPoolElements != null) {
88             readPools = FastList.newInstance();
89             Iterator JavaDoc i = readPoolElements.iterator();
90         
91             while (i.hasNext()) {
92                 Element JavaDoc e = (Element JavaDoc) i.next();
93                 readPools.add(e.getAttribute("name"));
94             }
95         }
96         return readPools;
97     }
98     
99     public static int getPurgeJobDays() {
100         String JavaDoc days = getElementAttr("thread-pool", "purge-job-days");
101         int purgeDays = 0;
102         try {
103             purgeDays = Integer.parseInt(days);
104         } catch (NumberFormatException JavaDoc 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 JavaDoc minString = getElementAttr("thread-pool", "failed-retry-min");
113         int retryMin = 30;
114         try {
115             retryMin = Integer.parseInt(minString);
116         } catch (NumberFormatException JavaDoc 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