Package ma.glasnost.orika.metadata

Examples of ma.glasnost.orika.metadata.Property


    @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());
    }
View Full Code Here


    @Test
    public void testParameterizedPropertyUtil() {
       
        Type<?> t = new TypeBuilder<TestEntry<Holder<Long>, Holder<String>>>() {}.build();
        PropertyResolverStrategy propertyResolver = UtilityResolver.getDefaultPropertyResolverStrategy();
        Property p = propertyResolver.getNestedProperty(t, "key.held");
        Assert.assertEquals(p.getType().getRawType(), Long.class);
        Assert.assertEquals(p.getType(), TypeFactory.valueOf(Long.class));
       
        Map<String, Property> properties = propertyResolver.getProperties(t);
        Assert.assertTrue(properties.containsKey("key"));
        Assert.assertEquals(properties.get("key").getType(), new TypeBuilder<Holder<Long>>() {}.build());
    }
View Full Code Here

   
   
    @Test
    public void testGetter() {
    
        Property prop = UtilityResolver.getDefaultPropertyResolverStrategy().getProperty(Year.class, "months{days{dayOfWeek}}");
        Assert.assertNotNull(prop);
        Assert.assertNotNull(prop.getContainer());
        Assert.assertNotNull(prop.getContainer().getContainer());
       
    }
View Full Code Here

        }
        return comparator.toString();
    }
   
    private Property root(Property prop) {
        Property root = prop;
        while (root.getContainer() != null) {
            root = root.getContainer();
        }
        return root;
    }
View Full Code Here

        for (Node child: children) {
            if (child.value != null) {
               
                int depth = 0;
                FieldMap value = child.value;
                Property prop = isSource ? value.getSource() : value.getDestination();
                while (prop.getContainer() != null) {
                    ++depth;
                    prop = prop.getContainer();
                }
               
                if (!nodes.containsKey(Integer.valueOf(depth))) {
                    nodes.put(Integer.valueOf(depth), value);
                }
View Full Code Here

        return out.toString();
    }
   
    public static Node findFieldMap(final FieldMap map, final NodeList nodes, boolean useSource) {
        LinkedList<Property> path = new LinkedList<Property>();
        Property root = useSource ? map.getSource() : map.getDestination();
        Property container = root;
        while (container.getContainer() != null) {
            path.addFirst(container.getContainer());
            container = container.getContainer();
        }
        Node currentNode = null;
        NodeList children = nodes;
       
        for(int p = 0, len=path.size(); p < len; ++p) {
            Property pathElement = path.get(p);
            currentNode = null;
            for (Node node: children) {
                if (node.property.equals(pathElement)) {
                   currentNode = node;
                   children = currentNode.children;
View Full Code Here

        return null;
    }
   
    public static Node addFieldMap(final FieldMap map, final NodeList nodes, boolean useSource) {
        LinkedList<Property> path = new LinkedList<Property>();
        Property root = useSource ? map.getSource() : map.getDestination();
        Property container = root;
       
        while (container.getContainer() != null) {
            path.addFirst(container.getContainer());
            container = container.getContainer();
        }
        /*
         * Attempt to locate the path within the tree of nodes
         * under which this fieldMap should be placed
         */
        Node currentNode = null;
        Node parentNode = null;
        NodeList children = nodes;
       
        for(int p = 0, len=path.size(); p < len; ++p) {
            Property pathElement = path.get(p);
           
            for (Node node: children) {
                if (node.property.equals(pathElement)) {
                   currentNode = node;
                   children = currentNode.children;
View Full Code Here

           
        return currentNode;
    }
   
    private static Property innermostElement(final Property p) {
        Property result = p;
        while (result.getElement() != null) {
            result = result.getElement();
        }
        return result;
    }
View Full Code Here

     * @throws MappingException
     *             if the expression cannot be resolved to a property for the
     *             type
     */
    protected Property getProperty(java.lang.reflect.Type type, String expr, boolean isNestedLookup, Property owner) throws MappingException {
        Property property = null;
       
        if (isSelfReferenceExpression(expr)) {
            property = new Property.Builder().name("").getter("").setter(" = %s").type(TypeFactory.valueOf(type)).container(owner).build(this);
        } else if (isNestedPropertyExpression(expr) && !isElementPropertyExpression(expr)) {
            property = getNestedProperty(type, expr, owner);
        } else if (isElementPropertyExpression(expr)) {
            property = getElementProperty(type, expr, owner);
        } else if (isIndividualElementExpression(expr)) {
            property = getIndividualElementProperty(type, expr, owner);
        } else {
            // TODO: perhaps in-line properties should be isolated to a given
            // ClassMapBuilder instance, rather than made available for other
            // mappings
            // of the class; can this cause problems?
            Map<String, Property> inlinePoperties = inlinePropertiesCache.get(type);
            if (inlinePoperties != null) {
                property = inlinePoperties.get(expr);
            }
            if (property == null) {
                Map<String, Property> properties = getProperties(type);
                if (properties.containsKey(expr)) {
                    property = properties.get(expr);
                } else if (isInlinePropertyExpression(expr)) {
                    property = resolveInlineProperty(type, expr);
                    if (property != null) {
                        synchronized (type) {
                            if (inlinePoperties == null) {
                                inlinePoperties = new HashMap<String, Property>(1);
                                inlinePropertiesCache.put(type, inlinePoperties);
                            }
                            inlinePoperties.put(property.getName(), property);
                        }
                    }
                } else {
                    throw new MappingException(expr + " does not belong to " + type);
                }
View Full Code Here

                }
            }
        }
          
        for (Entry<String, Property.Builder> entry: collectedMethods.entrySet()) {
            Property property = entry.getValue().build(this);
            processProperty(property.getName(), property.getType().getRawType(), entry.getValue().getReadMethod(), entry.getValue().getWriteMethod(), type, referenceType, properties);
        }
       
        if (includeJavaBeans) {
            super.collectProperties(type, referenceType, properties);
        }
View Full Code Here

TOP

Related Classes of ma.glasnost.orika.metadata.Property

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.