List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
From source file:org.apache.axis.utils.BeanUtils.java
public static BeanPropertyDescriptor[] processPropertyDescriptors(PropertyDescriptor[] rawPd, Class cls, TypeDesc typeDesc) {//from w w w. ja va2 s .c o m // Create a copy of the rawPd called myPd BeanPropertyDescriptor[] myPd = new BeanPropertyDescriptor[rawPd.length]; ArrayList pd = new ArrayList(); try { for (int i = 0; i < rawPd.length; i++) { // Skip the special "any" field if (rawPd[i].getName().equals(Constants.ANYCONTENT)) continue; pd.add(new BeanPropertyDescriptor(rawPd[i])); } // Now look for public fields Field fields[] = cls.getFields(); if (fields != null && fields.length > 0) { // See if the field is in the list of properties // add it if not. for (int i = 0; i < fields.length; i++) { Field f = fields[i]; // skip if field come from a java.* or javax.* package // WARNING: Is this going to make bad things happen for // users JavaBeans? Do they WANT these fields serialzed? String clsName = f.getDeclaringClass().getName(); if (clsName.startsWith("java.") || clsName.startsWith("javax.")) { continue; } // skip field if it is final, transient, or static if (!(Modifier.isStatic(f.getModifiers()) || Modifier.isFinal(f.getModifiers()) || Modifier.isTransient(f.getModifiers()))) { String fName = f.getName(); boolean found = false; for (int j = 0; j < rawPd.length && !found; j++) { String pName = ((BeanPropertyDescriptor) pd.get(j)).getName(); if (pName.length() == fName.length() && pName.substring(0, 1).equalsIgnoreCase(fName.substring(0, 1))) { found = pName.length() == 1 || pName.substring(1).equals(fName.substring(1)); } } if (!found) { pd.add(new FieldPropertyDescriptor(f.getName(), f)); } } } } // If typeDesc meta data exists, re-order according to the fields if (typeDesc != null && typeDesc.getFields(true) != null) { ArrayList ordered = new ArrayList(); // Add the TypeDesc elements first FieldDesc[] fds = typeDesc.getFields(true); for (int i = 0; i < fds.length; i++) { FieldDesc field = fds[i]; if (field.isElement()) { boolean found = false; for (int j = 0; j < pd.size() && !found; j++) { if (field.getFieldName().equals(((BeanPropertyDescriptor) pd.get(j)).getName())) { ordered.add(pd.remove(j)); found = true; } } } } // Add the remaining elements while (pd.size() > 0) { ordered.add(pd.remove(0)); } // Use the ordered list pd = ordered; } myPd = new BeanPropertyDescriptor[pd.size()]; for (int i = 0; i < pd.size(); i++) { myPd[i] = (BeanPropertyDescriptor) pd.get(i); } } catch (Exception e) { log.error(Messages.getMessage("badPropertyDesc00", cls.getName()), e); throw new InternalException(e); } return myPd; }
From source file:net.mindengine.blogix.db.readers.ObjectReader.java
private Map<String, Field> convertOnlyNonStaticFieldsToMap(Field[] declaredFields) { Map<String, Field> fields = new HashMap<String, Field>(); for (Field field : declaredFields) { if (!Modifier.isStatic(field.getModifiers())) { fields.put(field.getName(), field); }/*from w w w .j a v a 2 s .c om*/ } return fields; }
From source file:com.tmind.framework.pub.utils.MethodUtils.java
public static Method findMethod(Class start, String methodName, int argCount) { // For overridden methods we need to find the most derived version. // So we start with the given class and walk up the superclass chain. for (Class cl = start; cl != null; cl = cl.getSuperclass()) { Method methods[] = getPublicDeclaredMethods(cl); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method == null) { continue; }/*from w w w . j a va2 s . co m*/ // skip static methods. int mods = method.getModifiers(); if (Modifier.isStatic(mods)) { continue; } if (method.getName().equals(methodName) && method.getParameterTypes().length == argCount) { return method; } } } // Now check any inherited interfaces. This is necessary both when // the argument class is itself an interface, and when the argument // class is an abstract class. Class ifcs[] = start.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { Method m = findMethod(ifcs[i], methodName, argCount); if (m != null) { return m; } } return null; }
From source file:com.diversityarrays.dal.db.DalDatabaseUtil.java
static public Map<Field, Column> buildEntityFieldColumnMap(Class<? extends DalEntity> entityClass) { Map<Field, Column> columnByField = new LinkedHashMap<Field, Column>(); for (Field fld : entityClass.getDeclaredFields()) { if (!Modifier.isStatic(fld.getModifiers())) { Column column = fld.getAnnotation(Column.class); fld.setAccessible(true);//from ww w.jav a2 s .c o m columnByField.put(fld, column); } } return columnByField; }
From source file:gov.va.vinci.leo.tools.LeoUtils.java
/** * Create the set of ConfigurationParameter objects from the Param class of an object. * * @param c Param class//from w w w . j av a 2 s.c o m * @return Set of ConfigurationParameter objects */ public static Set<ConfigurationParameter> getStaticConfigurationParameters(Class c) { Set<ConfigurationParameter> list = new HashSet<ConfigurationParameter>(); Field[] fields = c.getFields(); for (Field field : fields) { try { if (field.getType().equals(ConfigurationParameter.class) && Modifier.isStatic(field.getModifiers())) { list.add((ConfigurationParameter) field.get(null)); } } catch (IllegalAccessException e) { // Handle exception here } } return list; }
From source file:org.apache.tajo.engine.function.FunctionLoader.java
private static StaticMethodInvocationDesc extractStaticMethodInvocation(Method method) { Preconditions.checkArgument(Modifier.isPublic(method.getModifiers())); Preconditions.checkArgument(Modifier.isStatic(method.getModifiers())); String methodName = method.getName(); Class returnClass = method.getReturnType(); Class[] paramClasses = method.getParameterTypes(); return new StaticMethodInvocationDesc(method.getDeclaringClass(), methodName, returnClass, paramClasses); }
From source file:com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter.java
/** * ?pipeline?//from w ww .j a v a 2s. com */ public void merge(PipelineParameter pipelineParameter) { try { Field[] fields = this.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; // Skip static and final fields. if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) { continue; } ReflectionUtils.makeAccessible(field); Object srcValue = field.get(pipelineParameter); if (srcValue != null) { // null field.set(this, srcValue); } } } catch (Exception e) { // ignore } }
From source file:org.apache.abdera.util.AbderaConfiguration.java
private static String getName(Class<? extends StreamWriter> sw) { String name = null;//from w w w. j a va 2 s . c o m try { Field field = sw.getField("NAME"); if (Modifier.isStatic(field.getModifiers())) { name = (String) field.get(null); } } catch (Exception e) { } return name; }
From source file:com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.java
/** * Finds {@link InjectionMetadata.InjectedElement} Metadata from annotated {@link Reference @Reference} methods * * @param beanClass The {@link Class} of Bean * @return non-null {@link List}//from w w w . j a va 2s . co m */ private List<InjectionMetadata.InjectedElement> findMethodReferenceMetadata(final Class<?> beanClass) { final List<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>(); ReflectionUtils.doWithMethods(beanClass, new ReflectionUtils.MethodCallback() { @Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { Method bridgedMethod = findBridgedMethod(method); if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) { return; } Reference reference = findAnnotation(bridgedMethod, Reference.class); if (reference != null && method.equals(ClassUtils.getMostSpecificMethod(method, beanClass))) { if (Modifier.isStatic(method.getModifiers())) { if (logger.isWarnEnabled()) { logger.warn("@Reference annotation is not supported on static methods: " + method); } return; } if (method.getParameterTypes().length == 0) { if (logger.isWarnEnabled()) { logger.warn("@Reference annotation should only be used on methods with parameters: " + method); } } PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, beanClass); elements.add(new ReferenceMethodElement(method, pd, reference)); } } }); return elements; }
From source file:net.servicefixture.util.ReflectionUtils.java
public static String getDefaultValue(Class type) { if (isEnumarationPatternClass(type)) { StringBuilder sb = new StringBuilder(); Field[] fields = type.getFields(); for (int i = 0; i < fields.length; i++) { if (type.equals(fields[i].getType()) && Modifier.isFinal(fields[i].getModifiers()) && Modifier.isPublic(fields[i].getModifiers()) && Modifier.isStatic(fields[i].getModifiers())) { try { sb.append(fields[i].getName()).append(";"); } catch (IllegalArgumentException e) { }//from www . j a v a2 s . co m } } return sb.toString(); } else if (type.isEnum()) { StringBuilder sb = new StringBuilder(); try { Object[] array = (Object[]) type.getMethod("values").invoke(null); for (int i = 0; i < array.length; i++) { sb.append(array[i]).append(";"); } } catch (Exception e) { } return sb.toString(); } else if (Calendar.class.isAssignableFrom(type) || XMLGregorianCalendar.class.isAssignableFrom(type)) { return "${calendar.after(0)}"; } else if (Date.class.isAssignableFrom(type)) { return "${date.after(0)}"; } else if (Number.class.isAssignableFrom(type) || "long".equals(type.getName()) || "int".equals(type.getName()) || "short".equals(type.getName()) || "float".equals(type.getName()) || "double".equals(type.getName())) { return "0"; } else if (String.class.equals(type)) { return "String"; } else if (Boolean.class.equals(type) || "boolean".equals(type.getName())) { return "true"; } return type.getName(); }