Package org.apache.torque.generator.configuration.controller

Examples of org.apache.torque.generator.configuration.controller.Output


        if (outletResult.isByteArrayResult())
        {
            // do nothing, no debugging for binary result
            return outletResult;
        }
        Output output = controllerState.getOutput();
        String lineBreak = output.getOrDetermineLineBreak(
                outletResult.getStringResult());
        String outputTypeString = output.getType();
        Map<String, OutputType> outputTypes
                = controllerState.getUnitConfiguration()
                    .getConfigurationHandlers()
                    .getOutputTypes();
        OutputType outputType = outputTypes.get(outputTypeString);
        if (outputType == null)
        {
            throw new GeneratorException("Unknown output type "
                    + outputTypeString
                    + " in output "
                    + output.getName());
        }
        String commentStart = outputType.getCommentStart(lineBreak);
        String commentAtStart = getCommentAtStart(controllerState);
        String commentAtEnd = getCommentAtEnd(controllerState);
        String commentEnd = outputType.getCommentEnd(lineBreak);
View Full Code Here


        {
            List<Output> outputFiles = unitConfiguration.getOutputList();
            assertEquals(3, outputFiles.size());

            {
                Output output = outputFiles.get(0);
                assertEquals(
                        new QualifiedName("org.apache.torque.generator.firstOutput"),
                        output.getName());
                assertEquals(
                        "skip",
                        output.getExistingTargetStrategy());
                assertEquals(
                        null,
                        output.getOutputDirKey());
                assertNull(output.getFilename());

                {
                    OutletReference outletConfiguration
                            = output.getContentOutlet();
                    assertEquals(
                            new QualifiedName(
                                "org.apache.torque.generator.test.readConfiguration.javaOutlet"),
                            outletConfiguration.getName());
                }

                {
                    JavaOutlet filenameOutlet
                            = (JavaOutlet) output.getFilenameOutlet();
                    assertEquals("Foo", filenameOutlet.getFoo());
                    assertEquals("Bar", filenameOutlet.getBar());
                    assertEquals(
                            new QualifiedName(
                                    "org.apache.torque.generator.configuration.filenameOutlet"),
                            filenameOutlet.getName());
                }

                {
                    Fileset sourceFileset = new Fileset(
                            projectPaths.getDefaultSourcePath(),
                            new HashSet<String>(),
                            new HashSet<String>());
                    FileSourceProvider sourceProvider = new FileSourceProvider(
                            new XmlSourceFormat(),
                            sourceFileset,
                            null);
                    sourceProvider.init(
                            configurationHandlers,
                            controllerState);
                    output.getSourceProvider().init(
                            configurationHandlers,
                            controllerState);
                    assertFileSourceProviderEquals(
                            sourceProvider,
                            (FileSourceProvider) output.getSourceProvider());
                }
                assertSourceProcessConfigurationEquals(
                        new SourceProcessConfiguration(),
                        output.getSourceProcessConfiguration());
            }

            {
                Output output = outputFiles.get(1);
                assertEquals(
                        new QualifiedName("secondOutput"),
                        output.getName());
                assertEquals(
                        "replace",
                        output.getExistingTargetStrategy());
                assertEquals(
                        "secondOutputDirKey",
                        output.getOutputDirKey());
                assertNull(output.getFilename());

                {
                    OutletReference outletConfiguration
                            = output.getContentOutlet();
                    assertEquals(
                            new QualifiedName(
                                "org.apache.torque.generator.test.readConfiguration.anotherOutlet"),
                            outletConfiguration.getName());
                }

                {
                    VelocityOutlet filenameOutlet
                            = (VelocityOutlet) output.getFilenameOutlet();
                    String templateContent
                            = filenameOutlet.getContent(controllerState);
                    // remove License from template by comparing only
                    // the last line
                    String templateContentLicenseRemoved
                            = StringUtils.substringAfterLast(templateContent, "\r\n");
                    assertEquals(
                            "test template output",
                            templateContentLicenseRemoved);
                    assertEquals(
                            new QualifiedName(
                                    "org.apache.torque.generator.configuration.filenameOutlet"),
                            filenameOutlet.getName());
                    assertTrue(filenameOutlet.isOptionsInContext());
                    assertTrue(filenameOutlet.isSourceAttributesInContext());
                    assertTrue(filenameOutlet.isVariablesInContext());
                }

                {
                    Fileset sourceFileset = new Fileset(
                            projectPaths.getDefaultSourcePath(),
                            createSetFrom("second.source.path.properties"),
                            createSetFrom("second.excluded.properties"));
                    FileSourceProvider sourceProvider = new FileSourceProvider(
                            new PropertiesSourceFormat(),
                            sourceFileset,
                            true);
                    sourceProvider.init(
                            configurationHandlers,
                            controllerState);
                    output.getSourceProvider().init(
                            configurationHandlers,
                            controllerState);
                    assertFileSourceProviderEquals(
                            sourceProvider,
                            (FileSourceProvider) output.getSourceProvider());
                }
                {
                    SourceProcessConfiguration sourceProcessConfiguration
                        = new SourceProcessConfiguration();
                    sourceProcessConfiguration.setStartElementsPath(
                            "properties/entry");
                    List<SourceTransformerDefinition> transformerDefinitions
                            = new ArrayList<SourceTransformerDefinition>();

                    transformerDefinitions.add(
                            new SourceTransformerDefinition(
                                    new ConfigurationTestTransformer(),
                                    null));
                    transformerDefinitions.add(
                            new SourceTransformerDefinition(
                                    new OtherConfigurationTestTransformer(),
                                    "database"));
                    sourceProcessConfiguration.setSourceTransformerDefinitions(
                            transformerDefinitions);
                    sourceProcessConfiguration.setSkipDecider(
                            "org.apache.torque.generator.configuration.ConfigurationTestSkipDecider");
                    assertSourceProcessConfigurationEquals(
                            sourceProcessConfiguration,
                            output.getSourceProcessConfiguration());
                }
            }
            {
                Output output = outputFiles.get(2);
                assertEquals(
                        new QualifiedName("thirdOutput"),
                        output.getName());
                assertEquals(
                        "append",
                        output.getExistingTargetStrategy());
                assertEquals(
                        "thirdOutputDirKey",
                        output.getOutputDirKey());
                assertEquals("outputFileName", output.getFilename());
                assertNull(output.getFilenameOutlet());

                {
                    OutletReference outletConfiguration
                            = output.getContentOutlet();
                    assertEquals(
                            new QualifiedName(
                                "org.apache.torque.generator.test.readConfiguration.thirdOutlet"),
                            outletConfiguration.getName());
                }

                {
                    JdbcMetadataSourceProvider sourceProvider
                            = new JdbcMetadataSourceProvider(
                                "jdbcUrl",
                                "jdbcDriver",
                                "jdbcUsername",
                                "jdbcPassword",
                                "jdbcSchema");
                    sourceProvider.init(
                            configurationHandlers,
                            controllerState);
                    output.getSourceProvider().init(
                            configurationHandlers,
                            controllerState);
                    assertJdbcMetadataSourceProviderEquals(
                            sourceProvider,
                            (JdbcMetadataSourceProvider) output.getSourceProvider());
                }
                assertSourceProcessConfigurationEquals(
                        new SourceProcessConfiguration(),
                        output.getSourceProcessConfiguration());
            }
        }

        {
            OutletConfiguration outletConfiguration
View Full Code Here

        {
            List<Output> outputList = unitConfiguration.getOutputList();
            assertEquals(4, outputList.size());

            {
                Output output = outputList.get(0);
                assertEquals(
                        new QualifiedName("parentOutput"),
                        output.getName());
                assertEquals(
                        "replace",
                        output.getExistingTargetStrategy());
                assertEquals(
                        "parentOutputDirKeyFromParent",
                        output.getOutputDirKey());
                assertNull(output.getFilename());
                {
                    OutletReference outletConfiguration
                            = output.getContentOutlet();
                    assertEquals(
                            new QualifiedName(
                                "org.apache.torque.generator.test.readConfiguration.testParentOutlet"),
                            outletConfiguration.getName());
                }
                {
                    JavaOutlet filenameOutlet
                            = (JavaOutlet) output.getFilenameOutlet();
                    assertEquals("ParentFoo", filenameOutlet.getFoo());
                    assertEquals("ParentBar", filenameOutlet.getBar());
                    assertEquals(
                            new QualifiedName(
                                    "org.apache.torque.generator.configuration.filenameOutlet"),
                            filenameOutlet.getName());
                }

                {
                    Fileset sourceFileset = new Fileset(
                            projectPaths.getDefaultSourcePath(),
                            createSetFrom("parentSource"),
                            new HashSet<String>());
                    FileSourceProvider sourceProvider = new FileSourceProvider(
                            new XmlSourceFormat(),
                            sourceFileset,
                            false);
                    output.getSourceProvider().init(
                            configurationHandlers,
                            controllerState);
                    sourceProvider.init(
                            configurationHandlers,
                            controllerState);
                    assertFileSourceProviderEquals(
                            sourceProvider,
                            (FileSourceProvider) output.getSourceProvider());
                }
                {
                    SourceProcessConfiguration sourceProcessConfiguration
                        = new SourceProcessConfiguration();
                    sourceProcessConfiguration.setStartElementsPath("parentSourceElement");
                    List<SourceTransformerDefinition> transformerDefinitions
                            = new ArrayList<SourceTransformerDefinition>();

                    transformerDefinitions.add(
                            new SourceTransformerDefinition(
                                    new OtherConfigurationTestTransformer(),
                                    "parent/database"));
                    sourceProcessConfiguration.setSourceTransformerDefinitions(
                            transformerDefinitions);
                    sourceProcessConfiguration.setSkipDecider(
                            "org.apache.torque.generator.configuration.OtherConfigurationTestSkipDecider");
                    assertSourceProcessConfigurationEquals(
                            sourceProcessConfiguration,
                            output.getSourceProcessConfiguration());
                }
            }
            {
                Output output = outputList.get(1);
                assertEquals(
                        new QualifiedName("org.apache.torque.generator.firstOutput"),
                        output.getName());
                assertEquals(
                        "skip",
                        output.getExistingTargetStrategy());
                assertEquals(
                        null,
                        output.getOutputDirKey());
                assertNull(output.getFilename());

                {
                    OutletReference outletConfiguration
                            = output.getContentOutlet();
                    assertEquals(
                            new QualifiedName(
                                "org.apache.torque.generator.test.readConfiguration.javaOutlet"),
                            outletConfiguration.getName());
                }
                {
                    JavaOutlet filenameOutlet
                            = (JavaOutlet) output.getFilenameOutlet();
                    assertEquals("Foo", filenameOutlet.getFoo());
                    assertEquals("Bar", filenameOutlet.getBar());
                    assertEquals(
                            new QualifiedName(
                                    "org.apache.torque.generator.configuration.filenameOutlet"),
                            filenameOutlet.getName());
                }

                {
                    Fileset sourceFileset = new Fileset(
                            projectPaths.getDefaultSourcePath(),
                            new HashSet<String>(),
                            new HashSet<String>());
                    FileSourceProvider sourceProvider = new FileSourceProvider(
                            new XmlSourceFormat(),
                            sourceFileset,
                            null);
                    sourceProvider.init(
                            configurationHandlers,
                            controllerState);
                    output.getSourceProvider().init(
                            configurationHandlers,
                            controllerState);
                    assertFileSourceProviderEquals(
                            sourceProvider,
                            (FileSourceProvider) output.getSourceProvider());
                }
                assertSourceProcessConfigurationEquals(
                        new SourceProcessConfiguration(),
                        output.getSourceProcessConfiguration());
            }

            {
                Output output = outputList.get(2);
                assertEquals(
                        new QualifiedName("secondOutput"),
                        output.getName());
                assertEquals(
                        "replace",
                        output.getExistingTargetStrategy());
                assertEquals(
                        output.getOutputDirKey(),
                        "secondOutputDirKey");
                assertNull(output.getFilename());

                {
                    OutletReference outletConfiguration
                            = output.getContentOutlet();
                    assertEquals(
                            new QualifiedName(
                                "org.apache.torque.generator.test.readConfiguration.anotherOutlet"),
                            outletConfiguration.getName());
                }
                {
                    VelocityOutlet filenameOutlet
                            = (VelocityOutlet) output.getFilenameOutlet();
                    String templateContent
                            = filenameOutlet.getContent(controllerState);
                    // remove License from template by comparing only
                    // the last line
                    String templateContentLicenseRemoved
                            = StringUtils.substringAfterLast(templateContent, "\r\n");
                    assertEquals(
                            "test template output",
                            templateContentLicenseRemoved);
                    assertEquals(
                            new QualifiedName(
                                    "org.apache.torque.generator.configuration.filenameOutlet"),
                            filenameOutlet.getName());
                }

                {
                    Fileset sourceFileset = new Fileset(
                            projectPaths.getDefaultSourcePath(),
                            createSetFrom("second.source.path.properties"),
                            createSetFrom("second.excluded.properties"));
                    FileSourceProvider sourceProvider = new FileSourceProvider(
                            new PropertiesSourceFormat(),
                            sourceFileset,
                            true);
                    sourceProvider.init(
                            configurationHandlers,
                            controllerState);
                    output.getSourceProvider().init(
                            configurationHandlers,
                            controllerState);
                    assertFileSourceProviderEquals(
                            sourceProvider,
                            (FileSourceProvider) output.getSourceProvider());
                }
                {
                    SourceProcessConfiguration sourceProcessConfiguration
                        = new SourceProcessConfiguration();
                    sourceProcessConfiguration.setStartElementsPath("properties/entry");
                    List<SourceTransformerDefinition> transformerDefinitions
                            = new ArrayList<SourceTransformerDefinition>();
                    transformerDefinitions.add(
                            new SourceTransformerDefinition(
                                    new ConfigurationTestTransformer(),
                                    null));
                    transformerDefinitions.add(
                            new SourceTransformerDefinition(
                                    new OtherConfigurationTestTransformer(),
                                    "database"));
                    sourceProcessConfiguration.setSourceTransformerDefinitions(
                            transformerDefinitions);
                    sourceProcessConfiguration.setSkipDecider(
                        "org.apache.torque.generator.configuration.ConfigurationTestSkipDecider");
                    assertSourceProcessConfigurationEquals(
                            sourceProcessConfiguration,
                            output.getSourceProcessConfiguration());
                }
            }
            {
                Output output = outputList.get(3);
                assertEquals(
                        new QualifiedName("thirdOutput"),
                        output.getName());
                assertEquals(
                        "append",
                        output.getExistingTargetStrategy());
                assertEquals(
                        "thirdOutputDirKey",
                        output.getOutputDirKey());
                assertEquals("outputFileName", output.getFilename());
                assertNull(output.getFilenameOutlet());

                {
                    OutletReference outletConfiguration
                            = output.getContentOutlet();
                    assertEquals(
                            new QualifiedName(
                                "org.apache.torque.generator.test.readConfiguration.thirdOutlet"),
                            outletConfiguration.getName());
                }

                {
                    JdbcMetadataSourceProvider sourceProvider
                            = new JdbcMetadataSourceProvider(
                                "jdbcUrl",
                                "jdbcDriver",
                                "jdbcUsername",
                                "jdbcPassword",
                                "jdbcSchema");
                    sourceProvider.init(
                            configurationHandlers,
                            controllerState);
                    output.getSourceProvider().init(
                            configurationHandlers,
                            controllerState);
                    assertJdbcMetadataSourceProviderEquals(
                            sourceProvider,
                            (JdbcMetadataSourceProvider) output.getSourceProvider());
                }
                assertSourceProcessConfigurationEquals(
                        new SourceProcessConfiguration(),
                        output.getSourceProcessConfiguration());
            }
        }

        {
            OutletConfiguration outletConfiguration
View Full Code Here

    public SourceElement transform(
            SourceElement root,
            ControllerState controllerState)
        throws SourceTransformerException
    {
        Output output = controllerState.getOutput();
        log.debug("adding all sources of output " + output.getName()
                + " to current source tree at element " + addTo);
        // the element where the additional source should be anchored.
        SourceElement addToSourceElement;
        List<SourceElement> sourceElementList
                = SourcePath.getElementsFromRoot(root, addTo);
        if (sourceElementList.isEmpty())
        {
            throw new SourceTransformerException(
                    "Source element " + addTo + " does not exist");
        }
        addToSourceElement = sourceElementList.get(0);


        UnitConfiguration unitConfiguration
                = controllerState.getUnitConfiguration();
        ConfigurationHandlers configurationHandlers
                = unitConfiguration.getConfigurationHandlers();
        Controller helperController = new Controller();

        SourceElement newSourceElement = new SourceElement(newElement);
        boolean newSourceElementAdded = false;
        try
        {
            // do not change state of original source provider,
            // instead make a copy.
            SourceProvider sourceProvider
                    = controllerState.getSourceProvider().copy();
            sourceProvider.init(configurationHandlers, controllerState);

            while (sourceProvider.hasNext())
            {
                Source source = sourceProvider.next();
                SourceElement rootElement = source.getRootElement();
                SourceProcessConfiguration sourceProcessConfiguration
                    = output.getSourceProcessConfiguration();
                List<SourceTransformerDefinition> transformerDefinitions
                    = sourceProcessConfiguration.getTransformerDefinitions();
                transformerDefinitions
                        = new ArrayList<SourceTransformerDefinition>
                             (transformerDefinitions);
View Full Code Here

TOP

Related Classes of org.apache.torque.generator.configuration.controller.Output

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.