Java Code Examples for org.simpleframework.xml.stream.OutputNode#setReference()

The following examples show how to use org.simpleframework.xml.stream.OutputNode#setReference() . 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: EntityWithAnyElementConverter.java    From sardine-android with Apache License 2.0 6 votes vote down vote up
@Override
public void write(OutputNode node, T entity) throws Exception {
    for(org.w3c.dom.Element domElement : entity.getAny()) {
        ElementConverter.write(node, domElement);
    }
    Map<String, Field> entityFields = getEntityFields();
    for (String fieldName : entityFields.keySet()) {
        Field field = entityFields.get(fieldName);
        Object value = getGetterForField(field).invoke(entity);
        if (value == null) {
            continue;
        }
        if (value instanceof String) {
            OutputNode childNode = node.getChild(fieldName);
            childNode.setReference(SardineUtil.DEFAULT_NAMESPACE_URI);
            childNode.setValue((String)value);
        } else {
            serializer.write(value, node);
        }
    }
}
 
Example 2
Source File: Composite.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>writeSection</code> method is used to perform serialization 
 * of the given source object. Serialization is performed by appending
 * elements and attributes from the source object to the provided XML
 * element object. How the objects contacts are serialized is 
 * determined by the XML schema class that the source object is an
 * instance of. If a required contact is null an exception is thrown.
 * 
 * @param source this is the source object to be serialized
 * @param node the XML element the object is to be serialized to
 * @param section this is the section that defines the XML structure
 */
private void writeSection(OutputNode node, Object source, Section section) throws Exception {
   NamespaceMap scope = node.getNamespaces();
   String prefix = section.getPrefix();

   if(prefix != null) {
      String reference = scope.getReference(prefix);
      
      if(reference == null) {     
         throw new ElementException("Namespace prefix '%s' in %s is not in scope", prefix, type);
      } else {
         node.setReference(reference);  
      }
   }
   writeAttributes(node, source, section);
   writeElements(node, source, section);
   writeText(node, source, section);
}
 
Example 3
Source File: EntityWithAnyElementConverter.java    From simpletask-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void write(OutputNode node, T entity) throws Exception {
    for(org.w3c.dom.Element domElement : entity.getAny()) {
        ElementConverter.write(node, domElement);
    }
    Map<String, Field> entityFields = getEntityFields();
    for (String fieldName : entityFields.keySet()) {
        Field field = entityFields.get(fieldName);
        Object value = getGetterForField(field).invoke(entity);
        if (value == null) {
            continue;
        }
        if (value instanceof String) {
            OutputNode childNode = node.getChild(fieldName);
            childNode.setReference(SardineUtil.DEFAULT_NAMESPACE_URI);
            childNode.setValue((String)value);
        } else {
            serializer.write(value, node);
        }
    }
}
 
Example 4
Source File: NamespaceDecorator.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This is use to apply the <code>Namespace</code> annotations on
 * the node. If there is no namespace then this will return and
 * the node will be left unchanged. If however the namespace is 
 * not null then the reference is applied to the specified node.
 * 
 * @param node this is the node to apply the namespace to
 */
private void namespace(OutputNode node) {
   if(primary != null) {
      String reference = primary.reference();
      
      node.setReference(reference);
   }
}