【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:XmlConfiguration.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
// ========================================================================
// Copyright (c) 1999 Mort Bay Consulting (Australia) Pty. Ltd.
// $Id: XmlConfiguration.java,v 3.11 2000/12/14 22:50:48 gregwilkins Exp $
// ========================================================================
package com.mortbay.Util;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Map;
import org.
xml.sax.SAXException;
/* ------------------------------------------------------------ */
/** Configure Objects from XML.
* This class reads an XML file conforming to the configure.dtd DTD
* and uses it to configure and object by calling set, put or other
* methods on the object.
*
* @see configure.dtd
* @version $Id: XmlConfiguration.java,v 3.11 2000/12/14 22:50:48 gregwilkins Exp $
* @author Greg Wilkins (gregw)
*/
public class XmlConfiguration
{
private static Class[] __primitives =
{
Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE,
Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPE
};
private static Class[] __primitiveHolders =
{
Boolean.class, Character.class, Byte.class, Short.class, Integer.class,
Long.class, Float.class, Double.class, Void.class
};
/* ------------------------------------------------------------ */
private static XmlParser __parser;
XmlParser.Node _config;
/* ------------------------------------------------------------ */
/** Constructor.
* Reads the XML configuration file.
* @param configuration
*/
public XmlConfiguration(URL configuration)
throws SAXException, IOException
{
synchronized(this.getClass())
{
if (__parser==null)
{
__parser = new XmlParser();
Resource configResource=Resource.newSystemResource
("com/mortbay/Util/configure.dtd");
__parser.redirectEntity
("configure.dtd",configResource);
__parser.redirectEntity
("configure_1_0.dtd",configResource);
__parser.redirectEntity
("http://jetty.mortbay.com/configure_1_0.dtd",
configResource);
__parser.redirectEntity
("-//Mort Bay Consulting//DTD Configure 1.0//EN",
configResource);
}
}
_config = __parser.parse(configuration.toString());
}
/* ------------------------------------------------------------ */
/** Configure an object.
* If the object is of the approprate class, the XML configuration
* script is applied to the object.
* @param obj The object to be configured.
* @exception ClassNotFoundException
* @exception NoSuchMethodException
* @exception InvocationTargetException
*/
public void configure(Object obj)
throws ClassNotFoundException,
NoSuchMethodException,
InvocationTargetException
{
//Check the class of the object
Class oClass = nodeClass(_config);
if (!oClass.isInstance(obj))
throw new IllegalArgumentException("Object is not of type "+oClass);
configure(obj,_config,0);
}
/* ------------------------------------------------------------ */
/** Create a new object and configure it.
* A new object is created and configured.
* @return The newly created configured object.
* @exception ClassNotFoundException
* @exception NoSuchMethodException
* @exception InvocationTargetException
* @exception InstantiationException
* @exception IllegalAccessException
*/
public Object newInstance()
throws ClassNotFoundException,
NoSuchMethodException,
InvocationTargetException,
Instan