use of org.eclipse.persistence.Version in project eclipselink by eclipse-ee4j.
the class DoPrivilegedTest method test.
/**
* Direct calls
*/
@Override
public void test() throws Exception {
String className = "org.eclipse.persistence.Version";
String fieldName = "buildNumber";
String fieldValue = "TopLink Blah";
String methodName = "setProduct";
Class<?> clazz = null;
Version version = null;
Method method = null;
try {
clazz = Class.forName(className);
Class<?>[] methodParameterTypes = { Class.forName("java.lang.String") };
ClassLoader clazzloader = clazz.getClassLoader();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
Class.forName(className, true, clazzloader);
version = (Version) clazz.getConstructor().newInstance();
Field[] fields = clazz.getFields();
Field field = getDeclaredField(clazz, fieldName, true);
try {
int intValueFromField = field.getInt(version);
} catch (Exception e) {
}
field.get(version);
try {
field.set(version, fieldValue);
} catch (Exception e) {
}
String lineSeparator = System.getProperty("file.separator");
method = getDeclaredMethod(clazz, methodName, methodParameterTypes, true);
method.getParameterTypes();
method.getReturnType();
Object[] parameters = { "TopLink Blah." };
method.invoke(version, parameters);
Constructor constructor = clazz.getConstructor((Class<?>[]) null);
constructor.setAccessible(true);
Constructor declaredConstructor = clazz.getDeclaredConstructor((Class<?>[]) null);
declaredConstructor.setAccessible(true);
constructor.newInstance((Object[]) null);
// new XMLSessionConfigLoader().loadInternal(new SessionManager(), clazzloader, false, false);
} catch (Exception e) {
throw (new TestProblemException("An exception has been caught."));
}
}
use of org.eclipse.persistence.Version in project eclipselink by eclipse-ee4j.
the class DoPrivilegedTest method testDoPrivileged.
public void testDoPrivileged() {
String className = "org.eclipse.persistence.Version";
String fieldName = "product";
String fieldValue = "TopLink Blah";
String methodName = "setProduct";
Class<?> clazz = null;
Version version = null;
Method method = null;
try {
clazz = AccessController.doPrivileged(new PrivilegedClassForName<>(className));
Class<?>[] methodParameterTypes = { AccessController.doPrivileged(new PrivilegedClassForName<>("java.lang.String")) };
ClassLoader clazzloader = AccessController.doPrivileged(new PrivilegedGetClassLoaderForClass(clazz));
ClassLoader classloader = AccessController.doPrivileged(new PrivilegedGetContextClassLoader(Thread.currentThread()));
AccessController.doPrivileged(new PrivilegedClassForName<>(className, true, clazzloader));
version = (Version) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(clazz));
Field[] fields = AccessController.doPrivileged(new PrivilegedGetFields(clazz));
Field field = AccessController.doPrivileged(new PrivilegedGetDeclaredField(clazz, fieldName, true));
try {
int intValueFromField = (Integer) AccessController.doPrivileged(new PrivilegedGetValueFromField(field, version));
} catch (Exception e) {
}
AccessController.doPrivileged(new PrivilegedGetValueFromField(field, version));
try {
AccessController.doPrivileged(new PrivilegedSetValueInField(field, version, fieldValue));
} catch (Exception e) {
}
String lineSeparator = PrivilegedAccessHelper.getLineSeparator();
method = AccessController.doPrivileged(new PrivilegedGetMethod(clazz, methodName, methodParameterTypes, true));
AccessController.doPrivileged(new PrivilegedGetMethodParameterTypes(method));
AccessController.doPrivileged(new PrivilegedGetMethodReturnType(method));
Object[] parameters = { "TopLink Blah." };
AccessController.doPrivileged(new PrivilegedMethodInvoker(method, version, parameters));
Constructor<?> constructor = AccessController.doPrivileged(new PrivilegedGetConstructorFor<>(clazz, null, true));
Constructor declaredConstructor = AccessController.doPrivileged(new PrivilegedGetDeclaredConstructorFor(clazz, null, true));
AccessController.doPrivileged(new PrivilegedInvokeConstructor(constructor, null));
// PrivilegedAccessController.loadDeploymentXML(new XMLSessionConfigLoader(),new SessionManager(), clazzloader, false, false);
} catch (Exception e) {
throw (new TestProblemException("An exception has been caught."));
}
}
Aggregations