Package org.exolab.castor.builder

Examples of org.exolab.castor.builder.SourceGenerator$Property


      if ( level01.getDataItems()[i] instanceof ElementaryDataItem ) {
        ElementaryDataItem edi = (ElementaryDataItem)level01.getDataItems()[i];
        String attrName = edi.getDataName();
        DataField dataField = (DataField)edi.interpret();
        if (dataField != null) {
          Property attr = (Property)attrs.get(attrName);
          Type type = dataField.getType() == Integer.class ? integerType : stringType;
          if (attr == null) {
            String timestampFormat = "";
            String dateFormat = "";
            String length = "" + dataField.getLength();
            String fraction = "" + dataField.getFraction();
            System.out.println("INFO [jIvalo]  - Adding new attribute: " + attrName);
            Property newAttr = addAttribute(c, attrName, type, timestampFormat, dateFormat, length, fraction);
          }
          else {
            System.out.println("INFO [jIvalo]  - Updating new attribute: " + attrName);
            attr.setType(type);
            setTagValue(attr, "length", "" + dataField.getLength());
            setTagValue(attr, "fraction", "" + dataField.getFraction());
            attrs.remove(attrName);
          }
        }
      }
      else if ( level01.getDataItems()[i] instanceof GroupDataItem ) {
        GroupDataItem gdi = (GroupDataItem)level01.getDataItems()[i];
        String className = c.getName() + "_" + gdi.getDataName();
        Class cl = getClass(p, className);
        if (cl == null) {
          addClass(p, className);
          System.out.println("INFO [jIvalo] Added class: " + className);
          cl = getClass(p, className);
        }
        else {
          System.out.println("INFO [jIvalo] Updating existing class: " + className);
        }
       
        if (cl != null) {
          addAttributes(gdi, p, cl, model);
   
          Property newAttr = null;
          if ( level01.getDataItems()[i] instanceof GroupDataItemOccurs ) {
            GroupDataItemOccurs gdio = (GroupDataItemOccurs)level01.getDataItems()[i];
            newAttr = c.createOwnedAttribute(className,p.getOwnedType(cl.getName()),gdio.getOccurs(),gdio.getOccurs());
          }
          else {
            newAttr = c.createOwnedAttribute(className,p.getOwnedType(cl.getName()),1,1);
          }
          if (newAttr != null) {
            newAttr.setVisibility(VisibilityKind.PUBLIC_LITERAL);
            addStereotype(newAttr, jIvaloAttributeStereotype);
            setTagValue(newAttr, "timestampFormat", "");
            setTagValue(newAttr, "dateFormat", "");
            setTagValue(newAttr, "length", "0");
            setTagValue(newAttr, "fraction", "0");
View Full Code Here


    cobolResourceDir = Namespaces.instance().getNamespace(namespace).getProperty("cobolResourceDir").getValue();
    targetPackage = Namespaces.instance().getNamespace(namespace).getProperty("targetPackage").getValue();
   
    jIvaloPackage = getPackage(jIvaloPackageName, model);
    jIvaloClass = getClass(jIvaloPackage, jIvaloClassName);
    Property attribute1 = getAttribute(jIvaloClass, "string");
    stringType = attribute1.getType();
    Property attribute2 = getAttribute(jIvaloClass, "integer");
    integerType = attribute2.getType();

    jIvaloClassStereotype = getStereotype(jIvaloClass, jIvaloClassSteroetypeName);
    jIvaloAttributeStereotype = getStereotype(attribute1, jIvaloAttrSteroetypeName);

  }
View Full Code Here

    Repositories.instance().getImplementation(encoding).writeModel(element,
        outputLocation, xmiVersion);
  }

  private Property addAttribute(Class c, String name, Type type, String timestampFormat, String dateFormat, String length, String fraction) {
    Property p = c.createOwnedAttribute(name, type, 1, 1);
    p.setVisibility(VisibilityKind.PUBLIC_LITERAL);
    setTagValue(p, "timestampFormat", timestampFormat);
    setTagValue(p, "dateFormat", dateFormat);
    setTagValue(p, "length", length);
    setTagValue(p, "fraction", fraction);
    return p;
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("./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

TOP

Related Classes of org.exolab.castor.builder.SourceGenerator$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.