Package org.andromda.core.mapping

Examples of org.andromda.core.mapping.Mapping


                final Collection mappings = mergeMappings.getMappings();
                if ((mappings != null) && !mappings.isEmpty())
                {
                    for (final Iterator mappingsIterator = mappings.iterator(); mappingsIterator.hasNext();)
                    {
                        final Mapping mapping = (Mapping)mappingsIterator.next();
                        final Collection froms = mapping.getFroms();

                        if (froms != null && !froms.isEmpty())
                        {
                            for (final Iterator fromsIterator = froms.iterator(); fromsIterator.hasNext();)
                            {
                                final String from = StringUtils.trimToEmpty((String)fromsIterator.next());
                                if (StringUtils.isNotEmpty(from) && string.contains(from))
                                {
                                    final String to = mapping.getTo() != null ? mapping.getTo().trim() : "";
                                    string = StringUtils.replace(string, from, to);
                                }
                            }
                        }
                    }
View Full Code Here


    private static final String FROM_6 = "Class<? extends FromType>";

    public void testGetTo()
    {
        Mappings mappings1 = new Mappings();
        Mapping mapping1 = new Mapping();
        mapping1.setTo(TO_1);
        mapping1.addFrom(FROM_1);
        mapping1.addFrom(FROM_2);
        mapping1.addFrom(FROM_3);
        mapping1.addFrom(FROM_4);
        mappings1.addMapping(mapping1);
        TypeMappings typeMappings1 = TypeMappings.getInstance(mappings1);

        // make sure the to == from when passing in a mappings1 that don't exist
        assertNotNull(typeMappings1.getTo(NOT_MAPPED_1));
        assertEquals(NOT_MAPPED_1, typeMappings1.getTo(NOT_MAPPED_1));
        assertEquals(typeMappings1.getTo(NOT_MAPPED_2), typeMappings1.getTo(NOT_MAPPED_2));

        // make sure we can retrieve the to using a from array.
        assertNotNull(typeMappings1.getTo(FROM_1));
        assertEquals(TO_1, typeMappings1.getTo(FROM_1));

        // make sure we can retrieve the to using a from non array.
        assertEquals(TO_1, typeMappings1.getTo(FROM_4));

        Mappings mappings2 = new Mappings();
        Mapping mapping2 = new Mapping();
        mapping2.setTo(TO_2);
        mapping2.addFrom(FROM_5);
        mappings2.addMapping(mapping2);
        TypeMappings typeMappings2 = TypeMappings.getInstance(mappings2);
        typeMappings2.setArraySuffix(ARRAY_SUFFIX);

        assertEquals(TO_2, typeMappings2.getTo(FROM_5));
        assertEquals(TO_2 + ARRAY_SUFFIX, typeMappings2.getTo(FROM_5 + ARRAY_SUFFIX));

        Mappings mappings3 = new Mappings();
        Mapping mapping3 = new Mapping();
        mapping3.setTo(TO_3);
        mapping3.addFrom(FROM_6);
        mappings3.addMapping(mapping3);
        TypeMappings typeMappings3 = TypeMappings.getInstance(mappings3);
        // make sure whitespace isn't deleted, only trimmed (Java generics would fail compilation otherwise for example)
        assertEquals(
            TO_3,
View Full Code Here

        String to = null;

        // first we check to see if there's an array
        // type mapping directly defined in the mappings
        Mapping mapping = this.mappings.getMapping(from);
        if (mapping == null && arraySuffix != null)
        {
            // if there is no mapping, remove the array suffix and
            // check for the mapping without the suffix.
            // if the from has an array suffix, then strip the array off
            // so we can find the mapping
            boolean isArray = from.endsWith(arraySuffix);
            if (isArray)
            {
                from = StringUtils.replace(from, arraySuffix, "");
            }
            mapping = this.mappings.getMapping(from);
            if (mapping != null)
            {
                StringBuffer toBuffer = new StringBuffer(mapping.getTo());
                if (isArray)
                {
                    // append the suffix back to the return value;
                    toBuffer.append(arraySuffix);
                }
                to = toBuffer.toString();
            }
        }
        else if (mapping != null)
        {
            to = mapping.getTo();
        }

        if (to == null)
        {
            to = initialFrom;
View Full Code Here

    private static final String FROM_6 = "Class<? extends FromType>";

    public void testGetTo()
    {
        Mappings mappings1 = new Mappings();
        Mapping mapping1 = new Mapping();
        mapping1.setTo(TO_1);
        mapping1.addFrom(FROM_1);
        mapping1.addFrom(FROM_2);
        mapping1.addFrom(FROM_3);
        mapping1.addFrom(FROM_4);
        mappings1.addMapping(mapping1);

        // make sure the to == from when passing in a mappings1 that don't exist
        assertNotNull(mappings1.getTo(NOT_MAPPED_1));
        assertEquals(
            NOT_MAPPED_1,
            mappings1.getTo(NOT_MAPPED_1));
        assertEquals(
            mappings1.getTo(NOT_MAPPED_2),
            mappings1.getTo(NOT_MAPPED_2));

        // make sure we can retrieve the to using a from array.
        assertNotNull(mappings1.getTo(FROM_1));
        assertEquals(
            TO_1,
            mappings1.getTo(FROM_1));

        // make sure we can retrieve the to using a from non array.
        assertEquals(
            TO_1,
            mappings1.getTo(FROM_4));

        Mappings mappings2 = new Mappings();
        Mapping mapping2 = new Mapping();
        mapping2.setTo(TO_2);
        mapping2.addFrom(FROM_5);
        mappings2.addMapping(mapping2);
        assertEquals(
            TO_2,
            mappings2.getTo(FROM_5));

        Mappings mappings3 = new Mappings();
        Mapping mapping3 = new Mapping();
        mapping3.setTo(TO_3);
        mapping3.addFrom(FROM_6);
        mappings3.addMapping(mapping3);
        // make sure whitespace isn't deleted, only trimmed (Java generics would fail compilation otherwise for example)
        assertEquals(
            TO_3,
            mappings3.getTo(FROM_6));
View Full Code Here

        final Collection mappings1 = testMappingsParent.getMappings();
        assertEquals(
            3,
            mappings1.size());
        final Iterator mappings1Iterator = mappings1.iterator();
        Mapping mapping1 = (Mapping)mappings1Iterator.next();
        assertEquals(
            "datatype::typeOne",
            mapping1.getFroms().iterator().next());
        assertEquals(
            "Type_One",
            mapping1.getTo());
        Mapping mapping2 = (Mapping)mappings1Iterator.next();
        assertEquals(
            "datatype::typeTwo",
            mapping2.getFroms().iterator().next());
        assertEquals(
            "Type_Two",
            mapping2.getTo());
        Mapping mapping3 = (Mapping)mappings1Iterator.next();
        assertEquals(
            "datatype::typeThree",
            mapping3.getFroms().iterator().next());
        assertEquals(
            "Type_Three",
            mapping3.getTo());

        final URL testMappingsUri = MappingsTest.class.getResource("TestMappings.xml");
        assertNotNull(testMappingsUri);
        Mappings testMappings = Mappings.getInstance(testMappingsUri);
        assertNotNull(testMappings);
        final Collection mappings2 = testMappings.getMappings();
        assertEquals(
            4,
            mappings2.size());
        final Iterator mappings2Iterator = mappings2.iterator();
        mapping1 = (Mapping)mappings2Iterator.next();
        assertEquals(
            "datatype::typeOne",
            mapping1.getFroms().iterator().next());
        assertEquals(
            "Type_One",
            mapping1.getTo());
        mapping2 = (Mapping)mappings2Iterator.next();
        assertEquals(
            "datatype::typeTwo",
            mapping2.getFroms().iterator().next());
        assertEquals(
            "Overridden",
            mapping2.getTo());
        mapping3 = (Mapping)mappings2Iterator.next();
        assertEquals(
            "datatype::typeThree",
            mapping3.getFroms().iterator().next());
        assertEquals(
            "Type_Three",
            mapping3.getTo());
        Mapping mapping4 = (Mapping)mappings2Iterator.next();
        assertEquals(
            "datatype::typeFour",
            mapping4.getFroms().iterator().next());
        assertEquals(
            "Type_Four",
            mapping4.getTo());
    }
View Full Code Here

        Mappings.initializeLogicalMappings();

        final Mappings mappings = Mappings.getInstance("TestMappingsExtendsLevelD");
        assertNotNull(mappings);

        final Mapping aaa = mappings.getMapping("datatype::aaa");
        assertNotNull(aaa);
        assertEquals("AAA", aaa.getTo());

        final Mapping bbb = mappings.getMapping("datatype::bbb");
        assertNotNull(bbb);
        assertEquals("BBB", bbb.getTo());

        final Mapping ccc = mappings.getMapping("datatype::ccc");
        assertNotNull(ccc);
        assertEquals("CCC", ccc.getTo());

        final Mapping ddd = mappings.getMapping("datatype::ddd");
        assertNotNull(ddd);
        assertEquals("DDD", ddd.getTo());
    }
View Full Code Here

                String name = type.getName();
                String pack = type.getPackage().getName();
               
                String datatype = pack+"::"+name;

                Mapping mapping = maps.getMapping( datatype );
               
                sqlType = mapping.getTo();
            }
        }
       
        return sqlType;
    }
View Full Code Here

                String name = tempType.getName();
                String pack = tempType.getPackage().getName();
               
                String datatype = pack+"::"+name;

                Mapping mapping = maps.getMapping( datatype );
               
                jdbcType = mapping.getTo();
            }
        }
        return jdbcType;
    }
View Full Code Here

           
            if ( maps != null )
            {
                String datatype = "datatype::String";

                Mapping mapping = maps.getMapping( datatype );
               
                sqlType = mapping.getTo();
            }
        }
       
        return sqlType;
    }
View Full Code Here

                String name = type.getName();
                String pack = type.getPackage().getName();
               
                String datatype = pack+"::"+name;

                Mapping mapping = maps.getMapping( datatype );
               
                sqlType = mapping.getTo();
            }
        }
       
        return sqlType;
    }
View Full Code Here

TOP

Related Classes of org.andromda.core.mapping.Mapping

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.