📄 xmlconfigurator.java.new
字号:
Object new_instance = null;
Class obj_class = null;
Constructor constructor = null;
try {
obj_class = Class.forName(attrs_class);
} catch (ClassNotFoundException cnfe) {
logCAT.error(
"endElement() - OBJECT Branch - Class.forName("
+ attrs_class
+ ") caught ClassNotFoundException");
}
if (argument_list.size() == 0) {
try {
new_instance = obj_class.newInstance();
} catch (InstantiationException ie) {
logCAT.error(
"endElement() - OBJECT Branch - obj_class.newInstance() caught InstantiationException");
} catch (IllegalAccessException iae) {
logCAT.error(
"endElement() - OBJECT Branch - obj_class.newInstance() caught IllegalAccessException");
}
} else {
int nargs = argclass_list.size();
Class[] ca = new Class[nargs];
try {
for (int i = 0; i < nargs; i++)
ca[i] = (Class) argclass_list.get(i);
constructor = obj_class.getConstructor(ca);
} catch (NoSuchMethodException nsme) {
logCAT.error(
"endElement() - OBJECT Branch - getConstructor(Class[]) caught NoSuchMethodFoundException");
}
try {
new_instance = constructor.newInstance(argument_list.toArray());
} catch (InstantiationException ie) {
logCAT.error(
"endElement() - OBJECT Branch - constructor.newInstance() caught InstantiationException");
} catch (IllegalAccessException iae) {
logCAT.error(
"endElement() - OBJECT Branch - constructor.newInstance() caught IllegalAccessException");
} catch (java.lang.reflect.InvocationTargetException ite) {
logCAT.error(
"endElement() - OBJECT Branch - constructor.newInstance() caught InvocationTargetException" + " uri:" + uri + " local:" + local + " raw:" + raw +" argumen :" + argument_list.toString()+ ite.getCause());
}
}
treemap.put(stack.peek(), new_instance);
stack.pop();
argument_list = null;
argclass_list = null;
context = N_CTX;
attrs_class = null;
return;
}
if (local.equals(CLASSMETHOD)) {
Class method_class = null;
Method method = null;
Object return_object = null;
try {
method_class = Class.forName(attrs_class);
} catch (ClassNotFoundException cnfe) {
logCAT.error(
"endElement() - CLASSMETHOD Branch - Class.forName("
+ attrs_class
+ ") caught ClassNotFoundException");
}
if (argument_list.size() == 0) {
try {
method = method_class.getMethod(attrs_method, null);
} catch (NoSuchMethodException nsme) {
logCAT.error(
"endElement() - CLASSMETHOD Branch - getConstructor(Class[]) caught NoSuchMethodFoundException");
}
} else {
int nargs = argclass_list.size();
Class[] ca = new Class[nargs];
try {
for (int i = 0; i < nargs; i++)
ca[i] = (Class) argclass_list.get(i);
method = method_class.getMethod(attrs_method, ca);
} catch (NoSuchMethodException nsme) {
logCAT.error(
"endElement() - CLASSMETHOD Branch - getConstructor(Class[]) caught NoSuchMethodFoundException");
}
}
try {
return_object = method.invoke(null, argument_list.toArray());
} catch (IllegalAccessException iae) {
logCAT.error(
"endElement() - CLASSMETHOD Branch - method.invoke() caught IllegalAccessException");
} catch (java.lang.reflect.InvocationTargetException ite) {
logCAT.error(
"endElement() - CLASSMETHOD Branch - method.invoke() caught InvocationTargetException") ;
}
if (return_object != null)
treemap.put(stack.peek(), return_object);
stack.pop();
argument_list = null;
argclass_list = null;
context = N_CTX;
attrs_class = null;
attrs_method = null;
return;
}
if (local.equals(INSTANCEMETHOD)) {
Class method_class = null;
Object instance = treemap.get(attrs_reference);
Object return_object = null;
// instance is obtained by key (reference)
Method method = null;
if (instance == null) {
logCAT.error(
"endElement() - INSTANCEMETHOD Branch - No reference found in table with key: "
+ attrs_reference);
}
method_class = instance.getClass();
if (argument_list.size() == 0) {
try {
method = method_class.getMethod(attrs_method, null);
} catch (NoSuchMethodException nsme) {
logCAT.error(
"endElement() - INSTANCEMETHOD Branch - getConstructor(Class[]) caught NoSuchMethodFoundException");
}
} else {
int nargs = argclass_list.size();
Class[] ca = new Class[nargs];
try {
for (int i = 0; i < nargs; i++)
ca[i] = (Class) argclass_list.get(i);
method = method_class.getMethod(attrs_method, ca);
} catch (NoSuchMethodException nsme) {
logCAT.error(
"endElement() - INSTANCEMETHOD Branch - getConstructor(Class[]) caught NoSuchMethodFoundException");
}
}
try {
return_object = method.invoke(instance, argument_list.toArray());
} catch (IllegalAccessException iae) {
logCAT.error(
"endElement() - INSTANCEMETHOD Branch - method.invoke() caught IllegalAccessException");
} catch (java.lang.reflect.InvocationTargetException ite) {
logCAT.error(
"endElement() - INSTANCEMETHOD Branch - method.invoke() caught InvocationTargetException");
}
if (return_object != null)
treemap.put(stack.peek(), return_object);
stack.pop();
argument_list = null;
argclass_list = null;
context = N_CTX;
attrs_reference = null;
attrs_method = null;
return;
}
if (local.equals(REFERENCE)
| local.equals(BOOLEAN)
| local.equals(BYTE)
| local.equals(SHORT)
| local.equals(INTEGER)
| local.equals(LONG)
| local.equals(FLOAT)
| local.equals(DOUBLE)
| local.equals(STRING)) {
switch (context) {
case P_CTX : // Nothing done while in a "Parameter context" - Do it later, at Parameter close
break;
case O_CTX :
case C_CTX :
case I_CTX :
argument_list.add(arg_object);
argclass_list.add(arg_class);
break;
default :
logCAT.error(
"endElement() detected an internal parsing error: invalid context");
break;
}
return;
}
}
public void error(SAXParseException ex) {
logCAT.error("[Error] " + getLocationString(ex) + ": " + ex.getMessage());
}
public void fatalError(SAXParseException ex) throws SAXException {
logCAT.fatal("[Fatal Error] " + getLocationString(ex) + ": " + ex.getMessage());
throw ex;
}
public static float floatValue(String key) {
if (initialized) {
Object obj = treemap.get(key);
if (obj == null) {
logCAT.error("floatValue() found a null value for key '" + key + "'");
System.exit(1);
return 0;
} else {
try {
return ((Float) obj).floatValue();
} catch (java.lang.ClassCastException e) {
logCAT.error("floatValue() caught ClassCastException: " + e);
System.exit(1);
return 0;
}
}
} else {
logCAT.error("floatValue() called before initialization");
System.exit(1);
return 0;
}
}
public static Object setParameter(Object key, Object value)
{
return treemap.put(key, value);
}
public static Object getClassParameter(Class cl, String pname) {
if (initialized) {
String name = cl.getName();
String key = name + "." + pname;
return treemap.get(key);
} else {
return null;
}
}
public static Object getClassParameter(Object obj, String pname) {
if (initialized) {
String name = obj.getClass().getName();
String key = name + "." + pname;
return treemap.get(key);
} else {
return null;
}
}
private String getLocationString(SAXParseException ex) {
StringBuffer str = new StringBuffer();
String systemId = ex.getSystemId();
if (systemId != null) {
int index = systemId.lastIndexOf('/');
if (index != -1)
systemId = systemId.substring(index + 1);
str.append(systemId);
}
str.append(':');
str.append(ex.getLineNumber());
str.append(':');
str.append(ex.getColumnNumber());
return str.toString();
}
public static Object getParameter(String key) {
if (initialized) {
return treemap.get(key);
} else {
return null;
}
}
/*public static synchronized void init(String[] uri_array)
throws ConfigurationException {
if (initialized) {
throw new ConfigurationException("XMLConfigurator - Initialization already completed");
} else {
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;
} 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -