[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/util FrameworkUtil.java, NONE,
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-08-29 02:01:35
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/util In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21323/framework/util Added Files: FrameworkUtil.java Log Message: no message --- NEW FILE: FrameworkUtil.java --- package org.jmonks.batchserver.framework.util; import java.util.Map; import java.util.StringTokenizer; import java.util.logging.Logger; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * <p> * FramworkUtil contains utility methods required by the framework. * </p> * <p> * Note : This class does not maintain any state. Keep all the methods as static * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public final class FrameworkUtil { private static Logger logger=Logger.getLogger(FrameworkUtil.class.getName()); /** * Private constructor to make sure it will not be instantiated. */ private FrameworkUtil() { /** * Just to make sure this class will not be instantiated. */ } /** * <p> * Loads the property elements exists in the given element to the given map. * This looks for the <property> elements in the given element and looks * for the value of "key" attribute and the values of <property> element * and load them as key values pairs. * </p> * <p> * Property elements should be in the following format.<br><br> * <property key="some-config-key1">some-config-value1</property> * </p> * * @param configElement DOM Element consists of <property> elements. * @param propertyMap Map to be loaded with property key values. * * @throws IllegalArgumentException If either configElement or propertyMap is null. */ public static void loadPropertiesFromElementToMap(Element configElement,Map propertyMap) { logger.entering(FrameworkUtil.class.getName(),"loadPropertiesFromElementToMap"); if(configElement==null) throw new IllegalArgumentException("Input configuration element configElement cannot be null"); if(propertyMap==null) throw new IllegalArgumentException("Input properties map propertyMap cannot be null"); NodeList propertyElements=configElement.getElementsByTagName("property"); for(int i=0;i<propertyElements.getLength();i++) { Element propertyElement=(Element)propertyElements.item(i); String key=propertyElement.getAttribute("key"); String value=""; NodeList propertyValueNodes=propertyElement.getChildNodes(); for(int j=0;j<propertyValueNodes.getLength();j++) { Node propertyValueNode=propertyValueNodes.item(j); if(propertyValueNode.getNodeType()==Node.TEXT_NODE || propertyValueNode.getNodeType()==Node.CDATA_SECTION_NODE) { value=propertyValueNode.getNodeValue(); break; } } propertyMap.put(key,value); } logger.exiting(FrameworkUtil.class.getName(),"loadPropertiesFromElementToMap"); } /** * <p> * Loads the property key value pairs exists in the given string to the given map. * This looks for the properties in concantenated by ":" and each property in turn * concatenated by "=". * </p> * <p> * Property elements should be in the following format.<br><br> * key1=value1:key2=value2 * </p> * * @param propertiesString String consists of properties. * @param propertyMap Map to be loaded with property key values. * * @throws IllegalArgumentException If either propertiesString or propertyMap is null. */ public static void loadPropertiesFromStringToMap(String propertiesString,Map propertyMap) { logger.entering(FrameworkUtil.class.getName(),"loadPropertiesFromStringToMap"); if(propertiesString==null) throw new IllegalArgumentException("Input properties string cannot be null"); if(propertyMap==null) throw new IllegalArgumentException("Input properties map propertyMap cannot be null"); StringTokenizer propertiesTokenizer=new StringTokenizer(propertiesString,":"); while(propertiesTokenizer.hasMoreTokens()) { String property=propertiesTokenizer.nextToken(); if(property!=null && !"".equals(property.trim())) { StringTokenizer propertyTokenizer=new StringTokenizer(property,"="); String key=propertyTokenizer.nextToken(); String value=propertyTokenizer.nextToken(); propertyMap.put(key,value); } } logger.exiting(FrameworkUtil.class.getName(),"loadPropertiesFromStringToMap"); } } |