List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
From source file:com.pmarlen.model.controller.EntityJPAToPlainPojoTransformer.java
public static void copyPlainValues(Entity entity, Object plain) { final Class entityClass; entityClass = entity.getClass();/*from w w w .j av a2 s .c o m*/ final String entityClassName = entityClass.getName(); Hashtable<String, Object> propertiesToCopy = new Hashtable<String, Object>(); Hashtable<String, Object> propertiesM2MToCopy = new Hashtable<String, Object>(); List<String> propertiesWithNULLValueToCopy = new ArrayList<String>(); List<String> propertiesKey = new ArrayList<String>(); try { final Field[] declaredFields = entityClass.getDeclaredFields(); for (Field f : declaredFields) { logger.trace("->create: \tcopy: " + entityClassName + "." + f.getName() + " accesible ? " + (f.isAccessible())); if (!f.isAccessible()) { if (f.isAnnotationPresent(javax.persistence.Id.class)) { propertiesKey.add(f.getName()); } if (f.isAnnotationPresent(javax.persistence.Id.class) && !f.isAnnotationPresent(javax.persistence.GeneratedValue.class) && !Modifier.isStatic(f.getModifiers())) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t ID elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } else if (!f.isAnnotationPresent(javax.persistence.Id.class) && !f.isAnnotationPresent(javax.persistence.OneToMany.class) && !f.isAnnotationPresent(javax.persistence.ManyToMany.class) && !Modifier.isStatic(f.getModifiers())) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } else if (!f.isAnnotationPresent(javax.persistence.Id.class) && f.isAnnotationPresent(javax.persistence.ManyToMany.class)) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesM2MToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t M2M elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } } } logger.trace("->create:copy values ?"); for (String p2c : propertiesToCopy.keySet()) { Object valueCopyed = propertiesToCopy.get(p2c); logger.trace("->create:\t\t copy value with SpringUtils: " + p2c + " = " + valueCopyed + ", is null?" + (valueCopyed == null)); BeanUtils.copyProperty(plain, p2c, valueCopyed); } for (String p2c : propertiesWithNULLValueToCopy) { logger.trace("->create:\t\t copy null with SpringUtils"); BeanUtils.copyProperty(plain, p2c, null); } } catch (Exception e) { logger.error("..in copy", e); } }
From source file:ModifierUtil.java
public static boolean isStatic(Member member) { return Modifier.isStatic(member.getModifiers()); }
From source file:Debug.java
public static Debug getDebugLevel(Class cls) throws NoSuchFieldException { try {/* w ww .ja v a 2 s. co m*/ Field fld = cls.getField("debug"); if (fld.getType() != Debug.class || !Modifier.isStatic(fld.getModifiers())) throw new NoSuchFieldException(); return (Debug) fld.get(null); } catch (IllegalArgumentException e) { throw new NoSuchFieldException(); } catch (IllegalAccessException e) { throw new NoSuchFieldException(); } catch (SecurityException e) { throw new NoSuchFieldException(); } }
From source file:JarClassLoader.java
public void invokeClass(String name, String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException { Class c = loadClass(name);/*from w w w .j ava2 s . c o m*/ Method m = c.getMethod("main", new Class[] { args.getClass() }); m.setAccessible(true); int mods = m.getModifiers(); if (m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) { throw new NoSuchMethodException("main"); } try { m.invoke(null, new Object[] { args }); } catch (IllegalAccessException e) { } }
From source file:net.mindengine.blogix.BlogixMain.java
private static Method findCommandMethod(String name) { Method[] methods = BlogixMain.class.getDeclaredMethods(); for (Method method : methods) { if (Modifier.isStatic(method.getModifiers()) && method.getName().equals("cmd_" + name)) { return method; }//w w w. ja v a 2 s . co m } return null; }
From source file:ModifierUtil.java
public static boolean isStatic(Class<?> clazz) { return Modifier.isStatic(clazz.getModifiers()); }
From source file:net.servicestack.client.Utils.java
public static Field[] getSerializableFields(Class type) { List<Field> fields = new ArrayList<Field>(); for (Class<?> c = type; c != null; c = c.getSuperclass()) { if (c == Object.class) break; for (Field f : c.getDeclaredFields()) { if (Modifier.isStatic(f.getModifiers())) continue; if (!Modifier.isPublic(f.getModifiers())) continue; fields.add(f);// www.j av a 2 s . co m } } return fields.toArray(new Field[fields.size()]); }
From source file:Main.java
/** * Converts a color into a string. If the color is equal to one of the defined * constant colors, that name is returned instead. Otherwise the color is * returned as hex-string.//from w w w. j a v a2 s . c om * * @param c * the color. * @return the string for this color. */ public static String colorToString(final Color c) { try { final Field[] fields = Color.class.getFields(); for (int i = 0; i < fields.length; i++) { final Field f = fields[i]; if (Modifier.isPublic(f.getModifiers()) && Modifier.isFinal(f.getModifiers()) && Modifier.isStatic(f.getModifiers())) { final String name = f.getName(); final Object oColor = f.get(null); if (oColor instanceof Color) { if (c.equals(oColor)) { return name; } } } } } catch (Exception e) { // } // no defined constant color, so this must be a user defined color final String color = Integer.toHexString(c.getRGB() & 0x00ffffff); final StringBuffer retval = new StringBuffer(7); retval.append("#"); final int fillUp = 6 - color.length(); for (int i = 0; i < fillUp; i++) { retval.append("0"); } retval.append(color); return retval.toString(); }
From source file:de.codesourcery.eve.apiclient.cache.FilesystemResponseCacheTest.java
private static Method findMethod(Class<?> clasz, String name) { for (Method m : clasz.getDeclaredMethods()) { final int mods = m.getModifiers(); if (Modifier.isStatic(mods) || Modifier.isFinal(mods)) { continue; }/*from w w w . j a v a2 s. com*/ if (m.getName().equals(name)) { return m; } } return null; }
From source file:Main.java
/** * Force the given class to be loaded fully. * /* www. jav a 2 s. c o m*/ * <p> * This method attempts to locate a static method on the given class the * attempts to invoke it with dummy arguments in the hope that the virtual * machine will prepare the class for the method call and call all of the * static class initializers. * * @param type * Class to force load. * * @throws NullArgumentException * Type is <i>null</i>. */ public static void forceLoad(final Class type) { if (type == null) System.out.println("Null Argument Exception"); // don't attempt to force primitives to load if (type.isPrimitive()) return; // don't attempt to force java.* classes to load String packageName = Classes.getPackageName(type); // System.out.println("package name: " + packageName); if (packageName.startsWith("java.") || packageName.startsWith("javax.")) { return; } // System.out.println("forcing class to load: " + type); try { Method methods[] = type.getDeclaredMethods(); Method method = null; for (int i = 0; i < methods.length; i++) { int modifiers = methods[i].getModifiers(); if (Modifier.isStatic(modifiers)) { method = methods[i]; break; } } if (method != null) { method.invoke(null, (Object[]) null); } else { type.newInstance(); } } catch (Exception ignore) { ignore.printStackTrace(); } }