Search in sources :

Example 1 with IsSetFieldRenderer

use of com.sun.tools.xjc.generator.bean.field.IsSetFieldRenderer in project jaxb-ri by eclipse-ee4j.

the class BIProperty method wrapUp.

/**
 * Common finalization of {@link CPropertyInfo} for the create***Property methods.
 */
private <T extends CPropertyInfo> T wrapUp(T prop, XSComponent source) {
    prop.javadoc = concat(javadoc, getBuilder().getBindInfo(source).getDocumentation());
    if (prop.javadoc == null)
        prop.javadoc = "";
    // decide the realization.
    FieldRenderer r;
    OptionalPropertyMode opm = getOptionalPropertyMode();
    if (prop.isCollection()) {
        CollectionTypeAttribute ct = getCollectionType();
        r = ct.get(getBuilder().model);
    } else {
        FieldRendererFactory frf = getBuilder().fieldRendererFactory;
        // according to the spec we should bahave as in jaxb1. So we ignore possiblity that property could be nullable
        switch(opm) {
            // the property type can be primitive type if we are to ignore absence
            case PRIMITIVE:
                r = frf.getRequiredUnboxed();
                break;
            case WRAPPER:
                // force the wrapper type
                r = prop.isOptionalPrimitive() ? frf.getSingle() : frf.getDefault();
                break;
            case ISSET:
                r = prop.isOptionalPrimitive() ? frf.getSinglePrimitiveAccess() : frf.getDefault();
                break;
            default:
                throw new Error();
        }
    }
    if (opm == OptionalPropertyMode.ISSET) {
        // only isSet is allowed on a collection. these 3 modes aren't really symmetric.
        // if the property is a primitive type, we need an explicit unset because
        // we can't overload the meaning of set(null).
        // if it's a collection, we need to be able to unset it so that we can distinguish
        // null list and empty list.
        r = new IsSetFieldRenderer(r, prop.isOptionalPrimitive() || prop.isCollection(), true);
    }
    prop.realization = r;
    JType bt = getBaseType();
    if (bt != null)
        prop.baseType = bt;
    return prop;
}
Also used : FieldRenderer(com.sun.tools.xjc.generator.bean.field.FieldRenderer) IsSetFieldRenderer(com.sun.tools.xjc.generator.bean.field.IsSetFieldRenderer) IsSetFieldRenderer(com.sun.tools.xjc.generator.bean.field.IsSetFieldRenderer) FieldRendererFactory(com.sun.tools.xjc.generator.bean.field.FieldRendererFactory) JType(com.sun.codemodel.JType)

Aggregations

JType (com.sun.codemodel.JType)1 FieldRenderer (com.sun.tools.xjc.generator.bean.field.FieldRenderer)1 FieldRendererFactory (com.sun.tools.xjc.generator.bean.field.FieldRendererFactory)1 IsSetFieldRenderer (com.sun.tools.xjc.generator.bean.field.IsSetFieldRenderer)1