Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.sapia.util.xml.idefix.serializer;
 
 
Class documentation

Author(s):
Jean-Cedric Desrochers
Copyright:
Copyright &.169; 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site
public class ArraySerializer implements SerializerIF {
  
Creates a new PrimitiveSerializer instance.
  public ArraySerializer() {
    super();
  }

  
Transforms the object passed in into an XML representation. This method is called when the object to transform is represents the root element of the XML document to create.

Parameters:
anObject The object to serialize.
aContext The serialization context to use.
Throws:
org.sapia.util.xml.idefix.SerializationException If an error occurs serializing the object.
  public void serialize(Object anObjectSerializationContext aContext)
    throws SerializationException {
    throw new UnsupportedOperationException(
      "The array serializer can serialize a root element");
  }

  
Transforms the object passed in into an XML representation. This method is called when the object to transform is nested inside another object.

Parameters:
anArray The array to serialize.
aNamespace The namespace of the object to serialize.
anObjectName The name of the object to serialize.
aContext The serialization context to use.
Throws:
org.sapia.util.xml.idefix.SerializationException If an error occurs serializing the object.
  public void serialize(Object anArrayNamespace aNamespace,
    String anObjectNameSerializationContext aContext)
    throws SerializationException {
    try {
      // Start the XML element
      aContext.getXmlBuffer().addNamespace(aNamespace.getURI(),
        aNamespace.getPrefix());
      aContext.getXmlBuffer().startElement(aNamespace.getURI(), anObjectName);
      // Get a serializer for the array
      SerializerIF aSerializer = aContext.getSerializerFactory().getSerializer(anArray.getClass()
                                                                                      .getComponentType());
      // Extract all the objects of the array
      int anArrayLength = Array.getLength(anArray);
      for (int i = 0; i < anArrayLengthi++) {
        Object anObject = Array.get(anArrayi);
        aSerializer.serialize(anObjectaContext);
      }
      // End the XML element
      aContext.getXmlBuffer().endElement(aNamespace.getURI(), anObjectName);
      aContext.getXmlBuffer().removeNamespace(aNamespace.getURI());
    } catch (SerializerNotFoundException snfe) {
      String aMessage = "Unable to found a serializer for the array: " +
        anArray;
      throw new SerializationException(aMessagesnfe);
    }
  }
New to GrepCode? Check out our FAQ X