Example usage for org.springframework.core.type ClassMetadata getSuperClassName

List of usage examples for org.springframework.core.type ClassMetadata getSuperClassName

Introduction

In this page you can find the example usage for org.springframework.core.type ClassMetadata getSuperClassName.

Prototype

@Nullable
String getSuperClassName();

Source Link

Document

Return the name of the super class of the underlying class, or null if there is no super class defined.

Usage

From source file:org.syncope.core.rest.controller.ConfigurationController.java

@PreAuthorize("hasRole('CONFIGURATION_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/validators")
public ModelAndView getValidators() {
    CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory();

    Set<String> validators = new HashSet<String>();
    try {/*from   w  ww. jav  a 2  s .  c o  m*/
        for (Resource resource : resResolver
                .getResources("classpath:org/syncope/core/persistence/validation/" + "attrvalue/*.class")) {

            ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource)
                    .getClassMetadata();
            if (ArrayUtils.contains(metadata.getInterfaceNames(), Validator.class.getName())
                    || AbstractValidator.class.getName().equals(metadata.getSuperClassName())) {

                try {
                    Class jobClass = Class.forName(metadata.getClassName());
                    if (!Modifier.isAbstract(jobClass.getModifiers())) {
                        validators.add(jobClass.getName());
                    }
                } catch (ClassNotFoundException e) {
                    LOG.error("Could not load class {}", metadata.getClassName(), e);
                }
            }
        }
    } catch (IOException e) {
        LOG.error("While searching for class implementing {}", Validator.class.getName(), e);
    }

    return new ModelAndView().addObject(validators);
}

From source file:org.syncope.core.rest.controller.ReportController.java

@PreAuthorize("hasRole('REPORT_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/reportletClasses")
public ModelAndView getReportletClasses() {
    CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory();

    Set<String> reportletClasses = new HashSet<String>();
    try {/*from   w  w  w .j a  va2 s.c o m*/
        for (Resource resource : resResolver.getResources("classpath*:**/*.class")) {

            ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource)
                    .getClassMetadata();
            if (ArrayUtils.contains(metadata.getInterfaceNames(), Reportlet.class.getName())
                    || AbstractReportlet.class.getName().equals(metadata.getSuperClassName())) {

                try {
                    Class jobClass = Class.forName(metadata.getClassName());
                    if (!Modifier.isAbstract(jobClass.getModifiers())) {

                        reportletClasses.add(jobClass.getName());
                    }
                } catch (ClassNotFoundException e) {
                    LOG.error("Could not load class {}", metadata.getClassName(), e);
                }
            }
        }
    } catch (IOException e) {
        LOG.error("While searching for class implementing {}", Reportlet.class.getName(), e);
    }

    ModelAndView result = new ModelAndView();
    result.addObject(reportletClasses);
    return result;
}

From source file:org.syncope.core.rest.controller.TaskController.java

@PreAuthorize("hasRole('TASK_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/jobClasses")
public ModelAndView getJobClasses() {
    CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory();

    Set<String> jobClasses = new HashSet<String>();
    try {/*  ww  w.j a v a2 s .c  om*/
        for (Resource resource : resResolver.getResources("classpath*:**/*.class")) {

            ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource)
                    .getClassMetadata();
            if (ArrayUtils.contains(metadata.getInterfaceNames(), Job.class.getName())
                    || AbstractTaskJob.class.getName().equals(metadata.getSuperClassName())
                    || ArrayUtils.contains(metadata.getInterfaceNames(), StatefulJob.class.getName())) {

                try {
                    Class jobClass = Class.forName(metadata.getClassName());
                    if (!Modifier.isAbstract(jobClass.getModifiers()) && !metadata.hasEnclosingClass()
                            && !jobClass.equals(SyncJob.class) && !jobClass.equals(ReportJob.class)
                            && !jobClass.equals(NotificationJob.class)) {

                        jobClasses.add(jobClass.getName());
                    }
                } catch (ClassNotFoundException e) {
                    LOG.error("Could not load class {}", metadata.getClassName(), e);
                }
            }
        }
    } catch (IOException e) {
        LOG.error("While searching for class implementing {}", Job.class.getName(), e);
    }

    ModelAndView result = new ModelAndView();
    result.addObject(jobClasses);
    return result;
}

From source file:org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter.java

@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
        throws IOException {

    // This method optimizes avoiding unnecessary creation of ClassReaders
    // as well as visiting over those readers.
    if (matchSelf(metadataReader)) {
        return true;
    }//from  w  w  w .  j a  va  2 s. c o m
    ClassMetadata metadata = metadataReader.getClassMetadata();
    if (matchClassName(metadata.getClassName())) {
        return true;
    }

    if (this.considerInherited) {
        String superClassName = metadata.getSuperClassName();
        if (superClassName != null) {
            // Optimization to avoid creating ClassReader for super class.
            Boolean superClassMatch = matchSuperClass(superClassName);
            if (superClassMatch != null) {
                if (superClassMatch.booleanValue()) {
                    return true;
                }
            } else {
                // Need to read super class to determine a match...
                try {
                    if (match(metadata.getSuperClassName(), metadataReaderFactory)) {
                        return true;
                    }
                } catch (IOException ex) {
                    logger.debug("Could not read super class [" + metadata.getSuperClassName()
                            + "] of type-filtered class [" + metadata.getClassName() + "]");
                }
            }
        }
    }

    if (this.considerInterfaces) {
        for (String ifc : metadata.getInterfaceNames()) {
            // Optimization to avoid creating ClassReader for super class
            Boolean interfaceMatch = matchInterface(ifc);
            if (interfaceMatch != null) {
                if (interfaceMatch.booleanValue()) {
                    return true;
                }
            } else {
                // Need to read interface to determine a match...
                try {
                    if (match(ifc, metadataReaderFactory)) {
                        return true;
                    }
                } catch (IOException ex) {
                    logger.debug("Could not read interface [" + ifc + "] for type-filtered class ["
                            + metadata.getClassName() + "]");
                }
            }
        }
    }

    return false;
}

From source file:ru.kwanza.dbtool.orm.impl.mapping.SpringEntityMappingRegistryImpl.java

private void scanPackage(String basePackage) {
    try {/*w w  w .j ava  2s  . c om*/
        final String packageSearchPath = createPackageSearchPath(basePackage);
        final Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
        for (Resource resource : resources) {
            if (log.isTraceEnabled()) {
                log.trace("Scanning " + resource);
            }
            if (resource.isReadable()) {
                try {
                    final MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    final ClassMetadata classMetadata = metadataReader.getClassMetadata();
                    final String className = classMetadata.getClassName();
                    if (!classMetadata.isAbstract()
                            && !Enum.class.getName().equals(classMetadata.getSuperClassName())) {
                        log.trace(className);
                        final ClassLoader classLoader = resourcePatternResolver.getClassLoader();
                        Class<?> entityClass = classLoader.loadClass(className);
                        if (entityClass.isAnnotationPresent(Entity.class)
                                || entityClass.isAnnotationPresent(AbstractEntity.class)) {
                            delegate.registerEntityClass(entityClass);
                        }
                    }
                } catch (Throwable e) {
                    throw new RuntimeException("Error while registering entity mapping: " + resource, e);
                }
            } else {
                if (log.isTraceEnabled()) {
                    log.trace("Ignored because not readable: " + resource);
                }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("I/O failure during classpath scanning", e);
    }
}