public static boolean isAnnotationPresent(final AnnotatedElement element, final Class<? extends Annotation> annotationClass) { return getAnnotation(element, annotationClass) != null; } }
public static <A extends Annotation> A getAnnotation(final Enum<?> enumConstant, final Class<A> annotationClass) { try { final Field field = enumConstant.getClass().getDeclaredField(enumConstant.name()); return getAnnotation(field, annotationClass); } catch (final Exception e) { throw new IllegalStateException(e); } }
@Override public <A extends Annotation> A getAnnotation(final Class<A> annotationClass) { return ReflectionUtils.getAnnotation(getMethod(), annotationClass); }
@Override public <A extends Annotation> A getAnnotation(final Class<A> annotationClass) { return ReflectionUtils.getAnnotation(getField(), annotationClass); }
public final <A extends Annotation> A getAnnotation(final Class<A> annotationClass) { return ReflectionUtils.getAnnotation(getMethod(), annotationClass); }
@Override public <A extends Annotation> A getAnnotation(final Class<A> annotationClass) { return ReflectionUtils.getAnnotation(getComponentClass(), annotationClass); }
MetricDescriptorImpl(final Class<? extends AnalyzerResult> resultClass, final Method method) { _resultClass = resultClass; _method = method; _method.setAccessible(true); final String metricName = ReflectionUtils.getAnnotation(_method, Metric.class).value(); if (StringUtils.isNullOrEmpty(metricName)) { throw new IllegalStateException("Metric method has no name: " + _method); } _name = metricName.trim(); _methodName = _method.getName(); }
try { final Method overriddenMethod = superClass.getMethod(methodName, methodParameterTypes); return getAnnotation(overriddenMethod, annotationClass); } catch (final NoSuchMethodException e) { logger.debug("Failed to get overridden method '{}' from {}", methodName, superClass); try { final Method overriddenMethod = interfaceClass.getMethod(methodName, methodParameterTypes); return getAnnotation(overriddenMethod, annotationClass); } catch (final NoSuchMethodException e) { logger.debug("Failed to get overridden method '{}' from {}", methodName, interfaceClass);
public String getDescription() { final Description annotation = ReflectionUtils.getAnnotation(_outcome, Description.class); if (annotation == null) { return ""; } final String description = annotation.value(); return DocumentationUtils.createHtmlParagraphs(description); } }
@Override public Enum<C> getOutcomeCategoryByName(final String categoryName) { if (categoryName == null) { return null; } final EnumSet<C> categories = getOutcomeCategories(); for (final Enum<C> c : categories) { if (c.name().equals(categoryName)) { return c; } } for (final Enum<C> c : categories) { // check aliases final Alias aliasAnnotation = ReflectionUtils.getAnnotation(c, Alias.class); if (aliasAnnotation != null) { final String[] aliases = aliasAnnotation.value(); for (final String alias : aliases) { if (categoryName.equals(alias)) { return c; } } } } return null; }
@Override public String getDisplayName() { // this is the 'descriptor' name, e.g. will be used for CSS styling final Description desc = ReflectionUtils.getAnnotation(_componentClass, Description.class); if (desc == null || StringUtils.isNullOrEmpty(desc.value())) { return _componentClass.getSimpleName(); } return desc.value(); }
@Override public String getDisplayName() { // this is the 'descriptor' name, e.g. will be used for CSS styling final Description desc = ReflectionUtils.getAnnotation(_componentClass, Description.class); if (desc == null || StringUtils.isNullOrEmpty(desc.value())) { return _componentClass.getSimpleName(); } return desc.value(); }
public boolean isRemoveableUponOptimization() { final Optimizeable optimizeable = ReflectionUtils.getAnnotation(_filterJob.getDescriptor().getComponentClass(), Optimizeable.class); if (optimizeable == null) { return true; } return optimizeable.removeableUponOptimization(); } }
@Override public Class<? extends AnalyzerResultReducer<?>> getResultReducerClass() { final Distributed distributedResult = ReflectionUtils.getAnnotation(getResultClass(), Distributed.class); if (distributedResult != null) { if (!distributedResult.value()) { return null; } final Class<? extends AnalyzerResultReducer<?>> reducer = distributedResult.reducer(); if (reducer != null && reducer != NoAnalyzerResultReducer.class) { return reducer; } } return null; }
protected AnnotationBasedRendererBeanDescriptor(final Class<R> rendererClass) throws DescriptorException { super(rendererClass, true); final RendererBean rendererBeanAnnotation = ReflectionUtils.getAnnotation(rendererClass, RendererBean.class); if (rendererBeanAnnotation == null) { throw new DescriptorException(rendererClass + " doesn't implement the RendererBean annotation"); } _renderingFormat = rendererBeanAnnotation.value(); if (_renderingFormat == null || _renderingFormat.isInterface() || Modifier .isAbstract(_renderingFormat.getModifiers())) { throw new DescriptorException("Rendering format (" + _renderingFormat + ") is not a non-abstract class"); } _formatOutputType = ReflectionUtils.getTypeParameter(_renderingFormat, RenderingFormat.class, 0); logger.debug("Found format output type: {}", _formatOutputType); if (_formatOutputType == null) { throw new DescriptorException("Could not determine output type of rendering format: " + _renderingFormat); } @SuppressWarnings("unchecked") final Class<? extends Renderable> rendererInputType = (Class<? extends Renderable>) ReflectionUtils.getTypeParameter(rendererClass, Renderer.class, 0); _rendererInputType = rendererInputType; logger.debug("Found renderer input type: {}", _rendererInputType); _rendererOutputType = ReflectionUtils.getTypeParameter(rendererClass, Renderer.class, 1); logger.debug("Found renderer output type: {}", _rendererOutputType); if (_rendererOutputType == null) { throw new DescriptorException("Could not determine output type of renderer: " + rendererClass); } if (!ReflectionUtils.is(_rendererOutputType, _formatOutputType)) { throw new DescriptorException("The renderer output type (" + _rendererOutputType + ") is not a valid instance or sub-class of format output type (" + _formatOutputType + ")"); } }
final Description description = ReflectionUtils.getAnnotation(result.getClass(), Description.class); final String descriptionText; if (description != null) {
@Override protected void onAfterRequestDeserialized(RPCRequest request) { final Principal principal = getThreadLocalRequest().getUserPrincipal(); if (principal == null || StringUtils.isNullOrEmpty(principal.getName())) { throw new DCSecurityException("No user principal - log in to use the system"); } if (!(principal instanceof Authentication)) { throw new IllegalStateException("Principal is not an instance of Authentication: " + principal); } final Authentication authentication = (Authentication) principal; final UserBean user = new UserBean(); user.updateUser(authentication, getTenantResolver()); final Method method = request.getMethod(); final RolesAllowed rolesAllowedAnnotation = ReflectionUtils.getAnnotation(method, RolesAllowed.class); if (rolesAllowedAnnotation != null) { String[] rolesAllowed = rolesAllowedAnnotation.value(); checkRoles(user, rolesAllowed, method); } final Class<?>[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { final Class<?> cls = parameterTypes[i]; if (cls == TenantIdentifier.class) { TenantIdentifier tenantIdentifier = (TenantIdentifier) request.getParameters()[i]; checkTenant(user, tenantIdentifier); break; } } }
final Convertable convertable = ReflectionUtils.getAnnotation(instance.getClass(), Convertable.class); if (convertable != null) { try {
final Convertable convertable = ReflectionUtils.getAnnotation(type, Convertable.class); if (convertable != null) { try {
final Description description = ReflectionUtils.getAnnotation(result.getClass(), Description.class); final String descriptionText; if (description != null) {