List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:org.force66.beantester.utils.InstantiationUtils.java
public static Constructor<?> findPublicConstructor(Class<?> klass) { Validate.notNull(klass, "Null class not allowed."); Constructor<?> nullConstructor = ConstructorUtils.getAccessibleConstructor(klass, new Class<?>[0]); if (nullConstructor != null) { return nullConstructor; }/* w w w. j a v a2 s . c om*/ Constructor<?>[] constructorArray = klass.getConstructors(); for (Constructor<?> constructor : constructorArray) { if (Modifier.isPublic(constructor.getModifiers())) { return constructor; } } return null; }
From source file:com.agileapes.couteau.context.spring.event.impl.GenericTranslationScheme.java
static boolean isGetter(Method method) { return Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0 && !method.getReturnType().equals(void.class) && (method.getName().matches("get[A-Z].*") || (method.getName().matches("is[A-Z].*") && method.getReturnType().equals(boolean.class))); }
From source file:org.opentele.server.core.util.CustomGroovyBeanJSONMarshaller.java
public void marshalObject(Object o, JSON json) throws ConverterException { JSONWriter writer = json.getWriter(); try {/*from ww w. j ava2 s . c o m*/ writer.object(); for (PropertyDescriptor property : BeanUtils.getPropertyDescriptors(o.getClass())) { String name = property.getName(); Method readMethod = property.getReadMethod(); if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) { Object value = readMethod.invoke(o, (Object[]) null); writer.key(name); json.convertAnother(value); } } for (Field field : o.getClass().getDeclaredFields()) { int modifiers = field.getModifiers(); if (Modifier.isPublic(modifiers) && !(Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers))) { writer.key(field.getName()); json.convertAnother(field.get(o)); } } writer.endObject(); } catch (ConverterException ce) { throw ce; } catch (Exception e) { throw new ConverterException("Error converting Bean with class " + o.getClass().getName(), e); } }
From source file:net.sf.beanlib.provider.BeanChecker.java
/** * Returns true if the fromBean is empty; or false otherwise. * It is considered empty if every publicly declared getter methods of the specified class * either return null or blank string.//from ww w . j av a 2 s . com * * @param fromBean java bean to check if empty or not. * @param k specified class name from which the getter methods are derived. */ public boolean empty(Object fromBean, Class<?> k) { Class<?> fromClass = fromBean.getClass(); Method[] ma = k.getDeclaredMethods(); try { // invoking all declaring getter methods of fromBean for (int i = 0; i < ma.length; i++) { Method m = ma[i]; String name = m.getName(); try { if (name.startsWith("get") && Modifier.isPublic(m.getModifiers())) { Method getter = fromClass.getMethod(name); Object attrValue = getter.invoke(fromBean); if (attrValue == null) { continue; } if (attrValue instanceof String) { String s = (String) attrValue; s = s.trim(); if (s.length() == 0) { continue; } } return false; } } catch (NoSuchMethodException ignore) { // ignore and proceed to the next method. } } return true; } catch (IllegalAccessException e) { log.error("", e); throw new BeanlibException(e); } catch (SecurityException e) { log.error("", e); throw new BeanlibException(e); } catch (InvocationTargetException e) { log.error("", e.getTargetException()); throw new BeanlibException(e.getTargetException()); } }
From source file:ome.util.ReflectionUtils.java
static List checkGettersAndSetters(Method[] methods) { List goodMethods = new ArrayList(); if (null == methods) { return goodMethods; }/* ww w. j av a2 s .c om*/ for (int i = 0; i < methods.length; i++) { boolean ok = true; Method method = methods[i]; int mod = method.getModifiers(); if (!Modifier.isPublic(mod) || Modifier.isStatic(mod)) { ok = false; } if (method.getName().startsWith("get")) { if (0 != method.getParameterTypes().length) { ok = false; } } else if (method.getName().startsWith("set")) { // No constaints yet on setters. } else { ok = false; } if (ok) { goodMethods.add(method); } } return goodMethods; }
From source file:com.taobao.adfs.database.tdhsocket.client.protocol.TDHSProtocolBinary.java
private static void encodeRequest(Request o, ByteArrayOutputStream out, String charestName) throws IllegalAccessException, IOException, TDHSEncodeException { for (Field f : o.getClass().getDeclaredFields()) { if (!Modifier.isPublic(f.getModifiers())) { f.setAccessible(true);//w w w .j a v a 2s. co m } Object v = f.get(o); if (v instanceof Request) { encodeRequest((Request) v, out, charestName); } else if (f.getName().startsWith("_")) { writeObjectToStream(v, out, f.getName(), charestName); } } }
From source file:arena.utils.ReflectionUtils.java
public static String[] getAttributeNamesUsingGetter(Class<?> entityClass) { // return BeanUtils.getPropertyDescriptors(entityClass); Class<?> clsMe = entityClass; List<String> voFieldNames = new ArrayList<String>(); while (clsMe != null) { Field[] fields = clsMe.getDeclaredFields(); for (int n = 0; n < fields.length; n++) { int modifiers = fields[n].getModifiers(); if (!Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) { String fieldName = fields[n].getName(); try { PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(entityClass, fieldName); if (pd.getReadMethod() != null) { voFieldNames.add(fieldName); }/*from w w w. j ava2 s . c o m*/ } catch (Throwable err) { // skip } } } // Loop back to parent class clsMe = clsMe.getSuperclass(); } return voFieldNames.toArray(new String[voFieldNames.size()]); }
From source file:fr.univlorraine.mondossierweb.config.DebugConfig.java
/** * Branche customizableTraceInterceptor sur les mthodes public des classes du package controllers * @return//from w w w. j ava 2 s. c o m */ @Bean public Advisor controllersAdvisor() { return new StaticMethodMatcherPointcutAdvisor(customizableTraceInterceptor()) { private static final long serialVersionUID = 5897279987213542868L; @Override public boolean matches(Method method, Class<?> clazz) { return Modifier.isPublic(method.getModifiers()) && clazz.getPackage() != null && clazz.getPackage().getName().startsWith(UserController.class.getPackage().getName()); } }; }
From source file:com.cuubez.visualizer.resource.ResourceMetaDataScanner.java
public SubResource scanMethods(Class<?> clazz, Method method) { int modifier = method.getModifiers(); if (Modifier.isStatic(modifier) || !Modifier.isPublic(modifier)) { return null; }// w ww . j a va 2 s . co m SubResource subResource = new SubResource(); subResource.setReflectionMethod(method); if (!scanHttpMethod(subResource, method)) { return null; } scanPath(subResource, method); scanConsume(subResource, method); scanProduce(subResource, method); scanDetail(subResource, method); scanName(subResource, method); scanHttpCodes(subResource, method); scanResponseType(subResource, method); subResource.setClazz(clazz); return subResource; }
From source file:org.grails.datastore.mapping.reflect.ReflectionUtils.java
/** * Make the given method accessible, explicitly setting it accessible if necessary. * The <code>setAccessible(true)</code> method is only called when actually necessary, * to avoid unnecessary conflicts with a JVM SecurityManager (if active). * * Based on the same method in Spring core. * * @param method the method to make accessible * @see java.lang.reflect.Method#setAccessible *//*w w w . j a v a2 s. com*/ public static void makeAccessible(Method method) { if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) { method.setAccessible(true); } }