diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/Cloneable.java b/hibernate-core/src/main/java/org/hibernate/internal/util/Cloneable.java deleted file mode 100644 index 04ac401cdf..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/Cloneable.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import org.hibernate.HibernateException; -import org.hibernate.internal.util.collections.ArrayHelper; - -/** - * An object that is shallow-cloneable - * - * @author Steve Ebersole - */ -public class Cloneable { - - private static final Object[] READER_METHOD_ARGS = ArrayHelper.EMPTY_OBJECT_ARRAY; - - /** - * Essentially performs a shallow copy of this SessionEventListenerConfig - * instance; meaning the SessionEventListenerConfig itself is cloned, but - * the individual listeners are not cloned. - * - * @return The SessionEventListenerConfig shallow copy. - */ - public Object shallowCopy() { - return AccessController.doPrivileged( - new PrivilegedAction() { - @Override - public Object run() { - return copyListeners(); - } - } - ); - } - - /** - * Checks to ensure the SessionEventListenerConfig is fully - * configured (basically, that none of the listeners is null). - * - * @throws HibernateException If the SessionEventListenerConfig - * is not fully configured. - */ - public void validate() throws HibernateException { - AccessController.doPrivileged( - new PrivilegedAction() { - @Override - public Object run() { - checkListeners(); - return null; - } - } - ); - - } - - private Object copyListeners() { - Object copy = null; - BeanInfo beanInfo = null; - try { - beanInfo = Introspector.getBeanInfo( getClass(), Object.class ); - internalCheckListeners( beanInfo ); - copy = getClass().newInstance(); - PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); - for ( PropertyDescriptor pd : pds ) { - try { - pd.getWriteMethod().invoke( - copy, - pd.getReadMethod().invoke( this, READER_METHOD_ARGS ) - ); - } - catch (Throwable t) { - throw new HibernateException( "Unable to copy listener [" + pd.getName() + "]" ); - } - } - } - catch (Exception t) { - throw new HibernateException( "Unable to copy listeners", t ); - } - finally { - if ( beanInfo != null ) { - // release the jdk internal caches every time to ensure this - // plays nicely with destroyable class-loaders - Introspector.flushFromCaches( getClass() ); - } - } - - return copy; - } - - private void checkListeners() { - BeanInfo beanInfo = null; - try { - beanInfo = Introspector.getBeanInfo( getClass(), Object.class ); - internalCheckListeners( beanInfo ); - } - catch (IntrospectionException t) { - throw new HibernateException( "Unable to validate listener config", t ); - } - finally { - if ( beanInfo != null ) { - // release the jdk internal caches every time to ensure this - // plays nicely with destroyable class-loaders - Introspector.flushFromCaches( getClass() ); - } - } - } - - private void internalCheckListeners(BeanInfo beanInfo) { - PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); - try { - for ( PropertyDescriptor pd : pds ) { - final Object listener = pd.getReadMethod().invoke( this, READER_METHOD_ARGS ); - if ( listener == null ) { - throw new HibernateException( "Listener [" + pd.getName() + "] was null" ); - } - if ( listener.getClass().isArray() ) { - Object[] listenerArray = (Object[]) listener; - for ( Object aListenerArray : listenerArray ) { - if ( aListenerArray == null ) { - throw new HibernateException( "Listener in [" + pd.getName() + "] was null" ); - } - } - } - } - } - catch (HibernateException e) { - throw e; - } - catch (Throwable t) { - throw new HibernateException( "Unable to validate listener config" ); - } - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/UniqueList.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/UniqueList.java deleted file mode 100644 index a8e48610ab..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/UniqueList.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.internal.util.collections; - -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.Spliterators; - -/** - * A collection of values that is simultaneously a List (ordered) and a Set (unique) - * - * @author Steve Ebersole - */ -public class UniqueList extends AbstractList implements Set, List { - private final List elements; - - public UniqueList() { - this( new ArrayList<>() ); - } - - public UniqueList(List elements) { - this.elements = elements; - } - - public UniqueList(int size) { - this.elements = CollectionHelper.arrayList( size ); - } - - @Override - public E get(int index) { - return elements.get( index ); - } - - @Override - public void add(int index, E element) { - if ( elements.contains( element ) ) { - return; - } - elements.add( index, element ); - } - - @Override - public int size() { - return elements.size(); - } - - @Override - public Iterator iterator() { - return elements.iterator(); - } - - @Override - public ListIterator listIterator() { - return elements.listIterator(); - } - - @Override - public ListIterator listIterator(int index) { - return elements.listIterator( index ); - } - - @Override - public Object[] toArray() { - return elements.toArray(); - } - - @Override - @SuppressWarnings("SuspiciousToArrayCall") - public T[] toArray(T[] a) { - return elements.toArray( a ); - } - - @Override - public Spliterator spliterator() { - return Spliterators.spliterator( this, Spliterator.ORDERED ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/io/CharSequenceReader.java b/hibernate-core/src/main/java/org/hibernate/internal/util/io/CharSequenceReader.java deleted file mode 100644 index 57bb7b22be..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/io/CharSequenceReader.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.internal.util.io; - -import java.io.IOException; -import java.io.Reader; - -/** - * @author Steve Ebersole - */ -public class CharSequenceReader extends Reader { - private CharSequence charSequence; - - private int length; - private int position = 0; - private int mark = 0; - - public CharSequenceReader(CharSequence charSequence) { - this.charSequence = charSequence; - this.length = charSequence.length(); - } - - @Override - public boolean markSupported() { - return true; - } - - @Override - public void mark(int readAheadLimit) throws IOException { - this.mark = this.position; - } - - public int read() throws IOException { - verifyOpen(); - - if ( this.position >= this.length ) { - return -1; - } - - return this.charSequence.charAt( this.position++ ); - } - - protected void verifyOpen() throws IOException { - if ( charSequence == null ) { - throw new IOException( "Stream closed" ); - } - } - - @Override - public int read(char[] dest, int off, int len) throws IOException { - verifyOpen(); - - if ( this.position >= this.length ) { - return -1; - } - - if ((off < 0) || (off > dest.length) || (len < 0) || - ((off + len) > dest.length) || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } - else if (len == 0) { - return 0; - } - - int n = Math.min( length - position, len ); - - for ( int i = 0; i < n; i++ ) { - dest[i] = charSequence.charAt( n ); - } - - position += n; - - return n; - } - - public void reset() { - this.position = this.mark; - } - - public long skip(long n) { - if ( n < 0L ) { - throw new IllegalArgumentException( "Number of characters to skip must be greater than zero: " + n ); - } - - if ( this.position >= length ) { - return -1L; - } - else { - int dest = (int)Math.min(this.charSequence.length(), (long)this.position + n); - int count = dest - this.position; - this.position = dest; - return count; - } - } - - @Override - public void close() throws IOException { - charSequence = null; - mark = 0; - position = 0; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/streams/GenericArrayCollector.java b/hibernate-core/src/main/java/org/hibernate/internal/util/streams/GenericArrayCollector.java deleted file mode 100644 index d40e2d8d6b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/streams/GenericArrayCollector.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.internal.util.streams; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collector; - -/** - * @author Steve Ebersole - */ -public class GenericArrayCollector implements Collector, T[]> { - public static GenericArrayCollector forType(Class type) { - return new GenericArrayCollector<>( type ); - } - - private final Class collectedType; - - public GenericArrayCollector(Class collectedType) { - this.collectedType = collectedType; - } - - @Override - public Supplier> supplier() { - return ArrayList::new; - } - - @Override - public BiConsumer, T> accumulator() { - return List::add; - } - - @Override - public BinaryOperator> combiner() { - return (ts, ts2) -> { - ts.addAll( ts2 ); - return ts; - }; - } - - @Override - @SuppressWarnings("unchecked") - public Function, T[]> finisher() { - return ts -> ts.toArray( (T[]) Array.newInstance( collectedType, ts.size() ) ); - } - - @Override - public Set characteristics() { - return EnumSet.of( Characteristics.CONCURRENT ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/streams/StingArrayCollector.java b/hibernate-core/src/main/java/org/hibernate/internal/util/streams/StingArrayCollector.java deleted file mode 100644 index cda1f41b5b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/streams/StingArrayCollector.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.internal.util.streams; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collector; - -/** - * A Java 8 Stream Collector for collecting Strings into a String[]. - * - * @author Steve Ebersole - */ -public class StingArrayCollector implements Collector, String[]> { - /** - * Singleton access - */ - public static final StingArrayCollector INSTANCE = new StingArrayCollector(); - - @Override - public Supplier> supplier() { - return ArrayList::new; - } - - @Override - public BiConsumer, String> accumulator() { - return List::add; - } - - @Override - public BinaryOperator> combiner() { - return (strings, strings2) -> { - strings.addAll( strings2 ); - return strings; - }; - } - - @Override - public Function, String[]> finisher() { - return strings -> strings.toArray( new String[strings.size()] ); - } - - @Override - public Set characteristics() { - return EnumSet.of( Characteristics.CONCURRENT ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/streams/StreamUtils.java b/hibernate-core/src/main/java/org/hibernate/internal/util/streams/StreamUtils.java deleted file mode 100644 index 44a39e9b04..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/streams/StreamUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.internal.util.streams; - -/** - * @author Steve Ebersole - */ -public class StreamUtils { - public static StingArrayCollector toStringArray() { - return StingArrayCollector.INSTANCE; - } - - public static GenericArrayCollector toArray(Class collectedType) { - return new GenericArrayCollector<>( collectedType ); - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/BaseXMLEventReader.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/BaseXMLEventReader.java deleted file mode 100644 index 298b19d4dc..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/BaseXMLEventReader.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.Characters; -import javax.xml.stream.events.EntityDeclaration; -import javax.xml.stream.events.EntityReference; -import javax.xml.stream.events.XMLEvent; -import javax.xml.stream.util.EventReaderDelegate; - -/** - * Base for XMLEventReader that implements the {@link #getElementText()} and {@link #nextTag()} APIs in a - * way that is agnostic from the rest of the XMLEventReader implementation. Both will use the subclasses - * {@link #internalNextEvent()} as the exclusive way to read events. - * - * Note, copied from the uPortal project by permission of author. See - * https://github.com/Jasig/uPortal/blob/master/uportal-war/src/main/java/org/jasig/portal/xml/stream/BaseXMLEventReader.java - * - * @author Eric Dalquist - */ -public abstract class BaseXMLEventReader extends EventReaderDelegate { - private XMLEvent previousEvent; - - public BaseXMLEventReader(XMLEventReader reader) { - super(reader); - } - - /** - * Subclass's version of {@link #nextEvent()}, called by {@link #next()} - */ - protected abstract XMLEvent internalNextEvent() throws XMLStreamException; - - /** - * @return The XMLEvent returned by the last call to {@link #internalNextEvent()} - */ - protected final XMLEvent getPreviousEvent() { - return this.previousEvent; - } - - @Override - public final XMLEvent nextEvent() throws XMLStreamException { - this.previousEvent = this.internalNextEvent(); - return this.previousEvent; - } - - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - @Override - public final Object next() { - try { - return this.nextEvent(); - } - catch (XMLStreamException e) { - return null; - } - } - - /* (non-Javadoc) - * @see javax.xml.stream.XMLEventReader#getElementText() - */ - @Override - public final String getElementText() throws XMLStreamException { - XMLEvent event = this.previousEvent; - if (event == null) { - throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null"); - } - if (!event.isStartElement()) { - throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation()); - } - - final StringBuilder text = new StringBuilder(); - while (!event.isEndDocument()) { - switch (event.getEventType()) { - case XMLStreamConstants.CHARACTERS: - case XMLStreamConstants.SPACE: - case XMLStreamConstants.CDATA: { - final Characters characters = event.asCharacters(); - text.append(characters.getData()); - break; - } - case XMLStreamConstants.ENTITY_REFERENCE: { - final EntityReference entityReference = (EntityReference)event; - final EntityDeclaration declaration = entityReference.getDeclaration(); - text.append(declaration.getReplacementText()); - break; - } - case XMLStreamConstants.COMMENT: - case XMLStreamConstants.PROCESSING_INSTRUCTION: { - //Ignore - break; - } - default: { - throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation()); - } - } - - event = this.nextEvent(); - } - - return text.toString(); - } - - /* (non-Javadoc) - * @see javax.xml.stream.XMLEventReader#nextTag() - */ - @Override - public final XMLEvent nextTag() throws XMLStreamException { - XMLEvent event = this.nextEvent(); - while ((event.isCharacters() && event.asCharacters().isWhiteSpace()) - || event.isProcessingInstruction() - || event.getEventType() == XMLStreamConstants.COMMENT) { - - event = this.nextEvent(); - } - - if (!event.isStartElement() && event.isEndElement()) { - throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation()); - } - - return event; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/BufferedXMLEventReader.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/BufferedXMLEventReader.java deleted file mode 100644 index 956f1267b5..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/BufferedXMLEventReader.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.XMLEvent; - -/** - * Buffers XML events for later re-reading - * - * Note, copied from the uPortal project by permission of author. See - * https://github.com/Jasig/uPortal/blob/master/uportal-war/src/main/java/org/jasig/portal/xml/stream/BufferedXMLEventReader.java - * - * @author Eric Dalquist - */ -public class BufferedXMLEventReader extends BaseXMLEventReader { - private final LinkedList eventBuffer = new LinkedList<>(); - private int eventLimit; - private ListIterator bufferReader; - - /** - * Create new buffering reader, no buffering is done until {@link #mark(int)} is called. - */ - public BufferedXMLEventReader(XMLEventReader reader) { - super(reader); - } - - /** - * Create new buffering reader. Calls {@link #mark(int)} with the specified event limit - * @see #mark(int) - */ - public BufferedXMLEventReader(XMLEventReader reader, int eventLimit) { - super(reader); - this.eventLimit = eventLimit; - } - - /** - * @return A copy of the current buffer - */ - public List getBuffer() { - return new ArrayList<>(this.eventBuffer); - } - - /* (non-Javadoc) - * @see org.jasig.portal.xml.stream.BaseXMLEventReader#internalNextEvent() - */ - @Override - protected XMLEvent internalNextEvent() throws XMLStreamException { - //If there is an iterator to read from reset was called, use the iterator - //until it runs out of events. - if (this.bufferReader != null) { - final XMLEvent event = this.bufferReader.next(); - - //If nothing left in the iterator, remove the reference and fall through to direct reading - if (!this.bufferReader.hasNext()) { - this.bufferReader = null; - } - - return event; - } - - //Get the next event from the underlying reader - final XMLEvent event = this.getParent().nextEvent(); - - //if buffering add the event - if (this.eventLimit != 0) { - this.eventBuffer.offer(event); - - //If limited buffer size and buffer is too big trim the buffer. - if (this.eventLimit > 0 && this.eventBuffer.size() > this.eventLimit) { - this.eventBuffer.poll(); - } - } - - return event; - } - - @Override - public boolean hasNext() { - return this.bufferReader != null || super.hasNext(); - } - - @Override - public XMLEvent peek() throws XMLStreamException { - if (this.bufferReader != null) { - final XMLEvent event = this.bufferReader.next(); - this.bufferReader.previous(); //move the iterator back - return event; - } - return super.peek(); - } - - /** - * Same as calling {@link #mark(int)} with -1. - */ - public void mark() { - this.mark(-1); - } - - /** - * Start buffering events - * @param eventLimit the maximum number of events to buffer. -1 will buffer all events, 0 will buffer no events. - */ - public void mark(int eventLimit) { - this.eventLimit = eventLimit; - - //Buffering no events now, clear the buffer and buffered reader - if (this.eventLimit == 0) { - this.eventBuffer.clear(); - this.bufferReader = null; - } - //Buffering limited set of events, lets trim the buffer if needed - else if (this.eventLimit > 0) { - //If there is an iterator check its current position and calculate the new iterator start position - int iteratorIndex = 0; - if (this.bufferReader != null) { - final int nextIndex = this.bufferReader.nextIndex(); - iteratorIndex = Math.max(0, nextIndex - (this.eventBuffer.size() - this.eventLimit)); - } - - //Trim the buffer until it is not larger than the limit - while (this.eventBuffer.size() > this.eventLimit) { - this.eventBuffer.poll(); - } - - //If there is an iterator re-create it using the newly calculated index - if (this.bufferReader != null) { - this.bufferReader = this.eventBuffer.listIterator(iteratorIndex); - } - } - } - - /** - * Reset the reader to these start of the buffered events. - */ - public void reset() { - if (this.eventBuffer.isEmpty()) { - this.bufferReader = null; - } - else { - this.bufferReader = this.eventBuffer.listIterator(); - } - } - - @Override - public void close() throws XMLStreamException { - this.mark(0); - super.close(); - } - - /** - * @return The number of events in the buffer. - */ - public int bufferSize() { - return this.eventBuffer.size(); - } - - /** - * If reading from the buffer after a {@link #reset()} call an {@link IllegalStateException} will be thrown. - */ - @Override - public void remove() { - if (this.bufferReader != null && this.bufferReader.hasNext()) { - throw new IllegalStateException("Cannot remove a buffered element"); - } - - super.remove(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/ErrorLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/ErrorLogger.java deleted file mode 100644 index b7724d56e9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/ErrorLogger.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.internal.CoreMessageLogger; - -import org.jboss.logging.Logger; - -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXParseException; - -/** - * Implements an {@link ErrorHandler} that mainly just logs errors/warnings. However, it does track - * the errors it encounters and makes them available via {@link #getErrors}. - * - * @author Steve Ebersole - * @author Hardy Ferentschik - */ -public class ErrorLogger implements ErrorHandler, Serializable { - - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, - ErrorLogger.class.getName() - ); - - // lazily initialized - private List errors; - private String file; - - public ErrorLogger() { - } - - public ErrorLogger(String file) { - this.file = file; - } - - @Override - public void error(SAXParseException error) { - if ( this.errors == null ) { - errors = new ArrayList<>(); - } - errors.add( error ); - } - - @Override - public void fatalError(SAXParseException error) { - error( error ); - } - - @Override - public void warning(SAXParseException warn) { - LOG.parsingXmlWarning( warn.getLineNumber(), warn.getMessage() ); - } - - public List getErrors() { - return errors; - } - - public void reset() { - errors = null; - } - - public boolean hasErrors() { - return errors != null && errors.size() > 0; - } - - public void logErrors() { - if ( errors != null ) { - for ( SAXParseException e : errors ) { - if ( file == null ) { - LOG.parsingXmlError( e.getLineNumber(), e.getMessage() ); - } - else { - LOG.parsingXmlErrorForFile( file, e.getLineNumber(), e.getMessage() ); - } - } - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/FilteringXMLEventReader.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/FilteringXMLEventReader.java deleted file mode 100644 index 47ed7df230..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/FilteringXMLEventReader.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import java.util.Deque; -import java.util.LinkedList; -import java.util.NoSuchElementException; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.EndElement; -import javax.xml.stream.events.StartElement; -import javax.xml.stream.events.XMLEvent; - -/** - * Base class for {@link XMLEventReader}s that want to modify or remove events from the reader stream. - * If a {@link StartElement} event is removed the subclass's {@link #filterEvent(XMLEvent, boolean)} will - * not see any events until after the matching {@link EndElement} event. - * - * Note, copied from the uPortal project by permission of author. See - * https://github.com/Jasig/uPortal/blob/master/uportal-war/src/main/java/org/jasig/portal/xml/stream/FilteringXMLEventReader.java - * - * @author Eric Dalquist - */ -public abstract class FilteringXMLEventReader extends BaseXMLEventReader { - private final Deque prunedElements = new LinkedList<>(); - private XMLEvent peekedEvent; - - public FilteringXMLEventReader(XMLEventReader reader) { - super(reader); - } - - @Override - protected final XMLEvent internalNextEvent() throws XMLStreamException { - return this.internalNext(false); - } - - @Override - public boolean hasNext() { - try { - return peekedEvent != null || (super.hasNext() && this.peek() != null); - } - catch (XMLStreamException e) { - throw new RuntimeException(e.getMessage(), e); - } - catch (NoSuchElementException e) { - return false; - } - } - - @Override - public final XMLEvent peek() throws XMLStreamException { - if (peekedEvent != null) { - return peekedEvent; - } - - peekedEvent = internalNext(true); - return peekedEvent; - } - - protected final XMLEvent internalNext(boolean peek) throws XMLStreamException { - XMLEvent event = null; - - if (peekedEvent != null) { - event = peekedEvent; - peekedEvent = null; - return event; - } - - do { - event = super.getParent().nextEvent(); - - //If there are pruned elements in the queue filtering events is still needed - if (!prunedElements.isEmpty()) { - //If another start element add it to the queue - if (event.isStartElement()) { - final StartElement startElement = event.asStartElement(); - prunedElements.push(startElement.getName()); - } - //If end element pop the newest name of the queue and double check that the start/end elements match up - else if (event.isEndElement()) { - final QName startElementName = prunedElements.pop(); - - final EndElement endElement = event.asEndElement(); - final QName endElementName = endElement.getName(); - - if (!startElementName.equals(endElementName)) { - throw new IllegalArgumentException("Malformed XMLEvent stream. Expected end element for " + startElementName + " but found end element for " + endElementName); - } - } - - event = null; - } - else { - final XMLEvent filteredEvent = this.filterEvent(event, peek); - - //If the event is being removed and it is a start element all elements until the matching - //end element need to be removed as well - if (filteredEvent == null && event.isStartElement()) { - final StartElement startElement = event.asStartElement(); - final QName name = startElement.getName(); - prunedElements.push(name); - } - - event = filteredEvent; - } - } - while (event == null); - - return event; - } - - /** - * @param event The current event - * @param peek If the event is from a {@link #peek()} call - * @return The event to return, if null is returned the event is dropped from the stream and the next event will be used. - */ - protected abstract XMLEvent filterEvent(XMLEvent event, boolean peek); -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/Origin.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/Origin.java deleted file mode 100644 index 06bf979aab..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/Origin.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import java.io.Serializable; - -/** - * Describes the origin of an xml document - * - * @author Steve Ebersole - */ -public interface Origin extends Serializable { - /** - * Retrieve the type of origin. This is not a discrete set, but might be something like - * {@code file} for file protocol URLs, or {@code resource} for classpath resource lookups. - * - * @return The origin type. - */ - String getType(); - - /** - * The name of the document origin. Interpretation is relative to the type, but might be the - * resource name or file URL. - * - * @return The name. - */ - String getName(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/OriginImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/OriginImpl.java deleted file mode 100644 index bee2806ae9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/OriginImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import java.io.Serializable; - -/** - * Basic implementation of {@link Origin} - * - * @author Steve Ebersole - */ -public class OriginImpl implements Origin, Serializable { - private final String type; - private final String name; - - public OriginImpl(String type, String name) { - this.type = type; - this.name = name; - } - - @Override - public String getType() { - return type; - } - - @Override - public String getName() { - return name; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/UnsupportedOrmXsdVersionException.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/UnsupportedOrmXsdVersionException.java deleted file mode 100644 index 5e3babd9ed..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/UnsupportedOrmXsdVersionException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import org.hibernate.HibernateException; - -/** - * @author Steve Ebersole - * - * @deprecated Migrating to boot package; all usages will eventually be replaced by - * {@link org.hibernate.boot.UnsupportedOrmXsdVersionException} - */ -@Deprecated -public class UnsupportedOrmXsdVersionException extends HibernateException { - public UnsupportedOrmXsdVersionException(String requestedVersion, Origin origin) { - super( - String.format( - "Encountered unsupported orm.xml xsd version [%s] in mapping document [type=%s, name=%s]", - requestedVersion, - origin.getType(), - origin.getName() - ) - ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/XMLStreamConstantsUtils.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/XMLStreamConstantsUtils.java deleted file mode 100644 index 6eb405bb6c..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/XMLStreamConstantsUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import javax.xml.stream.XMLStreamConstants; - -/** - * - * - * - * - * Note, copied from the uPortal project by permission of author. See - * https://github.com/Jasig/uPortal/blob/master/uportal-war/src/main/java/org/jasig/portal/xml/stream/XMLStreamConstantsUtils.java - * - * @author Eric Dalquist - */ -public final class XMLStreamConstantsUtils { - private XMLStreamConstantsUtils() { - } - - /** - * Get the human readable event name for the numeric event id - */ - public static String getEventName(int eventId) { - switch (eventId) { - case XMLStreamConstants.START_ELEMENT: - return "StartElementEvent"; - case XMLStreamConstants.END_ELEMENT: - return "EndElementEvent"; - case XMLStreamConstants.PROCESSING_INSTRUCTION: - return "ProcessingInstructionEvent"; - case XMLStreamConstants.CHARACTERS: - return "CharacterEvent"; - case XMLStreamConstants.COMMENT: - return "CommentEvent"; - case XMLStreamConstants.START_DOCUMENT: - return "StartDocumentEvent"; - case XMLStreamConstants.END_DOCUMENT: - return "EndDocumentEvent"; - case XMLStreamConstants.ENTITY_REFERENCE: - return "EntityReferenceEvent"; - case XMLStreamConstants.ATTRIBUTE: - return "AttributeBase"; - case XMLStreamConstants.DTD: - return "DTDEvent"; - case XMLStreamConstants.CDATA: - return "CDATA"; - } - return "UNKNOWN_EVENT_TYPE"; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/XmlInfrastructureException.java b/hibernate-core/src/main/java/org/hibernate/internal/util/xml/XmlInfrastructureException.java deleted file mode 100644 index 616a6a588a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/xml/XmlInfrastructureException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.xml; - -import org.hibernate.HibernateException; - -/** - * An error using XML infrastructure (jaxp, stax, etc). - * - * @author Steve Ebersole - */ -public class XmlInfrastructureException extends HibernateException { - public XmlInfrastructureException(String message) { - super( message ); - } - - public XmlInfrastructureException(String message, Throwable root) { - super( message, root ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java index abfab91e1f..cd7c14bf62 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java @@ -10,7 +10,6 @@ import org.hibernate.InvalidMappingException; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; -import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -30,7 +29,5 @@ public class NonExistentOrmVersionTest extends BaseUnitTestCase { } catch ( InvalidMappingException expected ) { } - catch ( UnsupportedOrmXsdVersionException expected ) { - } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java index 8fb2da1dba..abddef229c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java @@ -10,7 +10,6 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.xml.ErrorLogger; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -36,7 +35,7 @@ public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase { public LoggerInspectionRule logInspection = new LoggerInspectionRule( Logger.getMessageLogger( CoreMessageLogger.class, - ErrorLogger.class.getName() + "org.hibernate.internal.util.xml.ErrorLogger" ) );