Package org.exolab.castor.builder

Examples of org.exolab.castor.builder.SourceGenerator


import org.xml.sax.InputSource;

public class TestSourceGenerator extends TestCase {

    public void testGeneration() throws Exception {
        SourceGenerator generator = new SourceGenerator();
        String xmlSchema = getClass().getResource("test.xsd").toExternalForm();
        InputSource inputSource = new InputSource(xmlSchema);
        generator.setDestDir("./src/test/java");
        generator.setSuppressNonFatalWarnings(true);
       
        // uncomment the next line to set a binding file for source generation
//      generator.setBinding(new InputSource(getClass().getResource("binding.xml").toExternalForm()));

        // uncomment the next lines to set custom properties for source generation
//      Properties properties = new Properties();
//      properties.load(getClass().getResource("builder.properties").openStream());
//      generator.setDefaultProperties(properties);

        generator.generateSource(inputSource, getClass().getPackage().getName() + ".generated");
    }
View Full Code Here


import org.xml.sax.InputSource;

public class TestSourceGenerator extends TestCase {

    public void testGeneration() throws Exception {
        SourceGenerator generator = new SourceGenerator();
        String xmlSchema = getClass().getResource("test.xsd").toExternalForm();
        InputSource inputSource = new InputSource(xmlSchema);
        generator.setDestDir("./codegen/src/test/java");
        generator.setSuppressNonFatalWarnings(true);
       
        // uncomment to have JDO-specific class descriptors created
//        generator.setJdoDescriptorCreation(true);
       
        // uncomment to use Velocity for code generation
//        generator.setJClassPrinterType("velocity");
       
        // uncomment the next line to set a binding file for source generation
//      generator.setBinding(new InputSource(getClass().getResource("binding.xml").toExternalForm()));

        // uncomment the next lines to set custom properties for source generation
//      Properties properties = new Properties();
//      properties.load(getClass().getResource("builder.properties").openStream());
//      generator.setDefaultProperties(properties);

        generator.generateSource(inputSource, getClass().getPackage().getName() + ".generated");
    }
View Full Code Here

import org.xml.sax.InputSource;

public class TestSourceGenerator extends TestCase {

    public void testGeneration() throws Exception {
        SourceGenerator generator = new SourceGenerator();
        String xmlSchema = getClass().getResource("test.xsd").toExternalForm();
        InputSource inputSource = new InputSource(xmlSchema);
        generator.setDestDir("./codegen/src/test/java");
        generator.setSuppressNonFatalWarnings(true);
       
        // uncomment to have JDO-specific class descriptors created
//        generator.setJdoDescriptorCreation(true);
       
        // uncomment to use Velocity for code generation
//        generator.setJClassPrinterType("velocity");
       
        // uncomment the next line to set a binding file for source generation
//      generator.setBinding(new InputSource(getClass().getResource("binding.xml").toExternalForm()));

        // uncomment the next lines to set custom properties for source generation
//      Properties properties = new Properties();
//      properties.load(getClass().getResource("builder.properties").openStream());
//      generator.setDefaultProperties(properties);

        generator.generateSource(inputSource, getClass().getPackage().getName() + ".generated");
    }
View Full Code Here

        // 1. Run the source generator
        verbose("--> Running the source generator");

        try {
            final SourceGenerator sourceGen = createSourceGenerator();

            for (int i=0; i<_schemas.length; i++) {
                String schemaName = _schemas[i];
                File   schemaFile = new File(_outputRootFile, schemaName);

                if (!schemaFile.exists()) {
                    assertNotNull("Unable to find the schema: ", schemaName);
                }

                InputSource source = new InputSource(new FileReader(schemaFile));
                source.setSystemId(schemaFile.getAbsolutePath());
                sourceGen.generateSource(source, _package);
            }
        } catch (Exception e) {
            if (!checkExceptionWasExpected(e, FailureStepType.SOURCE_GENERATION)) {
                fail("Source Generator threw an Exception: " + e.getMessage());
            }
View Full Code Here

     * @throws IOException
     *             if any IOException occurs preparing the source generator.
     */
    private SourceGenerator createSourceGenerator() throws IOException {
        // Create our source generator
        final SourceGenerator sourceGen;
        if (_fieldInfoFactoryName != null) {
            FieldInfoFactory factory = new FieldInfoFactory(_fieldInfoFactoryName);
            sourceGen = new SourceGenerator(factory);
        } else {
            sourceGen = new SourceGenerator();
        }

        // Do we have a castorbuilder.properties file?
        if (_propertyFileName != null) {
            if (!(new File(_test.getTestFile(), _propertyFileName)).exists()) {
                fail("Test properties file '" + _propertyFileName + "' does not exist; check TestDescriptor.xml");
            }
            Properties prop = new Properties();
            prop.load(_test.getClassLoader().getResourceAsStream(_propertyFileName));
            sourceGen.setDefaultProperties(prop);
        } else {
            //don't forget to reset the properties
            sourceGen.setDefaultProperties(null);
        }

        // Do we have a binding file?
        if (_bindingFileName != null && _bindingFileName.length() >0) {
            File bindingFile = new File(_outputRootFile, _bindingFileName);

            if ( !bindingFile.exists()) {
                fail("Unable to find the specified binding file: " + _bindingFileName);
            }

            verbose("using binding file: " + bindingFile.getAbsolutePath());
            InputSource source = new InputSource(new FileReader(bindingFile));
            source.setSystemId(bindingFile.getAbsolutePath());
            sourceGen.setBinding(source);
        }

        // Final configuration of our source generator
        sourceGen.setEqualsMethod(true);
        sourceGen.setTestable(true);
        sourceGen.setSuppressNonFatalWarnings(true);
        sourceGen.setFailOnFirstError(true);
        sourceGen.setGenerateImportedSchemas(_genFromImported);
        sourceGen.setDestDir(_outputRootFile.getAbsolutePath());
        return sourceGen;
    }
View Full Code Here

    private String _cdrDirectoryName;
    private String _destDir = "./codegen/src/test/java";

    public final void setUp() throws Exception {
        super.setUp();
        _generator = new SourceGenerator();
        _generator.setDestDir(_destDir);
        _generator.setSuppressNonFatalWarnings(true);
        _generator.setJdoDescriptorCreation(true);
    }
View Full Code Here

            }
        } else {
            _lineSep = "\n"; // default
        }

        SourceGenerator sgen = null;
        if (_typeFactory != null) {
            try {
                Object factory = Class.forName(_typeFactory).newInstance();
                sgen = new SourceGenerator((FieldInfoFactory) factory);
            } catch (Exception ex) {
                project.log("Type factory " + _typeFactory + " is invalid.", Project.MSG_INFO);
                throw new BuildException(ex);
            }
        } else {
            // default
            sgen = new SourceGenerator();
        }

        sgen.setLineSeparator(_lineSep);
        sgen.setSuppressNonFatalWarnings(_force);
        sgen.setDestDir(_destDir.toString());
        if (_force) { project.log("Suppressing non fatal warnings.", Project.MSG_VERBOSE); }

        try {
            sgen.generateSource(_schema.getAbsolutePath(), _pkgName);
        } catch (IOException ex) {
            project.log("Failed to compile " + _schema, Project.MSG_INFO);
            throw new BuildException(ex);
        }
    }
View Full Code Here

            } else
                throw new BuildException("Invalid line-separator style.");
        } else
            lineSep = "\n"; // default

        SourceGenerator sgen = null;
        if (typeFactory != null) {
            try {
                sgen = new SourceGenerator((FieldInfoFactory)Class.forName(typeFactory).newInstance());
            } catch(Exception ex) {
                project.log("Type factory "+typeFactory+" is invalid.",project.MSG_INFO);
                throw new BuildException(ex);
            }
        } else {
            sgen = new SourceGenerator(); // default
        }
       
        sgen.setLineSeparator(lineSep);
        sgen.setSuppressNonFatalWarnings(force);
        sgen.setDestDir(destDir.toString());
        if (force)
            project.log("Suppressing non fatal warnings.",project.MSG_VERBOSE);
       
        try {
            sgen.generateSource(schema.getAbsolutePath(), pkgName);
        } catch(IOException ex) {
      project.log("Failed to compile " + schema,project.MSG_INFO);
            throw new BuildException(ex);
        }
    } //-- execute
View Full Code Here

TOP

Related Classes of org.exolab.castor.builder.SourceGenerator

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.