Java Code Examples for javax.xml.bind.annotation.XmlValue

The following examples show how to use javax.xml.bind.annotation.XmlValue. These examples are extracted from open source projects. 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 Project: proarc   Source File: TaskParameter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@XmlValue
/* Jackson 2.0 ignores @XmlValue for methods and thus @JsonProperty. */
@JsonProperty
public String getValue() {
    String value = null;
    if (valueType == ValueType.NUMBER) {
        BigDecimal n = getValueNumber();
        value = n == null ? null : n.toPlainString();
    } else if (valueType == ValueType.DATETIME) {
        Timestamp t = getValueDateTime();
        if (t != null) {
            value = ISODateTimeFormat.dateTime().withZoneUTC().print(t.getTime());
        }
    } else if (valueType == ValueType.STRING) {
        value = getValueString();
    } else {
        throw new IllegalStateException("Unsupported type: " + valueType);
    }
    return value;
}
 
Example 2
Source Project: TencentKona-8   Source File: AbstractField.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
 
Example 3
Source Project: jdk8u60   Source File: AbstractField.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
 
Example 4
Source Project: openjdk-jdk8u   Source File: AbstractField.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
 
Example 5
Source Project: openjdk-jdk9   Source File: AbstractField.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
 
Example 6
Source Project: hottub   Source File: AbstractField.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
 
Example 7
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
 
Example 8
Source Project: openjdk-8   Source File: AbstractField.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
 
Example 9
Source Project: c2mon   Source File: DOMFactory.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Generates an xml element from this pojo. Translating the fields like described
 * in the class description.
 * @param document The document in which the nodes should be.
 * @param rootName This is to use another name for the root element than the
 * simple class name.
 * @param pojo The pojo to take the fields from.
 * @param attributes The fields which should be used as attributes and not
 * as elements.
 * @return The create element representing the provided pojo.
 * @throws ParserConfigurationException Might throw a ParserConfigurationException.
 * @throws IllegalAccessException Might throw a IllegalAccessException.
 * @throws InstantiationException Might throw a InstantiationException.
 */
public Element generateSimpleElement(final Document document, final String rootName,
        final Object pojo, final List<String> attributes) 
        throws ParserConfigurationException,
        IllegalAccessException, InstantiationException {
    Element rootNode = document.createElementNS(getDefaultNamespace(), rootName);
    List<Field> fields = getNonTransientSimpleFields(pojo.getClass());
    for (Field field : fields) {            
        field.setAccessible(true);
        String fieldName = field.getName();
                                
        if (field.get(pojo) != null) {
            
            if (!attributes.contains(fieldName)) {
                
                Element element = document.createElementNS(getDefaultNamespace(), getElementName(field));
                
                // handle CDATAs
                if (field.isAnnotationPresent(XmlValue.class)) {
                    CDATASection cdata = document.createCDATASection(field.get(pojo).toString());
                    element.appendChild(cdata);
                }
                else {
                  element.setTextContent(field.get(pojo).toString());                    
                }
                
                rootNode.appendChild(element);                    
            }
            else {
                rootNode.setAttribute(getAttributeName(field), field.get(pojo).toString());
            }
        }
    }
    return rootNode;
}
 
Example 10
Source Project: ph-ubl   Source File: MainFindOccurrances.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create an XML name from the passed field. It uses the {@link XmlElement},
 * {@link XmlAttribute} and {@link XmlValue} annotations to differentiate.
 *
 * @param aField
 *        Source field
 * @return Never <code>null</code>.
 */
@Nonnull
public static String _getXMLName (@Nonnull final Field aField)
{
  final XmlElement aElement = aField.getAnnotation (XmlElement.class);
  if (aElement != null)
    return "/" + aElement.name ();
  final XmlAttribute aAttr = aField.getAnnotation (XmlAttribute.class);
  if (aAttr != null)
    return "/@" + aAttr.name ();
  if (aField.getAnnotation (XmlValue.class) != null)
    return "/value()";
  throw new IllegalStateException ("Field is neither XML element nor attribute nor value: " + aField);
}
 
Example 11
Source Project: sis   Source File: DefaultRecordType.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the record type value as a string. Current implementation returns the members with
 * one member per line, but it may change in any future version for adapting to common practice.
 */
@XmlValue
private String getValue() {
    switch (size()) {
        case 0:  return null;
        case 1:  return String.valueOf(memberTypes[0]);
        default: return toString(null, null);
    }
}
 
Example 12
Source Project: sis   Source File: DefaultRecord.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the record value as a string.
 */
@XmlValue
private String getValue() {
    if (values != null) {
        switch (Array.getLength(values)) {
            case 0:  break;
            case 1:  return String.valueOf(Array.get(values, 0));
            default: return definition.toString(null, values);
        }
    }
    return null;
}
 
Example 13
Source Project: micro-integrator   Source File: JNDIConfig.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getValue() {
	return value;
}
 
Example 14
Source Project: micro-integrator   Source File: RDBMSConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getValue() {
	return value;
}
 
Example 15
Source Project: micro-integrator   Source File: RDBMSConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getValue() {
	return value;
}
 
Example 16
Source Project: TencentKona-8   Source File: XmlValueQuick.java    License: GNU General Public License v2.0 4 votes vote down vote up
public XmlValueQuick(Locatable upstream, XmlValue core) {
    super(upstream);
    this.core = core;
}
 
Example 17
Source Project: TencentKona-8   Source File: XmlValueQuick.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected Quick newInstance(Locatable upstream, Annotation core) {
    return new XmlValueQuick(upstream, ((XmlValue) core));
}
 
Example 18
Source Project: sissi   Source File: Type.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getText() {
	return value;
}
 
Example 19
Source Project: sissi   Source File: TimeTzo.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getText() {
	return text;
}
 
Example 20
Source Project: sissi   Source File: Group.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getValue() {
	return this.value == null || this.value.isEmpty() ? null : this.value;
}
 
Example 21
Source Project: jdk8u60   Source File: XmlValueQuick.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Class<XmlValue> annotationType() {
    return XmlValue.class;
}
 
Example 22
Source Project: openjdk-jdk8u   Source File: XmlValueQuick.java    License: GNU General Public License v2.0 4 votes vote down vote up
public XmlValueQuick(Locatable upstream, XmlValue core) {
    super(upstream);
    this.core = core;
}
 
Example 23
Source Project: openjdk-jdk8u   Source File: XmlValueQuick.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected Quick newInstance(Locatable upstream, Annotation core) {
    return new XmlValueQuick(upstream, ((XmlValue) core));
}
 
Example 24
Source Project: openjdk-jdk8u   Source File: XmlValueQuick.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Class<XmlValue> annotationType() {
    return XmlValue.class;
}
 
Example 25
Source Project: reladomo-scala   Source File: MithraObject.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getClause() {
    return clause;
}
 
Example 26
Source Project: sissi   Source File: Desc.java    License: Apache License 2.0 4 votes vote down vote up
@XmlValue
public String getText() {
	return this.text;
}
 
Example 27
Source Project: staedi   Source File: TransactionBindTest.java    License: Apache License 2.0 4 votes vote down vote up
Class<?> classForValue(Class<?> bean) {
    return getAnnotatedClass(bean, XmlValue.class, a -> true);
}
 
Example 28
public XmlValueQuick(Locatable upstream, XmlValue core) {
    super(upstream);
    this.core = core;
}
 
Example 29
protected Quick newInstance(Locatable upstream, Annotation core) {
    return new XmlValueQuick(upstream, ((XmlValue) core));
}
 
Example 30
public Class<XmlValue> annotationType() {
    return XmlValue.class;
}