List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:org.acoveo.tools.Reflection.java
/** * Return a PrivilegeAction object for clazz.getDeclaredMethods(). * // w w w . j a v a 2 s. c o m * This method is from: * https://svn.apache.org/repos/asf/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java * * Requires security policy: * 'permission java.lang.RuntimePermission "accessDeclaredMembers";' * * @return Method[] */ public static final PrivilegedAction<Method[]> getDeclaredMethodsAction(final Class<?> clazz) { return new PrivilegedAction<Method[]>() { public Method[] run() { return clazz.getDeclaredMethods(); } }; }
From source file:org.springmodules.cache.interceptor.MethodMatcher.java
private Method[] methods(String className) throws IllegalArgumentException { Class declaringClass = load(className); return declaringClass.getDeclaredMethods(); }
From source file:com.haulmont.cuba.core.sys.CubaAnnotationsLoader.java
private boolean propertyBelongsTo(Field field, MetaProperty metaProperty, List<Class> systemInterfaces) { String getterName = "get" + StringUtils.capitalize(metaProperty.getName()); Class<?> aClass = field.getDeclaringClass(); //noinspection unchecked List<Class> allInterfaces = ClassUtils.getAllInterfaces(aClass); for (Class intf : allInterfaces) { Method[] methods = intf.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(getterName) && method.getParameterTypes().length == 0) { if (systemInterfaces.contains(intf)) return true; }// w ww . j a va 2s .c o m } } return false; }
From source file:com.egreen.tesla.widget.api.service.ServiceBuilder.java
public void setInstance(Object instance) { Class<? extends Object> objectClass = instance.getClass(); Method[] declaredMethods = objectClass.getDeclaredMethods(); for (Method method : declaredMethods) { methodMap.put(method.getName(), method); }//from w w w.j a va 2 s . c o m this.instance = instance; }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Does the given class and/or its superclasses at least have one or more * methods (with any argument types)? Includes non-public methods. * @param clazz the clazz to check// w ww . j a v a 2 s. co m * @param methodName the name of the method * @return whether there is at least one method with the given name */ public static boolean hasAtLeastOneMethodWithName(Class clazz, String methodName) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); Method[] declaredMethods = clazz.getDeclaredMethods(); for (int i = 0; i < declaredMethods.length; i++) { Method method = declaredMethods[i]; if (method.getName().equals(methodName)) { return true; } } Class[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { if (hasAtLeastOneMethodWithName(ifcs[i], methodName)) { return true; } } return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName)); }
From source file:ei.ne.ke.cassandra.cql3.EntitySpecificationUtils.java
/** * @param embeddedType//from w ww . jav a 2 s. c o m * @return the column mapping of the {@link java.reflect.Field} annotated with * {@link javax.persistence.EmbeddedId}. * * @see http://docs.oracle.com/javaee/6/api/index.html?javax/persistence/EmbeddedId.html */ public static <T> List<String> getCompoundKeyColumnNames(Class<T> embeddedType) { Preconditions.checkNotNull(embeddedType); List<String> columns = Lists.newArrayList(); for (Field embeddedField : embeddedType.getDeclaredFields()) { javax.persistence.Column c = embeddedField.getAnnotation(javax.persistence.Column.class); if (c == null) { continue; } String normalizedName = normalizeCqlElementName(c.name()); if (columns.contains(normalizedName)) { throw new IllegalStateException(String.format("Duplicate column name '%s'", normalizedName)); } columns.add(normalizedName); } for (Method embeddedMethod : embeddedType.getDeclaredMethods()) { javax.persistence.Column c = embeddedMethod.getAnnotation(javax.persistence.Column.class); if (c == null) { continue; } String normalizedName = normalizeCqlElementName(c.name()); if (columns.contains(normalizedName)) { throw new IllegalStateException(String.format("Duplicate column name '%s'", normalizedName)); } columns.add(normalizedName); } return columns; }
From source file:cherry.foundation.testtool.reflect.ReflectionResolverImpl.java
@Override public List<Method> resolveMethod(Class<?> beanClass, String methodName) { List<Method> list = new ArrayList<>(); for (Method m : beanClass.getDeclaredMethods()) { if (StringUtils.equals(m.getName(), methodName)) { list.add(m);/*from ww w .j av a 2 s.co m*/ } } return list; }
From source file:org.brushingbits.jnap.validation.constraints.AbstractConstraintValidator.java
/** * This method copies all the annotation properties to fields with the same name. * //from w w w .j av a2 s.c om * @param constraintAnnotation This constraint annotation. * @see PropertyAccessorFactory */ protected void bindParameters(A constraintAnnotation) { Class<?> annotationClass = constraintAnnotation.getClass(); Method[] methods = annotationClass.getDeclaredMethods(); ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(this); try { for (Method method : methods) { String methodName = method.getName(); if (accessor.isWritableProperty(methodName)) { accessor.setPropertyValue(methodName, method.invoke(constraintAnnotation, ArrayUtils.EMPTY_OBJECT_ARRAY)); } } } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } }
From source file:capital.scalable.restdocs.constraints.MethodParameterValidatorConstraintResolver.java
private Constraint createConstraint(Annotation annot, Class<? extends Annotation> type) { Map<String, Object> configuration = new HashMap(); for (Method method : type.getDeclaredMethods()) { String methodName = method.getName(); Object value = getAnnotValue(annot, method); configuration.put(methodName, value); }/* ww w . j a v a 2s .c om*/ return new Constraint(type.getName(), configuration); }
From source file:org.apache.axis2.json.gson.rpc.JsonInOnlyRPCMessageReceiver.java
public void invokeService(JsonReader jsonReader, Object serviceObj, String operation_name) throws AxisFault { Method method = null;/*from w w w . j av a 2 s. c o m*/ String msg; Class implClass = serviceObj.getClass(); Method[] allMethods = implClass.getDeclaredMethods(); method = JsonUtils.getOpMethod(operation_name, allMethods); Class[] paramClasses = method.getParameterTypes(); try { int paramCount = paramClasses.length; JsonUtils.invokeServiceClass(jsonReader, serviceObj, method, paramClasses, paramCount); } catch (IllegalAccessException e) { msg = "Does not have access to " + "the definition of the specified class, field, method or constructor"; log.error(msg, e); throw AxisFault.makeFault(e); } catch (InvocationTargetException e) { msg = "Exception occurred while trying to invoke service method " + (method != null ? method.getName() : "null"); log.error(msg, e); throw AxisFault.makeFault(e); } catch (IOException e) { msg = "Exception occur while encording or " + "access to the input string at the JsonRpcMessageReceiver"; log.error(msg, e); throw AxisFault.makeFault(e); } }