use of java.lang.reflect.InvocationTargetException in project midpoint by Evolveum.
the class FocusMainPanel method createTabPanel.
protected WebMarkupContainer createTabPanel(String panelId, FormSpecificationType formSpecificationType, PageAdminObjectDetails<F> parentPage) {
String panelClassName = formSpecificationType.getPanelClass();
Class<?> panelClass;
try {
panelClass = Class.forName(panelClassName);
} catch (ClassNotFoundException e) {
throw new SystemException("Panel class '" + panelClassName + "' as specified in admin GUI configuration was not found", e);
}
if (AbstractFocusTabPanel.class.isAssignableFrom(panelClass)) {
Constructor<?> constructor;
try {
constructor = panelClass.getConstructor(String.class, Form.class, LoadableModel.class, LoadableModel.class, LoadableModel.class, PageBase.class);
} catch (NoSuchMethodException | SecurityException e) {
throw new SystemException("Unable to locate constructor (String,Form,LoadableModel,LoadableModel,LoadableModel,PageBase) in " + panelClass + ": " + e.getMessage(), e);
}
AbstractFocusTabPanel<F> tabPanel;
try {
tabPanel = (AbstractFocusTabPanel<F>) constructor.newInstance(panelId, getMainForm(), getObjectModel(), assignmentsModel, projectionModel, parentPage);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new SystemException("Error instantiating " + panelClass + ": " + e.getMessage(), e);
}
return tabPanel;
} else if (AbstractObjectTabPanel.class.isAssignableFrom(panelClass)) {
Constructor<?> constructor;
try {
constructor = panelClass.getConstructor(String.class, Form.class, LoadableModel.class, PageBase.class);
} catch (NoSuchMethodException | SecurityException e) {
throw new SystemException("Unable to locate constructor (String,Form,LoadableModel,PageBase) in " + panelClass + ": " + e.getMessage(), e);
}
AbstractObjectTabPanel<F> tabPanel;
try {
tabPanel = (AbstractObjectTabPanel<F>) constructor.newInstance(panelId, getMainForm(), getObjectModel(), parentPage);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new SystemException("Error instantiating " + panelClass + ": " + e.getMessage(), e);
}
return tabPanel;
} else {
throw new UnsupportedOperationException("Tab panels that are not subclasses of AbstractObjectTabPanel or AbstractFocusTabPanel are not supported yet (got " + panelClass + ")");
}
}
use of java.lang.reflect.InvocationTargetException in project XobotOS by xamarin.
the class ObjectInputStream method readNewObject.
/**
* Read a new object from the stream. It is assumed the object has not been
* loaded yet (not a cyclic reference). Return the object read.
*
* If the object implements <code>Externalizable</code> its
* <code>readExternal</code> is called. Otherwise, all fields described by
* the class hierarchy are loaded. Each class can define how its declared
* instance fields are loaded by defining a private method
* <code>readObject</code>
*
* @param unshared
* read the object unshared
* @return the object read
*
* @throws IOException
* If an IO exception happened when reading the object.
* @throws OptionalDataException
* If optional data could not be found when reading the object
* graph
* @throws ClassNotFoundException
* If a class for one of the objects could not be found
*/
private Object readNewObject(boolean unshared) throws OptionalDataException, ClassNotFoundException, IOException {
ObjectStreamClass classDesc = readClassDesc();
if (classDesc == null) {
throw missingClassDescriptor();
}
int newHandle = nextHandle();
Class<?> objectClass = classDesc.forClass();
Object result = null;
Object registeredResult = null;
if (objectClass != null) {
// Now we know which class to instantiate and which constructor to
// run. We are allowed to run the constructor.
result = classDesc.newInstance(objectClass);
registerObjectRead(result, newHandle, unshared);
registeredResult = result;
} else {
result = null;
}
try {
// This is how we know what to do in defaultReadObject. And it is
// also used by defaultReadObject to check if it was called from an
// invalid place. It also allows readExternal to call
// defaultReadObject and have it work.
currentObject = result;
currentClass = classDesc;
// If Externalizable, just let the object read itself
// Note that this value comes from the Stream, and in fact it could be
// that the classes have been changed so that the info below now
// conflicts with the newer class
boolean wasExternalizable = (classDesc.getFlags() & SC_EXTERNALIZABLE) != 0;
if (wasExternalizable) {
boolean blockData = (classDesc.getFlags() & SC_BLOCK_DATA) != 0;
if (!blockData) {
primitiveData = input;
}
if (mustResolve) {
Externalizable extern = (Externalizable) result;
extern.readExternal(this);
}
if (blockData) {
// Similar to readHierarchy. Anything not read by
// readExternal has to be consumed here
discardData();
} else {
primitiveData = emptyStream;
}
} else {
// If we got here, it is Serializable but not Externalizable.
// Walk the hierarchy reading each class' slots
readHierarchy(result, classDesc);
}
} finally {
// Cleanup, needs to run always so that we can later detect invalid
// calls to defaultReadObject
currentObject = null;
currentClass = null;
}
if (objectClass != null) {
if (classDesc.hasMethodReadResolve()) {
Method methodReadResolve = classDesc.getMethodReadResolve();
try {
result = methodReadResolve.invoke(result, (Object[]) null);
} catch (IllegalAccessException ignored) {
} catch (InvocationTargetException ite) {
Throwable target = ite.getTargetException();
if (target instanceof ObjectStreamException) {
throw (ObjectStreamException) target;
} else if (target instanceof Error) {
throw (Error) target;
} else {
throw (RuntimeException) target;
}
}
}
}
// it
if (result != null && enableResolve) {
result = resolveObject(result);
}
if (registeredResult != result) {
registerObjectRead(result, newHandle, unshared);
}
return result;
}
use of java.lang.reflect.InvocationTargetException in project XobotOS by xamarin.
the class ObjectInputStream method readObjectForClass.
private void readObjectForClass(Object object, ObjectStreamClass classDesc) throws IOException, ClassNotFoundException, NotActiveException {
// Have to do this before calling defaultReadObject or anything that
// calls defaultReadObject
currentObject = object;
currentClass = classDesc;
boolean hadWriteMethod = (classDesc.getFlags() & SC_WRITE_METHOD) != 0;
Class<?> targetClass = classDesc.forClass();
final Method readMethod;
if (targetClass == null || !mustResolve) {
readMethod = null;
} else {
readMethod = classDesc.getMethodReadObject();
}
try {
if (readMethod != null) {
// We have to be able to fetch its value, even if it is private
readMethod.setAccessible(true);
try {
readMethod.invoke(object, this);
} catch (InvocationTargetException e) {
Throwable ex = e.getTargetException();
if (ex instanceof ClassNotFoundException) {
throw (ClassNotFoundException) ex;
} else if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else if (ex instanceof Error) {
throw (Error) ex;
}
throw (IOException) ex;
} catch (IllegalAccessException e) {
throw new RuntimeException(e.toString());
}
} else {
defaultReadObject();
}
if (hadWriteMethod) {
discardData();
}
} finally {
// Cleanup, needs to run always so that we can later detect invalid
// calls to defaultReadObject
// We did not set this, so we do not need to
currentObject = null;
// clean it
currentClass = null;
}
}
use of java.lang.reflect.InvocationTargetException in project XobotOS by xamarin.
the class InstrumentationTestCase method runMethod.
private void runMethod(Method runMethod, int tolerance, boolean isRepetitive) throws Throwable {
Throwable exception = null;
int runCount = 0;
do {
try {
runMethod.invoke(this, (Object[]) null);
exception = null;
} catch (InvocationTargetException e) {
e.fillInStackTrace();
exception = e.getTargetException();
} catch (IllegalAccessException e) {
e.fillInStackTrace();
exception = e;
} finally {
runCount++;
// Report current iteration number, if test is repetitive
if (isRepetitive) {
Bundle iterations = new Bundle();
iterations.putInt("currentiterations", runCount);
getInstrumentation().sendStatus(2, iterations);
}
}
} while ((runCount < tolerance) && (isRepetitive || exception != null));
if (exception != null) {
throw exception;
}
}
use of java.lang.reflect.InvocationTargetException in project OpenAM by OpenRock.
the class EntitlementConfiguration method getInstance.
/**
* Returns an instance of entitlement configuration.
*
* @param adminSubject Admin Subject who has rights to query and modify
* configuration datastore.
* @param realm Realm name.
* @return an instance of entitlement configuration.
*/
public static EntitlementConfiguration getInstance(Subject adminSubject, String realm) {
final Class clazz;
try {
//RFE: load different configuration plugin
clazz = Class.forName("com.sun.identity.entitlement.opensso.EntitlementService");
} catch (ClassNotFoundException e) {
PolicyConstants.DEBUG.error("EntitlementConfiguration.<init>", e);
return null;
}
Class[] parameterTypes = { String.class };
try {
Constructor constructor = clazz.getConstructor(parameterTypes);
Object[] args = { realm };
EntitlementConfiguration impl = (EntitlementConfiguration) constructor.newInstance(args);
impl.adminSubject = adminSubject;
return impl;
} catch (InstantiationException ex) {
PolicyConstants.DEBUG.error("PrivilegeIndexStore.getInstance", ex);
} catch (IllegalAccessException ex) {
PolicyConstants.DEBUG.error("PrivilegeIndexStore.getInstance", ex);
} catch (IllegalArgumentException ex) {
PolicyConstants.DEBUG.error("PrivilegeIndexStore.getInstance", ex);
} catch (InvocationTargetException ex) {
PolicyConstants.DEBUG.error("PrivilegeIndexStore.getInstance", ex);
} catch (NoSuchMethodException ex) {
PolicyConstants.DEBUG.error("PrivilegeIndexStore.getInstance", ex);
} catch (SecurityException ex) {
PolicyConstants.DEBUG.error("PrivilegeIndexStore.getInstance", ex);
}
return null;
}
Aggregations