org/objectweb/proactive/core/xml/io/StreamReader.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.io;
00032 
00033 import java.io.IOException;
00034 
00035 import org.apache.log4j.Logger;
00036 import org.apache.xerces.parsers.SAXParser;
00037 import org.objectweb.proactive.core.util.log.Loggers;
00038 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00039 import org.xml.sax.SAXException;
00040 import org.xml.sax.SAXNotRecognizedException;
00041 import org.xml.sax.SAXNotSupportedException;
00042 
00043 
00052 public class StreamReader implements XMLReader {
00053     static Logger logger = ProActiveLogger.getLogger(Loggers.XML);
00054     private org.xml.sax.XMLReader parser;
00055     private org.xml.sax.InputSource inputSource;
00056 
00057     public StreamReader(java.io.InputStream in, XMLHandler xmlHandler)
00058         throws java.io.IOException {
00059         this(new org.xml.sax.InputSource(in), xmlHandler);
00060     }
00061 
00062     public StreamReader(java.io.Reader reader, XMLHandler xmlHandler)
00063         throws java.io.IOException {
00064         this(new org.xml.sax.InputSource(reader), xmlHandler);
00065     }
00066 
00067     public StreamReader(org.xml.sax.InputSource inputSource,
00068         XMLHandler xmlHandler) throws java.io.IOException {
00069         this(inputSource, xmlHandler, null, null);
00070     }
00071 
00072     public StreamReader(org.xml.sax.InputSource inputSource,
00073         XMLHandler xmlHandler, java.net.URL schema,
00074         org.xml.sax.ErrorHandler errorHandler) throws java.io.IOException {
00075         this.inputSource = inputSource;
00076 
00077         DefaultHandlerAdapter adaptor = new DefaultHandlerAdapter(xmlHandler);
00078 
00079         //      javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
00080         //      parser = factory.newSAXParser().getXMLReader();
00081         parser = new SAXParser();
00082         //parser = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
00083         parser.setContentHandler(adaptor);
00084 
00085         if ((schema != null) || (errorHandler != null)) {
00086             try {
00087                 parser.setErrorHandler((errorHandler == null)
00088                     ? new SAXParserErrorHandler() : errorHandler);
00089 
00090                 if (schema != null) {
00091                     parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",
00092                         schema.toString());
00093 
00095                 }
00096 
00097                 parser.setFeature("http://xml.org/sax/features/validation", true);
00098                 parser.setFeature("http://apache.org/xml/features/validation/schema",
00099                     true);
00100 
00101                 //            parser.parse(inputSource);
00102             } catch (SAXNotRecognizedException e) {
00103                 logger.error("unrecognised feature: ");
00104                 logger.error("http://xml.org/sax/features/validation");
00105             } catch (SAXNotSupportedException e) {
00106                 logger.error("unrecognised feature: ");
00107                 logger.error("http://apache.org/xml/features/validation/schema");
00108             }
00109         }
00110     }
00111 
00112     // -- implements XMLReader ------------------------------------------------------
00113     public void read() throws SAXException, IOException {
00114             //parser.setFeature("http://xml.org/sax/features/validation",true);
00115             //parser.setFeature("http://apache.org/xml/features/validation/schema",true);
00116             parser.parse(inputSource);
00117     }
00118 }

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