📄 xmlconfigurator.java.new
字号:
System.exit(1);
}
} catch (Exception e) {
logCAT.error("Caught Exception: \n\t"+e);
e.printStackTrace(System.err);
System.exit(1);
}
}
}*/
public static synchronized void init(String[] uri_array)
throws ConfigurationException {
if (initialized) {
logCAT.warn("XMLConfigurator - Initialization again");
initialized = false;
}
try {
XMLConfigurator configurator = new XMLConfigurator();
XMLReader parser = (XMLReader) Class.forName(DEFAULT_PARSER_NAME).newInstance();
parser.setContentHandler(configurator);
parser.setErrorHandler(configurator);
parser.setFeature("http://xml.org/sax/features/validation", setValidation);
parser.setFeature("http://xml.org/sax/features/namespaces", setNameSpaces);
parser.setFeature(
"http://apache.org/xml/features/validation/schema",
setSchemaSupport);
parser.setFeature(
"http://apache.org/xml/features/validation/schema-full-checking",
setSchemaFullSupport);
for (int i = 0; i < uri_array.length; i++) {
logCAT.debug(uri_array[i]);
parser.parse(uri_array[i]);
// formatter.applyPattern(bundle.getString("config_file_parsed"));
// Object[] one_argument = {uri_array[i]};
// logCAT.info(formatter.format(one_argument));
}
initialized = true;
logCAT.debug("init successfully");
} catch (org.xml.sax.SAXParseException spe) {
logCAT.error("Caught SAXParseException: \n\t"+spe);
spe.printStackTrace(System.err);
System.exit(1);
} catch (org.xml.sax.SAXException se) {
logCAT.error("Caught SAXException: \n\t"+se);
if (se.getException() != null) {
se.getException().printStackTrace(System.err);
System.exit(1);
} else {
se.printStackTrace(System.err);
System.exit(1);
}
} catch (Exception e) {
logCAT.error("Caught Exception: \n\t"+e);
e.printStackTrace(System.err);
System.exit(1);
}
}
public static synchronized void init(InputStream in)
throws ConfigurationException {
if (initialized) {
logCAT.warn("XMLConfigurator - Initialization again");
initialized = false;
}
try {
XMLConfigurator configurator = new XMLConfigurator();
XMLReader parser = (XMLReader) Class.forName(DEFAULT_PARSER_NAME).newInstance();
parser.setContentHandler(configurator);
parser.setErrorHandler(configurator);
parser.setFeature("http://xml.org/sax/features/validation", setValidation);
parser.setFeature("http://xml.org/sax/features/namespaces", setNameSpaces);
parser.setFeature(
"http://apache.org/xml/features/validation/schema",
setSchemaSupport);
parser.setFeature(
"http://apache.org/xml/features/validation/schema-full-checking",
setSchemaFullSupport);
ByteArrayInputStream inReader = (ByteArrayInputStream)in;
parser.parse(new InputSource(inReader));
// formatter.applyPattern(bundle.getString("config_file_parsed"));
// Object[] one_argument = {uri_array[i]};
// logCAT.info(formatter.format(one_argument));
initialized = true;
logCAT.debug("init successfully");
} catch (org.xml.sax.SAXParseException spe) {
logCAT.error("Caught SAXParseException: \n\t"+spe);
spe.printStackTrace(System.err);
System.exit(1);
} catch (org.xml.sax.SAXException se) {
logCAT.error("Caught SAXException: \n\t"+se);
if (se.getException() != null) {
se.getException().printStackTrace(System.err);
System.exit(1);
} else {
se.printStackTrace(System.err);
System.exit(1);
}
} catch (Exception e) {
logCAT.error("Caught Exception: \n\t"+e);
e.printStackTrace(System.err);
System.exit(1);
}
}
public static int intValue(String key) {
if (initialized) {
Object obj = treemap.get(key);
if (obj == null) {
logCAT.error("intValue() found a null value for key '" + key + "'");
System.exit(1);
return 0;
} else {
try {
return ((Integer) obj).intValue();
} catch (java.lang.ClassCastException e) {
logCAT.error("intValue() caught ClassCastException: " + e);
System.exit(1);
return 0;
}
}
} else {
logCAT.error("intValue() called before initialization");
System.exit(1);
return 0;
}
}
public static long longValue(String key) {
if (initialized) {
Object obj = treemap.get(key);
if (obj == null) {
logCAT.error("longValue() found a null value for key '" + key + "'");
System.exit(1);
return 0;
} else {
try {
return ((Long) obj).longValue();
} catch (java.lang.ClassCastException e) {
logCAT.error("longValue() caught ClassCastException: " + e);
System.exit(1);
return 0;
}
}
} else {
logCAT.error("longValue() called before initialization");
System.exit(1);
return 0;
}
}
/*public static void main(String argv[]) {
// The following try {} catch(){} is needed to initialize XMLConfigurator.
// A better alternative is to set the util.XMLConfigurator.configuration
// property at JVM start time. That would cause class static initialization
// to be performed using the configuration file specified by the property setting
try {XMLConfigurator.init(argv);} catch (Exception e) {}
XMLConfigurator.print();
//************************************************************
// Get and print a double paremeter value from XMLConfigurator
System.out.println("The parameter 'double' evaluates to: "+ XMLConfigurator.doubleValue("Double"));
//************************************************************
// Get the Locale and Application bundle from XMLConfigurator
java.util.Locale myLocale = (java.util.Locale)XMLConfigurator.getParameter("Locale");
java.util.ResourceBundle myBundle = (java.util.ResourceBundle)XMLConfigurator.getParameter("Application_MsgBundle");
//************************************************************
// Suppose we use the retrieved object to issue Application-level localized messages
Object[] msg_arguments1 = {myBundle.getString("WORD001"), new java.util.Date()};
java.text.MessageFormat formatter = new java.text.MessageFormat("");
formatter.setLocale(myLocale);
formatter.applyPattern(myBundle.getString("MSG_001"));
logCAT.info(formatter.format(msg_arguments1));
//************************************************************
// Get the bundle for the current class from XMLConfigurator
java.util.ResourceBundle classBundle = (java.util.ResourceBundle)XMLConfigurator.getParameter("xmlconfig.XMLConfigurator.class_bundle");
//************************************************************
// Suppose we use the retrieved object to issue localized messages relative to the current class
Object[] msg_arguments2 = {classBundle.getString("WORD001"), new java.util.Date()};
formatter = new java.text.MessageFormat("");
formatter.setLocale(myLocale);
formatter.applyPattern(classBundle.getString("MSG_001"));
logCAT.info(formatter.format(msg_arguments2));
return;
}*/
/*public static void print() {
Set keyset = treemap.keySet();
String key;
String value;
System.out.println("Printing objects managed by XMLConfigurator");
System.out.println("___________________________________________");
for (Iterator i = keyset.iterator(); i.hasNext(); ) {
key = (String) i.next();
value = treemap.get(key).toString();
System.out.println(key + ": " + value);
}
System.out.println("___________________________________________");
} */
public static short shortValue(String key) {
if (initialized) {
Object obj = treemap.get(key);
if (obj == null) {
logCAT.error("shortValue() found a null value for key '" + key + "'");
System.exit(1);
return 0;
} else {
try {
return ((Short) obj).shortValue();
} catch (java.lang.ClassCastException e) {
logCAT.error("shortValue() caught ClassCastException: " + e);
System.exit(1);
return 0;
}
}
} else {
logCAT.error("shortValue() called before initialization");
System.exit(1);
return 0;
}
}
public void startDocument() {
treemap = new TreeMap();
stack = new Stack();
}
public void startElement(
String uri,
String local,
String raw,
Attributes attrs) {
data_element_typename = local; // Keep current element name for use when processing element character data
String strName;
if (local.equals(APPLICATION)) {
stack.push("");
return;
}
if (local.equals(TOPIC)) {
stack.push(stack.peek() + attrs.getValue(0) + "|");
return;
}
if (local.equals(PACKAGE) | local.equals(CLASS)) {
stack.push(stack.peek() + attrs.getValue(0) + ".");
return;
}
if (local.equals(PARAMETER)) {
stack.push(stack.peek() + attrs.getValue(0));
context = P_CTX;
return;
}
if (local.equals(OBJECT)) {
strName = attrs.getValue("name");
logCAT.debug("attrs_name:"+strName);
stack.push(stack.peek() + strName);
argument_list = new ArrayList();
argclass_list = new ArrayList();
context = O_CTX;
attrs_class = attrs.getValue("class");
logCAT.debug("attrs_class:"+attrs_class);
return;
}
if (local.equals(PROPERTY)) {
System.setProperty(stack.peek() + attrs.getValue(0), attrs.getValue(1));
return;
}
if (local.equals(CLASSMETHOD)) {
stack.push(stack.peek() + attrs.getValue(0));
argument_list = new ArrayList();
argclass_list = new ArrayList();
context = C_CTX;
attrs_class = attrs.getValue(1);
attrs_method = attrs.getValue(2);
return;
}
if (local.equals(INSTANCEMETHOD)) {
stack.push(stack.peek() + attrs.getValue(0));
argument_list = new ArrayList();
argclass_list = new ArrayList();
context = I_CTX;
attrs_reference = attrs.getValue(1);
attrs_method = attrs.getValue(2);
return;
}
}
public void warning(SAXParseException ex) {
logCAT.warn("[Warning] " + getLocationString(ex) + ": " + ex.getMessage());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -