List of usage examples for java.lang.reflect Method isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:org.wso2.carbon.appmgt.mdm.wso2mdm.MDMOperationsImpl.java
/** * @param action action of the operation. Eg. install, uninstall, update * @param app application object// www . j a v a 2 s . c o m * @param tenantId tenantId * @param type type of the resource. Eg: role, user, device * @param params ids of the resources which belong to type */ public void performAction(User currentUser, String action, App app, int tenantId, String type, String[] params, HashMap<String, String> configProperties) { String tokenApiURL = configProperties.get(Constants.PROPERTY_TOKEN_API_URL); String clientKey = configProperties.get(Constants.PROPERTY_CLIENT_KEY); String clientSecret = configProperties.get(Constants.PROPERTY_CLIENT_SECRET); String authUser = configProperties.get(Constants.PROPERTY_AUTH_USER); String authPass = configProperties.get(Constants.PROPERTY_AUTH_PASS); JSONObject requestObj = new JSONObject(); if ("user".equals(type)) { JSONArray resources = new JSONArray(); for (String param : params) { resources.add(param); } requestObj.put("userList", resources); } else if ("role".equals(type)) { JSONArray resources = new JSONArray(); for (String param : params) { resources.add(param); } requestObj.put("userList", resources); } else { JSONArray resources = new JSONArray(); for (String param : params) { JSONObject obj = new JSONObject(); String[] paramDevices = param.split("---"); obj.put("id", paramDevices[0]); obj.put("type", paramDevices[1]); resources.add(obj); } requestObj.put("deviceIdentifiers", resources); } JSONObject requestApp = new JSONObject(); Method[] methods = app.getClass().getMethods(); for (Method method : methods) { if (method.isAnnotationPresent(Property.class)) { try { Object value = method.invoke(app); if (value != null) { requestApp.put(method.getAnnotation(Property.class).name(), value); } } catch (IllegalAccessException e) { String errorMessage = "Illegal Action"; if (log.isDebugEnabled()) { log.error(errorMessage, e); } else { log.error(errorMessage); } } catch (InvocationTargetException e) { String errorMessage = "Target invocation failed"; if (log.isDebugEnabled()) { log.error(errorMessage, e); } else { log.error(errorMessage); } } } } if ("ios".equals(requestApp.get("platform"))) { JSONObject iosProperties = new JSONObject(); if ("enterprise".equals(requestApp.get("type"))) { iosProperties.put("isRemoveApp", true); iosProperties.put("isPreventBackup", true); } else if ("public".equals(requestApp.get("type"))) { iosProperties.put("iTunesId", Integer.parseInt(requestApp.get("identifier").toString())); iosProperties.put("isRemoveApp", true); iosProperties.put("isPreventBackup", true); } else if ("webapp".equals(requestApp.get("type"))) { iosProperties.put("label", requestApp.get("name")); iosProperties.put("isRemoveApp", true); } requestApp.put("properties", iosProperties); } else if ("webapp".equals(requestApp.get("platform"))) { JSONObject webappProperties = new JSONObject(); webappProperties.put("label", requestApp.get("name")); webappProperties.put("isRemoveApp", true); requestApp.put("properties", webappProperties); } //make type to uppercase requestApp.put("type", requestApp.get("type").toString().toUpperCase()); requestObj.put("application", requestApp); HttpClient httpClient = new HttpClient(); StringRequestEntity requestEntity = null; if (log.isDebugEnabled()) log.debug("Request Payload for MDM: " + requestObj.toJSONString()); try { requestEntity = new StringRequestEntity(requestObj.toJSONString(), "application/json", "UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e); } String requestURL = configProperties.get(Constants.PROPERTY_SERVER_URL); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); String actionURL = null; if ("install".equals("install")) { actionURL = String.format(Constants.API_INSTALL_APP, tenantDomain); } else { actionURL = String.format(Constants.API_UNINSTALL_APP, tenantDomain); } PostMethod postMethod = new PostMethod(requestURL + actionURL); postMethod.setRequestEntity(requestEntity); if (executeMethod(tokenApiURL, clientKey, clientSecret, authUser, authPass, httpClient, postMethod)) { if (log.isDebugEnabled()) log.debug(action + " operation performed successfully on " + type + " " + params.toString()); } else { if (log.isDebugEnabled()) log.debug(action + " operation unsuccessful"); } }
From source file:org.josso.selfservices.password.PasswordManagementServiceImpl.java
public ProcessResponse handleRequest(ProcessRequest request) throws PasswordManagementException { String processId = request.getProcessId(); String actionName = null;//w w w .jav a2 s .co m if (log.isDebugEnabled()) log.debug("Handling request for process [" + processId + "]"); try { PasswordManagementProcess p = runningProcesses.get(processId); if (p == null) throw new PasswordManagementException("No such process " + processId); String nextStep = p.getState().getNextStep(); if (log.isDebugEnabled()) log.debug("Handling request for process [" + processId + "]"); Method[] methods = p.getClass().getMethods(); for (Method method : methods) { if (log.isDebugEnabled()) log.debug("Processing method : " + method.getName()); if (!method.isAnnotationPresent(Action.class)) continue; Action action = method.getAnnotation(Action.class); if (log.isDebugEnabled()) log.debug("Processing method annotation : " + action); for (String actionStep : action.fromSteps()) { if (log.isDebugEnabled()) log.debug("Processing annotation step : " + actionStep); if (actionStep.equals(nextStep)) { actionName = method.getName(); if (log.isDebugEnabled()) log.debug("Dispatching request from step " + nextStep + " to process [" + processId + "] action " + actionName); // Store response next step in process state : ProcessResponse r = (ProcessResponse) method.invoke(p, request); ((BaseProcessState) p.getState()).setNextStep(r.getNextStep()); return r; } } } throw new PasswordManagementException("Step [" + nextStep + "] not supported by process"); } catch (InvocationTargetException e) { throw new PasswordManagementException( "Cannot invoke process action [" + actionName + "] : " + e.getMessage(), e); } catch (IllegalAccessException e) { throw new PasswordManagementException( "Cannot invoke process action [" + actionName + "] : " + e.getMessage(), e); } }
From source file:com.jsmartframework.web.manager.BeanHelper.java
void setAuthMethods(Class<?> clazz) { if (!authMethods.containsKey(clazz)) { List<Method> methods = new ArrayList<>(); for (Method method : getBeanMethods(clazz)) { if (!method.isAnnotationPresent(AuthMethod.class)) { continue; }// w w w . ja va 2s. co m Class<?> returnType = method.getReturnType(); if (Boolean.class == returnType || boolean.class == returnType) { methods.add(method); } } authMethods.put(clazz, methods.toArray(new Method[methods.size()])); } }
From source file:com.videobox.web.util.dwr.AutoAnnotationDiscoveryContainer.java
private void addDataConverterObject(String className) { Class<?> cls;/*from w w w . j av a2 s. c o m*/ try { cls = Class.forName(className); } catch (ClassNotFoundException e) { throw new IllegalStateException("No such class: " + className); } StringBuilder excludes = new StringBuilder(); for (Method m : cls.getMethods()) { if (logger.isDebugEnabled()) { logger.debug("CHECKING " + cls.getSimpleName() + "." + m.getName() + "(" + m.getParameterTypes().length + ") -> " + Arrays.asList(m.getAnnotations())); } if (!m.isAnnotationPresent(RemoteProperty.class)) { if (logger.isDebugEnabled()) { logger.debug("EXCLUDING " + cls.getSimpleName() + "." + m.getName() + " -> " + Arrays.asList(m.getAnnotations())); } excludes.append(propName(m)).append(','); } } BeanConverter beanConverter = new BeanConverter(); beanConverter.setInstanceType(cls); beanConverter.setExclude(excludes.toString()); ConverterManager cm = this.getBean(ConverterManager.class); cm.addConverter(cls.getName(), beanConverter); if (logger.isDebugEnabled()) { logger.debug("CONVERTER: " + cls.getName() + " -> " + excludes); } }
From source file:de.taimos.dvalin.test.jaxrs.TestProxyBeanPostProcessor.java
private InjectionMetadata buildResourceMetadata(Class<?> clazz) { LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>(); Class<?> targetClass = clazz; do {//from w ww.ja v a 2 s . c om LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>(); for (Field field : targetClass.getDeclaredFields()) { if (field.isAnnotationPresent(TestProxy.class)) { if (Modifier.isStatic(field.getModifiers())) { throw new IllegalStateException("@TestProxy annotation is not supported on static fields"); } currElements.add(new TestProxyElement(field, null)); } } for (Method method : targetClass.getDeclaredMethods()) { Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) { continue; } if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { if (bridgedMethod.isAnnotationPresent(TestProxy.class)) { if (Modifier.isStatic(method.getModifiers())) { throw new IllegalStateException( "@TestProxy annotation is not supported on static methods"); } if (method.getParameterTypes().length != 1) { throw new IllegalStateException( "@TestProxy annotation requires a single-arg method: " + method); } PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz); currElements.add(new TestProxyElement(method, pd)); } } } elements.addAll(0, currElements); targetClass = targetClass.getSuperclass(); } while ((targetClass != null) && (targetClass != Object.class)); return new InjectionMetadata(clazz, elements); }
From source file:de.taimos.dvalin.jaxrs.remote.RemoteServiceBeanPostProcessor.java
private InjectionMetadata buildResourceMetadata(Class<?> clazz) { LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>(); Class<?> targetClass = clazz; do {// w w w.j a va 2 s. c om LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>(); for (Field field : targetClass.getDeclaredFields()) { if (field.isAnnotationPresent(RemoteService.class)) { if (Modifier.isStatic(field.getModifiers())) { throw new IllegalStateException( "@RemoteService annotation is not supported on static fields"); } currElements.add(new RemoteServiceElement(field, field, null)); } } for (Method method : targetClass.getDeclaredMethods()) { Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) { continue; } if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { if (bridgedMethod.isAnnotationPresent(RemoteService.class)) { if (Modifier.isStatic(method.getModifiers())) { throw new IllegalStateException( "@RemoteService annotation is not supported on static methods"); } if (method.getParameterTypes().length != 1) { throw new IllegalStateException( "@RemoteService annotation requires a single-arg method: " + method); } PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz); currElements.add(new RemoteServiceElement(method, bridgedMethod, pd)); } } } elements.addAll(0, currElements); targetClass = targetClass.getSuperclass(); } while ((targetClass != null) && (targetClass != Object.class)); return new InjectionMetadata(clazz, elements); }
From source file:com.jayway.jaxrs.hateoas.DefaultHateoasContext.java
private void mapMethod(Class<?> clazz, String rootPath, Method method) { String httpMethod = findHttpMethod(method); if (httpMethod != null) { String path = getPath(rootPath, method); String[] consumes = getConsumes(method); String[] produces = getProduces(method); if (method.isAnnotationPresent(Linkable.class)) { Linkable linkAnnotation = method.getAnnotation(Linkable.class); String id = linkAnnotation.value(); if (linkableMapping.containsKey(id)) { throw new IllegalArgumentException( "Id '" + id + "' mapped in class " + clazz + " is already mapped from another class"); }//from ww w. ja v a 2 s. c o m LinkableParameterInfo[] parameterInfo = extractMethodParameterInfo(method); LinkableInfo linkableInfo = new LinkableInfo(id, path, httpMethod, consumes, produces, linkAnnotation.label(), linkAnnotation.description(), linkAnnotation.templateClass(), parameterInfo); linkableMapping.put(id, linkableInfo); } else { logger.info("Method {} is missing Linkable annotation", method); } } else { //this might be a sub resource method if (method.isAnnotationPresent(Path.class)) { String path = method.getAnnotation(Path.class).value(); if (path.endsWith("/")) { path = StringUtils.removeEnd(path, "/"); } Class<?> subResourceType = method.getReturnType(); mapClass(subResourceType, rootPath + path); } } }
From source file:com.sinosoft.one.data.jade.statement.UpdateQuerier.java
public UpdateQuerier(EntityManager em, StatementMetaData metaData) { this.em = em; Method method = metaData.getMethod(); // ?//from w w w. java 2 s .c om Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } this.returnType = returnType; if (returnType == Identity.class || (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class)))) { returnGeneratedKeys = true; } else { returnGeneratedKeys = false; } }
From source file:org.optaplanner.core.impl.domain.solution.cloner.FieldAccessingSolutionCloner.java
private boolean isFieldADeepCloneProperty(Field field, Class fieldInstanceClass) { if (field.isAnnotationPresent(DeepPlanningClone.class)) { return true; }// w w w . j av a 2 s. c om Method getterMethod = ReflectionHelper.getGetterMethod(fieldInstanceClass, field.getName()); if (getterMethod != null && getterMethod.isAnnotationPresent(DeepPlanningClone.class)) { return true; } return false; }
From source file:com.lp.server.util.logger.HvDtoLogger.java
private void logImpl(Object object1, Object object2) { HvDtoLogClass logClassAnnotation = getLoggable(object1); if (logClassAnnotation == null) return;// w w w . j a v a 2 s.c o m Method[] methods = object1.getClass().getMethods(); for (Method theMethod : methods) { if (!theMethod.getName().startsWith("get")) continue; if (theMethod.getName().startsWith("getClass")) continue; // if(theMethod.getName().endsWith("Dto")) continue ; if (theMethod.isAnnotationPresent(Transient.class)) continue; if (theMethod.isAnnotationPresent(HvDtoLogIgnore.class)) continue; findDifference(logClassAnnotation, theMethod, object1, object2); } }