diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java index 657bb1ebd1dca72f0ab64d4e1ce3525bf328d747..6952087521dbcb399a8972d33f41d81def4b968a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java @@ -139,7 +139,7 @@ public abstract class BeanFactoryUtils { * @param type the type that beans must match * @return the array of matching bean names, or an empty array if none */ - public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class type) { + public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class type) { Assert.notNull(lbf, "ListableBeanFactory must not be null"); String[] result = lbf.getBeanNamesForType(type); if (lbf instanceof HierarchicalBeanFactory) { @@ -181,7 +181,7 @@ public abstract class BeanFactoryUtils { * @return the array of matching bean names, or an empty array if none */ public static String[] beanNamesForTypeIncludingAncestors( - ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit) { + ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit) { Assert.notNull(lbf, "ListableBeanFactory must not be null"); String[] result = lbf.getBeanNamesForType(type, includeNonSingletons, allowEagerInit); diff --git a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java index 5a010f49466f700c603ece78ed2c53019925bd69..f14f164ce6f7d490f9c52361101e0fa65f1e1ed3 100644 --- a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java @@ -130,7 +130,7 @@ public abstract class AbstractApplicationEventMulticaster implements Application protected Collection getApplicationListeners(ApplicationEvent event) { Class eventType = event.getClass(); Object source = event.getSource(); - Class sourceType = (source == null ? null : source.getClass()); + Class sourceType = (source != null ? source.getClass() : null); ListenerCacheKey cacheKey = new ListenerCacheKey(eventType, sourceType); ListenerRetriever retriever = this.retrieverCache.get(cacheKey); if (retriever != null) { @@ -193,11 +193,11 @@ public abstract class AbstractApplicationEventMulticaster implements Application */ private static class ListenerCacheKey { - private final Class eventType; + private final Class eventType; - private final Class sourceType; + private final Class sourceType; - public ListenerCacheKey(Class eventType, Class sourceType) { + public ListenerCacheKey(Class eventType, Class sourceType) { this.eventType = eventType; this.sourceType = sourceType; } @@ -208,14 +208,13 @@ public abstract class AbstractApplicationEventMulticaster implements Application return true; } ListenerCacheKey otherKey = (ListenerCacheKey) other; - return ObjectUtils.nullSafeEquals(this.eventType, otherKey.eventType) - && ObjectUtils.nullSafeEquals(this.sourceType, otherKey.sourceType); + return ObjectUtils.nullSafeEquals(this.eventType, otherKey.eventType) && + ObjectUtils.nullSafeEquals(this.sourceType, otherKey.sourceType); } @Override public int hashCode() { - return ObjectUtils.nullSafeHashCode(this.eventType) * 29 - + ObjectUtils.nullSafeHashCode(this.sourceType); + return ObjectUtils.nullSafeHashCode(this.eventType) * 29 + ObjectUtils.nullSafeHashCode(this.sourceType); } } diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index 3da70f602b6266c46bcd4e4a8a4f21d89c7b9389..916b322576da47478e8678dc8331b3d27d5b60bd 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ import java.util.concurrent.locks.ReentrantLock; * references at any time, so it may appear that an unknown thread is silently removing * entries. * - *

If not explicitly specified this implementation will use + *

If not explicitly specified, this implementation will use * {@linkplain SoftReference soft entry references}. * * @param The key type @@ -56,8 +56,7 @@ import java.util.concurrent.locks.ReentrantLock; * @author Phillip Webb * @since 3.2 */ -public class ConcurrentReferenceHashMap extends AbstractMap implements - ConcurrentMap { +public class ConcurrentReferenceHashMap extends AbstractMap implements ConcurrentMap { private static final int DEFAULT_INITIAL_CAPACITY = 16; @@ -82,6 +81,9 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen */ private final float loadFactor; + /** + * The reference type: SOFT or WEAK. + */ private final ReferenceType referenceType; /** @@ -99,8 +101,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * Create a new {@code ConcurrentReferenceHashMap} instance. */ public ConcurrentReferenceHashMap() { - this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, - DEFAULT_REFERENCE_TYPE); + this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, DEFAULT_REFERENCE_TYPE); } /** @@ -108,8 +109,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @param initialCapacity the initial capacity of the map */ public ConcurrentReferenceHashMap(int initialCapacity) { - this(initialCapacity, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, - DEFAULT_REFERENCE_TYPE); + this(initialCapacity, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, DEFAULT_REFERENCE_TYPE); } /** @@ -119,45 +119,44 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * exceeds this value resize will be attempted */ public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor) { - this(initialCapacity, loadFactor, DEFAULT_CONCURRENCY_LEVEL, - DEFAULT_REFERENCE_TYPE); + this(initialCapacity, loadFactor, DEFAULT_CONCURRENCY_LEVEL, DEFAULT_REFERENCE_TYPE); } /** * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map - * @param concurrencyLevel the expected number of threads that will concurrently write - * to the map + * @param concurrencyLevel the expected number of threads that will concurrently + * write to the map */ public ConcurrentReferenceHashMap(int initialCapacity, int concurrencyLevel) { - this(initialCapacity, DEFAULT_LOAD_FACTOR, concurrencyLevel, - DEFAULT_REFERENCE_TYPE); + this(initialCapacity, DEFAULT_LOAD_FACTOR, concurrencyLevel, DEFAULT_REFERENCE_TYPE); } /** * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map - * @param loadFactor the load factor. When the average number of references per table - * exceeds this value resize will be attempted - * @param concurrencyLevel the expected number of threads that will concurrently write - * to the map + * @param loadFactor the load factor. When the average number of references per + * table exceeds this value, resize will be attempted. + * @param concurrencyLevel the expected number of threads that will concurrently + * write to the map */ - public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, - int concurrencyLevel) { + public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) { this(initialCapacity, loadFactor, concurrencyLevel, DEFAULT_REFERENCE_TYPE); } /** * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map - * @param loadFactor the load factor. When the average number of references per table - * exceeds this value resize will be attempted - * @param concurrencyLevel the expected number of threads that will concurrently write - * to the map + * @param loadFactor the load factor. When the average number of references per + * table exceeds this value, resize will be attempted. + * @param concurrencyLevel the expected number of threads that will concurrently + * write to the map * @param referenceType the reference type used for entries */ - public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, - int concurrencyLevel, ReferenceType referenceType) { + @SuppressWarnings("unchecked") + public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel, + ReferenceType referenceType) { + Assert.isTrue(concurrencyLevel > 0, "ConcurrencyLevel must be positive"); Assert.isTrue(initialCapacity >= 0, "InitialCapacity must not be negative"); Assert.isTrue(loadFactor > 0f, "LoadFactor must be positive"); @@ -167,17 +166,12 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen int size = 1 << this.shift; this.referenceType = referenceType; int roundedUpSegmentCapactity = (int) ((initialCapacity + size - 1L) / size); - this.segments = createSegmentsArray(size); + this.segments = (Segment[]) Array.newInstance(Segment.class, size); for (int i = 0; i < this.segments.length; i++) { this.segments[i] = new Segment(roundedUpSegmentCapactity); } } - @SuppressWarnings("unchecked") - private Segment[] createSegmentsArray(int size) { - return (Segment[]) Array.newInstance(Segment.class, size); - } - protected final float getLoadFactor() { return this.loadFactor; @@ -222,7 +216,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen public V get(Object key) { Reference reference = getReference(key, Restructure.WHEN_NECESSARY); Entry entry = (reference == null ? null : reference.get()); - return (entry == null ? null : entry.getValue()); + return (entry != null ? entry.getValue() : null); } @Override @@ -388,7 +382,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Use {@link WeakReference}s. */ - WEAK; + WEAK } @@ -421,14 +415,12 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen */ private int resizeThreshold; - public Segment(int initialCapacity) { this.referenceManager = createReferenceManager(); this.initialSize = 1 << calculateShift(initialCapacity, MAXIMUM_SEGMENT_SIZE); setReferences(createReferenceArray(this.initialSize)); } - public Reference getReference(Object key, int hash, Restructure restructure) { if (restructure == Restructure.WHEN_NECESSARY) { restructureIfNecessary(false); @@ -452,17 +444,13 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @return the result of the operation */ public T doTask(final int hash, final Object key, final Task task) { - boolean resize = task.hasOption(TaskOption.RESIZE); - if (task.hasOption(TaskOption.RESTRUCTURE_BEFORE)) { restructureIfNecessary(resize); } - if (task.hasOption(TaskOption.SKIP_IF_EMPTY) && (this.count == 0)) { return task.execute(null, null, null); } - lock(); try { final int index = getIndex(hash, this.references); @@ -480,7 +468,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } }; return task.execute(reference, entry, entries); - } finally { + } + finally { unlock(); if (task.hasOption(TaskOption.RESTRUCTURE_AFTER)) { restructureIfNecessary(resize); @@ -569,8 +558,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } } - private Reference findInChain(Reference reference, Object key, - int hash) { + private Reference findInChain(Reference reference, Object key, int hash) { while (reference != null) { if (reference.getHash() == hash) { Entry entry = reference.get(); @@ -752,6 +740,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * Various options supported by a {@link Task}. */ private static enum TaskOption { + RESTRUCTURE_BEFORE, RESTRUCTURE_AFTER, SKIP_IF_EMPTY, RESIZE } @@ -783,8 +772,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen public boolean contains(Object o) { if (o != null && o instanceof Map.Entry) { Map.Entry entry = (java.util.Map.Entry) o; - Reference reference = ConcurrentReferenceHashMap.this.getReference( - entry.getKey(), Restructure.NEVER); + Reference reference = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER); Entry other = (reference == null ? null : reference.get()); if (other != null) { return ObjectUtils.nullSafeEquals(entry.getValue(), other.getValue()); @@ -797,8 +785,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen public boolean remove(Object o) { if (o instanceof Map.Entry) { Map.Entry entry = (Map.Entry) o; - return ConcurrentReferenceHashMap.this.remove(entry.getKey(), - entry.getValue()); + return ConcurrentReferenceHashMap.this.remove(entry.getKey(), entry.getValue()); } return false; } @@ -897,6 +884,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * The types of restructuring that can be performed. */ protected static enum Restructure { + WHEN_NECESSARY, NEVER } @@ -916,8 +904,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @param next the next reference in the chain or {@code null} * @return a new {@link Reference} */ - public Reference createReference(Entry entry, int hash, - Reference next) { + public Reference createReference(Entry entry, int hash, Reference next) { if (ConcurrentReferenceHashMap.this.referenceType == ReferenceType.WEAK) { return new WeakEntryReference(entry, hash, next, this.queue); } @@ -941,15 +928,13 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Internal {@link Reference} implementation for {@link SoftReference}s. */ - private static final class SoftEntryReference extends - SoftReference> implements Reference { + private static final class SoftEntryReference extends SoftReference> implements Reference { private final int hash; private final Reference nextReference; - public SoftEntryReference(Entry entry, int hash, Reference next, - ReferenceQueue> queue) { + public SoftEntryReference(Entry entry, int hash, Reference next, ReferenceQueue> queue) { super(entry, queue); this.hash = hash; this.nextReference = next; @@ -973,15 +958,13 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Internal {@link Reference} implementation for {@link WeakReference}s. */ - private static final class WeakEntryReference extends - WeakReference> implements Reference { + private static final class WeakEntryReference extends WeakReference> implements Reference { private final int hash; private final Reference nextReference; - public WeakEntryReference(Entry entry, int hash, Reference next, - ReferenceQueue> queue) { + public WeakEntryReference(Entry entry, int hash, Reference next, ReferenceQueue> queue) { super(entry, queue); this.hash = hash; this.nextReference = next; @@ -1000,4 +983,5 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen clear(); } } + } diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java index 0d32a3fc08c515b48e466fd2d6ad300947fa2b24..fd43354a68b2d95aab38e6f14c5d75dcb254c46f 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,12 +51,12 @@ import org.springframework.util.StringUtils; * an {@code XMLEventReader}, and calls the corresponding methods on the SAX callback interfaces. * * @author Arjen Poutsma + * @since 3.0 * @see XMLEventReader * @see #setContentHandler(org.xml.sax.ContentHandler) * @see #setDTDHandler(org.xml.sax.DTDHandler) * @see #setEntityResolver(org.xml.sax.EntityResolver) * @see #setErrorHandler(org.xml.sax.ErrorHandler) - * @since 3.0 */ class StaxEventXMLReader extends AbstractStaxXMLReader { @@ -70,11 +70,11 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { private String encoding; + /** * Constructs a new instance of the {@code StaxEventXmlReader} that reads from the given * {@code XMLEventReader}. The supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or * {@code XMLStreamConstants.START_ELEMENT} state. - * * @param reader the {@code XMLEventReader} to read from * @throws IllegalStateException if the reader is not at the start of a document or element */ @@ -89,17 +89,17 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { catch (XMLStreamException ex) { throw new IllegalStateException("Could not read first element: " + ex.getMessage()); } - this.reader = reader; } + @Override protected void parseInternal() throws SAXException, XMLStreamException { boolean documentStarted = false; boolean documentEnded = false; int elementDepth = 0; - while (reader.hasNext() && elementDepth >= 0) { - XMLEvent event = reader.nextEvent(); + while (this.reader.hasNext() && elementDepth >= 0) { + XMLEvent event = this.reader.nextEvent(); if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) { handleStartDocument(event); documentStarted = true; @@ -165,36 +165,28 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { this.encoding = startDocument.getCharacterEncodingScheme(); } } - if (getContentHandler() != null) { final Location location = event.getLocation(); getContentHandler().setDocumentLocator(new Locator2() { - public int getColumnNumber() { - return location != null ? location.getColumnNumber() : -1; + return (location != null ? location.getColumnNumber() : -1); } - public int getLineNumber() { - return location != null ? location.getLineNumber() : -1; + return (location != null ? location.getLineNumber() : -1); } - public String getPublicId() { - return location != null ? location.getPublicId() : null; + return (location != null ? location.getPublicId() : null); } - public String getSystemId() { - return location != null ? location.getSystemId() : null; + return (location != null ? location.getSystemId() : null); } - public String getXMLVersion() { return xmlVersion; } - public String getEncoding() { return encoding; } }); - getContentHandler().startDocument(); } } @@ -311,7 +303,6 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { private Attributes getAttributes(StartElement event) { AttributesImpl attributes = new AttributesImpl(); - for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); QName qName = attribute.getName(); @@ -323,8 +314,7 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { if (type == null) { type = "CDATA"; } - attributes - .addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); + attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); } if (hasNamespacePrefixesFeature()) { for (Iterator i = event.getNamespaces(); i.hasNext();) { diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java index bca48d1cdbe661cce2c0a7878c87f7798f155986..26394c56a678e39d270ca9fef07d3bbd17c08ffc 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,16 +31,16 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * SAX {@code XMLReader} that reads from a StAX {@code XMLStreamReader}. Reads from an + * SAX {@code XMLReader} that reads from a StAX {@code XMLStreamReader}. Reads from an * {@code XMLStreamReader}, and calls the corresponding methods on the SAX callback interfaces. * * @author Arjen Poutsma + * @since 3.0 * @see XMLStreamReader * @see #setContentHandler(org.xml.sax.ContentHandler) * @see #setDTDHandler(org.xml.sax.DTDHandler) * @see #setEntityResolver(org.xml.sax.EntityResolver) * @see #setErrorHandler(org.xml.sax.ErrorHandler) - * @since 3.0 */ class StaxStreamXMLReader extends AbstractStaxXMLReader { @@ -52,11 +52,11 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { private String encoding; + /** - * Constructs a new instance of the {@code StaxStreamXmlReader} that reads from the given - * {@code XMLStreamReader}. The supplied stream reader must be in {@code XMLStreamConstants.START_DOCUMENT} + * Construct a new instance of the {@code StaxStreamXmlReader} that reads from the given + * {@code XMLStreamReader}. The supplied stream reader must be in {@code XMLStreamConstants.START_DOCUMENT} * or {@code XMLStreamConstants.START_ELEMENT} state. - * * @param reader the {@code XMLEventReader} to read from * @throws IllegalStateException if the reader is not at the start of a document or element */ @@ -69,12 +69,13 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { this.reader = reader; } + @Override protected void parseInternal() throws SAXException, XMLStreamException { boolean documentStarted = false; boolean documentEnded = false; int elementDepth = 0; - int eventType = reader.getEventType(); + int eventType = this.reader.getEventType(); while (true) { if (eventType != XMLStreamConstants.START_DOCUMENT && eventType != XMLStreamConstants.END_DOCUMENT && !documentStarted) { @@ -118,8 +119,8 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { handleEntityReference(); break; } - if (reader.hasNext() && elementDepth >= 0) { - eventType = reader.next(); + if (this.reader.hasNext() && elementDepth >= 0) { + eventType = this.reader.next(); } else { break; @@ -131,66 +132,58 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { } private void handleStartDocument() throws SAXException { - if (XMLStreamConstants.START_DOCUMENT == reader.getEventType()) { - String xmlVersion = reader.getVersion(); + if (XMLStreamConstants.START_DOCUMENT == this.reader.getEventType()) { + String xmlVersion = this.reader.getVersion(); if (StringUtils.hasLength(xmlVersion)) { this.xmlVersion = xmlVersion; } - this.encoding = reader.getCharacterEncodingScheme(); + this.encoding = this.reader.getCharacterEncodingScheme(); } - if (getContentHandler() != null) { - final Location location = reader.getLocation(); - + final Location location = this.reader.getLocation(); getContentHandler().setDocumentLocator(new Locator2() { - public int getColumnNumber() { - return location != null ? location.getColumnNumber() : -1; + return (location != null ? location.getColumnNumber() : -1); } - public int getLineNumber() { - return location != null ? location.getLineNumber() : -1; + return (location != null ? location.getLineNumber() : -1); } - public String getPublicId() { - return location != null ? location.getPublicId() : null; + return (location != null ? location.getPublicId() : null); } - public String getSystemId() { - return location != null ? location.getSystemId() : null; + return (location != null ? location.getSystemId() : null); } - public String getXMLVersion() { return xmlVersion; } - public String getEncoding() { return encoding; } }); getContentHandler().startDocument(); - if (reader.standaloneSet()) { - setStandalone(reader.isStandalone()); + if (this.reader.standaloneSet()) { + setStandalone(this.reader.isStandalone()); } } } private void handleStartElement() throws SAXException { if (getContentHandler() != null) { - QName qName = reader.getName(); + QName qName = this.reader.getName(); if (hasNamespacesFeature()) { - for (int i = 0; i < reader.getNamespaceCount(); i++) { - startPrefixMapping(reader.getNamespacePrefix(i), reader.getNamespaceURI(i)); + for (int i = 0; i < this.reader.getNamespaceCount(); i++) { + startPrefixMapping(this.reader.getNamespacePrefix(i), this.reader.getNamespaceURI(i)); } - for (int i = 0; i < reader.getAttributeCount(); i++) { - String prefix = reader.getAttributePrefix(i); - String namespace = reader.getAttributeNamespace(i); + for (int i = 0; i < this.reader.getAttributeCount(); i++) { + String prefix = this.reader.getAttributePrefix(i); + String namespace = this.reader.getAttributeNamespace(i); if (StringUtils.hasLength(namespace)) { startPrefixMapping(prefix, namespace); } } - getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName), - getAttributes()); + getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), + toQualifiedName(qName), getAttributes()); } else { getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes()); @@ -200,11 +193,11 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { private void handleEndElement() throws SAXException { if (getContentHandler() != null) { - QName qName = reader.getName(); + QName qName = this.reader.getName(); if (hasNamespacesFeature()) { getContentHandler().endElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName)); - for (int i = 0; i < reader.getNamespaceCount(); i++) { - String prefix = reader.getNamespacePrefix(i); + for (int i = 0; i < this.reader.getNamespaceCount(); i++) { + String prefix = this.reader.getNamespacePrefix(i); if (prefix == null) { prefix = ""; } @@ -218,31 +211,33 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { } private void handleCharacters() throws SAXException { - if (getContentHandler() != null && reader.isWhiteSpace()) { - getContentHandler() - .ignorableWhitespace(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); + if (getContentHandler() != null && this.reader.isWhiteSpace()) { + getContentHandler().ignorableWhitespace(this.reader.getTextCharacters(), + this.reader.getTextStart(), this.reader.getTextLength()); return; } - if (XMLStreamConstants.CDATA == reader.getEventType() && getLexicalHandler() != null) { + if (XMLStreamConstants.CDATA == this.reader.getEventType() && getLexicalHandler() != null) { getLexicalHandler().startCDATA(); } if (getContentHandler() != null) { - getContentHandler().characters(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); + getContentHandler().characters(this.reader.getTextCharacters(), + this.reader.getTextStart(), this.reader.getTextLength()); } - if (XMLStreamConstants.CDATA == reader.getEventType() && getLexicalHandler() != null) { + if (XMLStreamConstants.CDATA == this.reader.getEventType() && getLexicalHandler() != null) { getLexicalHandler().endCDATA(); } } private void handleComment() throws SAXException { if (getLexicalHandler() != null) { - getLexicalHandler().comment(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); + getLexicalHandler().comment(this.reader.getTextCharacters(), + this.reader.getTextStart(), this.reader.getTextLength()); } } private void handleDtd() throws SAXException { if (getLexicalHandler() != null) { - javax.xml.stream.Location location = reader.getLocation(); + javax.xml.stream.Location location = this.reader.getLocation(); getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId()); } if (getLexicalHandler() != null) { @@ -252,10 +247,10 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { private void handleEntityReference() throws SAXException { if (getLexicalHandler() != null) { - getLexicalHandler().startEntity(reader.getLocalName()); + getLexicalHandler().startEntity(this.reader.getLocalName()); } if (getLexicalHandler() != null) { - getLexicalHandler().endEntity(reader.getLocalName()); + getLexicalHandler().endEntity(this.reader.getLocalName()); } } @@ -267,29 +262,28 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { private void handleProcessingInstruction() throws SAXException { if (getContentHandler() != null) { - getContentHandler().processingInstruction(reader.getPITarget(), reader.getPIData()); + getContentHandler().processingInstruction(this.reader.getPITarget(), this.reader.getPIData()); } } private Attributes getAttributes() { AttributesImpl attributes = new AttributesImpl(); - - for (int i = 0; i < reader.getAttributeCount(); i++) { - String namespace = reader.getAttributeNamespace(i); + for (int i = 0; i < this.reader.getAttributeCount(); i++) { + String namespace = this.reader.getAttributeNamespace(i); if (namespace == null || !hasNamespacesFeature()) { namespace = ""; } - String type = reader.getAttributeType(i); + String type = this.reader.getAttributeType(i); if (type == null) { type = "CDATA"; } - attributes.addAttribute(namespace, reader.getAttributeLocalName(i), - toQualifiedName(reader.getAttributeName(i)), type, reader.getAttributeValue(i)); + attributes.addAttribute(namespace, this.reader.getAttributeLocalName(i), + toQualifiedName(this.reader.getAttributeName(i)), type, this.reader.getAttributeValue(i)); } if (hasNamespacePrefixesFeature()) { - for (int i = 0; i < reader.getNamespaceCount(); i++) { - String prefix = reader.getNamespacePrefix(i); - String namespaceUri = reader.getNamespaceURI(i); + for (int i = 0; i < this.reader.getNamespaceCount(); i++) { + String prefix = this.reader.getNamespacePrefix(i); + String namespaceUri = this.reader.getNamespaceURI(i); String qName; if (StringUtils.hasLength(prefix)) { qName = "xmlns:" + prefix; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java index 3af593bd8b17c63caf80e6468cb65de6dd1d8fb4..d68b231ba561d1c85720896b7c458975dfd25a95 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; - import javax.servlet.http.HttpServletRequest; import org.springframework.util.AntPathMatcher; @@ -54,6 +53,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition fileExtensions = new ArrayList(); + /** * Creates a new instance with the given URL patterns. * Each pattern that is not empty and does not start with "/" is prepended with "/". @@ -66,7 +66,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition patterns, UrlPathHelper urlPathHelper, PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch, @@ -119,8 +117,9 @@ public final class PatternsRequestCondition extends AbstractRequestCondition asList(String... patterns) { - return patterns != null ? Arrays.asList(patterns) : Collections.emptyList(); + return (patterns != null ? Arrays.asList(patterns) : Collections.emptyList()); } private static Set prependLeadingSlash(Collection patterns) { @@ -188,7 +187,6 @@ public final class PatternsRequestCondition extends AbstractRequestConditionA matching pattern is obtained by making checks in the following order: *

- * * @param request the current request - * * @return the same instance if the condition contains no patterns; - * or a new condition with sorted matching patterns; - * or {@code null} if no patterns match. + * or a new condition with sorted matching patterns; + * or {@code null} if no patterns match. */ @Override public PatternsRequestCondition getMatchingCondition(HttpServletRequest request) { @@ -210,9 +206,8 @@ public final class PatternsRequestCondition extends AbstractRequestCondition matches = new ArrayList(); - for (String pattern : patterns) { + for (String pattern : this.patterns) { String match = getMatchingPattern(pattern, lookupPath); if (match != null) { matches.add(match); @@ -260,7 +255,6 @@ public final class PatternsRequestCondition extends AbstractRequestConditionIt is assumed that both instances have been obtained via * {@link #getMatchingCondition(HttpServletRequest)} to ensure they * contain only patterns that match the request and are sorted with @@ -271,7 +265,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition patternComparator = this.pathMatcher.getPatternComparator(lookupPath); - Iterator iterator = patterns.iterator(); + Iterator iterator = this.patterns.iterator(); Iterator iteratorOther = other.patterns.iterator(); while (iterator.hasNext() && iteratorOther.hasNext()) { int result = patternComparator.compare(iterator.next(), iteratorOther.next());