List of usage examples for java.lang.reflect Method isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:org.socialsignin.spring.data.dynamodb.repository.support.EnableScanAnnotationPermissions.java
public EnableScanAnnotationPermissions(Class<?> repositoryInterface) { // Check to see if global EnableScan is declared at interface level if (repositoryInterface.isAnnotationPresent(EnableScan.class)) { this.findAllUnpaginatedScanEnabled = true; this.countUnpaginatedScanEnabled = true; this.deleteAllUnpaginatedScanEnabled = true; this.findAllPaginatedScanEnabled = true; } else {/*from w ww. j a v a 2 s.c om*/ // Check declared methods for EnableScan annotation Method[] methods = ReflectionUtils.getAllDeclaredMethods(repositoryInterface); for (Method method : methods) { if (!method.isAnnotationPresent(EnableScan.class) || method.getParameterTypes().length > 0) { // Only consider methods which have the EnableScan // annotation and which accept no parameters continue; } if (method.getName().equals("findAll")) { findAllUnpaginatedScanEnabled = true; continue; } if (method.getName().equals("deleteAll")) { deleteAllUnpaginatedScanEnabled = true; continue; } if (method.getName().equals("count")) { countUnpaginatedScanEnabled = true; continue; } } for (Method method : methods) { if (!method.isAnnotationPresent(EnableScanCount.class) || method.getParameterTypes().length != 1) { // Only consider methods which have the EnableScanCount // annotation and which have a single pageable parameter continue; } if (method.getName().equals("findAll") && Pageable.class.isAssignableFrom(method.getParameterTypes()[0])) { findAllUnpaginatedScanCountEnabled = true; continue; } } for (Method method : methods) { if (!method.isAnnotationPresent(EnableScan.class) || method.getParameterTypes().length != 1) { // Only consider methods which have the EnableScan // annotation and which have a single pageable parameter continue; } if (method.getName().equals("findAll") && Pageable.class.isAssignableFrom(method.getParameterTypes()[0])) { findAllPaginatedScanEnabled = true; continue; } } } if (!findAllUnpaginatedScanCountEnabled && repositoryInterface.isAnnotationPresent(EnableScanCount.class)) { findAllUnpaginatedScanCountEnabled = true; } }
From source file:it.geosolutions.geobatch.annotations.GenericActionService.java
/** * The canCreateAction method lookup for a checkConfiguration annotated method and invoke it, the result of that method will be returned to the caller. * If no annotated method will be found the result returned will be forced to TRUE (but log a message under WARN level) * If an exception occurrs during the method invocation the result will be forced to FALSE * Please note that it executes (or try to executes) just the first method found. So annotate more than one method per class does not make sense. * @param actionConfig/*from w w w .j a v a2s . c o m*/ * @return */ public boolean checkConfiguration(ActionConfiguration actionConfig) { Boolean isConfigurationOk = true; Method el = null; for (Method method : actionType.getDeclaredMethods()) { if (method.isAnnotationPresent(CheckConfiguration.class)) { el = method; break; } } if (el != null) { el.setAccessible(true); StringBuilder sb = new StringBuilder(); sb.append("Found a @CheckConfiguration annotated method called: ").append(el.getName()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(sb.toString()); } try { isConfigurationOk = (Boolean) el.invoke( actionType.getDeclaredConstructor(actionConfig.getClass()).newInstance(actionConfig)); } catch (Exception e) { if (LOGGER.isWarnEnabled()) { StringBuilder sb2 = new StringBuilder(); sb2.append("An exception has occurred while invoking the CheckConfiguration").append( ". The result will be forced to false, please check and fix this abnormal situation. "); if (e.getMessage() != null) sb2.append(e.getMessage()); LOGGER.warn(sb2.toString(), e); } isConfigurationOk = false; } } return isConfigurationOk; }
From source file:org.squidy.designer.zoom.impl.PluginShape.java
/** * @param pluggable//from w ww.j av a 2 s . co m */ private void buildPlugin(Pluggable pluggable) { Class<? extends Pluggable> pluggableType = pluggable.getClass(); Plugin plugin = pluggableType.getAnnotation(Plugin.class); setTitle(plugin.name()); image.setImage(Toolkit.getDefaultToolkit().getImage(ImageUtils.getPluginIconURL(plugin))); PBounds bounds = getBoundsReference(); PBounds imageBounds = image.getBoundsReference(); image.offset(bounds.getCenterX() - imageBounds.getCenterX(), 10); PNode node = null; Method[] methods = pluggableType.getDeclaredMethods(); for (Method method : methods) { if (method.isAnnotationPresent(Plugin.Interface.class)) { node = ReflectionUtil.<PNode>callMethod(method, pluggable); } else if (method.isAnnotationPresent(Plugin.Logic.class)) { Plugin.Logic logic = method.getAnnotation(Plugin.Logic.class); for (Plugin.Event event : logic.events()) { Set<Method> eventMethods = EVENT_TO_METHOD.get(event); if (eventMethods == null) { eventMethods = new HashSet<Method>(); EVENT_TO_METHOD.put(event, eventMethods); } eventMethods.add(method); } } } cropScroll = new CropScroll(node, new Dimension(90, 78), 0.3); addChild(cropScroll); cropScroll.setOffset(getBoundsReference().getCenterX() - cropScroll.getBoundsReference().getCenterX(), 15); }
From source file:info.rmapproject.webapp.auth.AuthenticationInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HandlerMethod hm = (HandlerMethod) handler; Method method = hm.getMethod(); if (method.getDeclaringClass().isAnnotationPresent(Controller.class)) { if (method.isAnnotationPresent(LoginRequired.class)) { OAuthProviderAccount account = (OAuthProviderAccount) request.getSession() .getAttribute(ACCOUNT_SESSION_ATTRIBUTE); if (account == null) { response.sendRedirect(request.getContextPath() + USER_LOGIN_PATH); return false; }//from w w w. j a va 2 s. co m User user = (User) request.getSession().getAttribute(USER_SESSION_ATTRIBUTE); if ((!method.getName().equals(SIGNUPFORM_METHOD) && !method.getName().equals(ADDUSER_METHOD)) && (user == null || user.getUserId() == 0)) { //new user, get them signed up! response.sendRedirect(request.getContextPath() + USER_SIGNUP_PATH); return false; } } } return true; }
From source file:org.blocks4j.reconf.client.proxy.ConfigurationRepositoryFactory.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { boolean updateAnnotationPresent = method.isAnnotationPresent(UpdateConfigurationRepository.class); boolean configurationAnnotationPresent = method.isAnnotationPresent(ConfigurationItem.class); if (!configurationAnnotationPresent && !updateAnnotationPresent) { return method.invoke(this, args); }/*from w w w . java2 s . co m*/ if (updateAnnotationPresent) { updater.syncNow(method.getAnnotation(UpdateConfigurationRepository.class).onErrorThrow()); } Object configValue = null; if (configurationAnnotationPresent) { configValue = updater.getValueOf(method); } return configValue; }
From source file:nl.kpmg.lcm.server.documentation.MethodDocumentator.java
private String getMethodType(Method method) { String type = "unkown"; if (method.isAnnotationPresent(GET.class)) { type = "GET"; } else if (method.isAnnotationPresent(POST.class)) { type = "POST"; } else if (method.isAnnotationPresent(PUT.class)) { type = "PUT"; } else if (method.isAnnotationPresent(DELETE.class)) { type = "DELETE"; }/* w ww . j a va 2 s. com*/ return type; }
From source file:org.sprintapi.hyperdata.gson.HyperDataAdapterFactory.java
@SuppressWarnings("unchecked") @Override/*from w ww . ja v a 2 s . c o m*/ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { Class<? super T> raw = type.getRawType(); if (!Object.class.isAssignableFrom(raw) || HyperMap.class.isAssignableFrom(raw)) { return null; // it's a primitive or HyperMap } if (!raw.isAnnotationPresent(HyperdataContainer.class)) { return null; // it's not hyperdata } MetadataAccess metadataAccess = new MetadataAccess(); Set<String> profiles = new LinkedHashSet<String>(); Class<?> c = raw; while (c != null) { if (c.getClass().equals(Object.class)) { break; } HyperdataContainer hdc = c.getAnnotation(HyperdataContainer.class); if ((hdc != null) && (hdc.profile().length > 0)) { profiles.addAll(Arrays.asList(hdc.profile())); } Class<?>[] interfaces = c.getInterfaces(); if (interfaces != null) { for (Class<?> i : interfaces) { hdc = i.getAnnotation(HyperdataContainer.class); if ((hdc != null) && (hdc.profile().length > 0)) { profiles.addAll(Arrays.asList(hdc.profile())); } } } c = c.getSuperclass(); } metadataAccess.profile = profiles.toArray(new String[0]); for (Method method : raw.getMethods()) { if (method.isAnnotationPresent(MetadataContainer.class)) { if (method.getName().startsWith("get")) { metadataAccess.getter = method; metadataAccess.fieldName = method.getName().substring(3); } else if (method.getName().startsWith("set")) { metadataAccess.setter = method; metadataAccess.fieldName = method.getName().substring(3); } } } if (metadataAccess.fieldName != null) { if (metadataAccess.getter == null) { for (Method method : raw.getMethods()) { if (method.getName().equals("get" + metadataAccess.fieldName)) { metadataAccess.getter = method; break; } } } else if (metadataAccess.setter == null) { for (Method method : raw.getMethods()) { if (method.getName().equals("set" + metadataAccess.fieldName)) { metadataAccess.setter = method; break; } } } metadataAccess.fieldName = WordUtils.uncapitalize(metadataAccess.fieldName); } ObjectConstructor<T> constructor = constructorConstructor.get(type); return (TypeAdapter<T>) new HyperDataTypeAdapter(metadataAccess, constructorConstructor, (ObjectConstructor<Object>) constructor, getBoundFields(gson, type, raw), gson, this); }
From source file:com.github.lightdocs.ModelBuilder.java
/** * @param cls/*from w ww . j ava 2 s . com*/ * required * @return true if there is any Path or GET/POST/etc annotation. */ private boolean hasPathAnnotation(Class<?> cls) { if (cls.isAnnotationPresent(Path.class)) { return true; } else { for (Method m : cls.getMethods()) { if (m.isAnnotationPresent(Path.class)) { return true; } } return false; } }
From source file:cn.edu.zju.bigdata.controller.JerseyController.java
@GET @Path("/_list") @Produces({ "application/json" }) //@ReturnType("java.lang.List<String>") public Response listAPI() { List<String> apiList = new ArrayList<String>(); Reflections reflections = new Reflections("cn.edu.zju.bigdata.controller"); Set<Class<?>> allClasses = reflections.getTypesAnnotatedWith(Path.class); for (Class<?> controller : allClasses) { String apiPath = controller.getAnnotation(Path.class).value(); for (Method method : controller.getMethods()) { // Filter the API with the @RequestMapping Annotation String apiMethod = method.isAnnotationPresent(GET.class) ? "GET" : method.isAnnotationPresent(POST.class) ? "POST" : method.isAnnotationPresent(PUT.class) ? "PUT" : method.isAnnotationPresent(DELETE.class) ? "DELETE" : method.isAnnotationPresent(HEAD.class) ? "HEAD" : null; if (apiMethod == null) continue; if (method.isAnnotationPresent(Path.class)) apiPath += method.getAnnotation(Path.class).value(); // Filter out /_list itself if (apiPath.equals("/_list")) continue; apiList.add(apiMethod + " " + apiPath); }/*www . j a v a 2 s . c om*/ } return Response.ok().entity(apiList).build(); }
From source file:com.zxy.commons.mybatis.SelectDataSourceAspect.java
/** * ?key/*from w ww . j a v a 2 s . c om*/ * * @param point JoinPoint */ @After("aspect()") public void after(JoinPoint point) { Object target = point.getTarget(); String method = point.getSignature().getName(); //logger.info("target={}, method={}", target.toString(), method); // Class<?>[] classz = target.getClass().getInterfaces(); Class<?>[] parameterTypes = ((MethodSignature) point.getSignature()).getMethod().getParameterTypes(); try { Method mt = target.getClass().getMethod(method, parameterTypes); //logger.debug("m.getName={}", m.getName()); if (mt != null && mt.isAnnotationPresent(SelectDataSource.class)) { HandleDataSource.clearCustomerType(); } //logger.info("method.name={}, datasource.key={}", m.getName(), HandleDataSource.getDataSource()); } catch (Exception e) { logger.error("after() error.", e); HandleDataSource.clearCustomerType(); } }