1 package org.sapia.util.xml.idefix.serializer; 2 3 import org.sapia.util.xml.Namespace; 4 import org.sapia.util.xml.idefix.NamespaceFactoryIF; 5 import org.sapia.util.xml.idefix.SerializationContext; 6 import org.sapia.util.xml.idefix.SerializationException; 7 import org.sapia.util.xml.idefix.SerializerIF; 8 import org.sapia.util.xml.idefix.SerializerNotFoundException; 9 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 13 14 24 public class CollectionSerializer implements SerializerIF { 25 28 public CollectionSerializer() { 29 super(); 30 } 31 32 40 public void serialize(Object anObject, SerializationContext aContext) 41 throws SerializationException { 42 Namespace aNamespace = NamespaceFactoryIF.DEFAULT_NAMESPACE; 43 String anObjectName = SerializerHelper.getLocalClassName(anObject); 44 serialize(anObject, aNamespace, anObjectName, aContext); 45 } 46 47 57 public void serialize(Object aCollection, Namespace aNamespace, 58 String anObjectName, SerializationContext aContext) 59 throws SerializationException { 60 Object anObject = null; 61 62 try { 63 for (Iterator it = ((Collection ) aCollection).iterator(); it.hasNext();) { 65 anObject = it.next(); 66 67 SerializerIF aSerializer = aContext.getSerializerFactory() 69 .getSerializer(anObject.getClass()); 70 71 aSerializer.serialize(anObject, aContext); 73 } 74 } catch (SerializerNotFoundException snfe) { 75 String aMessage = "Unable to find a serializer for the object: " + 76 anObject; 77 throw new SerializationException(aMessage, snfe); 78 } 79 } 80 } 81 | Popular Tags |