1 31 package org.objectweb.proactive.core.xml.handler; 32 33 import org.objectweb.proactive.core.xml.io.Attributes; 34 35 43 public class CollectionUnmarshaller extends AbstractUnmarshallerDecorator { 44 45 protected java.util.ArrayList resultList; 46 protected Class targetClass; 47 48 49 53 public CollectionUnmarshaller(boolean lenient) { 54 this(null, lenient); 55 } 56 57 public CollectionUnmarshaller() { 58 this(null); 59 } 60 61 public CollectionUnmarshaller(Class targetClass, boolean lenient) { 62 super(lenient); 63 this.targetClass = targetClass; 64 } 65 66 public CollectionUnmarshaller(Class targetClass) { 67 super(); 68 this.targetClass = targetClass; 69 } 70 71 72 76 80 public Object getResultObject() throws org.xml.sax.SAXException { 81 int size = 0; 82 if (resultList != null) { 83 size = resultList.size(); 84 } 85 Object [] resultArray = null; 86 if (targetClass == null) { 87 resultArray = new Object [size]; 88 } else { 89 resultArray = (Object []) java.lang.reflect.Array.newInstance(targetClass, size); 90 } 91 if (size > 0) { 92 resultList.toArray(resultArray); 93 } 94 resultList = null; 96 return resultArray; 98 } 99 100 101 public void startContextElement(String name, Attributes attributes) throws org.xml.sax.SAXException { 102 resultList = new java.util.ArrayList (); 103 } 104 105 106 107 111 protected void notifyEndActiveHandler(String name, UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException { 112 Object o = activeHandler.getResultObject(); 113 if (o != null) resultList.add(o); 114 } 115 116 117 121 122 126 } | Popular Tags |