Example usage for java.lang.reflect Modifier isAbstract

List of usage examples for java.lang.reflect Modifier isAbstract

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isAbstract.

Prototype

public static boolean isAbstract(int mod) 

Source Link

Document

Return true if the integer argument includes the abstract modifier, false otherwise.

Usage

From source file:at.treedb.backup.Export.java

/**
 * Ignore abstract and some special class for default dump.
 * //from w w w . j  a  v a 2  s.  com
 * @param clazz
 * @return {@code
 */
private static boolean isIgnoreClass(Class<?> clazz) {
    if (Modifier.isAbstract(clazz.getModifiers()) || clazz.equals(DBFSblock.class)
            || clazz.equals(DBinfo.class)) {
        return true;
    }
    return false;
}

From source file:com.zyf.framework.plugin.SqlSessionFactoryBean.java

/**
 * Build a {@code SqlSessionFactory} instance.
 *
 * The default implementation uses the standard MyBatis {@code XMLConfigBuilder} API to build a
 * {@code SqlSessionFactory} instance based on an Reader.
 * Since 1.3.0, it can be specified a {@link Configuration} instance directly(without config file).
 *
 * @return SqlSessionFactory//w  w  w.j a  v  a  2  s  .  co  m
 * @throws IOException if loading the config file failed
 */
protected SqlSessionFactory buildSqlSessionFactory() throws IOException {

    Configuration configuration;

    XMLConfigBuilder xmlConfigBuilder = null;
    if (this.configuration != null) {
        configuration = this.configuration;
        if (configuration.getVariables() == null) {
            configuration.setVariables(this.configurationProperties);
        } else if (this.configurationProperties != null) {
            configuration.getVariables().putAll(this.configurationProperties);
        }
    } else if (this.configLocation != null) {
        xmlConfigBuilder = new XMLConfigBuilder(this.configLocation.getInputStream(), null,
                this.configurationProperties);
        configuration = xmlConfigBuilder.getConfiguration();
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(
                    "Property 'configuration' or 'configLocation' not specified, using default MyBatis Configuration");
        }
        configuration = new Configuration();
        if (this.configurationProperties != null) {
            configuration.setVariables(this.configurationProperties);
        }
    }

    if (this.objectFactory != null) {
        configuration.setObjectFactory(this.objectFactory);
    }

    if (this.objectWrapperFactory != null) {
        configuration.setObjectWrapperFactory(this.objectWrapperFactory);
    }

    if (this.vfs != null) {
        configuration.setVfsImpl(this.vfs);
    }

    if (hasLength(this.typeAliasesPackage)) {
        String[] typeAliasPackageArray = tokenizeToStringArray(this.typeAliasesPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeAliasPackageArray) {
            configuration.getTypeAliasRegistry().registerAliases(packageToScan,
                    typeAliasesSuperType == null ? Object.class : typeAliasesSuperType);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Scanned package: '" + packageToScan + "' for aliases");
            }
        }
    }

    if (!isEmpty(this.typeAliases)) {
        for (Class<?> typeAlias : this.typeAliases) {
            configuration.getTypeAliasRegistry().registerAlias(typeAlias);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Registered type alias: '" + typeAlias + "'");
            }
        }
    }

    if (!isEmpty(this.plugins)) {
        for (Interceptor plugin : this.plugins) {
            configuration.addInterceptor(plugin);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Registered plugin: '" + plugin + "'");
            }
        }
    }

    if (hasLength(this.typeHandlersPackage)) {
        String[] typeHandlersPackageArray = tokenizeToStringArray(this.typeHandlersPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeHandlersPackageArray) {
            configuration.getTypeHandlerRegistry().register(packageToScan);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Scanned package: '" + packageToScan + "' for type handlers");
            }
        }
    }

    if (!isEmpty(this.typeHandlers)) {
        for (TypeHandler<?> typeHandler : this.typeHandlers) {

            //TODO:
            ClazzTypeScan cts = typeHandler.getClass().getAnnotation(ClazzTypeScan.class);
            if (cts == null) {
                configuration.getTypeHandlerRegistry().register(typeHandler);
            } else {
                TypeScan typescan = cts.value();
                if (typeScanMap.containsKey(typescan.name())) {
                    String scanpath = typeScanMap.get(typescan.name());

                    ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<>();
                    resolverUtil.find(new ResolverUtil.IsA(DescriptionID.class), scanpath);
                    Set<Class<? extends Class<?>>> handlerSet = resolverUtil.getClasses();
                    for (Class<?> type : handlerSet) {
                        try {
                            Constructor<?> c = typeHandler.getClass().getConstructor(Class.class);
                            c.newInstance(type);
                        } catch (NoSuchMethodException | SecurityException e) {
                            e.printStackTrace();
                        } catch (InstantiationException e) {
                            e.printStackTrace();
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        } catch (IllegalArgumentException e) {
                            e.printStackTrace();
                        } catch (InvocationTargetException e) {
                            e.printStackTrace();
                        }

                        if (!type.isAnonymousClass() && !type.isInterface()
                                && !Modifier.isAbstract(type.getModifiers())) {
                            configuration.getTypeHandlerRegistry().register(type, typeHandler.getClass());
                        }
                    }

                }
            }

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Registered type handler: '" + typeHandler + "'");
            }
        }
    }

    if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
        try {
            configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
        } catch (SQLException e) {
            throw new NestedIOException("Failed getting a databaseId", e);
        }
    }

    if (this.cache != null) {
        configuration.addCache(this.cache);
    }

    if (xmlConfigBuilder != null) {
        try {
            xmlConfigBuilder.parse();

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Parsed configuration file: '" + this.configLocation + "'");
            }
        } catch (Exception ex) {
            throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
        } finally {
            ErrorContext.instance().reset();
        }
    }

    if (this.transactionFactory == null) {
        this.transactionFactory = new SpringManagedTransactionFactory();
    }

    configuration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource));

    if (!isEmpty(this.mapperLocations)) {
        for (Resource mapperLocation : this.mapperLocations) {
            if (mapperLocation == null) {
                continue;
            }

            try {
                XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
                        configuration, mapperLocation.toString(), configuration.getSqlFragments());
                xmlMapperBuilder.parse();
            } catch (Exception e) {
                throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
            } finally {
                ErrorContext.instance().reset();
            }

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Parsed mapper file: '" + mapperLocation + "'");
            }
        }

        // ThinkGem ?MapperXML?
        if (mapperRefresh.isEnabled()) {
            System.out.println("mapperRefresh loading.............");
            mapperRefresh.setConfiguration(configuration);
            mapperRefresh.setMapperLocations(mapperLocations);
            mapperRefresh.run();
        }

    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Property 'mapperLocations' was not specified or no matching resources found");
        }
    }

    return this.sqlSessionFactoryBuilder.build(configuration);
}

From source file:edu.isi.karma.rdf.OfflineRdfGenerator.java

private KR2RMLRDFWriter createBloomFilterWriter(PrintWriter bloomfilterpw, Boolean isRDF, String baseURI)
        throws Exception {

    Reflections reflections = new Reflections("edu.isi.karma.kr2rml.writer");

    Set<Class<? extends KR2RMLRDFWriter>> subTypes = reflections.getSubTypesOf(KR2RMLRDFWriter.class);

    for (Class<? extends KR2RMLRDFWriter> subType : subTypes) {
        if (!Modifier.isAbstract(subType.getModifiers()) && !subType.isInterface()
                && subType.getName().equals("BloomFilterKR2RMLRDFWriter"))
            try {
                KR2RMLRDFWriter writer = subType.newInstance();
                writer.setWriter(bloomfilterpw);
                Properties p = new Properties();
                p.setProperty("is.rdf", isRDF.toString());
                p.setProperty("base.uri", baseURI);
                writer.initialize(p);/* w  w  w .  j a va2  s.  co m*/
                return writer;
            } catch (Exception e) {
                bloomfilterpw.close();
                throw new Exception("Unable to instantiate bloom filter writer", e);
            }
    }

    bloomfilterpw.close();
    throw new Exception("Bloom filter writing support not enabled.  Please recompile with -Pbloom");
}

From source file:com.p5solutions.core.utils.ReflectionUtility.java

/**
 * Check if the method is abstract.//from  w  ww.  ja  v a2 s .  co m
 * 
 * @param method
 * @return
 */
public static boolean isAbstract(Method method) {
    return Modifier.isAbstract(method.getModifiers());
}

From source file:org.kuali.rice.krad.service.impl.RemoteModuleServiceBase.java

/**
 * @see org.kuali.rice.krad.service.ModuleService#getExternalizableBusinessObjectImplementation(java.lang.Class)
 */// w ww  .  ja v  a  2  s . co m
@Override
public <E extends ExternalizableBusinessObject> Class<E> getExternalizableBusinessObjectImplementation(
        Class<E> externalizableBusinessObjectInterface) {
    if (getModuleConfiguration() == null) {
        throw new IllegalStateException(
                "Module configuration has not been initialized for the module service.");
    }
    Map<Class, Class> ebos = getModuleConfiguration().getExternalizableBusinessObjectImplementations();
    if (ebos == null) {
        return null;
    }
    if (ebos.containsValue(externalizableBusinessObjectInterface)) {
        return externalizableBusinessObjectInterface;
    } else {
        Class<E> implementationClass = ebos.get(externalizableBusinessObjectInterface);

        int implClassModifiers = implementationClass.getModifiers();
        if (Modifier.isInterface(implClassModifiers) || Modifier.isAbstract(implClassModifiers)) {
            throw new RuntimeException("Implementation class must be non-abstract class: ebo interface: "
                    + externalizableBusinessObjectInterface.getName() + " impl class: "
                    + implementationClass.getName() + " module: "
                    + getModuleConfiguration().getNamespaceCode());
        }
        return implementationClass;
    }

}

From source file:org.codehaus.enunciate.modules.rest.RESTOperation.java

/**
 * Create a new instance of something of the specified collection type.
 *
 * @param collectionType The collection type.
 * @return the new instance.//from   w w w. j a  v  a2 s .  c o m
 */
public static Collection newCollectionInstance(Class collectionType) {
    if (Collection.class.isAssignableFrom(collectionType)) {
        Collection collection;
        if ((collectionType.isInterface()) || (Modifier.isAbstract(collectionType.getModifiers()))) {
            if (Set.class.isAssignableFrom(collectionType)) {
                if (SortedSet.class.isAssignableFrom(collectionType)) {
                    collection = new TreeSet();
                } else {
                    collection = new HashSet();
                }
            } else {
                collection = new ArrayList();
            }
        } else {
            try {
                collection = (Collection) collectionType.newInstance();
            } catch (Exception e) {
                throw new IllegalArgumentException(
                        "Unable to create an instance of " + collectionType.getName() + ".", e);
            }
        }
        return collection;
    } else {
        throw new IllegalArgumentException("Invalid list type: " + collectionType.getName());
    }
}

From source file:org.dd4t.databind.builder.json.JsonModelConverter.java

private <T extends BaseViewModel> BaseViewModel buildModelForField(final JsonNode currentField,
        final Class<T> modelClassToUse) throws SerializationException {

    if (Modifier.isAbstract(modelClassToUse.getModifiers())
            || Modifier.isInterface(modelClassToUse.getModifiers())) {

        // Get root element name
        final String rootElementName = getRootElementNameFromComponentOrEmbeddedField(currentField);
        if (StringUtils.isNotEmpty(rootElementName)) {
            // attempt get a concrete class for this interface

            final Class<? extends BaseViewModel> concreteClass = databinder
                    .getConcreteModel(modelClassToUse.getCanonicalName(), rootElementName);
            if (concreteClass == null) {
                LOG.error("Attempt to find a concrete model class for interface or abstract class: {} failed "
                        + "miserably as there was no registered class for root element name: '{}' Will return null"
                        + ".", modelClassToUse.getCanonicalName(), rootElementName);
                return null;
            }/*from w w w  .  j  a  v  a  2 s. c  o m*/
            LOG.debug("Building: {}", concreteClass.getCanonicalName());
            return getBaseViewModel(currentField, concreteClass);
        } else {
            LOG.error(
                    "Attempt to find a concrete model class for interface or abstract class: {} failed "
                            + "miserably as a root element name could not be found. Will return null.",
                    modelClassToUse.getCanonicalName());
            return null;
        }

    } else {

        return getBaseViewModel(currentField, modelClassToUse);
    }
}

From source file:org.bremersee.common.exception.ExceptionRegistry.java

/**
 * Find an instance of the given throwable class.
 *
 * @param clazz   the throwable class/*from  ww w.j a  v  a2 s  .co  m*/
 * @param message an optional message
 * @param cause   an optional cause
 * @return the throwable instance
 */
private static Throwable findThrowable(final Class<? extends Throwable> clazz, final String message,
        final Throwable cause) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Finding throwable of class [" + clazz + "] ...");
    }
    Class<? extends Throwable> cls = clazz;
    while (Modifier.isAbstract(cls.getModifiers())) {
        //noinspection unchecked
        cls = (Class<? extends Throwable>) cls.getSuperclass();
    }
    Throwable t = findThrowableByMessageAndCause(cls, message, cause);
    if (t == null) {
        t = findThrowableByMessage(cls, message, cause);
    }
    if (t == null) {
        t = findThrowableByCause(cls, message, cause);
    }
    if (t == null) {
        t = findThrowableByDefaultConstructor(cls, message, cause);
    }
    if (t == null) {
        Class<?> superCls = cls.getSuperclass();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Finding throwable of class [" + cls + "] failed. Trying super class [" + superCls
                    + "] ...");
        }
        if (Throwable.class.isAssignableFrom(superCls)) {
            //noinspection unchecked
            return findThrowable((Class<? extends Throwable>) superCls, message, cause);
        } else {
            InternalServerError ise = new InternalServerError();
            LOG.error("Finding throwable for class [" + clazz.getName() + "] failed.", ise); // NOSONAR
            throw ise;
        }
    }
    return t;
}

From source file:ca.uhn.fhir.parser.BaseParser.java

@SuppressWarnings("unchecked")
ChildNameAndDef getChildNameAndDef(BaseRuntimeChildDefinition theChild, IBase theValue) {
    Class<? extends IBase> type = theValue.getClass();
    String childName = theChild.getChildNameByDatatype(type);
    BaseRuntimeElementDefinition<?> childDef = theChild.getChildElementDefinitionByDatatype(type);
    if (childDef == null) {
        // if (theValue instanceof IBaseExtension) {
        // return null;
        // }/*from w  w w  .java2 s .  co  m*/

        /*
         * For RI structures Enumeration class, this replaces the child def
         * with the "code" one. This is messy, and presumably there is a better
         * way..
         */
        BaseRuntimeElementDefinition<?> elementDef = myContext.getElementDefinition(type);
        if (elementDef.getName().equals("code")) {
            Class<? extends IBase> type2 = myContext.getElementDefinition("code").getImplementingClass();
            childDef = theChild.getChildElementDefinitionByDatatype(type2);
            childName = theChild.getChildNameByDatatype(type2);
        }

        // See possibly the user has extended a built-in type without
        // declaring it anywhere, as in XmlParserDstu3Test#testEncodeUndeclaredBlock
        if (childDef == null) {
            Class<?> nextSuperType = theValue.getClass();
            while (IBase.class.isAssignableFrom(nextSuperType) && childDef == null) {
                if (Modifier.isAbstract(nextSuperType.getModifiers()) == false) {
                    BaseRuntimeElementDefinition<?> def = myContext
                            .getElementDefinition((Class<? extends IBase>) nextSuperType);
                    Class<?> nextChildType = def.getImplementingClass();
                    childDef = theChild
                            .getChildElementDefinitionByDatatype((Class<? extends IBase>) nextChildType);
                    childName = theChild.getChildNameByDatatype((Class<? extends IBase>) nextChildType);
                }
                nextSuperType = nextSuperType.getSuperclass();
            }
        }

        if (childDef == null) {
            throwExceptionForUnknownChildType(theChild, type);
        }
    }

    return new ChildNameAndDef(childName, childDef);
}

From source file:org.glowroot.agent.weaving.ClassAnalyzer.java

private void removeAdviceAlreadyWovenIntoSuperClass(Map<AnalyzedMethodKey, Set<Advice>> matchingAdvisorSets) {
    for (AnalyzedClass superAnalyzedClass : superAnalyzedClasses) {
        for (AnalyzedMethod superAnalyzedMethod : superAnalyzedClass.analyzedMethods()) {
            if (Modifier.isAbstract(superAnalyzedMethod.modifiers())) {
                continue;
            }/*  w  ww .ja v  a2  s. c o  m*/
            AnalyzedMethodKey key = AnalyzedMethodKey.wrap(superAnalyzedMethod);
            Set<Advice> matchingAdvisorSet = matchingAdvisorSets.get(key);
            if (matchingAdvisorSet == null) {
                continue;
            }
            matchingAdvisorSet.removeAll(superAnalyzedMethod.advisors());
            if (matchingAdvisorSet.isEmpty()) {
                matchingAdvisorSets.remove(key);
            }
        }
    }
}