Example usage for java.lang.reflect Modifier isStatic

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

Introduction

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

Prototype

public static boolean isStatic(int mod) 

Source Link

Document

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

Usage

From source file:com.streamsets.datacollector.definition.ConfigDefinitionExtractor.java

private List<ErrorMessage> validate(String configPrefix, Class klass, List<String> stageGroups,
        boolean validateDependencies, boolean isBean, boolean isComplexField, Object contextMsg) {
    List<ErrorMessage> errors = new ArrayList<>();
    boolean noConfigs = true;
    for (Field field : klass.getFields()) {
        if (field.getAnnotation(ConfigDef.class) != null && field.getAnnotation(ConfigDefBean.class) != null) {
            errors.add(new ErrorMessage(DefinitionError.DEF_152, contextMsg, field.getName()));
        } else {//from w w  w.ja va2 s  . co m
            if (field.getAnnotation(ConfigDef.class) != null
                    || field.getAnnotation(ConfigDefBean.class) != null) {
                if (Modifier.isStatic(field.getModifiers())) {
                    errors.add(new ErrorMessage(DefinitionError.DEF_151, contextMsg, klass.getSimpleName(),
                            field.getName()));
                }
                if (Modifier.isFinal(field.getModifiers())) {
                    errors.add(new ErrorMessage(DefinitionError.DEF_154, contextMsg, klass.getSimpleName(),
                            field.getName()));
                }
            }
            if (field.getAnnotation(ConfigDef.class) != null) {
                noConfigs = false;
                List<ErrorMessage> subErrors = validateConfigDef(configPrefix, stageGroups, field,
                        isComplexField, Utils.formatL("{} Field='{}'", contextMsg, field.getName()));
                errors.addAll(subErrors);
            } else if (field.getAnnotation(ConfigDefBean.class) != null) {
                noConfigs = false;
                List<ErrorMessage> subErrors = validateConfigDefBean(configPrefix + field.getName() + ".",
                        field, stageGroups, isComplexField,
                        Utils.formatL("{} BeanField='{}'", contextMsg, field.getName()));
                errors.addAll(subErrors);
            }
        }
    }
    if (isBean && noConfigs) {
        errors.add(new ErrorMessage(DefinitionError.DEF_160, contextMsg));
    }
    if (errors.isEmpty() & validateDependencies) {
        errors.addAll(validateDependencies(getConfigDefinitions(configPrefix, klass, stageGroups, contextMsg),
                contextMsg));
    }
    return errors;
}

From source file:net.sf.jasperreports.engine.query.JRHibernateQueryExecuter.java

private static final Type loadTypeConstant(Class<?> typeConstantsClass, String name) {
    try {//from   w  w  w  .j av  a2s  .c  o  m
        Field constant = typeConstantsClass.getField(name);
        if (!Modifier.isStatic(constant.getModifiers()) || !Type.class.isAssignableFrom(constant.getType())) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_UNRESOLVED_TYPE_CONSTANT,
                    new Object[] { name, typeConstantsClass.getName() });
        }
        Type type = (Type) constant.get(null);
        return type;
    } catch (NoSuchFieldException e) {
        throw new JRRuntimeException(e);
    } catch (SecurityException e) {
        throw new JRRuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new JRRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new JRRuntimeException(e);
    }
}

From source file:in.hatimi.nosh.support.CommandExecutor.java

private Method findMainMethod() {
    Method[] methods = cmdCls.getMethods();
    for (Method method : methods) {
        if (!method.getName().equals("execute")) {
            continue; //method name must be 'execute'
        }/*from   w ww.  jav  a  2 s.  c  o m*/
        int mod = method.getModifiers();
        if (Modifier.isAbstract(mod)) {
            continue; //method cannot be abstract.
        }
        if (Modifier.isStatic(mod)) {
            continue; //method cannot be static.
        }
        if (Modifier.isSynchronized(mod)) {
            continue; //method cannot be synthetic.
        }
        if (!Modifier.isPublic(mod)) {
            continue; //method must be public.
        }
        if (method.getReturnType() != Void.TYPE) {
            continue; //method must not return a value.
        }
        Class<?>[] paramTypes = method.getParameterTypes();
        if (paramTypes.length > 1) {
            continue; //method can take at most one parameter.
        }
        if (paramTypes.length == 1 && !paramTypes[0].equals(String[].class)) {
            continue; //if single parameter, must be String[]
        }
        return method;
    }
    return null;
}

From source file:objenome.util.bytecode.SgUtils.java

private static void checkModifiers(int type, int modifiers) {
    for (int modifier = ABSTRACT; modifier <= STRICTFP; modifier++) {
        if (Modifier.isPrivate(modifiers) && !MODIFIERS_MATRIX[PRIVATE][type]) {
            throwIllegalArgument(type, PRIVATE);
        }/*from   ww w. ja  v  a2 s . c  o  m*/
        if (Modifier.isProtected(modifiers) && !MODIFIERS_MATRIX[PROTECTED][type]) {
            throwIllegalArgument(type, PROTECTED);
        }
        if (Modifier.isPublic(modifiers) && !MODIFIERS_MATRIX[PUBLIC][type]) {
            throwIllegalArgument(type, PUBLIC);
        }
        if (Modifier.isStatic(modifiers) && !MODIFIERS_MATRIX[STATIC][type]) {
            throwIllegalArgument(type, STATIC);
        }
        if (Modifier.isAbstract(modifiers) && !MODIFIERS_MATRIX[ABSTRACT][type]) {
            throwIllegalArgument(type, ABSTRACT);
        }
        if (Modifier.isFinal(modifiers) && !MODIFIERS_MATRIX[FINAL][type]) {
            throwIllegalArgument(type, FINAL);
        }
        if (Modifier.isNative(modifiers) && !MODIFIERS_MATRIX[NATIVE][type]) {
            throwIllegalArgument(type, NATIVE);
        }
        if (Modifier.isSynchronized(modifiers) && !MODIFIERS_MATRIX[SYNCHRONIZED][type]) {
            throwIllegalArgument(type, SYNCHRONIZED);
        }
        if (Modifier.isTransient(modifiers) && !MODIFIERS_MATRIX[TRANSIENT][type]) {
            throwIllegalArgument(type, TRANSIENT);
        }
        if (Modifier.isVolatile(modifiers) && !MODIFIERS_MATRIX[VOLATILE][type]) {
            throwIllegalArgument(type, VOLATILE);
        }
        if (Modifier.isStrict(modifiers) && !MODIFIERS_MATRIX[STRICTFP][type]) {
            throwIllegalArgument(type, STRICTFP);
        }
    }
}

From source file:io.github.huherto.springyRecords.RecordMapper.java

/**
 * Initialize the mapping metadata for the given class.
 * @param mappedClass the mapped class.//from  w  w  w  .ja v a 2s  .  c om
 */
protected void initialize(Class<T> mappedClass) {
    this.mappedClass = mappedClass;
    this.mappedFields = new HashMap<String, Field>();

    Field fields[] = mappedClass.getFields();
    for (Field field : fields) {
        int mod = field.getModifiers();
        if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
            for (Annotation a : field.getAnnotations()) {
                if (a.annotationType().isAssignableFrom(Column.class)) {
                    Column c = (Column) a;
                    String columnName = c.name();
                    mappedFields.put(columnName, field);
                }
            }
        }
    }
}

From source file:jp.co.opentone.bsol.linkbinder.dto.AbstractDto.java

/**
 * aClass???List?????.//from  ww w.java2 s.  c o m
 * @param aClass
 *            class
 * @return 
 */
private List<Field> getInstanceFields(Class<?> aClass) {

    List<Field> fields = new ArrayList<Field>();
    for (Field field : aClass.getDeclaredFields()) {
        if (!Modifier.isStatic(field.getModifiers())) {
            fields.add(field);
        }
    }
    return fields;
}

From source file:ColorUtils.java

private static boolean isConstantColorField(Field field) {
    return Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())
            && Color.class == field.getType();
}

From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java

@SuppressWarnings("deprecation")
private static ConnectorRegistry create(ApplicationConfig config) throws Exception {

    Map<String, String> paramValues = config.getParamValues();
    String appId = config.getApplicationId();
    String connectorId = (String) paramValues.get("connectorId");

    File file1 = new File(CoreUtils.getConnectorDir() + File.separatorChar + connectorId);

    URL[] urls = new URL[] { file1.toURL() };
    ClassLoader cl = ClassLoaderRepository.getClassLoader(urls, true);

    //URLClassLoader cl = new URLClassLoader(urls,
    //        ConnectorMBeanRegistry.class.getClassLoader());

    Registry.MODELER_MANIFEST = MBEANS_DESCRIPTOR;
    URL res = cl.getResource(MBEANS_DESCRIPTOR);

    logger.info("Application ID   : " + appId);
    logger.info("Connector Archive: " + file1.getAbsoluteFile());
    logger.info("MBean Descriptor : " + res.toString());

    //Thread.currentThread().setContextClassLoader(cl);
    //Registry.setUseContextClassLoader(true);

    ConnectorRegistry registry = new ConnectorRegistry();
    registry.loadMetadata(cl);//from   w  w w  .  j  a  va 2  s  . c o  m

    String[] mbeans = registry.findManagedBeans();

    MBeanServer server = MBeanServerFactory.newMBeanServer(DOMAIN_CONNECTOR);

    for (int i = 0; i < mbeans.length; i++) {
        ManagedBean managed = registry.findManagedBean(mbeans[i]);
        String clsName = managed.getType();
        String domain = managed.getDomain();
        if (domain == null) {
            domain = DOMAIN_CONNECTOR;
        }

        Class<?> cls = Class.forName(clsName, true, cl);
        Object objMBean = null;

        // Use the factory method when it is defined.
        Method[] methods = cls.getMethods();
        for (Method method : methods) {
            if (method.getName().equals(FACTORY_METHOD) && Modifier.isStatic(method.getModifiers())) {
                objMBean = method.invoke(null);
                logger.info("Create MBean using factory method.");
                break;
            }
        }

        if (objMBean == null) {
            objMBean = cls.newInstance();
        }

        // Call the initialize method if the MBean extends ConnectorSupport class
        if (objMBean instanceof ConnectorSupport) {
            Method method = cls.getMethod("initialize", new Class[] { Map.class });
            Map<String, String> props = config.getParamValues();
            method.invoke(objMBean, new Object[] { props });
        }
        ModelMBean mm = managed.createMBean(objMBean);

        String beanObjName = domain + ":name=" + mbeans[i];
        server.registerMBean(mm, new ObjectName(beanObjName));
    }

    registry.setMBeanServer(server);
    entries.put(appId, registry);
    return registry;
}

From source file:com.Da_Technomancer.crossroads.API.packets.Message.java

private static boolean acceptField(Field f, Class<?> type) {
    int mods = f.getModifiers();
    if (Modifier.isFinal(mods) || Modifier.isStatic(mods) || Modifier.isTransient(mods))
        return false;

    return handlers.containsKey(type);
}

From source file:hsa.awp.common.util.StaticInitializerBeanFactoryPostProcessor.java

/**
 * Look for a static setter method for field named fieldName in Method[]. Return null if none found.
 *
 * @param methods   {@link Method} array where to look for the setter
 * @param fieldName the name of the field
 * @return the static setter {@link Method} object
 *///from  ww w.  j a va  2 s  .  co  m
private Method findStaticSetter(Method[] methods, String fieldName) {

    String methodName = setterName(fieldName);
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().equals(methodName) && Modifier.isStatic(methods[i].getModifiers())) {
            return methods[i];
        }
    }
    return null;
}