Java Code Examples for javax.xml.bind.annotation.XmlNsForm#UNQUALIFIED

The following examples show how to use javax.xml.bind.annotation.XmlNsForm#UNQUALIFIED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractField.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 2
Source File: AbstractField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String mostUsedURI = parent()._package().getMostUsedNamespaceURI();
    String propName = prop.getName(false);

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(mostUsedURI)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (parent().parent().getModel().options.runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 3
Source File: AbstractField.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 4
Source File: AbstractField.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 5
Source File: AbstractField.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 6
Source File: AbstractField.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 7
Source File: AbstractField.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 8
Source File: AbstractField.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 9
Source File: AbstractField.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);

    String enclosingTypeNS;

    if(parent().target.getTypeName()==null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example 10
Source File: PackageOutlineImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}
 
Example 11
Source File: PackageOutlineImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}
 
Example 12
Source File: PackageOutlineImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}
 
Example 13
Source File: PackageOutlineImpl.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}
 
Example 14
Source File: PackageOutlineImpl.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}
 
Example 15
Source File: PackageOutlineImpl.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}
 
Example 16
Source File: PackageOutlineImpl.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}
 
Example 17
Source File: PackageOutlineImpl.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calculate the element form defaulting.
 *
 * Compare the most frequently used property URI to the most frequently used
 * element/type URI.  If they match, then return QUALIFIED
 */
private XmlNsForm getFormDefault() {
    if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
    else return XmlNsForm.QUALIFIED;
}