List of usage examples for java.lang Class getMethods
@CallerSensitive public Method[] getMethods() throws SecurityException
From source file:com.wordnik.swagger.testframework.JavaTestCaseExecutor.java
/** * Populates the swagger input model object. *// ww w .j a va 2s . c o m * Input model is created when number of inputs to a method exceed certain limit. * @param inputDefinitions * @return */ private Object populateInputModelObject(Class swaggerInputClass, Map<String, String> inputDefinitions) throws Exception { Object object = swaggerInputClass.getConstructor().newInstance(); Method[] methods = swaggerInputClass.getMethods(); for (Method method : methods) { if (method.getName().startsWith("get")) { String methodName = method.getName(); String fieldName = methodName.substring(3); fieldName = namingPolicyProvider.applyMethodNamingPolicy(fieldName); Object value = inputDefinitions.get(fieldName); BeanUtils.setProperty(object, fieldName, value); } } return object; }
From source file:com.vecna.taglib.processor.JspAnnotationsProcessor.java
/** * Build JSP function models from an annotated class * @param type class with annotated static methods * @return JSP function models/*from ww w . j a v a2 s. c o m*/ */ public Collection<JspFunctionModel> getFunctionMetadata(Class<?> type) { Collection<JspFunctionModel> functions = new ArrayList<JspFunctionModel>(); for (Method method : type.getMethods()) { if (Modifier.isStatic(method.getModifiers()) && Modifier.isPublic(method.getModifiers()) && method.isAnnotationPresent(JspFunction.class)) { JspFunction functionAnnotation = method.getAnnotation(JspFunction.class); JspFunctionModel metadata = new JspFunctionModel(); metadata.name = functionAnnotation.name(); metadata.functionClass = type.getName(); JspFunctionSignature signature = new JspFunctionSignature(); signature.name = method.getName(); signature.argumentTypes = method.getParameterTypes(); signature.returnType = method.getReturnType(); metadata.signature = signature; functions.add(metadata); } } return functions; }
From source file:com.dbs.sdwt.jpa.JpaUtil.java
public boolean isEntityIdManuallyAssigned(Class<?> type) { for (Method method : type.getMethods()) { if (isPrimaryKey(method)) { return isManuallyAssigned(method); }/* w ww .jav a 2 s .com*/ } return false; // no pk found, should not happen }
From source file:org.openmrs.module.metadatasharing.reflection.OpenmrsClassScanner.java
protected void initServiceSaveMethodsCache() throws IOException { if (serviceSaveMethodsCache != null && serviceSaveMethodsCacheTimeout.after(new Date())) { return;/*w ww . ja va 2 s. c om*/ } log.debug("Refreshing OpenmrsService classes cache"); long future = new Date().getTime(); future += CACHE_TIMEOUT_IN_MS; serviceSaveMethodsCacheTimeout = new Date(future); serviceSaveMethodsCache = new HashMap<Class<?>, ClassMethod<OpenmrsService>>(); List<Class<OpenmrsService>> services = getClasses(OpenmrsService.class, false); for (Class<OpenmrsService> service : services) { Method[] methods = service.getMethods(); for (Method method : methods) { if (method.getName().startsWith("save")) { if (Arrays.equals(method.getParameterTypes(), new Class<?>[] { method.getReturnType() })) { if (canBeSaved(method.getReturnType())) { serviceSaveMethodsCache.put(method.getReturnType(), new ClassMethod<OpenmrsService>(service, method)); } } } } } //META-114 HACK try { serviceSaveMethodsCache.put(PersonAttributeType.class, new ClassMethod(PersonService.class, PersonService.class.getMethod("savePersonAttributeType", PersonAttributeType.class))); serviceSaveMethodsCache.put(RelationshipType.class, new ClassMethod(PersonService.class, PersonService.class.getMethod("saveRelationshipType", RelationshipType.class))); } catch (Exception ex) { } }
From source file:net.famzangl.minecraft.minebot.ai.command.CommandRegistry.java
private void getCommandsForClass(Class<?> commandClass, List<CommandDefinition> commands) { for (final Method m : commandClass.getMethods()) { if (Modifier.isStatic(m.getModifiers()) && m.isAnnotationPresent(AICommandInvocation.class)) { LOGGER.debug(MARKER_REGISTER, "Registering method: %s#%s()", commandClass.getCanonicalName(), m.getName());/*ww w. j av a2s . c o m*/ commands.addAll(getCommandsForMethod(m)); } } }
From source file:com.github.lightdocs.ModelBuilder.java
/** * Builds a documentation model from a list of JAXRS annotated classes. * /* w w w.j a v a 2 s. com*/ * @param jaxrsClasses * required non empty list of classes or interfaces * @return a ServiceDocumentation object */ public ServiceDocumentation buildModelFor(String... jaxrsClasses) { Validate.notEmpty(jaxrsClasses); ServiceDocumentation model = new ServiceDocumentation(); for (String className : jaxrsClasses) { Class<?> clazz = loadClass(className); Validate.isTrue(hasPathAnnotation(clazz), "No JAXRS annotations were present on " + clazz); for (Method method : clazz.getMethods()) { if (hasHttpMethodAnnotation(method)) { Resource resource = model.resource(getRootResourceURIFor(method.getDeclaringClass())); HttpMethod operationMethod = HttpMethod.valueOf(findJAXRSHttpMethodAnnotation(method).value()); String classPathValue = standardizePathAnnotationValue( method.getDeclaringClass().getAnnotation(Path.class)); String methodPathValue = standardizePathAnnotationValue(method.getAnnotation(Path.class)); String operationPath = buildEffectiveURIFor(classPathValue, methodPathValue); Operation operation = resource.operation(operationMethod, operationPath); eventBus.post(new OperationAddedEvent(method, operation)); } } } return model; }
From source file:com.invariantproperties.sandbox.springentitylistener.listener.HibernateEntityListenersAdapter.java
public void findMethodsForListener(Object listener) { Class<?> c = listener.getClass(); for (Method m : c.getMethods()) { if (Void.TYPE.equals(m.getReturnType())) { Class<?>[] types = m.getParameterTypes(); if (types.length == 1) { // check for all annotations now... if (m.getAnnotation(PrePersist.class) != null) { if (!preInsert.containsKey(types[0])) { preInsert.put(types[0], new LinkedHashMap<Method, Object>()); }//from w w w . ja va 2 s . c om preInsert.get(types[0]).put(m, listener); } if (m.getAnnotation(PostPersist.class) != null) { if (!postInsert.containsKey(types[0])) { postInsert.put(types[0], new LinkedHashMap<Method, Object>()); } postInsert.get(types[0]).put(m, listener); } if (m.getAnnotation(PreUpdate.class) != null) { if (!preUpdate.containsKey(types[0])) { preUpdate.put(types[0], new LinkedHashMap<Method, Object>()); } preUpdate.get(types[0]).put(m, listener); } if (m.getAnnotation(PostUpdate.class) != null) { if (!postUpdate.containsKey(types[0])) { postUpdate.put(types[0], new LinkedHashMap<Method, Object>()); } postUpdate.get(types[0]).put(m, listener); } if (m.getAnnotation(PreRemove.class) != null) { if (!preRemove.containsKey(types[0])) { preRemove.put(types[0], new LinkedHashMap<Method, Object>()); } preRemove.get(types[0]).put(m, listener); } if (m.getAnnotation(PostRemove.class) != null) { if (!postRemove.containsKey(types[0])) { postRemove.put(types[0], new LinkedHashMap<Method, Object>()); } postRemove.get(types[0]).put(m, listener); } if (m.getAnnotation(PostLoad.class) != null) { if (!postLoad.containsKey(types[0])) { postLoad.put(types[0], new LinkedHashMap<Method, Object>()); } postLoad.get(types[0]).put(m, listener); } } } } }
From source file:ar.com.jrules.core.service.LoadJRules.java
private void validateExcuteRuleAnnotationParameters() { log.debug("Found " + this.clazzWithMethodThatJRulesImplement.size() + " class with JRule implementation"); for (Class<?> clazz : this.clazzWithMethodThatJRulesImplement) { for (Method method : clazz.getMethods()) { ExecuteRule executeRuleAnnotation = method.getAnnotation(ExecuteRule.class); if (executeRuleAnnotation != null) { if (executeRuleAnnotation.ruleClass().length == 0 && executeRuleAnnotation.ruleSetName().length == 0) { throw new JRuleConfigurationException( "Found error in ExecuteRule configuration. The method '" + method.getName() + "' in class " + clazz.getCanonicalName() + " has not properly declared annotation @ExecuteRule. Remember to declare a 'ruleClass' or 'ruleSetName'"); }/*from w w w . j ava 2 s. c om*/ } } } }
From source file:ar.com.allium.rules.core.service.LoadAlliumRules.java
private void validateExcuteRuleAnnotationParameters() { log.debug("Found " + this.clazzWithMethodThatAlliumRulesImplement.size() + " class with AlliumRule implementation"); for (Class<?> clazz : this.clazzWithMethodThatAlliumRulesImplement) { for (Method method : clazz.getMethods()) { ExecuteRule executeRuleAnnotation = method.getAnnotation(ExecuteRule.class); if (executeRuleAnnotation != null) { if (executeRuleAnnotation.ruleClass().length == 0 && executeRuleAnnotation.ruleSetName().length == 0) { throw new AlliumRuleConfigurationException( "Found error in ExecuteRule configuration. The method '" + method.getName() + "' in class " + clazz.getCanonicalName() + " has not properly declared annotation @ExecuteRule. Remember to declare a 'ruleClass' or 'ruleSetName'"); }/*w ww. j ava 2s . co m*/ } } } }
From source file:koper.aop.AbstractSendMessageAdvice.java
/** * methodName ??/*w ww .jav a 2 s. c o m*/ * @param clazz * @param methodName * @param argCount * @return * @throws NoSuchMethodException */ protected Method getMethodFromClass(Class<?> clazz, String methodName, int argCount) throws NoSuchMethodException { Method[] methods = clazz.getMethods(); for (Method method0 : methods) { String methodName0 = method0.getName(); if (methodName0.equals(methodName) && method0.getParameterCount() == argCount) { return method0; } } return null; }