Skip to content

CastorCodeGenTask with binding.xml and wrapper=true not working for Boolean #77

@elendrim

Description

@elendrim

Hello,

I'm using ant integration (org.castor.anttask.CastorCodeGenTask) to generate Descriptor classes.
I'm using ant through gradle.
But I have an issue using binding.xml and wrapper="true" with a boolean.

ant gradle integration
build.gradle

    task castor(description: "Generate Java source files from XSD.", group: "build") {

	doLast() {

		def srcHome = "${projectDir}/src";

		ant.taskdef(name:"castorSrcgen",
					classname:"org.castor.anttask.CastorCodeGenTask",
					classpath:configurations.castorAnt.asPath )
					
		ant.castorSrcgen(file:"${srcHome}/config/edi/BaseTypes.xsd", bindingFile:"${srcHome}/config/edi/binding.xml",
				todir:"${srcHome}", package:"tea.edi.binding", types:"j2", warnings:"false", verbose:"true" )


	}
}

BaseType.xsd

<?xml version="1.0"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://TEA.Ecar.BaseSchemas" attributeFormDefault="unqualified" 
		elementFormDefault="qualified" targetNamespace="http://TEA.Ecar.BaseSchemas" xmlns:xs="http://www.w3.org/2001/XMLSchema">
	
	
	<xs:complexType name="CaracteristiquesVehicule">
		<xs:attribute name="priorite" type="xs:boolean" use="optional" />
		
	</xs:complexType>
	
</xs:schema>

binding.xml

    <binding defaultBindingType="type">
	  <namingXML>
		<elementName>
			<suffix>Elt</suffix>
		</elementName>
	</namingXML>
	
	<attributeBinding name="/complexType:CaracteristiquesVehicule/@priorite">
		<member wrapper="true" />
	</attributeBinding>
	
   </binding>

This will generated a CaracteristiquesVehiculeDescriptor like this :

//-- priorite
        desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(java.lang.Boolean.class, "priorite", "priorite", org.exolab.castor.xml.NodeType.Attribute);
        handler = new org.exolab.castor.xml.XMLFieldHandler() {
            @Override
            public java.lang.Object getValue( java.lang.Object object ) 
                throws IllegalStateException
            {
                CaracteristiquesVehicule target = (CaracteristiquesVehicule) object;
                return target.getPriorite();
            }
            @Override
            public void setValue( java.lang.Object object, java.lang.Object value) 
                throws IllegalStateException, IllegalArgumentException
            {
                try {
                    CaracteristiquesVehicule target = (CaracteristiquesVehicule) object;
                    // if null, use delete method for optional primitives 
                    if (value == null) {
                        target.deletePriorite();
                        return;
                    }
                    target.setPriorite( ((java.lang.Boolean) value));
                } catch (java.lang.Exception ex) {
                    throw new IllegalStateException(ex.toString());
                }
            }
            @Override
            @SuppressWarnings("unused")
            public java.lang.Object newInstance(java.lang.Object parent) {
                return null;
            }
        };
        desc.setSchemaType("boolean");
        desc.setHandler(handler);
        desc.setMultivalued(false);
        addFieldDescriptor(desc);

But, because we use "wrapper="true" target.deletePriorite(); doesn't exist in the CaracteristiquesVehicule class generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions