Example usage for java.lang Class getDeclaredMethods

List of usage examples for java.lang Class getDeclaredMethods

Introduction

In this page you can find the example usage for java.lang Class getDeclaredMethods.

Prototype

@CallerSensitive
public Method[] getDeclaredMethods() throws SecurityException 

Source Link

Document

Returns an array containing Method objects reflecting all the declared methods of the class or interface represented by this Class object, including public, protected, default (package) access, and private methods, but excluding inherited methods.

Usage

From source file:nl.knaw.dans.common.ldap.repo.LdapMapper.java

private void populateMethodLists() {
    annotatedGetMethods = Collections.synchronizedList(new ArrayList<Method>());
    annotatedSetMethods = Collections.synchronizedList(new ArrayList<Method>());
    Class<?> superC = clazz;
    while (superC != null) {
        Method[] methods = superC.getDeclaredMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(LdapAttribute.class)) {
                if (method.getReturnType().equals(void.class)) {
                    // this is a setter method
                    annotatedSetMethods.add(method);
                } else {
                    // its a getter method
                    annotatedGetMethods.add(method);
                }/* w  ww. ja  va  2s  . co  m*/
            }
        }
        superC = superC.getSuperclass();
    }
}

From source file:message.mybatis.common.mapper.MapperHelper.java

/**
 * Mapper??MapperTemplate/*from w  w  w  . j  a v  a2 s .co  m*/
 *
 * @param mapperClass
 * @return
 * @throws Exception
 */
private MapperTemplate fromMapperClass(Class<?> mapperClass) {
    Method[] methods = mapperClass.getDeclaredMethods();
    Class<?> templateClass = null;
    Class<?> tempClass = null;
    Set<String> methodSet = new HashSet<String>();
    for (Method method : methods) {
        if (method.isAnnotationPresent(SelectProvider.class)) {
            SelectProvider provider = method.getAnnotation(SelectProvider.class);
            tempClass = provider.type();
            methodSet.add(method.getName());
        } else if (method.isAnnotationPresent(InsertProvider.class)) {
            InsertProvider provider = method.getAnnotation(InsertProvider.class);
            tempClass = provider.type();
            methodSet.add(method.getName());
        } else if (method.isAnnotationPresent(DeleteProvider.class)) {
            DeleteProvider provider = method.getAnnotation(DeleteProvider.class);
            tempClass = provider.type();
            methodSet.add(method.getName());
        } else if (method.isAnnotationPresent(UpdateProvider.class)) {
            UpdateProvider provider = method.getAnnotation(UpdateProvider.class);
            tempClass = provider.type();
            methodSet.add(method.getName());
        }
        if (templateClass == null) {
            templateClass = tempClass;
        } else if (templateClass != tempClass) {
            throw new RuntimeException("Mapper??MapperTemplate?!");
        }
    }
    if (templateClass == null || !MapperTemplate.class.isAssignableFrom(templateClass)) {
        templateClass = EmptyMapperProvider.class;
    }
    MapperTemplate mapperTemplate = null;
    try {
        mapperTemplate = (MapperTemplate) templateClass.getConstructor(Class.class, MapperHelper.class)
                .newInstance(mapperClass, this);
    } catch (Exception e) {
        throw new RuntimeException("MapperTemplate:" + e.getMessage());
    }
    //
    for (String methodName : methodSet) {
        try {
            mapperTemplate.addMethodMap(methodName, templateClass.getMethod(methodName, MappedStatement.class));
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(templateClass.getCanonicalName() + "" + methodName + "!");
        }
    }
    return mapperTemplate;
}

From source file:org.anyframe.iam.admin.common.web.JsonErrorAdvisingBeanPostProcessor.java

@SuppressWarnings("unchecked")
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {

    //  ? bean ? 
    log.debug("postProcessBeforeInitialization with : " + beanName);

    Class clazz = bean.getClass();

    // JsonError Annotation ?  MethodMatcher
    AnnotationMethodMatcher annotationMethodMatcher = new AnnotationMethodMatcher(JsonError.class);

    // advice(JsonIAMException   JsonExceptionTransfer) + Pointcut 
    // ? Advisor/*from   w  w w. j av  a 2s . c  o  m*/
    DefaultPointcutAdvisor advisor = (DefaultPointcutAdvisor) context.getBean("jsonErrorAdvisor");

    //  bean Class ?     JsonError Annotation ?   
    // ?
    for (Method method : clazz.getDeclaredMethods()) {
        // JsonError Annotation ?   
        if (annotationMethodMatcher.matches(method, clazz)) {
            // maching method  
            log.debug("maching method : " + clazz.getSimpleName() + "." + method.getName());

            // jsonErrorAdvisor    Pointcut ?  -   JsonError
            // Annotation ?  Bean ?  Pointcut  
            if (advisor.getPointcut() == Pointcut.TRUE) {
                advisor.setPointcut(
                        new ComposablePointcut(new RootClassFilter(clazz), annotationMethodMatcher));
                //  ? Pointcut ?  ??  JsonError Annotation ?
                //  Bean ?  Pointcut ? union  ?.
            } else {
                ComposablePointcut pointcut = (ComposablePointcut) advisor.getPointcut();
                pointcut.union(new ComposablePointcut(new RootClassFilter(clazz), annotationMethodMatcher));
                advisor.setPointcut(pointcut);
            }
        }
    }

    return bean;
}

From source file:com.neelo.glue.ApplicationModule.java

public void register(Class<?> resourceClass) {
    log.info("Registering: " + resourceClass.getName());

    Resource resource = null;/*from   w  w w  .ja  v  a  2s.co m*/

    if (resourceClass.isAnnotationPresent(Resource.class)) {
        resource = resourceClass.getAnnotation(Resource.class);
    } else {
        log.warn("Class not registerd. Missing " + Resource.class.getSimpleName() + " annotation");
        return;
    }

    ResourceBuilder builder = new ResourceBuilder(resourceClass, resource.path(), resource.layout());

    Method[] methods = resourceClass.getDeclaredMethods();
    for (Method method : methods) {
        if (method.isAnnotationPresent(Get.class)) {
            Get get = method.getAnnotation(Get.class);

            RouteBuilder route = builder.get(method, get.path(), get.content());

            route.setLayout(StringUtils.isNotBlank(get.layout()) ? get.layout() : resource.layout());
            if (StringUtils.isNotBlank(get.name()))
                route.setName(get.name());

            routes.add(route);
        } else if (method.isAnnotationPresent(Post.class)) {
            Post post = method.getAnnotation(Post.class);

            RouteBuilder route = builder.post(method, post.path(), post.content());

            route.setLayout(StringUtils.isNotBlank(post.layout()) ? post.layout() : resource.layout());
            if (StringUtils.isNotBlank(post.name()))
                route.setName(post.name());

            routes.add(route);
        }
    }
}

From source file:com.snaplogic.snaps.uniteller.BaseService.java

@Override
protected void process(Document document, String inputViewName) {
    try {/*from   w w w.  j a va  2s . com*/
        AccountBean bean = account.connect();
        String UFSConfigFilePath = urlEncoder.validateAndEncodeURI(bean.getConfigFilePath(), PATTERN, null)
                .toString();
        String UFSSecurityFilePath = urlEncoder
                .validateAndEncodeURI(bean.getSecurityPermFilePath(), PATTERN, null).toString();
        /* instantiating USFCreationClient */
        Class<?> CustomUSFCreationClient = Class.forName(UFS_FOLIO_CREATION_CLIENT_PKG_URI);
        Constructor<?> constructor = CustomUSFCreationClient
                .getDeclaredConstructor(new Class[] { IUFSConfigMgr.class, IUFSSecurityMgr.class });
        Object USFCreationClientObj = constructor.newInstance(CustomUFSConfigMgr.getInstance(UFSConfigFilePath),
                CustomUFSSecurityMgr.getInstance(UFSSecurityFilePath));
        Method setAutoUpdatePsw = CustomUSFCreationClient.getDeclaredMethod("setAutoUpdatePsw", Boolean.TYPE);
        setAutoUpdatePsw.invoke(USFCreationClientObj, autoUpdatePsw);
        /* Preparing the request for USF */
        Object data;
        if (document != null && (data = document.get()) != null) {
            if (data instanceof Map) {
                Map<String, Object> map = (Map<String, Object>) data;
                Class<?> UFSRequest = Class.forName(getUFSReqClassType());
                Object UFSRequestObj = UFSRequest.newInstance();
                Object inputFieldValue = null;
                Calendar cal = Calendar.getInstance();
                for (Method method : UFSRequest.getDeclaredMethods()) {
                    if (isSetter(method)
                            && (inputFieldValue = map.get(method.getName().substring(3))) != null) {
                        try {
                            String paramType = method.getParameterTypes()[0].getName();
                            if (paramType.equalsIgnoreCase(String.class.getName())) {
                                method.invoke(UFSRequest.cast(UFSRequestObj), String.valueOf(inputFieldValue));
                            } else if (paramType.equalsIgnoreCase(Double.class.getSimpleName())) {
                                method.invoke(UFSRequest.cast(UFSRequestObj),
                                        Double.parseDouble(String.valueOf(inputFieldValue)));
                            } else if (paramType.equalsIgnoreCase(INT)) {
                                method.invoke(UFSRequest.cast(UFSRequestObj),
                                        Integer.parseInt(String.valueOf(inputFieldValue)));
                            } else if (paramType.equalsIgnoreCase(Calendar.class.getName())) {
                                try {
                                    cal.setTime(sdtf.parse(String.valueOf(inputFieldValue)));
                                } catch (ParseException pe1) {
                                    try {
                                        cal.setTime(sdf.parse(String.valueOf(inputFieldValue)));
                                    } catch (ParseException pe) {
                                        writeToErrorView(
                                                String.format(DATE_PARSER_ERROR, DATETIME_FORMAT, DATE_FORMAT),
                                                pe.getMessage(), ERROR_RESOLUTION, pe);
                                    }
                                }
                                method.invoke(UFSRequest.cast(UFSRequestObj), cal);
                            }
                        } catch (IllegalArgumentException iae) {
                            writeToErrorView(String.format(ILLEGAL_ARGS_EXE, method.getName()),
                                    iae.getMessage(), ERROR_RESOLUTION, iae);
                        } catch (InvocationTargetException ite) {
                            writeToErrorView(ite.getTargetException().getMessage(), ite.getMessage(),
                                    ERROR_RESOLUTION, ite);
                        }
                    }
                }
                /* Invoking the request over USFCreationClient */
                Object UFSResponseObj = null;
                Method creationClientMethod = CustomUSFCreationClient
                        .getMethod(getCamelCaseForMethod(resourceType), UFSRequest);
                try {
                    UFSResponseObj = creationClientMethod.invoke(USFCreationClientObj,
                            UFSRequest.cast(UFSRequestObj));
                } catch (IllegalArgumentException iae) {
                    writeToErrorView(String.format(ILLEGAL_ARGS_EXE, creationClientMethod.getName()),
                            iae.getMessage(), ERROR_RESOLUTION, iae);
                } catch (InvocationTargetException ite) {
                    writeToErrorView(ite.getTargetException().getMessage(), ite.getMessage(), ERROR_RESOLUTION,
                            ite);
                }
                if (null != UFSResponseObj) {
                    outputViews.write(documentUtility.newDocument(processResponseObj(UFSResponseObj)));
                    counter.inc();
                }
            } else {
                writeToErrorView(NO_DATA_ERRMSG, NO_DATA_WARNING, NO_DATA_REASON, NO_DATA_RESOLUTION);
            }
        }
    } catch (Exception ex) {
        writeToErrorView(ERRORMSG, ex.getMessage(), ERROR_RESOLUTION, ex);
    }
}

From source file:com.evolveum.midpoint.prism.marshaller.PrismBeanInspector.java

private Method findMethod(Class classType, Handler<Method> selector) {
    for (Method field : classType.getDeclaredMethods()) {
        if (selector.handle(field)) {
            return field;
        }//  w w w.j a v  a2s .com
    }
    Class superclass = classType.getSuperclass();
    if (superclass == null || superclass.equals(Object.class)) {
        return null;
    }
    return findMethod(superclass, selector);
}

From source file:com.evolveum.midpoint.prism.marshaller.PrismBeanInspector.java

private Method findElementMethodInObjectFactoryUncached(Class objectFactoryClass, String propName) {
    for (Method method : objectFactoryClass.getDeclaredMethods()) {
        XmlElementDecl xmlElementDecl = method.getAnnotation(XmlElementDecl.class);
        if (xmlElementDecl == null) {
            continue;
        }/*from  w ww  .java  2  s . c o m*/
        if (propName.equals(xmlElementDecl.name())) {
            return method;
        }
    }
    return null;
}

From source file:com.linkedin.pinot.controller.api.ControllerRestApplication.java

private void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
    TreeSet<String> pathsOrderedByLength = new TreeSet<String>(
            ComparatorUtils.chainedComparator(new Comparator<String>() {
                private IntComparator _intComparator = IntComparators.NATURAL_COMPARATOR;

                @Override//w  ww .  j  a v a  2 s  . c o m
                public int compare(String o1, String o2) {
                    return _intComparator.compare(o1.length(), o2.length());
                }
            }, ComparatorUtils.NATURAL_COMPARATOR));

    for (Method method : clazz.getDeclaredMethods()) {
        Annotation annotationInstance = method.getAnnotation(Paths.class);
        if (annotationInstance != null) {
            pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
        }
    }

    for (String routePath : pathsOrderedByLength) {
        LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
        router.attach(routePath, clazz);
    }
}

From source file:com.cpjit.swagger4j.APIParser.java

private List<Method> scanAPIMethod(Class<?> clazz) {
    APIs apis = clazz.getAnnotation(APIs.class);
    if (apis == null) {
        return Collections.emptyList();
    }/*  w  w  w.  j a v a 2s  .  co m*/
    return Arrays.stream(clazz.getDeclaredMethods()).filter(method -> method.getAnnotation(API.class) != null)
            .collect(Collectors.toList());
}