List of usage examples for java.lang.reflect Method getAnnotations
public Annotation[] getAnnotations()
From source file:org.qifu.base.interceptor.ControllerAuthorityCheckInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String url = request.getServletPath(); Subject subject = SecurityUtils.getSubject(); if (subject.hasRole(Constants.SUPER_ROLE_ALL) || subject.hasRole(Constants.SUPER_ROLE_ADMIN)) { this.log((String) subject.getPrincipal(), Constants.getSystem(), url, true); return true; }// w w w . j a v a 2s .c om Method method = ((HandlerMethod) handler).getMethod(); Annotation[] actionMethodAnnotations = method.getAnnotations(); if (this.isControllerAuthority(actionMethodAnnotations, subject)) { this.log((String) subject.getPrincipal(), Constants.getSystem(), url, true); return true; } if (subject.isPermitted(url) || subject.isPermitted("/" + url)) { this.log((String) subject.getPrincipal(), Constants.getSystem(), url, true); return true; } logger.warn("[decline] user=" + subject.getPrincipal() + " url=" + url); String isQifuPageChange = request.getParameter(Constants.QIFU_PAGE_IN_TAB_IFRAME); if (YesNo.YES.equals(isQifuPageChange)) { // dojox.layout.ContentPane X-Requested-With XMLHttpRequest this.log((String) subject.getPrincipal(), Constants.getSystem(), url, false); response.sendRedirect(NO_AUTH_PAGE); return false; } String header = request.getHeader("X-Requested-With"); if ("XMLHttpRequest".equalsIgnoreCase(header)) { response.getWriter().print(Constants.NO_AUTHZ_JSON_DATA); response.getWriter().flush(); response.getWriter().close(); this.log((String) subject.getPrincipal(), Constants.getSystem(), url, false); return false; } this.log((String) subject.getPrincipal(), Constants.getSystem(), url, false); response.sendRedirect(NO_AUTH_PAGE); return false; }
From source file:com.nominanuda.hyperapi.HyperApiWsSkelton.java
protected AnnotatedType getAnnotatedReturnType(Method m) { AnnotatedType at = new AnnotatedType(m.getReturnType(), m.getAnnotations()); return at;//from ww w . jav a 2 s.co m }
From source file:org.specrunner.parameters.core.AccessImpl.java
/** * Get annotation for methods.//from w w w .j a v a 2 s . com * * @param method * The write method. * @return The annotations. */ protected Annotation[] getMethodAnnotations(Method method) { Annotation[] annotations = method.getAnnotations(); if (UtilConverter.getConverter(annotations) == null) { annotations = method.getParameterAnnotations()[0]; } return annotations; }
From source file:com.googlecode.jsonschema2pojo.integration.config.CustomAnnotatorIT.java
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void defaultCustomAnnotatorIsNoop() throws ClassNotFoundException, SecurityException, NoSuchMethodException { ClassLoader resultsClassLoader = generateAndCompile("/schema/properties/primitiveProperties.json", "com.example", config("annotationStyle", "none")); // turn off core annotations Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties"); Method getter = generatedType.getMethod("getA"); assertThat(generatedType.getAnnotations().length, is(0)); assertThat(getter.getAnnotations().length, is(0)); }
From source file:org.lunarray.model.descriptor.builder.annotation.resolver.property.accessor.AccessorPropertyResolver.java
/** * Process the property.//from w w w . j a v a 2 s. c o m * * @param entityType * The entity type. * @param methods * The methods. * @param fields * The fields. * @param method * The accessor method. * @param <P> * The property type. * @return The property. */ private <P> DescribedProperty<P> processProperty(final DescribedEntity<?> entityType, final List<Method> methods, final List<Field> fields, final Method method) { final PropertyBuilder<P> builder = AbstractProperty.createBuilder(); for (final Annotation a : method.getAnnotations()) { builder.addAnnotation(a); } final PropertyMatcher<Method> resolver = this.getAccessorMatcherResolver(); @SuppressWarnings("unchecked") // About as sure as we can get. final Class<P> type = (Class<P>) resolver.extractType(method); builder.accessor(method).genericType(resolver.extractGenericType(method)); final String name = resolver.extractName(method); builder.name(name).type(type).entityType(entityType); // Resolve field. for (final Field field : fields) { if (this.getFieldMatcherResolver().matches(field, name, type)) { for (final Annotation a : field.getAnnotations()) { builder.addAnnotation(a); } builder.raw(field); } } // Resolve mutator. Method mutator = null; for (final Method mutatorCandidate : methods) { if (this.getMutatorMatcherResolver().matches(mutatorCandidate, name, type)) { for (final Annotation a : mutatorCandidate.getAnnotations()) { builder.addAnnotation(a); } mutator = mutatorCandidate; } } if (CheckUtil.isNull(mutator)) { builder.addModifier(Modifier.FINAL); } else { builder.mutator(mutator); } return builder.buildDescribed(); }
From source file:com.ettrema.httpclient.calsync.parse.BeanPropertyMapper.java
/** * Find a property with the given annotation and return its value * * @param bean/*w w w. java 2 s . c om*/ * @param annotationClass * @return */ public <T> T getProperty(Object bean, Class annotationClass, Class<T> valueClass) { PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean); for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null) { Method read = pd.getReadMethod(); Annotation[] annotations = read.getAnnotations(); for (Annotation anno : annotations) { if (anno.annotationType() == annotationClass) { return propertyAccessor.get(bean, read, valueClass); } } } } return null; }
From source file:org.jdal.ui.bind.ControlInitializerSupport.java
/** * Get field or method annotations/*from ww w. j a v a2 s. c o m*/ * @param property * @param clazz * @return */ protected Annotation[] getAnnotations(String property, Class<?> clazz) { Field field = ReflectionUtils.findField(clazz, property); Annotation[] fa = new Annotation[] {}; if (field != null) { fa = field.getAnnotations(); } Method method = BeanUtils.getPropertyDescriptor(clazz, property).getReadMethod(); if (method != null) { Annotation[] ma = method.getAnnotations(); Annotation[] annotations = (Annotation[]) ArrayUtils.addAll(fa, ma); return annotations; } return fa; }
From source file:com.ettrema.httpclient.calsync.parse.BeanPropertyMapper.java
public void toBean(Object bean, String icalText) { VCardEngine cardEngine = new VCardEngine(); VCard vcard;/*from ww w.j av a 2 s.c o m*/ try { vcard = cardEngine.parse(icalText); } catch (IOException ex) { throw new RuntimeException(ex); } PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean); for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null) { Method read = pd.getReadMethod(); Annotation[] annotations = read.getAnnotations(); for (Annotation anno : annotations) { Mapper mapper = mapOfMappers.get(anno.annotationType()); if (mapper != null) { mapper.mapToBean(vcard, bean, pd); } } } } }
From source file:com.ettrema.httpclient.calsync.parse.BeanPropertyMapper.java
public String toVCard(Object bean) { VCard card = new VCardImpl(); card.setBegin(new BeginType()); PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean); for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null) { Method read = pd.getReadMethod(); Annotation[] annotations = read.getAnnotations(); for (Annotation anno : annotations) { Mapper mapper = mapOfMappers.get(anno.annotationType()); if (mapper != null) { mapper.mapToCard(card, bean, pd); }//from w ww. j av a 2s .c o m } } } FormattedNameFeature fname = card.getFormattedName(); if (fname == null) { NameFeature nameFeature = card.getName(); if (nameFeature != null) { String formattedName = nameFeature.getGivenName() + " " + nameFeature.getFamilyName(); fname = new FormattedNameType(formattedName); card.setFormattedName(fname); } } card.setEnd(new EndType()); VCardWriter writer = new VCardWriter(); writer.setVCard(card); String text = writer.buildVCardString(); return text; }
From source file:org.jsonschema2pojo.integration.config.CustomAnnotatorIT.java
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void defaultCustomAnnotatorIsNoop() throws ClassNotFoundException, SecurityException, NoSuchMethodException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile( "/schema/properties/primitiveProperties.json", "com.example", config("annotationStyle", "none")); // turn off core annotations Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties"); Method getter = generatedType.getMethod("getA"); assertThat(generatedType.getAnnotations().length, is(0)); assertThat(getter.getAnnotations().length, is(0)); }