以下是InitContext过程中要做的。
String getJndiProperty(
final
int i) {
return (String) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
try {
return System.getProperty(PROPS[i]);
} catch (SecurityException e) {
return null;
}
}
}
);
}
String[] getJndiProperties() {
if (getSystemPropsFailed) {
return null; // after one failure, don't bother trying again
}
Properties sysProps = (Properties) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
try {
return System.getProperties();
} catch (SecurityException e) {
getSystemPropsFailed = true;
return null;
}
}
}
);
if (sysProps == null) {
return null;
}
String[] jProps = new String[PROPS.length];
for ( int i = 0; i < PROPS.length; i++) {
jProps[i] = sysProps.getProperty(PROPS[i]);
}
return jProps;
}
return (String) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
try {
return System.getProperty(PROPS[i]);
} catch (SecurityException e) {
return null;
}
}
}
);
}
String[] getJndiProperties() {
if (getSystemPropsFailed) {
return null; // after one failure, don't bother trying again
}
Properties sysProps = (Properties) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
try {
return System.getProperties();
} catch (SecurityException e) {
getSystemPropsFailed = true;
return null;
}
}
}
);
if (sysProps == null) {
return null;
}
String[] jProps = new String[PROPS.length];
for ( int i = 0; i < PROPS.length; i++) {
jProps[i] = sysProps.getProperty(PROPS[i]);
}
return jProps;
}
转载于:https://blog.51cto.com/pz0513/112349