/** * Creates a new NestedProperty * * @param expression * @param property * @param path */ public NestedProperty(String expression, Property property, Property[] path) { super(expression,property.getName(),property.getGetter(),property.getSetter(),property.getType(),property.getElementType(), property.getContainer()); this.path = collapse(property.getPath(), path); this.tail = property; }
/** * @param owningProperty * @param elementProperty * @param resolver */ public NestedElementProperty(Property owningProperty, Property elementProperty, PropertyResolverStrategy resolver) { super(getElementExpression(owningProperty, elementProperty), elementProperty.getName(), elementProperty.getGetter(), elementProperty.getSetter(), elementProperty.getType(), elementProperty.getElementType(), initContainer(owningProperty, elementProperty.getExpression(), resolver) ); Property element = initElement(getContainer(), elementProperty.getExpression(), resolver); if (element == null) { element = elementProperty; } this.elementProperty = element; }
/** * @return a copy of this property instance */ public Property copy() { return copy(this.type); }
/** * @param aInverse * @return this FieldMapBuilder */ public FieldMapBuilder<A, B> aInverse(final String aInverse) { final Type<?> type = aProperty.isCollection() ? aProperty.getElementType() : aProperty.getType(); aInverseProperty = classMapBuilder.resolveProperty(type, aInverse); return this; }
protected static String getGetter(final Property property, String variableExpression) { if (property.getGetter() == null) return null; String var = variableExpression; if (property.hasPath()) { for (final Property p : property.getPath()) { var = getGetter(p, var); } } String getter = "((" + property.getType().getCanonicalName() + ")" + var; if (!property.isArrayElement() && !"".equals(property.getName()) && !property.getGetter().startsWith("[")) { getter += "." + property.getGetter() + ")"; } else { getter += property.getGetter() + ")"; } return getter; }
public boolean apply(FieldMap fieldMap) { return (fieldMap.getSource().isListElement() || fieldMap.getSource().isArrayElement()) && (fieldMap.getDestination().getType().isImmutable() || (!fieldMap.getDestination().isCollection() && !fieldMap.getDestination().isArray() && !fieldMap.getDestination().isMap() && !fieldMap.getDestination() .isEnum())); } };
public boolean apply(FieldMap fieldMap) { return fieldMap.getSource().isMapKey() && (fieldMap.getDestination().getType().isImmutable() || (!fieldMap.getDestination().isCollection() && !fieldMap.getDestination().isArray() && !fieldMap.getDestination().isMap() && !fieldMap.getDestination() .isEnum())); } };
/** * Returns a fully type-cast setter for the property which has no reliance * on java generics. * * @param property * the Property for which to return the getter * @param variableExpression * the String value to use for the variable on which the getter * is called * @return */ protected static String getSetter(final Property property, final String variableExpression) { if (property.getSetter() == null) return null; String var = variableExpression; if (property.hasPath()) { for (final Property p : property.getPath()) { var = getGetter(p, var); } } return var + (property.isArrayElement() || "".equals(property.getName()) || property.getSetter().startsWith("[") ? "" : ".") + property.getSetter(); }
@Test public void testAdHocResolution() { Property prop = propertyResolver.getProperty(A.class, "name:{readTheNameForThisBean|assignTheName}.firstName"); Assert.assertNotNull(prop); Assert.assertEquals("firstName", prop.getName()); Assert.assertEquals("name.firstName", prop.getExpression()); Assert.assertEquals(TypeFactory.valueOf(String.class), prop.getType()); }
public String toString() { return "[" + propertyA.getExpression() + ", " + propertyB.getExpression() + "] {\n" + " wordMatchScore: " + wordMatchScore + "\n" + " commonWordScore: " + commonWordsScore + "\n" + " containsScore: " + containsScore + "\n" + " typeMatchScore: " + typeMatchScore + "\n" + " ------------------- \n" + " total: " + score + "\n" + "}"; }
private Property root(Property prop) { Property root = prop; while (root.getContainer() != null) { root = root.getContainer(); } return root; }
public static Node findFieldMap(final FieldMap map, final NodeList nodes, boolean useSource) { LinkedList<Property> path = new LinkedList<Property>(); Property container = useSource ? map.getSource() : map.getDestination(); while (container.getContainer() != null) { path.addFirst(container.getContainer()); container = container.getContainer(); } Node currentNode = null; NodeList children = nodes; for (Property pathElement : path) { currentNode = null; for (Node node : children) { if (node.property.equals(pathElement)) { currentNode = node; children = currentNode.children; break; } } if (currentNode == null) { return null; } } for (Node node: children) { if (map.equals(node.value)) { return node; } } return null; }
@Test public void resolveProperties() { PropertyResolver propertyResolver = new IntrospectorPropertyResolver(); Property aliasesFirst = propertyResolver.getProperty(TypeFactory.valueOf(PersonDto.class), "aliases" + NESTED_OPEN + "[0]" + NESTED_CLOSE); Assert.assertNotNull(aliasesFirst); Assert.assertEquals(TypeFactory.valueOf(String.class), aliasesFirst.getType()); Assert.assertNotNull(aliasesFirst.getContainer()); Assert.assertEquals(TypeFactory.valueOf(String[][].class), aliasesFirst.getContainer().getType()); }
private static String isNull(Property property, String name) { if (property == null) { return name + " == null"; } else { String getterNull = getGetter(property, name) + " == null"; if (property.isListElement()) { return "(" + unwrap(getGetter(property, name)) + ".size() <= " + property.getName().replaceAll("[\\[\\]]", "") + " || " + getterNull + ")"; } else if (property.isArrayElement()) { return "(" + unwrap(getGetter(property, name)) + ".length <= " + property.getName().replaceAll("[\\[\\]]", "") + " || " + getterNull + ")"; } else { return getterNull; } } }
parentRef = destNode.parent.elementRef; if (isSelfOrParentComparison(destNode.parent, defaultParent)) { return new VariableRef(prop.getElement(), parentRef); } else { return null; } else if (prop.getContainer() != null) { parentRef = defaultParent.elementRef; return new VariableRef(parentRef.type(), parentRef.name()); if (propertyResolver.existsProperty(parentRef.type(), prop.getExpression())) { return new VariableRef(prop, defaultParent.elementRef); } else {
/** * @param fieldMap */ protected void addFieldMap(FieldMap fieldMap) { getMappedFields().add(fieldMap); getMappedPropertiesForTypeA().add(fieldMap.getSourceExpression()); getMappedPropertiesForTypeB().add(fieldMap.getDestinationExpression()); if (fieldMap.is(aManyToOneElementMap())) { getMappedPropertiesForTypeA().add(fieldMap.getSource().getContainer().getExpression()); } else if (fieldMap.is(aOneToManyElementMap())) { getMappedPropertiesForTypeB().add(fieldMap.getDestination().getContainer().getExpression()); } else if (fieldMap.is(aMultiOccurrenceElementMap())) { getMappedPropertiesForTypeA().add(fieldMap.getSource().getContainer().getExpression()); getMappedPropertiesForTypeB().add(fieldMap.getDestination().getContainer().getExpression()); } }
public VariableRef(Property property, String name) { this.name = name; this.property = property; this.type = property.getType(); }
public String name() { return property != null ? property.getName() : name; }
public boolean apply(FieldMap fieldMap) { return "class".equals(fieldMap.getSource().getName()) && "class".equals(fieldMap.getDestination().getName()) && Class.class.equals(fieldMap.getSource().getRawType()); } };
@Test public void testOverridePropertyDefinition() { Map<String, Property> properties = propertyResolver.getProperties(PostalAddress.class); Property city = properties.get("city"); Assert.assertNotNull(city.getSetter()); }