Refine search
private static boolean isXdkFactory(final Object factory, final String className) { final Class<?> xdkFactoryClass = AccessController.doPrivileged(ReflectionHelper.classForNamePA(className, null)); if (xdkFactoryClass == null) { return false; } return xdkFactoryClass.isAssignableFrom(factory.getClass()); } }
/** * Returns an {@code OsgiRegistry} instance. Call this method only if sure that the application is running in OSGi * environment, otherwise a call to this method can lead to an {@link ClassNotFoundException}. * * @return an {@code OsgiRegistry} instance. */ public static synchronized OsgiRegistry getInstance() { if (instance == null) { final ClassLoader classLoader = AccessController .doPrivileged(ReflectionHelper.getClassLoaderPA(ReflectionHelper.class)); if (classLoader instanceof BundleReference) { final BundleContext context = FrameworkUtil.getBundle(OsgiRegistry.class).getBundleContext(); if (context != null) { // context could be still null if the current bundle has not been started instance = new OsgiRegistry(context); } } } return instance; }
for (final Field field : AccessController.doPrivileged(ReflectionHelper.getAllFieldsPA(clazz))) { if (field.getName().equals(propertyName)) { propertyType = field.getType(); final String getGetter = "get" + getterPropertyName; for (final Method method : AccessController.doPrivileged(ReflectionHelper.getMethodsPA(clazz))) { final String methodName = method.getName(); && ReflectionHelper.isGetter(method) && (propertyType == null || propertyType.isAssignableFrom(method.getReturnType()))) { return AccessController.doPrivileged(ReflectionHelper.findMethodOnClassPA(clazz, method));
/** * Get privileged exception action to obtain Class from given class name. * If run using security manager, the returned privileged exception action * must be invoked within a doPrivileged block. * <p/> * The actual context class loader will be utilized if accessible and non-null. * Otherwise the defining class loader of the calling class will be utilized. * * @param <T> class type. * @param name class name. * @return privileged exception action to obtain the Class. * The action could throw {@link ClassNotFoundException} or return {@code null} if the class cannot be found. * @throws ClassNotFoundException in case the class cannot be loaded with the context class loader. * @see AccessController#doPrivileged(java.security.PrivilegedExceptionAction) */ public static <T> PrivilegedExceptionAction<Class<T>> classForNameWithExceptionPEA(final String name) throws ClassNotFoundException { return classForNameWithExceptionPEA(name, getContextClassLoader()); }
/** * Get privileged action to obtain Class from given class name. * <p> * If run using security manager, the returned privileged action * must be invoked within a doPrivileged block. * The context class loader will be utilized if accessible and non-null. * Otherwise the defining class loader of this class will * be utilized. * </p> * * @param <T> class type. * @param name class name. * @return privileged action to obtain desired Class. * The action could return {@code null} if the class cannot be found. * @see AccessController#doPrivileged(java.security.PrivilegedAction) */ public static <T> PrivilegedAction<Class<T>> classForNamePA(final String name) { return classForNamePA(name, getContextClassLoader()); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
try { final Class<T> tClass = AccessController.doPrivileged( ReflectionHelper.<T>classForNameWithExceptionPEA(cn, loader)); } catch (final PrivilegedActionException pae) { final Throwable thrown = pae.getCause();
private static Method findAnnotatedMethod(final Class<?> c, Method m) { if (c == Object.class) { return null; } m = AccessController.doPrivileged(ReflectionHelper.findMethodOnClassPA(c, m)); if (m == null) { return null; } if (hasAnnotations(m)) { return m; } // Super classes take precedence over interfaces final Class<?> sc = c.getSuperclass(); if (sc != null && sc != Object.class) { final Method sm = findAnnotatedMethod(sc, m); if (sm != null) { return sm; } } for (final Class<?> ic : c.getInterfaces()) { final Method im = findAnnotatedMethod(ic, m); if (im != null) { return im; } } return null; }
private Class getClassForName(final String className) { try { final OsgiRegistry osgiRegistry = ReflectionHelper.getOsgiRegistryInstance(); if (osgiRegistry != null) { return osgiRegistry.classForNameWithException(className); } else { return AccessController.doPrivileged(ReflectionHelper.classForNameWithExceptionPEA(className, classloader)); } } catch (final ClassNotFoundException ex) { throw new RuntimeException(LocalizationMessages.ERROR_SCANNING_CLASS_NOT_FOUND(className), ex); } catch (final PrivilegedActionException pae) { final Throwable cause = pae.getCause(); if (cause instanceof ClassNotFoundException) { throw new RuntimeException(LocalizationMessages.ERROR_SCANNING_CLASS_NOT_FOUND(className), cause); } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else { throw new RuntimeException(cause); } } }
final ClassLoader contextClassLoader = AccessController.doPrivileged(ReflectionHelper.getContextClassLoaderPA()); try { AccessController.doPrivileged(ReflectionHelper.getClassLoaderPA(wadlGenerator.getClass())); AccessController.doPrivileged(ReflectionHelper.setContextClassLoaderPA(jerseyModuleClassLoader)); AccessController.doPrivileged(ReflectionHelper.setContextClassLoaderPA(contextClassLoader));
final List<ClassTypePair> typePairs = ReflectionHelper.getTypeArgumentAndClass(type); final ClassTypePair typePair = (typePairs.size() == 1) ? typePairs.get(0) : null; final Method valueOf = AccessController.doPrivileged(ReflectionHelper.getValueOfStringMethodPA(wrappedRaw)); if (valueOf != null) { try {
if (ignoreOnClassNotFound) { try { AccessController.doPrivileged(ReflectionHelper.classForNameWithExceptionPEA(nextName, loader)); } catch (final ClassNotFoundException ex) { handleClassNotFoundException(); } catch (final PrivilegedActionException pae) { final Throwable thrown = pae.getException(); if (thrown instanceof ClassNotFoundException) { handleClassNotFoundException();
/** * Get accessor method mappings (field -> getter/setter) for given class. * * @param clazz entity class to obtain property methods for. * @param isGetter flag determining whether to look for getters or setters. * @return non-null map of field-accessor mappings. */ public static Map<String, Method> getPropertyMethods(final Class<?> clazz, final boolean isGetter) { final Map<String, Method> methods = new HashMap<>(); for (final Method method : AccessController.doPrivileged(ReflectionHelper.getDeclaredMethodsPA(clazz))) { if ((isGetter && ReflectionHelper.isGetter(method)) || (!isGetter && ReflectionHelper.isSetter(method))) { methods.put(ReflectionHelper.getPropertyName(method), method); } } final Class<?> parent = clazz.getSuperclass(); // We're interested in fields/accessors in superclasses but not those from i.e. Object/Enum. if (parent != null && !parent.getPackage().getName().startsWith("java.lang")) { methods.putAll(getPropertyMethods(parent, isGetter)); } return methods; }
@Override protected Function<ContainerRequest, ?> createValueProvider(Parameter parameter) { if (parameter.isAnnotationPresent(Pac4JProfileManager.class)) { if (ProfileManager.class.isAssignableFrom(parameter.getRawType())) { return manager.get(); } throw new IllegalStateException("Cannot inject a Pac4J profile manager into a parameter of type " + parameter.getRawType().getName()); } if (parameter.isAnnotationPresent(Pac4JProfile.class)) { if (CommonProfile.class.isAssignableFrom(parameter.getRawType())) { return profile.get(); } if (Optional.class.isAssignableFrom(parameter.getRawType())) { List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(parameter.getRawType()); ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null; if (ctp == null || CommonProfile.class.isAssignableFrom(ctp.rawClass())) { return optProfile.get(); } } throw new IllegalStateException( "Cannot inject a Pac4J profile into a parameter of type " + parameter.getRawType().getName()); } return null; } }
targetGenericType = ReflectionHelper.getTypeArgument(genericType, 0); } else { targetGenericType = genericType; final Class<?> targetType = ReflectionHelper.erasure(targetGenericType); final Parameter parameter = Parameter.create( componentClass, componentClass,
boolean isHk2Factory = ReflectionHelper.isSubClassOf(genericType, Factory.class); targetGenericType = ReflectionHelper.getTypeArgument(genericType, 0); } else { targetGenericType = genericType; final Class<?> targetType = ReflectionHelper.erasure(targetGenericType); final Parameter parameter = Parameter.create( componentClass, componentClass,
ReflectionHelper.getClass(callback.getClass(), InvocationCallback.class); final Type[] typeArguments = ReflectionHelper.getParameterizedTypeArguments(pair); if (typeArguments == null || typeArguments.length == 0) { callbackParamType = Object.class; callbackParamType = typeArguments[0]; callbackParamClass = ReflectionHelper.erasure(callbackParamType); } else { callbackParamType = responseType.getType(); callbackParamClass = ReflectionHelper.erasure(responseType.getRawType());
@Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } }));
public DefaultConfigurationProvider() { this.inOsgi = ReflectionHelper.getOsgiRegistryInstance() != null; }
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) { if (Optional.class.equals(rawType)) { final List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(genericType); final ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null;