List of usage examples for java.lang Class getDeclaredAnnotation
@Override @SuppressWarnings("unchecked") public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass)
From source file:org.springframework.core.KotlinDetector.java
/** * Determine whether the given {@code Class} is a Kotlin type * (with Kotlin metadata present on it). *///from w w w. j a va2 s.c o m public static boolean isKotlinType(Class<?> clazz) { return (kotlinMetadata != null && clazz.getDeclaredAnnotation(kotlinMetadata) != null); }
From source file:org.apache.tajo.engine.function.hiveudf.HiveFunctionLoader.java
static void buildFunctionsFromUDF(Set<Class<? extends UDF>> classes, List<FunctionDesc> list, String jarurl) { for (Class<? extends UDF> clazz : classes) { String[] names;//from w w w . ja v a 2 s . co m String value = null, extended = null; Description desc = clazz.getAnnotation(Description.class); // Check @Description annotation (if exists) if (desc != null) { names = desc.name().split(","); for (int i = 0; i < names.length; i++) { names[i] = names[i].trim(); } value = desc.value(); extended = desc.extended(); } else { names = new String[] { clazz.getName().replace('.', '_') }; } // actual function descriptor building FunctionDescBuilder builder = new FunctionDescBuilder(); UDFType type = clazz.getDeclaredAnnotation(UDFType.class); if (type != null) { builder.setDeterministic(type.deterministic()); } builder.setFunctionType(CatalogProtos.FunctionType.UDF); if (value != null) { builder.setDescription(value); } if (extended != null) { builder.setExample(extended); } UDFInvocationDesc udfInvocation = new UDFInvocationDesc(CatalogProtos.UDFtype.HIVE, clazz.getName(), jarurl, true); // verify 'evaluate' method and extract return type and parameter types for (Method method : clazz.getMethods()) { if (method.getName().equals("evaluate")) { registerMethod(method, names, udfInvocation, builder, list); } } } }
From source file:org.dspace.app.rest.utils.Utils.java
/** * // w w w .j av a 2s. c om * @param rel * @param domainClass * @return the LinkRest annotation corresponding to the specified rel in the * domainClass. Null if not found */ public LinkRest getLinkRest(String rel, Class<RestModel> domainClass) { LinkRest linkRest = null; LinksRest linksAnnotation = domainClass.getDeclaredAnnotation(LinksRest.class); if (linksAnnotation != null) { LinkRest[] links = linksAnnotation.links(); for (LinkRest l : links) { if (StringUtils.equals(rel, l.name())) { linkRest = l; break; } } } return linkRest; }
From source file:com.zuoxiaolong.blog.common.web.CommonHandlerExceptionResolver.java
private void logException(Object handler, Exception exception, Map<String, String[]> parameterMap) { if (handler != null && HandlerMethod.class.isAssignableFrom(handler.getClass())) { try {//from w ww. j a v a 2 s . c o m HandlerMethod handlerMethod = (HandlerMethod) handler; Class<?> beanType = handlerMethod.getBeanType(); String methodName = handlerMethod.getMethod().getName(); RequestMapping controllerRequestMapping = beanType.getDeclaredAnnotation(RequestMapping.class); String classMapping = ""; if (controllerRequestMapping != null) { classMapping = controllerRequestMapping.value()[0]; } RequestMapping methodRequestMapping = handlerMethod.getMethodAnnotation(RequestMapping.class); String methodMapping = ""; if (methodRequestMapping != null) { methodMapping = methodRequestMapping.value()[0]; } if (!methodMapping.startsWith("/")) { methodMapping = "/" + methodMapping; } Logger logger = LoggerFactory.getLogger(beanType); logger.error("RequestMapping is:"); logger.error(classMapping + methodMapping); logger.error("HandlerMethod is:"); logger.error(beanType.getSimpleName() + "." + methodName + "()"); logger.error("ParameterMap is:"); logger.error(JsonUtils.toJson(parameterMap), exception); } catch (Exception e) { LOGGER.error(handler + " execute failed.", exception); } } else { LOGGER.error(handler + " execute failed.", exception); } }
From source file:io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterAspect.java
private RateLimiter getRateLimiterAnnotation(ProceedingJoinPoint proceedingJoinPoint) { RateLimiter rateLimiter = null;//from w ww . ja v a 2 s.c o m Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); if (targetClass.isAnnotationPresent(RateLimiter.class)) { rateLimiter = targetClass.getAnnotation(RateLimiter.class); if (rateLimiter == null) { rateLimiter = targetClass.getDeclaredAnnotation(RateLimiter.class); } if (rateLimiter == null) { logger.debug("TargetClass has no declared annotation 'RateLimiter'"); } } return rateLimiter; }
From source file:com.github.tddts.jet.view.fx.spring.DialogProvider.java
private <T extends Dialog<?>> T createDialog(Class<T> type) { if (!type.isAnnotationPresent(FxDialog.class)) { throw new DialogException("Dialog class should have a @FxDialog annotation!"); }/* w w w. jav a 2 s . c om*/ FxDialog dialogAnnotation = type.getDeclaredAnnotation(FxDialog.class); T dialog = getDialog(type, dialogAnnotation); fxBeanWirer.initBean(dialog); dialogCache.put(type, dialog); return dialog; }
From source file:io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerAspect.java
private CircuitBreaker getBackendMonitoredAnnotation(ProceedingJoinPoint proceedingJoinPoint) { if (logger.isDebugEnabled()) { logger.debug("circuitBreaker parameter is null"); }/* w w w . j a v a 2 s . c o m*/ CircuitBreaker circuitBreaker = null; Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); if (targetClass.isAnnotationPresent(CircuitBreaker.class)) { circuitBreaker = targetClass.getAnnotation(CircuitBreaker.class); if (circuitBreaker == null) { if (logger.isDebugEnabled()) { logger.debug("TargetClass has no annotation 'CircuitBreaker'"); } circuitBreaker = targetClass.getDeclaredAnnotation(CircuitBreaker.class); if (circuitBreaker == null) { if (logger.isDebugEnabled()) { logger.debug("TargetClass has no declared annotation 'CircuitBreaker'"); } } } } return circuitBreaker; }
From source file:com.m4rc310.cb.builders.ComponentBuilder.java
private Object getNewInstanceObjectAnnotated(String ref, Object... args) { Object ret = null;//from w w w. j ava 2 s . c o m try { for (Class in : ClassScan.findAll().annotatedWith(Adialog.class).recursively() .in(conf.get("path_gui").toString(), "com.m4rc310.gui")) { Adialog ad = (Adialog) in.getDeclaredAnnotation(Adialog.class); if (ad.ref().equals(ref)) { if (ret != null) { throw new Exception(String.format("H mais de uma classe refernciada como [%s]!", ref)); } Class[] types = new Class[args.length]; Constructor constructor = null; for (int i = 0; i < args.length; i++) { types[i] = args[i].getClass(); Class type = args[i].getClass(); for (Class ai : type.getInterfaces()) { try { constructor = in.getDeclaredConstructor(ai); break; } catch (NoSuchMethodException | SecurityException e) { infoError(e); } } } constructor = constructor == null ? in.getDeclaredConstructor(types) : constructor; // Constructor constructor = in.getDeclaredConstructor(types); constructor.setAccessible(true); ret = constructor.newInstance(args); } } return ret; } catch (Exception e) { infoError(e); throw new UnsupportedOperationException(e); } }
From source file:com.m4rc310.cb.builders.ComponentBuilder.java
public void _showDialog(Object objAnnotated, String ref, Object relative, Object... args) { if (objAnnotated != null) { objectAnnotated = objAnnotated;//from w w w . ja v a 2 s .co m // Class[] classArgs = new Class[args.length]; // MethodUtils.method(objectAnnotated, "setValuesToSearch", classArgs).invoke(args[0]); } else { objectAnnotated = getNewInstanceObjectAnnotated(ref, args); } Class<? extends Object> objectAnnotatedClass = objectAnnotated.getClass(); dialog = new JDialogDefalt(); if (objectAnnotatedClass.isAnnotationPresent(Amethod.class)) { Amethod am = objectAnnotatedClass.getDeclaredAnnotation(Amethod.class); final String methodOnError = am.methodOnError(); LogServer.getInstance().debug(null, "Adicionando Listener de erro: {0}", methodOnError); if (!methodOnError.isEmpty()) { dialog.addPropertyChangeListener("onError", (PropertyChangeEvent evt) -> { getTargetsForMethodName(methodOnError).stream().forEach((tar) -> { MethodUtils.declaredMethod(tar, methodOnError, String.class, String.class) .invoke(evt.getPropertyName(), evt.getNewValue()); }); }); } } Adialog ad = objectAnnotatedClass.getDeclaredAnnotation(Adialog.class); String title = getString(ad.title(), ref); if (ad.debug()) { title = getString("title.title.mode.debug", title); } dialog.setTitle(title); dialog.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { MethodUtils.method(objectAnnotated, "setComponentsBuilder", ComponentBuilder.class) .invoke(ComponentBuilder.this); MethodUtils.method(objectAnnotated, "setDialog", Dialog.class).invoke(dialog); MethodUtils.method(objectAnnotated, "setGui", GuiUtils.class).invoke(gui); } }); dialog.setLayout(new MigLayout(ad.layoutDialog())); dialog.abiliteCloseOnESC(); putContainer(objectAnnotated.hashCode(), dialog); addTargets(objectAnnotated); loadAllFields(objectAnnotated, objectAnnotated.getClass()); buildAllComponents(); printDialog(); dialog.setFontSize(ad.fontSize()); dialog.setModal(ad.modal()); dialog.setResizable(ad.resizable()); dialog.pack(); dialog.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); dialog.setLocationRelativeTo((Component) relative); dialog.showWindow(); }
From source file:io.swagger.v3.core.util.AnnotationsUtils.java
public static io.swagger.v3.oas.annotations.media.Schema getSchemaDeclaredAnnotation(Class<?> cls) { if (cls == null) { return null; }/*ww w .j a v a 2 s . c om*/ io.swagger.v3.oas.annotations.media.Schema mp = null; io.swagger.v3.oas.annotations.media.ArraySchema as = cls .getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.ArraySchema.class); if (as != null) { mp = as.schema(); } else { mp = cls.getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.Schema.class); } return mp; }