Example usage for java.lang.reflect Modifier isPublic

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

Introduction

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

Prototype

public static boolean isPublic(int mod) 

Source Link

Document

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

Usage

From source file:org.codehaus.groovy.grails.commons.metaclass.BaseApiProvider.java

private boolean isConstructorCallMethod(Method method) {
    return method != null && Modifier.isStatic(method.getModifiers())
            && Modifier.isPublic(method.getModifiers()) && method.getName().equals(CONSTRUCTOR_METHOD)
            && method.getParameterTypes().length > 0;
}

From source file:org.apache.pig.scripting.groovy.GroovyScriptEngine.java

@Override
protected Map<String, List<PigStats>> main(PigContext context, String scriptFile) throws IOException {

    PigServer pigServer = new PigServer(context, false);

    ////w  ww.j  a v a2 s.c o m
    // Register dependencies
    //

    String groovyJar = getJarPath(groovy.util.GroovyScriptEngine.class);

    if (null != groovyJar) {
        pigServer.registerJar(groovyJar);
    }

    //
    // Register UDFs
    //

    registerFunctions(scriptFile, null, context);

    try {

        //
        // Load the script
        //

        Class c = gse.loadScriptByName(new File(scriptFile).toURI().toString());

        //
        // Extract the main method
        //

        Method main = c.getMethod("main", String[].class);

        if (null == main || !Modifier.isStatic(main.getModifiers()) || !Modifier.isPublic(main.getModifiers())
                || !Void.TYPE.equals(main.getReturnType())) {
            throw new IOException("No method 'public static void main(String[] args)' was found.");
        }

        //
        // Invoke the main method
        //

        Object[] args = new Object[1];
        String[] argv = (String[]) ObjectSerializer
                .deserialize(context.getProperties().getProperty(PigContext.PIG_CMD_ARGS_REMAINDERS));
        args[0] = argv;

        main.invoke(null, args);

    } catch (Exception e) {
        throw new IOException(e);
    }

    return getPigStatsMap();
}

From source file:com.cloudbees.jenkins.support.impl.LoadStats.java

/**
 * The fields that a {@link LoadStatistics} has change as you move from pre-1.607 to post 1.607, so better to
 * just look and see what there is rather than hard-code.
 *
 * @return the fields that correspond to {@link MultiStageTimeSeries}
 *//*from   w w  w  . ja va2  s.co  m*/
private static List<Field> findFields() {
    List<Field> result = new ArrayList<Field>();
    for (Field f : LoadStatistics.class.getFields()) {
        if (Modifier.isPublic(f.getModifiers()) && MultiStageTimeSeries.class.isAssignableFrom(f.getType())
                && f.getAnnotation(Deprecated.class) == null) {
            result.add(f);
        }
    }
    return result;
}

From source file:lite.flow.util.ActivityInspector.java

/**
 *  Component can have multiple Entry methods.
 * @param clazz// w ww.  java  2s.  co  m
 * @return
 */
static public ArrayList<Method> getEntryMethods(Class<?> clazz) {

    ArrayList<Method> methods = new ArrayList<>();

    for (Method method : clazz.getDeclaredMethods()) {
        if (Modifier.isPublic(method.getModifiers())) {
            methods.add(method);
        }
    }

    return methods;
}

From source file:org.apache.openjpa.enhance.PCSubclassValidator.java

public void assertCanSubclass() {
    Class superclass = meta.getDescribedType();
    String name = superclass.getName();
    if (superclass.isInterface())
        addError(loc.get("subclasser-no-ifaces", name), meta);
    if (Modifier.isFinal(superclass.getModifiers()))
        addError(loc.get("subclasser-no-final-classes", name), meta);
    if (Modifier.isPrivate(superclass.getModifiers()))
        addError(loc.get("subclasser-no-private-classes", name), meta);
    if (PersistenceCapable.class.isAssignableFrom(superclass))
        addError(loc.get("subclasser-super-already-pc", name), meta);

    try {//from w  w  w . ja v a 2s .c  om
        Constructor c = superclass.getDeclaredConstructor(new Class[0]);
        if (!(Modifier.isProtected(c.getModifiers()) || Modifier.isPublic(c.getModifiers())))
            addError(loc.get("subclasser-private-ctor", name), meta);
    } catch (NoSuchMethodException e) {
        addError(loc.get("subclasser-no-void-ctor", name), meta);
    }

    // if the BCClass we loaded is already pc and the superclass is not,
    // then we should never get here, so let's make sure that the
    // calling context is caching correctly by throwing an exception.
    if (pc.isInstanceOf(PersistenceCapable.class) && !PersistenceCapable.class.isAssignableFrom(superclass))
        throw new InternalException(loc.get("subclasser-class-already-pc", name));

    if (AccessCode.isProperty(meta.getAccessType()))
        checkPropertiesAreInterceptable();

    if (errors != null && !errors.isEmpty())
        throw new UserException(errors.toString());
    else if (contractViolations != null && !contractViolations.isEmpty() && log.isWarnEnabled())
        log.warn(contractViolations.toString());
}

From source file:gobblin.runtime.cli.ConstructorAndPublicMethodsCliObjectFactory.java

private boolean canUseConstructor(Constructor<?> constructor) {
    if (!Modifier.isPublic(constructor.getModifiers())) {
        return false;
    }/* ww  w  . j  a  v a 2 s.c  om*/
    if (!constructor.isAnnotationPresent(CliObjectSupport.class)) {
        return false;
    }
    for (Class<?> param : constructor.getParameterTypes()) {
        if (param != String.class) {
            return false;
        }
    }
    return constructor.getParameterTypes().length == constructor.getAnnotation(CliObjectSupport.class)
            .argumentNames().length;
}

From source file:org.exoplatform.social.core.test.AbstractCoreTest.java

@Override
/**/*from  ww w . j a  v a 2 s  .  c o m*/
 * Override to run the test and assert its state.
 * @throws Throwable if any exception is thrown
 */
protected void runTest() throws Throwable {
    String fName = getName();
    assertNotNull("TestCase.fName cannot be null", fName); // Some VMs crash when calling getMethod(null,null);
    Method runMethod = null;
    try {
        // use getMethod to get all public inherited
        // methods. getDeclaredMethods returns all
        // methods of this class but excludes the
        // inherited ones.
        runMethod = getClass().getMethod(fName, (Class[]) null);
    } catch (NoSuchMethodException e) {
        fail("Method \"" + fName + "\" not found");
    }
    if (!Modifier.isPublic(runMethod.getModifiers())) {
        fail("Method \"" + fName + "\" should be public");
    }

    try {
        MaxQueryNumber queryNumber = runMethod.getAnnotation(MaxQueryNumber.class);
        if (queryNumber != null) {
            wantCount = true;
            maxQuery = queryNumber.value();
        }
        runMethod.invoke(this);
    } catch (InvocationTargetException e) {
        e.fillInStackTrace();
        throw e.getTargetException();
    } catch (IllegalAccessException e) {
        e.fillInStackTrace();
        throw e;
    }

    if (wantCount && count > maxQuery) {
        throw new AssertionFailedError(
                "" + count + " JDBC queries was executed but the maximum is : " + maxQuery);
    }

}

From source file:org.jdto.impl.BeanPropertyUtils.java

/**
 * Determine wether a method is accessor or not, by looking at some properties.
 * @param method//ww w .j  a  v a  2s  . c om
 * @param maxParams
 * @param hasReturnType 
 * @param prefixes
 * @return 
 */
private static boolean isAccessorMethod(Method method, int maxParams, boolean hasReturnType,
        String... prefixes) {

    //first of all, we only want public methods.
    if (!Modifier.isPublic(method.getModifiers())) {
        return false;
    }

    //check if the method should return something or not.
    if (hasReturnType) {
        if (method.getReturnType() == Void.TYPE) {
            return false;
        }
    }

    //check the method parameter length
    int parameterAmount = method.getParameterTypes().length;

    if (parameterAmount > maxParams) {
        return false;
    }

    //check the naming conventions
    String methodName = method.getName();
    if (!org.jdto.util.StringUtils.startsWithAny(methodName, prefixes)) {
        return false;
    }

    //well everything has succeeded, then is an accessor!

    return true;
}

From source file:org.apache.tapestry.listener.ListenerMap.java

private static Map buildMethodMap(Class beanClass) {
    if (LOG.isDebugEnabled())
        LOG.debug("Building method map for class " + beanClass.getName());

    Map result = new HashMap();
    Method[] methods = beanClass.getMethods();

    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];/*from   w ww .java  2s . c  o m*/
        int mods = m.getModifiers();

        if (Modifier.isStatic(mods))
            continue;

        // Probably not necessary, getMethods() returns only public
        // methods.

        if (!Modifier.isPublic(mods))
            continue;

        // Must return void

        if (m.getReturnType() != Void.TYPE)
            continue;

        Class[] parmTypes = m.getParameterTypes();

        if (parmTypes.length != 1)
            continue;

        // parm must be IRequestCycle

        if (!parmTypes[0].equals(IRequestCycle.class))
            continue;

        // Ha!  Passed all tests.

        result.put(m.getName(), m);
    }

    return result;

}

From source file:org.jdto.util.MethodUtils.java

/**
 * <p>Return an accessible method (that is, one that can be invoked via
 * reflection) that implements the specified method, by scanning through all
 * implemented interfaces and subinterfaces. If no such method can be found,
 * return//w  ww .  ja va  2  s  . c  om
 * <code>null</code>.</p>
 *
 * <p> There isn't any good reason why this method must be private. It is
 * because there doesn't seem any reason why other classes should call this
 * rather than the higher level methods.</p>
 *
 * @param cls Parent class for the interfaces to be checked
 * @param methodName Method name of the method we wish to call
 * @param parameterTypes The parameter type signatures
 * @return the accessible method or
 * <code>null</code> if not found
 */
private static Method getAccessibleMethodFromInterfaceNest(Class cls, String methodName,
        Class[] parameterTypes) {
    Method method = null;

    // Search up the superclass chain
    for (; cls != null; cls = cls.getSuperclass()) {

        // Check the implemented interfaces of the parent class
        Class[] interfaces = cls.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {
            // Is this interface public?
            if (!Modifier.isPublic(interfaces[i].getModifiers())) {
                continue;
            }
            // Does the method exist on this interface?
            try {
                method = interfaces[i].getDeclaredMethod(methodName, parameterTypes);
            } catch (NoSuchMethodException e) {
                /*
                 * Swallow, if no method is found after the loop then this
                 * method returns null.
                 */
            }
            if (method != null) {
                break;
            }
            // Recursively check our parent interfaces
            method = getAccessibleMethodFromInterfaceNest(interfaces[i], methodName, parameterTypes);
            if (method != null) {
                break;
            }
        }
    }
    return method;
}