/** * Looks up a list of {@link PropertyAccessor} for a particular object. * * <p>This method will return all accessors that is capable of handling the object and xpath * expression provided, no order is guaranteed. * * @param object The target object. * @param xpath An xpath expression denoting a property of the target object. * @param hints Hints to pass on to factories. * @return List of Property accessors, or <code>null</code> if object is null */ public static List<PropertyAccessor> findPropertyAccessors( Object object, String xpath, Class target, Hints hints) { if (object == null) return null; List<PropertyAccessor> list = new ArrayList<PropertyAccessor>(); for (PropertyAccessorFactory factory : FACTORY_CACHE) { PropertyAccessor accessor = factory.createPropertyAccessor(object.getClass(), xpath, target, hints); if (accessor != null && accessor.canHandle(object, xpath, target)) { list.add(accessor); } } return list; } }
/** * Looks up a {@link PropertyAccessor} for a particular object. * * <p>This method will return the first accessor that is capabile of handling the object and * xpath expression provided, no order is guaranteed. * * @param object The target object. * @param xpath An xpath expression denoting a property of the target object. * @param hints Hints to pass on to factories. * @return A property accessor, or <code>null</code> if one could not be found. * @deprecated Use findPropertyAccessors, returned property accessor might not work * @see findPropertyAccessors */ public static PropertyAccessor findPropertyAccessor( Object object, String xpath, Class target, Hints hints) { if (object == null) return null; for (PropertyAccessorFactory factory : FACTORY_CACHE) { PropertyAccessor accessor = factory.createPropertyAccessor(object.getClass(), xpath, target, hints); if (accessor != null && accessor.canHandle(object, xpath, target)) { return accessor; } } return null; }
public void testCanHandleType() { assertTrue(accessor.canHandle(type, "foo", null)); assertTrue(accessor.canHandle(type, "sf:foo", null)); assertTrue(accessor.canHandle(type, "foo[1]", null)); assertTrue(accessor.canHandle(type, "sf:foo[1]", null)); assertTrue(accessor.canHandle(type, "bar", null)); assertTrue(accessor.canHandle(type, COMPLEX_PROPERTY, null)); assertFalse(accessor.canHandle(type, "illegal", null)); assertFalse(accessor.canHandle(type, "sf:foo[0]", null)); assertFalse(accessor.canHandle(type, "sf:foo[2]", null)); }
|| !accessor.canHandle(obj, attPath, target) || !tryAccessor(accessor, obj, target, value, e)) { boolean success = false;
public void testGet() { assertEquals(Integer.valueOf(1), accessor.get(feature, "foo", null)); assertEquals(Integer.valueOf(1), accessor.get(feature, "sf:foo", null)); assertEquals(Integer.valueOf(1), accessor.get(feature, "foo[1]", null)); assertEquals(Integer.valueOf(1), accessor.get(feature, "sf:foo[1]", null)); assertEquals(new Double(2.0), accessor.get(feature, "bar", null)); assertEquals(new Double(3.0), accessor.get(feature, COMPLEX_PROPERTY, null)); assertEquals( "fid", SimpleFeaturePropertyAccessorFactory.FID_ACCESS.get(feature, "@id", null)); assertEquals( "fid", SimpleFeaturePropertyAccessorFactory.FID_ACCESS.get(feature, "@gml:id", null)); assertFalse(accessor.canHandle(feature, "illegal", null)); assertNull(accessor.get(feature, "illegal", null)); }
PropertyAccessor accessor = factory.createPropertyAccessor(object.getClass(), xpath, target, hints); if (accessor != null && accessor.canHandle(object, xpath, target)) { list.add(accessor);
PropertyAccessor accessor = factory.createPropertyAccessor(object.getClass(), xpath, target, hints); if (accessor != null && accessor.canHandle(object, xpath, target)) { return accessor;
PropertyAccessor accessor = factory.createPropertyAccessor(object.getClass(), xpath, target, hints); if (accessor != null && accessor.canHandle(object, xpath, target)) { return accessor;
private PropertyAccessor getPropertyAccessor(Object obj, Class target) { if(lastAccessor == null) lastAccessor = PropertyAccessors.findPropertyAccessor( obj, attPath, target, hints ); else if(!lastAccessor.canHandle(obj, attPath, target)) lastAccessor = PropertyAccessors.findPropertyAccessor( obj, attPath, target, hints ); return lastAccessor; }
AtomicReference<Exception> e = new AtomicReference<Exception>(); if (accessor == null || !accessor.canHandle(obj, attPath, target) || !tryAccessor(accessor, obj, target, value, e)) { boolean success = false;