use of java.lang.reflect.InvocationTargetException in project OpenAM by OpenRock.
the class ApplicationManager method newApplication.
/**
* Creates an application.
*
* @param name Name of application.
* @param applicationType application type.
* @throws EntitlementException if application class is not found.
*/
public static Application newApplication(String name, ApplicationType applicationType) throws EntitlementException {
Class clazz = applicationType.getApplicationClass();
Class[] parameterTypes = { String.class, ApplicationType.class };
Constructor constructor;
try {
constructor = clazz.getConstructor(parameterTypes);
Object[] parameters = { name, applicationType };
return (Application) constructor.newInstance(parameters);
} catch (NoSuchMethodException ex) {
throw new EntitlementException(6, ex);
} catch (SecurityException ex) {
throw new EntitlementException(6, ex);
} catch (InstantiationException ex) {
throw new EntitlementException(6, ex);
} catch (IllegalAccessException ex) {
throw new EntitlementException(6, ex);
} catch (IllegalArgumentException ex) {
throw new EntitlementException(6, ex);
} catch (InvocationTargetException ex) {
throw new EntitlementException(6, ex);
}
}
use of java.lang.reflect.InvocationTargetException in project OpenAM by OpenRock.
the class ApplicationPrivilegeManager method getInstance.
/**
* Returns an instance of application privilege manager.
*
* @param realm
* Realm name.
* @param caller
* Administrator subject.
*
* @return an instance of application privilege manager.
*/
public static ApplicationPrivilegeManager getInstance(String realm, Subject caller) {
try {
final Class[] parameterTypes = { String.class, Subject.class, ResourceTypeService.class };
final Constructor<? extends ApplicationPrivilegeManager> constructor = DEFAULT_IMPL.getConstructor(parameterTypes);
final ResourceTypeService resourceTypeService = InjectorHolder.getInstance(ResourceTypeService.class);
return constructor.newInstance(realm, caller, resourceTypeService);
} catch (InstantiationException ex) {
PolicyConstants.DEBUG.error("ApplicationPrivilegeManager.getInstance", ex);
} catch (IllegalAccessException ex) {
PolicyConstants.DEBUG.error("ApplicationPrivilegeManager.getInstance", ex);
} catch (IllegalArgumentException ex) {
PolicyConstants.DEBUG.error("ApplicationPrivilegeManager.getInstance", ex);
} catch (InvocationTargetException ex) {
PolicyConstants.DEBUG.error("ApplicationPrivilegeManager.getInstance", ex);
} catch (NoSuchMethodException ex) {
PolicyConstants.DEBUG.error("ApplicationPrivilegeManager.getInstance", ex);
} catch (SecurityException ex) {
PolicyConstants.DEBUG.error("ApplicationPrivilegeManager.getInstance", ex);
}
return null;
}
use of java.lang.reflect.InvocationTargetException in project OpenAM by OpenRock.
the class UmaEmailService method getMailServer.
private MailServer getMailServer(String realm) throws MessagingException {
try {
ServiceConfigManager mailmgr = new ServiceConfigManager(AccessController.doPrivileged(AdminTokenAction.getInstance()), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
ServiceConfig mailscm = mailmgr.getOrganizationConfig(realm, null);
if (!mailscm.exists()) {
throw new MessagingException("EmailService is not configured for realm, " + realm);
}
Map<String, Set<String>> mailattrs = mailscm.getAttributes();
String mailServerClass = mailattrs.get("forgerockMailServerImplClassName").iterator().next();
return Class.forName(mailServerClass).asSubclass(MailServer.class).getDeclaredConstructor(String.class).newInstance(realm);
} catch (IllegalAccessException | SSOException | InstantiationException | ClassNotFoundException | InvocationTargetException | NoSuchMethodException | SMSException e) {
throw new MessagingException("Failed to load mail server", e);
}
}
use of java.lang.reflect.InvocationTargetException in project android_frameworks_base by ResurrectionRemix.
the class ViewDebug method capturedViewExportMethods.
private static String capturedViewExportMethods(Object obj, Class<?> klass, String prefix) {
if (obj == null) {
return "null";
}
StringBuilder sb = new StringBuilder();
final Method[] methods = capturedViewGetPropertyMethods(klass);
int count = methods.length;
for (int i = 0; i < count; i++) {
final Method method = methods[i];
try {
Object methodValue = method.invoke(obj, (Object[]) null);
final Class<?> returnType = method.getReturnType();
CapturedViewProperty property = method.getAnnotation(CapturedViewProperty.class);
if (property.retrieveReturn()) {
//we are interested in the second level data only
sb.append(capturedViewExportMethods(methodValue, returnType, method.getName() + "#"));
} else {
sb.append(prefix);
sb.append(method.getName());
sb.append("()=");
if (methodValue != null) {
final String value = methodValue.toString().replace("\n", "\\n");
sb.append(value);
} else {
sb.append("null");
}
sb.append("; ");
}
} catch (IllegalAccessException e) {
//Exception IllegalAccess, it is OK here
//we simply ignore this method
} catch (InvocationTargetException e) {
//Exception InvocationTarget, it is OK here
//we simply ignore this method
}
}
return sb.toString();
}
use of java.lang.reflect.InvocationTargetException in project android_frameworks_base by ResurrectionRemix.
the class BitmapUtils method createVideoThumbnail.
public static Bitmap createVideoThumbnail(String filePath) {
// MediaMetadataRetriever is available on API Level 8
// but is hidden until API Level 10
Class<?> clazz = null;
Object instance = null;
try {
clazz = Class.forName("android.media.MediaMetadataRetriever");
instance = clazz.newInstance();
Method method = clazz.getMethod("setDataSource", String.class);
method.invoke(instance, filePath);
// The method name changes between API Level 9 and 10.
if (Build.VERSION.SDK_INT <= 9) {
return (Bitmap) clazz.getMethod("captureFrame").invoke(instance);
} else {
byte[] data = (byte[]) clazz.getMethod("getEmbeddedPicture").invoke(instance);
if (data != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
if (bitmap != null)
return bitmap;
}
return (Bitmap) clazz.getMethod("getFrameAtTime").invoke(instance);
}
} catch (IllegalArgumentException ex) {
// Assume this is a corrupt video file
} catch (RuntimeException ex) {
// Assume this is a corrupt video file.
} catch (InstantiationException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (ClassNotFoundException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (NoSuchMethodException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (IllegalAccessException e) {
Log.e(TAG, "createVideoThumbnail", e);
} finally {
try {
if (instance != null) {
clazz.getMethod("release").invoke(instance);
}
} catch (Exception ignored) {
}
}
return null;
}
Aggregations