From: Wolfgang M. M. <wol...@us...> - 2004-08-10 20:27:23
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24902/src/org/exist/util Added Files: XMLReaderObjectFactory.java XMLReaderPool.java Log Message: Refactored some methods to improve performance during storage and indexing. --- NEW FILE: XMLReaderObjectFactory.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2000-04, Wolfgang M. Meier (wol...@ex...) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: XMLReaderObjectFactory.java,v 1.1 2004/08/10 20:27:14 wolfgang_m Exp $ */ package org.exist.util; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.commons.pool.BasePoolableObjectFactory; import org.exist.EXistException; import org.exist.storage.BrokerPool; import org.xml.sax.XMLReader; /** * Factory to create new XMLReader objects on demand. The factory is used * by {@link org.exist.util.XMLReaderPool}. * * @author wolf */ public class XMLReaderObjectFactory extends BasePoolableObjectFactory { private final static int VALIDATION_ENABLED = 0; private final static int VALIDATION_AUTO = 1; private final static int VALIDATION_DISABLED = 2; private BrokerPool pool; /** * */ public XMLReaderObjectFactory(BrokerPool pool) { super(); this.pool = pool; } /* (non-Javadoc) * @see org.apache.commons.pool.BasePoolableObjectFactory#makeObject() */ public Object makeObject() throws Exception { System.out.println("Creating new SAXReader"); Configuration config = pool.getConfiguration(); // get validation settings int validation = VALIDATION_AUTO; String option = (String) config.getProperty("indexer.validation"); if (option != null) { if (option.equals("true")) validation = VALIDATION_ENABLED; else if (option.equals("auto")) validation = VALIDATION_AUTO; else validation = VALIDATION_DISABLED; } // create a SAX parser SAXParserFactory saxFactory = SAXParserFactory.newInstance(); if (validation == VALIDATION_AUTO || validation == VALIDATION_ENABLED) saxFactory.setValidating(true); else saxFactory.setValidating(false); saxFactory.setNamespaceAware(true); try { saxFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true); saxFactory.setFeature("http://apache.org/xml/features/validation/dynamic", validation == VALIDATION_AUTO); saxFactory.setFeature("http://apache.org/xml/features/validation/schema", validation == VALIDATION_AUTO || validation == VALIDATION_ENABLED); SAXParser sax = saxFactory.newSAXParser(); XMLReader parser = sax.getXMLReader(); return parser; } catch (ParserConfigurationException e) { throw new EXistException(e); } } } --- NEW FILE: XMLReaderPool.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2000-04, Wolfgang M. Meier (wol...@ex...) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: XMLReaderPool.java,v 1.1 2004/08/10 20:27:14 wolfgang_m Exp $ */ package org.exist.util; import org.apache.commons.pool.PoolableObjectFactory; import org.apache.commons.pool.impl.StackObjectPool; import org.xml.sax.XMLReader; /** * Maintains a pool of XMLReader objects. The pool is available through * {@link BrokerPool#getParserPool()}. * * @author wolf */ public class XMLReaderPool extends StackObjectPool { /** * @param arg0 * @param arg1 * @param arg2 */ public XMLReaderPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) { super(factory, maxIdle, initIdleCapacity); } public synchronized XMLReader borrowXMLReader() { try { return (XMLReader)borrowObject(); } catch(Exception e) { throw new IllegalStateException("error while returning XMLReader: " + e.getMessage()); } } public synchronized void returnXMLReader(XMLReader reader) { try { returnObject(reader); } catch (Exception e) { throw new IllegalStateException("error while returning XMLReader: " + e.getMessage()); } } } |