/** * Returns a new or cached BeanPropertyAccessor for the given class. */ public static <B> BeanPropertyAccessor<B> forClass(Class<B> clazz) { return forClass(clazz, PropertySet.ALL); }
public static <B> BeanPropertyAccessor<B> forClass(Class<B> clazz, PropertySet set) { synchronized (cAccessors) { Map<Class, SoftReference<BeanPropertyAccessor>> accessors = cAccessors.get(set); if (accessors == null) { accessors = new WeakIdentityMap<Class, SoftReference<BeanPropertyAccessor>>(); cAccessors.put(set, accessors); } BeanPropertyAccessor bpa; SoftReference<BeanPropertyAccessor> ref = accessors.get(clazz); if (ref != null) { bpa = ref.get(); if (bpa != null) { return bpa; } } bpa = generate(clazz, set); accessors.put(clazz, new SoftReference<BeanPropertyAccessor>(bpa)); return bpa; } }
private static RuntimeClassFile generateClassFile(Class beanType, PropertySet set) { BeanProperty[][] props = getBeanProperties(beanType, set); RuntimeClassFile cf = new RuntimeClassFile (BeanPropertyAccessor.class.getName(), BeanPropertyAccessor.class.getName(), beanType.getClassLoader()); cf.markSynthetic(); cf.setSourceFile(BeanPropertyAccessor.class.getName()); try { cf.setTarget(System.getProperty("java.specification.version")); } catch (Exception e) { } MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, null); ctor.markSynthetic(); CodeBuilder b = new CodeBuilder(ctor); b.loadThis(); b.invokeSuperConstructor(null); b.returnVoid(); generateAccessMethod(cf, beanType, props[0], READ_METHOD); generateAccessMethod(cf, beanType, props[0], TRY_READ_METHOD); generateAccessMethod(cf, beanType, props[0], HAS_READ_METHOD); generateAccessMethod(cf, beanType, props[1], WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], TRY_WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], HAS_WRITE_METHOD); generateSearchMethod(cf, beanType, props[0]); return cf; }
if (property.getReadMethod() == null || property.getWriteMethod() == null || BeanPropertyAccessor.throwsCheckedException(property.getReadMethod()) || BeanPropertyAccessor.throwsCheckedException(property.getWriteMethod())) } else { factory = new Standard<B> (BeanPropertyAccessor.forClass (clazz, BeanPropertyAccessor.PropertySet.READ_WRITE_UNCHECKED_EXCEPTIONS), supportedProperties);
int[] cases = new int[hashCapacity(properties.length)]; int caseCount = cases.length; for (int i=0; i<caseCount; i++) { List[] caseMethods = caseMethods(caseCount, properties);
@Override public boolean containsKey(Object key) { return mAccessor.hasReadableProperty((String) key); }
@Override public boolean containsValue(Object value) { return mAccessor.hasPropertyValue(mBean, value); }
@Override public boolean containsValue(Object value) { for (String key : keySet()) { Object propValue = mAccessor.getPropertyValue(mBean, key); if (propValue == null) { if (value == null) { return true; } } else if (propValue.equals(value)) { return true; } } return false; }
if (property.getReadMethod() == null || property.getWriteMethod() == null || BeanPropertyAccessor.throwsCheckedException(property.getReadMethod()) || BeanPropertyAccessor.throwsCheckedException(property.getWriteMethod())) } else { factory = new Standard<B> (BeanPropertyAccessor.forClass (clazz, BeanPropertyAccessor.PropertySet.READ_WRITE_UNCHECKED_EXCEPTIONS), supportedProperties);
int[] cases = new int[hashCapacity(properties.length)]; int caseCount = cases.length; for (int i=0; i<caseCount; i++) { List[] caseMethods = caseMethods(caseCount, properties);
@Override public boolean containsKey(Object key) { if (key == null) { return false; } String strKey = (String) key; if (mFromKey != null && mFromKey.compareTo(strKey) > 0) { return false; } if (mToKey != null && mToKey.compareTo(strKey) <= 0) { return false; } return mAccessor.hasReadableProperty(strKey); }
@Override public boolean containsValue(Object value) { return mAccessor.hasPropertyValue(mBean, value); }
@Override public boolean containsValue(Object value) { for (String key : keySet()) { Object propValue = mAccessor.getPropertyValue(mBean, key); if (propValue == null) { if (value == null) { return true; } } else if (propValue.equals(value)) { return true; } } return false; }
private static RuntimeClassFile generateClassFile(Class beanType, PropertySet set) { BeanProperty[][] props = getBeanProperties(beanType, set); RuntimeClassFile cf = new RuntimeClassFile (BeanPropertyAccessor.class.getName(), BeanPropertyAccessor.class.getName(), beanType.getClassLoader()); cf.markSynthetic(); cf.setSourceFile(BeanPropertyAccessor.class.getName()); cf.setTarget("1.5"); MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, null); ctor.markSynthetic(); CodeBuilder b = new CodeBuilder(ctor); b.loadThis(); b.invokeSuperConstructor(null); b.returnVoid(); generateAccessMethod(cf, beanType, props[0], READ_METHOD); generateAccessMethod(cf, beanType, props[0], TRY_READ_METHOD); generateAccessMethod(cf, beanType, props[0], HAS_READ_METHOD); generateAccessMethod(cf, beanType, props[1], WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], TRY_WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], HAS_WRITE_METHOD); generateSearchMethod(cf, beanType, props[0]); return cf; }
@Override public boolean containsKey(Object key) { return mAccessor.hasReadableProperty((String) key); }
/** * Returns a new or cached BeanPropertyAccessor for the given class. */ public static <B> BeanPropertyAccessor<B> forClass(Class<B> clazz) { return forClass(clazz, PropertySet.ALL); }
public static <B> BeanPropertyAccessor<B> forClass(Class<B> clazz, PropertySet set) { synchronized (cAccessors) { Cache<Class, SoftReference<BeanPropertyAccessor>> accessors = cAccessors.get(set); if (accessors == null) { accessors = new WeakIdentityCache<Class, SoftReference<BeanPropertyAccessor>>(17); cAccessors.put(set, accessors); } BeanPropertyAccessor bpa; SoftReference<BeanPropertyAccessor> ref = accessors.get(clazz); if (ref != null) { bpa = ref.get(); if (bpa != null) { return bpa; } } bpa = generate(clazz, set); accessors.put(clazz, new SoftReference<BeanPropertyAccessor>(bpa)); return bpa; } }
@Override public boolean containsKey(Object key) { if (key == null) { return false; } String strKey = (String) key; if (mFromKey != null && mFromKey.compareTo(strKey) > 0) { return false; } if (mToKey != null && mToKey.compareTo(strKey) <= 0) { return false; } return mAccessor.hasReadableProperty(strKey); }