/** {@inheritDoc} */ public DocumentBuilder getBuilder() throws XMLParserException { DocumentBuilder builder = null; long version = 0; if (dirtyBuilderConfiguration) { initializePool(); } synchronized(this) { version = getPoolVersion(); if (!builderPool.isEmpty()) { builder = builderPool.pop().get(); } // Will be null if either the stack was empty, or the SoftReference // has been garbage-collected if (builder == null) { builder = createBuilder(); } } if (builder != null) { return new DocumentBuilderProxy(builder, this, version); } return null; }
/** {@inheritDoc} */ public Document newDocument() { checkValidState(); return builder.newDocument(); }
/** * Check whether the parser is in a valid and usable state, and if not, throw a runtime exception. * * @throws IllegalStateException thrown if the parser is in a state such that it can not be used */ protected void checkValidState() throws IllegalStateException { if (isReturned()) { throw new IllegalStateException("DocumentBuilderProxy has already been returned to its owning pool"); } }
/** {@inheritDoc} */ public void returnBuilder(DocumentBuilder builder) { if (!(builder instanceof DocumentBuilderProxy)) { return; } DocumentBuilderProxy proxiedBuilder = (DocumentBuilderProxy) builder; if (proxiedBuilder.getOwningPool() != this) { return; } synchronized (this) { if (proxiedBuilder.isReturned()) { return; } if (proxiedBuilder.getPoolVersion() != poolVersion) { return; } DocumentBuilder unwrappedBuilder = proxiedBuilder.getProxiedBuilder(); unwrappedBuilder.reset(); SoftReference<DocumentBuilder> builderReference = new SoftReference<DocumentBuilder>(unwrappedBuilder); if (builderPool.size() < maxPoolSize) { proxiedBuilder.setReturned(true); builderPool.push(builderReference); } } }
/** {@inheritDoc} */ public void returnBuilder(DocumentBuilder builder) { if (!(builder instanceof DocumentBuilderProxy)) { return; } DocumentBuilderProxy proxiedBuilder = (DocumentBuilderProxy) builder; if (proxiedBuilder.getOwningPool() != this) { return; } synchronized (this) { if (proxiedBuilder.isReturned()) { return; } if (proxiedBuilder.getPoolVersion() != poolVersion) { return; } DocumentBuilder unwrappedBuilder = proxiedBuilder.getProxiedBuilder(); unwrappedBuilder.reset(); SoftReference<DocumentBuilder> builderReference = new SoftReference<DocumentBuilder>(unwrappedBuilder); if (builderPool.size() < maxPoolSize) { proxiedBuilder.setReturned(true); builderPool.push(builderReference); } } }
/** {@inheritDoc} */ public DocumentBuilder getBuilder() throws XMLParserException { DocumentBuilder builder = null; long version = 0; if (dirtyBuilderConfiguration) { initializePool(); } synchronized(this) { version = getPoolVersion(); if (!builderPool.isEmpty()) { builder = builderPool.pop().get(); } // Will be null if either the stack was empty, or the SoftReference // has been garbage-collected if (builder == null) { builder = createBuilder(); } } if (builder != null) { return new DocumentBuilderProxy(builder, this, version); } return null; }
/** {@inheritDoc} */ public void setErrorHandler(ErrorHandler eh) { checkValidState(); return; }
/** {@inheritDoc} */ public boolean isXIncludeAware() { checkValidState(); return builder.isXIncludeAware(); }
/** {@inheritDoc} */ public boolean isNamespaceAware() { checkValidState(); return builder.isNamespaceAware(); }
/** {@inheritDoc} */ public void setErrorHandler(ErrorHandler eh) { checkValidState(); return; }
/** {@inheritDoc} */ public Document parse(String uri) throws SAXException, IOException { checkValidState(); return builder.parse(uri); }
/** {@inheritDoc} */ public Document parse(InputStream is, String systemId) throws SAXException, IOException { checkValidState(); return builder.parse(is, systemId); }
/** {@inheritDoc} */ public Document newDocument() { checkValidState(); return builder.newDocument(); }
/** {@inheritDoc} */ public boolean isValidating() { checkValidState(); return builder.isValidating(); }
/** {@inheritDoc} */ public void setEntityResolver(EntityResolver er) { checkValidState(); return; }
/** {@inheritDoc} */ public Document parse(InputSource is) throws SAXException, IOException { checkValidState(); return builder.parse(is); }
/** {@inheritDoc} */ public Document parse(File f) throws SAXException, IOException { checkValidState(); return builder.parse(f); }
/** {@inheritDoc} */ public boolean isValidating() { checkValidState(); return builder.isValidating(); }
/** {@inheritDoc} */ public Schema getSchema() { checkValidState(); return builder.getSchema(); }
/** {@inheritDoc} */ public DOMImplementation getDOMImplementation() { checkValidState(); return builder.getDOMImplementation(); }