org/objectweb/proactive/core/xml/handler/CollectionUnmarshaller.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.xml.handler;
00032 
00033 import org.objectweb.proactive.core.xml.io.Attributes;
00034 
00035 
00044 public class CollectionUnmarshaller extends AbstractUnmarshallerDecorator {
00045     protected java.util.ArrayList resultList;
00046     protected Class targetClass;
00047 
00048     //
00049     // -- CONSTRUCTORS -----------------------------------------------
00050     //  
00051     public CollectionUnmarshaller(boolean lenient) {
00052         this(null, lenient);
00053     }
00054 
00055     public CollectionUnmarshaller() {
00056         this(null);
00057     }
00058 
00059     public CollectionUnmarshaller(Class targetClass, boolean lenient) {
00060         super(lenient);
00061         this.targetClass = targetClass;
00062     }
00063 
00064     public CollectionUnmarshaller(Class targetClass) {
00065         super();
00066         this.targetClass = targetClass;
00067     }
00068 
00069     //
00070     // -- PUBLIC METHODS -----------------------------------------------
00071     //
00072     //
00073     // -- implements UnmarshallerHandler ------------------------------------------------------
00074     //  
00075     public Object getResultObject() throws org.xml.sax.SAXException {
00076         int size = 0;
00077         if (resultList != null) {
00078             size = resultList.size();
00079         }
00080         Object[] resultArray = null;
00081         if (targetClass == null) {
00082             resultArray = new Object[size];
00083         } else {
00084             resultArray = (Object[]) java.lang.reflect.Array.newInstance(targetClass,
00085                     size);
00086         }
00087         if (size > 0) {
00088             resultList.toArray(resultArray);
00089         }
00090 
00091         // clean-up
00092         resultList = null;
00093         //targetClass = null;
00094         return resultArray;
00095     }
00096 
00097     public void startContextElement(String name, Attributes attributes)
00098         throws org.xml.sax.SAXException {
00099         resultList = new java.util.ArrayList();
00100     }
00101 
00102     //
00103     // -- PROTECTED METHODS ------------------------------------------------------
00104     //
00105     protected void notifyEndActiveHandler(String name,
00106         UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
00107         Object o = activeHandler.getResultObject();
00108         if (o != null) {
00109             resultList.add(o);
00110         }
00111     }
00112 
00113     //
00114     // -- PRIVATE METHODS ------------------------------------------------------
00115     //
00116     //
00117     // -- INNER CLASSES ------------------------------------------------------
00118     //
00119 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1