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:com.cnksi.core.tools.utils.Reflections.java

/**
 * ?private/protectedpublic?????JDKSecurityManager
 */// www.  ja  v a  2  s  .  c  o m
public static void makeAccessible(Method method) {

    if ((!Modifier.isPublic(method.getModifiers())
            || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) {
        method.setAccessible(true);
    }
}

From source file:com.kangyonggan.cms.util.Reflections.java

/**
 * ?private/protected???public?????JDKSecurityManager
 *//*from www .j  a  v a 2 s.  c  o  m*/
public static void makeAccessible(Field field) {
    boolean temp = (!Modifier.isPublic(field.getModifiers())
            || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
            || Modifier.isFinal(field.getModifiers())) && !field.isAccessible();
    if (temp) {
        field.setAccessible(true);
    }
}

From source file:org.apache.axis2.jaxws.server.endpoint.injection.impl.WebServiceContextInjectorImpl.java

public void injectOnField(Object resource, Object instance, Field field) throws ResourceInjectionException {
    if (instance == null) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot inject Resource on a null Service Instance.");
        }//from   w w w  .  ja  v  a 2s . c  o  m
        throw new ResourceInjectionException(Messages.getMessage("WebServiceContextInjectionImplErr1"));
    }
    if (field == null) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot inject WebServiceContext on ServiceInstance Field, field cannot be NULL");
        }
        throw new ResourceInjectionException(Messages.getMessage("WebServiceContextInjectionImplErr3"));
    }
    try {
        if (!Modifier.isPublic(field.getModifiers())) {
            setAccessible(field, true);
        }
        //Inject Resource.
        field.set(instance, resource);
    } catch (IllegalAccessException e) {
        throw new ResourceInjectionException(e);
    }

}

From source file:com.zigbee.framework.common.util.BeanCopyUtil.java

/**
 * ?//from   w w w. ja  va  2 s  .  com
 * @author tun.tan
 * @Date 2011-9-29 ?11:18:42
 */
public static void copyProps(Object source, Object target, String[] igonre) {
    Assert.notNull(source, "Source must not be null");
    Assert.notNull(target, "Target must not be null");
    Class<?> actualEditable = target.getClass();
    PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
    Object methodName = null;
    //      Object targetValue=null;
    //?
    for (PropertyDescriptor targetPd : targetPds) {
        if (targetPd.getWriteMethod() != null) {

            try {
                PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
                if (igonre != null) {
                    boolean jump = false;
                    //
                    for (int i = 0; i < igonre.length; i++) {
                        if (igonre[i] == null) {//
                            continue;
                        }
                        if (targetPd.getName().equals(igonre[i])) {//?
                            logger.info(targetPd.getName());
                            jump = true;
                        }
                    }
                    if (jump) {//
                        continue;
                    }
                }
                if (sourcePd != null && sourcePd.getReadMethod() != null) {//
                    Method readMethod = sourcePd.getReadMethod();
                    if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
                        readMethod.setAccessible(true);
                    }
                    Object value = readMethod.invoke(source);
                    //Check whether the value is empty, only copy the properties which are not empty
                    //                  targetValue=value;
                    if (value != null) {//
                        Method writeMethod = targetPd.getWriteMethod();
                        methodName = writeMethod.getName();
                        if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
                            readMethod.setAccessible(true);
                        }
                        writeMethod.invoke(target, value);
                    }

                }
            } catch (BeansException e) {
                e.printStackTrace();
                String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage();
                logger.error(errMsg);
                throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause());

            } catch (SecurityException e) {
                e.printStackTrace();
                String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage();
                logger.error(errMsg);
                throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause());

            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage();
                logger.error(errMsg);
                throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause());

            } catch (IllegalAccessException e) {
                e.printStackTrace();
                String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage();
                logger.error(errMsg);
                throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause());

            } catch (InvocationTargetException e) {
                e.printStackTrace();
                String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage();
                logger.error(errMsg);
                throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause());

            }

        }
    }
}

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

private boolean canUseMethod(Method method) {
    if (!Modifier.isPublic(method.getModifiers())) {
        return false;
    }/*from www  .  j a v  a  2  s .  co  m*/
    if (BLACKLISTED_FROM_CLI.contains(method.getName())) {
        return false;
    }
    if (method.isAnnotationPresent(NotOnCli.class)) {
        return false;
    }
    Class<?>[] parameters = method.getParameterTypes();
    if (parameters.length >= 2) {
        return false;
    }
    if (parameters.length == 1 && parameters[0] != String.class) {
        return false;
    }
    return true;
}

From source file:com.cnksi.core.tools.utils.Reflections.java

/**
 * ?private/protected???public?????JDKSecurityManager
 *//*from   w  w  w .j a  v  a 2s .  c o m*/
public static void makeAccessible(Field field) {

    if ((!Modifier.isPublic(field.getModifiers())
            || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
            || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
        field.setAccessible(true);
    }
}

From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java

private static void readConfigParamVerify(ExcelReadSheetProcessor<?> sheetProcessor,
        Map<Integer, Map<String, ExcelReadFieldMappingAttribute>> fieldMapping) {
    Class<?> clazz = sheetProcessor.getTargetClass();

    for (Entry<Integer, Map<String, ExcelReadFieldMappingAttribute>> indexFieldMapping : fieldMapping
            .entrySet()) {//  w  w  w . ja v a2s .  c  o m
        for (Map.Entry<String, ExcelReadFieldMappingAttribute> filedMapping : indexFieldMapping.getValue()
                .entrySet()) {
            String fieldName = filedMapping.getKey();
            if (fieldName != null) {
                PropertyDescriptor pd = getPropertyDescriptor(clazz, fieldName);
                if (pd == null || pd.getWriteMethod() == null) {
                    throw new IllegalArgumentException("In fieldMapping config {colIndex:"
                            + indexFieldMapping.getKey() + "["
                            + convertColIntIndexToCharIndex(indexFieldMapping.getKey()) + "]<->fieldName:"
                            + filedMapping.getKey() + "}, " + " class " + clazz.getName()
                            + " can't find field '" + filedMapping.getKey() + "' and can not also find "
                            + filedMapping.getKey() + "'s writter method.");
                }
                if (!Modifier.isPublic(pd.getWriteMethod().getDeclaringClass().getModifiers())) {
                    pd.getWriteMethod().setAccessible(true);
                }
            }
        }
    }
}

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

@Override
/**/*w  w  w.j  av a 2s. c om*/
 * 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 (hasByteMan) {
        if (wantCount && count > maxQuery) {
            throw new AssertionFailedError(
                    "" + count + " JDBC queries was executed but the maximum is : " + maxQuery);
        }
    }
}

From source file:org.apache.solr.update.processor.UpdateIndexAuthorizationProcessorTest.java

/**
 * Ensure no new methods have been added to base class that are not invoking
 * Sentry//w ww .j a  v a2s. co  m
 */
@Test
public void testAllMethodsChecked() throws Exception {
    Method[] methods = UpdateRequestProcessor.class.getDeclaredMethods();
    TreeSet<String> foundNames = new TreeSet<String>();
    for (Method method : methods) {
        if (Modifier.isPublic(method.getModifiers())) {
            foundNames.add(method.getName());
        }
    }
    assertEquals(methodNames.size(), foundNames.size());
    assertTrue(foundNames.containsAll(methodNames));
}

From source file:$.Reflections.java

/**
     * ?private/protectedpublic?????JDKSecurityManager
     *//*from  ww w  .jav  a 2s. c o m*/
    public static void makeAccessible(Method method) {
        if ((!Modifier.isPublic(method.getModifiers())
                || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) {
            method.setAccessible(true);
        }
    }