[ 
http://jira.codehaus.org/browse/JIBX-390?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=262979#action_262979
 ] 

John Landers commented on JIBX-390:
-----------------------------------

In case anyone can't wait here is a quick change to the code.
It doesn't handle all the possible types but string and number.
Add code changes below and build jibx-tools.jar

org.jibx.schema.codegen.Item.java
add field: 
    protected String m_default;
add to constructor:
        if ( comp.type() == SchemaBase.ATTRIBUTE_TYPE )
        {
                m_default = ((AttributeElement)comp).getDefault();
        }
        if ( comp.type() == SchemaBase.ELEMENT_TYPE )
        {
                m_default = ((ElementElement)comp).getDefault();
        }
Add method:
    public String getDefault() {
        return m_default;
    }

Then to org.jibx.schema.codegen.StructureClassHolder.java
in method addSimpleProperty after line:
        FieldBuilder field = builder.addField(fname, type);
add these lines (only works for string and number types):
        if ( node.getItem().getDefault() != null )
        {
                if ( type.equals(String.class.getName() ))
                {
                        field.setStringInitializer(node.getItem().getDefault());
                }
                else // assume number but could cause exception add check for 
number type. 
                {
                        field.setNumberInitializer(node.getItem().getDefault());
                }
        }



> CodeGen generates default initialisation in POJO
> ------------------------------------------------
>
>                 Key: JIBX-390
>                 URL: http://jira.codehaus.org/browse/JIBX-390
>             Project: JiBX
>          Issue Type: Improvement
>          Components: CodeGen
>    Affects Versions: JiBX 1.2.2
>            Reporter: James Cowan
>
> As per email below.
> List:       jibx-users
> Subject:    Re: [jibx-users] CodeGen - attribute default value
> From:       Dennis Sosnoski <dms () sosnoski ! com>
> Date:       2009-06-20 23:52:18
> Message-ID: 4A3D7632.8080509 () sosnoski ! com
> [Download message RAW]
> Hi Alex,
> Yes, the default="..." is currently ignored by the code generation from 
> schema. It should be pretty easy to implement, and if you'll add a Jira 
> to get this in the tracking system I'll make sure it's corrected for the 
> 1.2.2 release (now planned for early July).
>   - Dennis
> Dennis M. Sosnoski
> XML and Web Services in Java
> Training and Consulting
> http://www.sosnoski.com - http://www.sosnoski.co.nz
> Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
> Alexander Ziller wrote:
> > Hello all
> >
> > I m trying to replace our prior XML binding framework JAXB with JiBX since
> > it's WAY faster. I only have a few problems so far, most of them are easily
> > solved. But no this one:
> >
> > When using CodeGen, could it be, that it ignores default values of
> > attributes?
> >
> > Example:
> >
> >  * Schema fragment(s) for this class:
> >  * <pre>
> >  * ....
> >  *     &lt;xs:attribute type="xs:string" default="true" name="enabled"/>
> >  * ....
> >
> > The class gets initialized with start value NULL for the field "enabled"
> > instead of TRUE. Is this a missing feature?
> >
> > I would have to rewrite half of our code because JAXB seems to recognize
> > this feature and acts accordingly.
> >
> > Regards
> >
> > Alex
> >
> >

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
jibx-devs mailing list
jibx-devs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-devs

Reply via email to