@Nullable public static MethodProperty getMethodPropertyOrNull(Method method, MappedClass declaringClass) { try { return new MethodProperty(method, declaringClass); } catch (IllegalArgumentException e) { return null; } }
public MethodProperty(Method method, Annotation[] annotations, MappedClass declaringClass) { super(getPropertyName(method), annotations, declaringClass); this.method = method; if (method.getName().startsWith("set")) { getter = false; } else { getter = true; } }
@Override public boolean isVirtual() { return getSetter() == null; }
@Nullable private Method getSetter() { Method setter = null; if (!getter) { setter = method; } else { Class<?> clazz = method.getDeclaringClass(); Class<?> type = getType(); if (boolean.class.equals(type) || Boolean.class.equals(type)) { try { setter = clazz.getDeclaredMethod("is" + capitalize(getName()), type); } catch (SecurityException e) { // ignore } catch (NoSuchMethodException e) { // ignore } } if (setter == null) { try { setter = clazz.getDeclaredMethod("get" + capitalize(getName()), type); } catch (SecurityException e) { // ignore } catch (NoSuchMethodException e) { // ignore } } } return setter; }
@Override public void setValue(BeanMap beanMap, Object value) { beanMap.put(getName(), value); }
@Nullable private MappedPath getPathMapping(String classNs, Method method, MappedClass declaringClass) { MethodProperty property = MethodProperty.getMethodPropertyOrNull(method, declaringClass); if (property != null) { List<MappedPredicate> path = getPredicatePath(classNs, property); return getMappedPath(property, path); } else { return null; } }
@Override public Object getValue(BeanMap instance) { return instance.get(getName()); }
@Test public void ToString() throws SecurityException, NoSuchMethodException { Configuration configuration = new DefaultConfiguration(TEST.NS, MappedPathTest.class); MappedClass mappedClass = configuration.getMappedClass(MappedPathTest.class); MethodProperty property = new MethodProperty(MappedPathTest.class.getMethod("getProperty"), mappedClass); MappedPredicate predicate = new MappedPredicate(TEST.NS, new DummyPredicate(RDF.type), null); MappedPath path = new MappedPath(property, Collections.<MappedPredicate> singletonList(predicate), false); assertEquals("public java.lang.String com.mysema.rdfbean.object.MappedPathTest.getProperty() { http://www.w3.org/1999/02/22-rdf-syntax-ns#type }", path.toString()); }