List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:Main.java
public static boolean isPublicField(Field field) { final int mod = field.getModifiers(); return Modifier.isPublic(mod); }
From source file:Main.java
public static boolean isPublicMethod(Method method) { final int mod = method.getModifiers(); return Modifier.isPublic(mod); }
From source file:Main.java
public static boolean isPublic(int modifier) { return Modifier.isPublic(modifier); }
From source file:Main.java
/** * set attribute is accessible/*from ww w . ja v a2 s.c om*/ * * @param field {@link java.lang.reflect.Field} */ public static void makeAccessible(final Field field) { if (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())) { field.setAccessible(true); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants.java
public static Map<String, String> exportConstants() { Map<String, String> constants = new HashMap<String, String>(); java.lang.reflect.Field[] fields = EditConfigurationConstants.class.getDeclaredFields(); for (java.lang.reflect.Field f : fields) { if (Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers())) { try { constants.put(f.getName(), f.get(null).toString()); } catch (Exception ex) { log.error("An exception occurred in trying to retrieve this field ", ex); }//www . j a v a 2 s.c om } } return constants; }
From source file:Main.java
public static List<Field> getPublicFields(Class<?> clazz) { List<Field> publicList = new ArrayList<Field>(); List<Field> accessibleList = getAccessibleFields(clazz, Object.class); for (Field f : accessibleList) { if (Modifier.isPublic(f.getModifiers()) == true) { publicList.add(f);/*from w w w . j ava 2 s . com*/ } } accessibleList.clear(); return publicList; }
From source file:Util.java
private static void fillSetterMethods(Class<?> pojoClass, Map<String, Method> baseMap) { if (pojoClass.getSuperclass() != Object.class) fillSetterMethods(pojoClass.getSuperclass(), baseMap); Method[] methods = pojoClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i];/* w ww .j av a 2 s. c o m*/ if (!Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 1 && m.getName().startsWith(SET) && Modifier.isPublic(m.getModifiers())) { baseMap.put(toProperty(SET.length(), m.getName()), m); } } }
From source file:Util.java
private static void fillGetterMethods(Class<?> pojoClass, Map<String, Method> baseMap) { if (pojoClass.getSuperclass() != Object.class) fillGetterMethods(pojoClass.getSuperclass(), baseMap); Method[] methods = pojoClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i];/*from w ww .j a v a2s . c o m*/ if (!Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0 && m.getReturnType() != null && Modifier.isPublic(m.getModifiers())) { String name = m.getName(); if (name.startsWith(IS)) baseMap.put(toProperty(IS.length(), name), m); else if (name.startsWith(GET)) baseMap.put(toProperty(GET.length(), name), m); } } }
From source file:SampleModifier.java
public static void printModifiers(Object o) { Class c = o.getClass();/*from w ww . java 2s . c o m*/ int m = c.getModifiers(); if (Modifier.isPublic(m)) System.out.println("public"); if (Modifier.isAbstract(m)) System.out.println("abstract"); if (Modifier.isFinal(m)) System.out.println("final"); }
From source file:Main.java
public static Map<String, Object> getProperties(Object bean) { Map<String, Object> map = new HashMap<String, Object>(); for (Method method : bean.getClass().getMethods()) { String name = method.getName(); if ((name.length() > 3 && name.startsWith("get") || name.length() > 2 && name.startsWith("is")) && Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 0 && method.getDeclaringClass() != Object.class) { int i = name.startsWith("get") ? 3 : 2; String key = name.substring(i, i + 1).toLowerCase() + name.substring(i + 1); try { map.put(key, method.invoke(bean, new Object[0])); } catch (Exception e) { }//from w w w .ja v a 2 s .c om } } return map; }