2012-07-06 三级考试
1、多线程处理
2、本试题中会涉及到一些常用的公共的jar,请自行加载使用。
3、XML文件解析
4、Java 集合类使用,排序
5、Java对象处理,涉及对象clone
6、正则表达式;
7、逻辑思维。
<?xml version="1.0"encoding="utf-8"?>
<parameters>
<parameter name=”parameter1”>
<param name=”param11”value=”value11”type=”String”/>
</parameter>
</parameters>
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* <一句话功能简述>
* @author
* @version [ , Oct 12, 2012]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class Toolkit
{
/**
* 获取*.properties文件内容
* @param key 文件名
* @return [参数说明]
*/
public static Properties getConfiguration(String key)
{
Properties config = new Properties();
InputStream inStream = null;
inStream = Toolkit.class.getClassLoader().getResourceAsStream(key);
try
{
config.load(inStream);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (inStream != null)
{
try
{
inStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
return config;
}
/**
* 获取XML中配置参数
* @return [参数说明]
*/
public static Map getXMLConfiguation()
{
Map contains = new HashMap(100);
Document docDB = null;
String localXMLPath = "bb.parameter.xml";
try
{
File file = new File(localXMLPath);
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(false);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
docDB = builder.parse(file);
List<NodeData> nodeValueList = new ArrayList<NodeData>();
XMLTree xmlTree = null;
if (!docDB.hasChildNodes())
{
System.out.println("No data found for xml file.");
}
else
{
NodeList nodeList = docDB.getElementsByTagName("param");
for (int i = 0; i < nodeList.getLength(); i++)
{
Node item = nodeList.item(i);
NamedNodeMap attributes = item.getAttributes();
String type = attributes.getNamedItem("type").getNodeValue();
String name = attributes.getNamedItem("name").getNodeValue();
String value = attributes.getNamedItem("value").getNodeValue();
if (type.equalsIgnoreCase("String"))
{
contains.put(name, value);
}
else if (type.equalsIgnoreCase("int"))
{
contains.put(name, new Integer(value));
}
else
{
//Double float boolean等数据类型依次处理
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return contains;
}
/**
* 对外公共接口
* @param key 键值
* @return [参数说明]
*/
public static String getConfig(String key)
{
Properties config = getConfiguration("bb.properties");
Map xmlConfig = getXMLConfiguation();
String ret = null;
if (null != config.get(key))
{
ret = config.get(key).toString();
}
else if (xmlConfig.containsKey(key))
{
ret = xmlConfig.get(key).toString();
}
return ret;
}
public static void main(String[] args)
{
String ss = getConfig("filePath");
String ss1 = getConfig("bb.blds.context.name");
System.out.println(ss);
System.out.println(ss1);
}
}
import java.io.File;
import java.util.Date;
/**
*<一句话功能简述>
*@author yKF45160
*@version [V300R003C02LG00A1,Oct12,2012]
*@see [相关类/方法]
*@since [产品/模块版本]
*/
publicclass LookConfigextends Thread
{
privatestatic DatemodifyDate1 =null;
privatestatic DatemodifyDate2 =null;
/**
*<默认构造函数>
*/
public LookConfig()
{
File configProp = new File("bb.parameter.xml");
File configxml = new File("bb.properties");
modifyDate1 = new Date(configProp.lastModified());
modifyDate2 = new Date(configxml.lastModified());
}
/**
*run
*/
publicvoid run()
{
File configProp = new File("bb.parameter.xml");
File configxml = new File("bb.properties");
Date date1 = new Date(configProp.lastModified());
Date date2 = new Date(configxml.lastModified());
if (modifyDate1.after(date1) ||modifyDate2.after(date2))
{
//通知相关业务进行修改
}
}
}