Package org.apache.torque.generator.source

Examples of org.apache.torque.generator.source.SourceElement$ChildList


     */
    private void addForeignFieldInBean(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement localTable = foreignKey.getParent();
        String referencedBySuffix = getForeignReferencedBySuffix(
                foreignKey, controllerState);
        // the field name to create the name of the bean getter and setter
        String beanGetterSetterFieldName
                = (String) localTable.getAttribute(
                        TableAttributeName.BEAN_CLASS_NAME)
                    + referencedBySuffix;

        // the field name for the variable used
        String foreignFieldInBeanName
                = (String) controllerState.getOption(
                        TemplateOptionName.OM_FOREIGN_FIELD_NAME_PREFIX)
                    + localTable.getAttribute(
                            TableAttributeName.BEAN_CLASS_NAME)
                    + controllerState.getOption(
                            TemplateOptionName.OM_FOREIGN_FIELD_NAME_SUFFIX)
                    + referencedBySuffix;
        SourceElement foreignFieldInBeanElement
                = new SourceElement(
                    ForeignKeyChildElementName.FOREIGN_FIELD_IN_BEAN);

        foreignFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.FIELD_NAME,
                foreignFieldInBeanName);
        foreignFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.FIELD_ACCESS_MODIFIER,
                "protected");

        String fieldContainedType = (String) localTable.getAttribute(
                TableAttributeName.BEAN_CLASS_NAME);
        foreignFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.FIELD_CONTAINED_TYPE,
                fieldContainedType);

        String fieldType = (String) controllerState.getOption(
                TemplateOptionName.OM_FOREIGN_FIELD_TYPE)
                + "<" + fieldContainedType + ">";
        foreignFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.FIELD_TYPE,
                fieldType);

        {
            String initType = (String) controllerState.getOption(
                    TemplateOptionName.OM_FOREIGN_FIELD_INIT_TYPE)
                    + "<" + fieldContainedType + ">";
            foreignFieldInBeanElement.setAttribute(
                    JavaFieldAttributeName.INITIALIZER_TYPE,
                    initType);
        }

        foreignFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.DEFAULT_VALUE,
                "null");
        {
            String getterName = FieldHelper.getGetterName(
                        beanGetterSetterFieldName,
                        fieldType,
                        controllerState)
                    + "s";
            foreignFieldInBeanElement.setAttribute(
                    JavaFieldAttributeName.GETTER_NAME,
                    getterName);
        }
        {
            String setterName = FieldHelper.getSetterName(
                        beanGetterSetterFieldName)
                    + "s";
            foreignFieldInBeanElement.setAttribute(
                    JavaFieldAttributeName.SETTER_NAME,
                        setterName);
        }
        foreignKey.getChildren().add(foreignFieldInBeanElement);
    }
View Full Code Here


            = new File("src/test/resources/org/apache/torque/generator/source/xml/source.xml");
        FileSource fileSource = new FileSource(
                new XmlSourceFormat(),
                xmlFile,
                controllerState);
        SourceElement rootElement = fileSource.getRootElement();

        String result = new SourceToXml().toXml(rootElement, true);
        String expected = FileUtils.readFileToString(new File(
                "src/test/resources/org/apache/torque/generator/source/xml/sourceToXmlResult.xml"));
        // remove license from expected file
View Full Code Here

                "src/test/resources/org/apache/torque/generator/source/xml/source.xml");
        FileSource fileSource = new FileSource(
                new XmlSourceFormat(),
                xmlFile,
                controllerState);
        SourceElement rootElement = fileSource.getRootElement();
        rootElement.getChildren().get(2).getChildren().add(
                rootElement.getChildren().get(0).getChildren().get(0));

        String result = new SourceToXml().toXml(rootElement, true);
        String expected = FileUtils.readFileToString(new File(
                "src/test/resources/org/apache/torque/generator/source/xml/sourceToXmlWithReferenceResult.xml"));
        // remove license from expected file
View Full Code Here

    }

    @Test
    public void testSourceToXmlTextEscaping() throws Exception
    {
        SourceElement rootElement = new SourceElement("root");
        rootElement.setAttribute((String) null, "X&<>Y'\"Z");
        String result = new SourceToXml().toXml(rootElement, true);
        assertEquals(
                "<root id=\"1\">X&amp;&lt;&gt;Y&apo;&quot;Z</root>\n",
                result);
    }
View Full Code Here

    @Test
    public void testExecute() throws Exception
    {
        JdbcMetadataSource source
                = new JdbcMetadataSource(DRIVER, URL, null, null, null);
        SourceElement rootElement = source.createRootElement();
        assertEquals("database", rootElement.getName());
        List<SourceElement> tableElements = rootElement.getChildren();
        assertEquals(2, tableElements.size());
        for (SourceElement tableElement : tableElements)
        {
            assertEquals("table", tableElement.getName());
            Object tableName = tableElement.getAttribute("name");
            if ("AUTHOR".equals(tableName))
            {
                List<SourceElement> columnElements
                        = tableElement.getChildren();
                assertEquals(2, columnElements.size());
                for (SourceElement columnElement : columnElements)
                {
                    assertEquals("column", columnElement.getName());
                    Object columnName = columnElement.getAttribute("name");
                    if ("AUTHOR_ID".equals(columnName))
                    {
                        assertEquals(
                                "true",
                                columnElement.getAttribute("primaryKey"));
                        assertNull(columnElement.getAttribute("required"));
                        assertEquals(
                                "INTEGER",
                                columnElement.getAttribute("type"));
                        assertNull(columnElement.getAttribute("size"));
                        assertNull(columnElement.getAttribute("scale"));
                        // do not check default value as it is currently
                        // not generated correctly
                        // assertNull(columnElement.getAttribute("default"));
                    }
                    else if ("NAME".equals(columnName))
                    {
                        assertNull(columnElement.getAttribute("primaryKey"));
                        assertEquals(
                                "true",
                                columnElement.getAttribute("required"));
                        assertEquals(
                                "VARCHAR",
                                columnElement.getAttribute("type"));
                        assertEquals(
                                "50",
                                columnElement.getAttribute("size"));
                        assertNull(columnElement.getAttribute("scale"));
                        assertNull(columnElement.getAttribute("default"));
                    }
                    else
                    {
                        fail("Unknown column : " + columnName);
                    }
                }
            }
            else if ("BOOK".equals(tableName))
            {
                assertEquals(5, tableElement.getChildren().size());
                List<SourceElement> columnElements
                        = tableElement.getChildren("column");
                assertEquals(4, columnElements.size());
                for (SourceElement columnElement : columnElements)
                {
                    assertEquals("column", columnElement.getName());
                    Object columnName = columnElement.getAttribute("name");
                    if ("BOOK_ID".equals(columnName))
                    {
                        assertEquals(
                                "true",
                                columnElement.getAttribute("primaryKey"));
                        assertNull(columnElement.getAttribute("required"));
                        assertEquals(
                                "INTEGER",
                                columnElement.getAttribute("type"));
                        assertNull(columnElement.getAttribute("size"));
                        assertNull(columnElement.getAttribute("scale"));
                        // do not check default value as it is currently
                        // not generated correctly
                        // assertNull(columnElement.getAttribute("default"));
                    }
                    else if ("ISBN".equals(columnName))
                    {
                        assertNull(columnElement.getAttribute("primaryKey"));
                        assertNull(columnElement.getAttribute("required"));
                        assertEquals(
                                "VARCHAR",
                                columnElement.getAttribute("type"));
                        assertEquals(
                                "15",
                                columnElement.getAttribute("size"));
                        assertNull(columnElement.getAttribute("scale"));
                        assertNull(columnElement.getAttribute("default"));
                    }
                    else if ("AUTHOR_ID".equals(columnName))
                    {
                        assertNull(columnElement.getAttribute("primaryKey"));
                        assertEquals(
                                "true",
                                columnElement.getAttribute("required"));
                        assertEquals(
                                "INTEGER",
                                columnElement.getAttribute("type"));
                        assertNull(columnElement.getAttribute("size"));
                        assertNull(columnElement.getAttribute("scale"));
                        assertNull(columnElement.getAttribute("default"));
                    }
                    else if ("TITLE".equals(columnName))
                    {
                        assertNull(columnElement.getAttribute("primaryKey"));
                        assertEquals(
                                "true",
                                columnElement.getAttribute("required"));
                        assertEquals(
                                "VARCHAR",
                                columnElement.getAttribute("type"));
                        assertEquals(
                                "255",
                                columnElement.getAttribute("size"));
                        assertNull(columnElement.getAttribute("scale"));
                        assertEquals(
                                "no title",
                                columnElement.getAttribute("default"));
                    }
                    else
                    {
                        fail("Unknown column : " + columnName);
                    }
                }
                List<SourceElement> foreignKeyElements
                        = tableElement.getChildren("foreign-key");
                assertEquals(1, foreignKeyElements.size());
                SourceElement foreignKeyElement = foreignKeyElements.get(0);
                assertEquals(
                        "AUTHOR",
                        foreignKeyElement.getAttribute("foreignTable"));
            }
            else
            {
                fail("Unknown table : " + tableName);
            }
View Full Code Here

    }

    @Test
    public void testSourceToXmlAttributeEscaping() throws Exception
    {
        SourceElement rootElement = new SourceElement("root");
        rootElement.setAttribute("attribute", "&<>'\"");
        String result = new SourceToXml().toXml(rootElement, true);
        assertEquals(
                "<root attribute=\"&amp;&lt;&gt;&apo;&quot;\" id=\"1\"/>\n",
                result);
    }
View Full Code Here

    }

    @Test
    public void testSourceToXmlNoAutomaticIds() throws Exception
    {
        SourceElement rootElement = new SourceElement("root");
        rootElement.getChildren().add(new SourceElement("child"));
        String result = new SourceToXml().toXml(rootElement, false);
        assertEquals(
                "<root>\n  <child/>\n</root>\n",
                result);
    }
View Full Code Here

            "src/test/resources/org/apache/torque/generator/source/xml/source.xml");
        FileSource fileSource = new FileSource(
                new XmlSourceFormat(),
                xmlFile,
                controllerState);
        SourceElement rootElement = fileSource.getRootElement();

        assertEquals("root", rootElement.getName());
        assertEquals(1, rootElement.getAttributeNames().size());
        assertEquals(
                "rootElementAttributeValue",
                rootElement.getAttribute("rootElementAttribute"));
        assertEquals(4, rootElement.getChildren().size());
        SourceElement child1 = rootElement.getChildren().get(0);
        SourceElement child2 = rootElement.getChildren().get(1);
        SourceElement child3 = rootElement.getChildren().get(2);
        SourceElement child4 = rootElement.getChildren().get(3);

        assertEquals(1, child1.getChildren().size());
        assertEquals(0, child2.getChildren().size());
        assertEquals(1, child3.getChildren().size());
        assertEquals(0, child4.getChildren().size());

        assertEquals("secondLevelElement1", child1.getName());
        assertEquals("secondLevelElement2", child2.getName());
        assertEquals("secondLevelElement3", child3.getName());
        assertEquals("secondLevelElement4", child4.getName());

        assertEquals(0, child1.getAttributeNames().size());
        SourceElement tlElement1 = child1.getChildren().get(0);
        assertEquals("thirdLevelElement1", tlElement1.getName());
        assertEquals(1, tlElement1.getAttributeNames().size());
        assertEquals("tlaValue", tlElement1.getAttribute("tla"));

        assertEquals(0, child2.getAttributeNames().size());

        assertEquals(2, child3.getAttributeNames().size());
        assertEquals("slaValue", child3.getAttribute("sla"));
        assertEquals(
                " text For Second Level Element 3 ",
                child3.getAttribute((String) null));
        SourceElement tlElement2 = child3.getChildren().get(0);
        assertEquals("thirdLevelElement2", tlElement2.getName());
        assertEquals(1, tlElement2.getAttributeNames().size());
        assertEquals("tla2Value", tlElement2.getAttribute("tla2"));

        assertEquals(1, child4.getAttributeNames().size());
        assertEquals(
                "  text For Second Level Element 4  ",
                child4.getAttribute((String) null));
View Full Code Here

                + "sourceConformingWithSchema.xml");
        FileSource fileSource = new FileSource(
                new XmlSourceFormat(),
                xmlFile,
                controllerState);
        SourceElement rootElement = fileSource.getRootElement();
        assertEquals("value", rootElement.getAttribute("attribute"));
    }
View Full Code Here

    }

    @Test
    public void testNoPrefixSuffix() throws SourceTransformerException
    {
        SourceElement sourceElement
                = new SourceElement("elementName");
        sourceElement.setAttribute("name", "vaL_ue");

        transformer.setTargetAttributeName("targetAttribute");
        SourceElement result = transformer.transform(sourceElement, null);
        assertEquals("vaLUe", result.getAttribute("targetAttribute"));
    }
View Full Code Here

TOP

Related Classes of org.apache.torque.generator.source.SourceElement$ChildList

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.