/**
* Returns an XmlConfigurator based on the provided properties string (if
* possible).
*
* @param properties a string representing a system resource containing a
* JGroups XML configuration, a string representing a URL
* pointing to a JGroups ML configuration, or a string
* representing a file name that contains a JGroups XML
* configuration.
*
* @return an XmlConfigurator instance based on the provided properties
* string; <code>null</code> if the provided properties string does
* not point to an XML configuration.
*
* @throws IOException if the provided properties string appears to be a
* valid URL but is unreachable, or if the JGroups XML
* configuration pointed to by the URL can not be
* parsed.
*/
static XmlConfigurator getXmlConfigurator(String properties) throws IOException {
XmlConfigurator returnValue=null;
InputStream configStream=getConfigStream(properties);
if (configStream != null) {
checkJAXPAvailability();
returnValue=XmlConfigurator.getInstance(configStream);
}
return returnValue;
}
参数properties为JCHANNEL构造函数传过来,一般为udp.xml.
getConfigStream返回一个配置输入流,
XmlConfigurator.getInstance(configStream),解析流并构造一个XmlConfigurator 的实例。
输入流调用过程:
public static InputStream getConfigStream(String properties) throws IOException {
InputStream configStream = null;
if (propertiesOverride != null)
return getConfigStream(propertiesOverride);
// Check to see if the properties string is the name of a file.
try {
configStream=new FileInputStream(properties);
}
catch(FileNotFoundException fnfe) {
// the properties string is likely not a file
}
catch(AccessControlException access_ex) {
// fixes http://jira.jboss.com/jira/browse/JGRP-94
}
// Check to see if the properties string is a URL.
if(configStream == null) {
try {
configStream=new URL(properties).openStream();
}
catch (MalformedURLException mre) {
// the properties string is not a URL
}
}
// Commented so the caller is notified of this condition, but left in
// the code for documentation purposes.
//
// catch (IOException ioe) {
// the specified URL string was not reachable
// }
// Check to see if the properties string is the name of a resource,
// e.g. udp.xml.
if(configStream == null && properties.endsWith("xml")) {
configStream=Util.getResourceAsStream(properties, ConfiguratorFactory.class);
}
return configStream;
}
XmlConfigurator对象构造过程如下:
public static XmlConfigurator getInstance(InputStream stream) throws java.io.IOException {
return parse(stream);
}
解析流调用过程如下,参数stream为XML配置内容
protected static XmlConfigurator parse(InputStream stream) throws java.io.IOException {
/**
* CAUTION: crappy code ahead ! I (bela) am not an XML expert, so the code below is pretty amateurish...
* But it seems to work, and it is executed only on startup, so no perf loss on the critical path.
* If somebody<span style