[SPR-8388] Improved documentation on default registered PropertyEditors; fixed typos and grammar in JavaDoc; suppressed warnings due to generics; etc.

This commit is contained in:
Sam Brannen 2011-06-01 20:54:48 +00:00
parent 4642cca893
commit 919b996027
4 changed files with 53 additions and 52 deletions

View File

@ -91,17 +91,17 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
private boolean configValueEditorsActive = false; private boolean configValueEditorsActive = false;
private Map<Class, PropertyEditor> defaultEditors; private Map<Class<?>, PropertyEditor> defaultEditors;
private Map<Class, PropertyEditor> overriddenDefaultEditors; private Map<Class<?>, PropertyEditor> overriddenDefaultEditors;
private Map<Class, PropertyEditor> customEditors; private Map<Class<?>, PropertyEditor> customEditors;
private Map<String, CustomEditorHolder> customEditorsForPath; private Map<String, CustomEditorHolder> customEditorsForPath;
private Set<PropertyEditor> sharedEditors; private Set<PropertyEditor> sharedEditors;
private Map<Class, PropertyEditor> customEditorCache; private Map<Class<?>, PropertyEditor> customEditorCache;
/** /**
@ -152,9 +152,9 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @param propertyEditor the editor to register * @param propertyEditor the editor to register
* @see #registerCustomEditor(Class, PropertyEditor) * @see #registerCustomEditor(Class, PropertyEditor)
*/ */
public void overrideDefaultEditor(Class requiredType, PropertyEditor propertyEditor) { public void overrideDefaultEditor(Class<?> requiredType, PropertyEditor propertyEditor) {
if (this.overriddenDefaultEditors == null) { if (this.overriddenDefaultEditors == null) {
this.overriddenDefaultEditors = new HashMap<Class, PropertyEditor>(); this.overriddenDefaultEditors = new HashMap<Class<?>, PropertyEditor>();
} }
this.overriddenDefaultEditors.put(requiredType, propertyEditor); this.overriddenDefaultEditors.put(requiredType, propertyEditor);
} }
@ -166,7 +166,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the default editor, or <code>null</code> if none found * @return the default editor, or <code>null</code> if none found
* @see #registerDefaultEditors * @see #registerDefaultEditors
*/ */
public PropertyEditor getDefaultEditor(Class requiredType) { public PropertyEditor getDefaultEditor(Class<?> requiredType) {
if (!this.defaultEditorsActive) { if (!this.defaultEditorsActive) {
return null; return null;
} }
@ -186,7 +186,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* Actually register the default editors for this registry instance. * Actually register the default editors for this registry instance.
*/ */
private void createDefaultEditors() { private void createDefaultEditors() {
this.defaultEditors = new HashMap<Class, PropertyEditor>(64); this.defaultEditors = new HashMap<Class<?>, PropertyEditor>(64);
// Simple editors, without parameterization capabilities. // Simple editors, without parameterization capabilities.
// The JDK does not contain a default editor for any of these target types. // The JDK does not contain a default editor for any of these target types.
@ -269,11 +269,11 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
// Management of custom editors // Management of custom editors
//--------------------------------------------------------------------- //---------------------------------------------------------------------
public void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor) { public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) {
registerCustomEditor(requiredType, null, propertyEditor); registerCustomEditor(requiredType, null, propertyEditor);
} }
public void registerCustomEditor(Class requiredType, String propertyPath, PropertyEditor propertyEditor) { public void registerCustomEditor(Class<?> requiredType, String propertyPath, PropertyEditor propertyEditor) {
if (requiredType == null && propertyPath == null) { if (requiredType == null && propertyPath == null) {
throw new IllegalArgumentException("Either requiredType or propertyPath is required"); throw new IllegalArgumentException("Either requiredType or propertyPath is required");
} }
@ -285,7 +285,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
} }
else { else {
if (this.customEditors == null) { if (this.customEditors == null) {
this.customEditors = new LinkedHashMap<Class, PropertyEditor>(16); this.customEditors = new LinkedHashMap<Class<?>, PropertyEditor>(16);
} }
this.customEditors.put(requiredType, propertyEditor); this.customEditors.put(requiredType, propertyEditor);
this.customEditorCache = null; this.customEditorCache = null;
@ -301,7 +301,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @deprecated as of Spring 3.0, in favor of PropertyEditorRegistrars or ConversionService usage * @deprecated as of Spring 3.0, in favor of PropertyEditorRegistrars or ConversionService usage
*/ */
@Deprecated @Deprecated
public void registerSharedEditor(Class requiredType, PropertyEditor propertyEditor) { public void registerSharedEditor(Class<?> requiredType, PropertyEditor propertyEditor) {
registerCustomEditor(requiredType, null, propertyEditor); registerCustomEditor(requiredType, null, propertyEditor);
if (this.sharedEditors == null) { if (this.sharedEditors == null) {
this.sharedEditors = new HashSet<PropertyEditor>(); this.sharedEditors = new HashSet<PropertyEditor>();
@ -319,8 +319,8 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
return (this.sharedEditors != null && this.sharedEditors.contains(propertyEditor)); return (this.sharedEditors != null && this.sharedEditors.contains(propertyEditor));
} }
public PropertyEditor findCustomEditor(Class requiredType, String propertyPath) { public PropertyEditor findCustomEditor(Class<?> requiredType, String propertyPath) {
Class requiredTypeToUse = requiredType; Class<?> requiredTypeToUse = requiredType;
if (propertyPath != null) { if (propertyPath != null) {
if (this.customEditorsForPath != null) { if (this.customEditorsForPath != null) {
// Check property-specific editor first. // Check property-specific editor first.
@ -354,7 +354,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* can be <code>null</code> if not known) * can be <code>null</code> if not known)
* @return whether a matching custom editor has been found * @return whether a matching custom editor has been found
*/ */
public boolean hasCustomEditorForElement(Class elementType, String propertyPath) { public boolean hasCustomEditorForElement(Class<?> elementType, String propertyPath) {
if (propertyPath != null && this.customEditorsForPath != null) { if (propertyPath != null && this.customEditorsForPath != null) {
for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) { for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) {
if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath)) { if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath)) {
@ -379,7 +379,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the type of the property, or <code>null</code> if not determinable * @return the type of the property, or <code>null</code> if not determinable
* @see BeanWrapper#getPropertyType(String) * @see BeanWrapper#getPropertyType(String)
*/ */
protected Class getPropertyType(String propertyPath) { protected Class<?> getPropertyType(String propertyPath) {
return null; return null;
} }
@ -389,7 +389,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @param requiredType the type to look for * @param requiredType the type to look for
* @return the custom editor, or <code>null</code> if none specific for this property * @return the custom editor, or <code>null</code> if none specific for this property
*/ */
private PropertyEditor getCustomEditor(String propertyName, Class requiredType) { private PropertyEditor getCustomEditor(String propertyName, Class<?> requiredType) {
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName); CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
return (holder != null ? holder.getPropertyEditor(requiredType) : null); return (holder != null ? holder.getPropertyEditor(requiredType) : null);
} }
@ -402,7 +402,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the custom editor, or <code>null</code> if none found for this type * @return the custom editor, or <code>null</code> if none found for this type
* @see java.beans.PropertyEditor#getAsText() * @see java.beans.PropertyEditor#getAsText()
*/ */
private PropertyEditor getCustomEditor(Class requiredType) { private PropertyEditor getCustomEditor(Class<?> requiredType) {
if (requiredType == null || this.customEditors == null) { if (requiredType == null || this.customEditors == null) {
return null; return null;
} }
@ -415,14 +415,14 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
} }
if (editor == null) { if (editor == null) {
// Find editor for superclass or interface. // Find editor for superclass or interface.
for (Iterator<Class> it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) { for (Iterator<Class<?>> it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
Class key = it.next(); Class<?> key = it.next();
if (key.isAssignableFrom(requiredType)) { if (key.isAssignableFrom(requiredType)) {
editor = this.customEditors.get(key); editor = this.customEditors.get(key);
// Cache editor for search type, to avoid the overhead // Cache editor for search type, to avoid the overhead
// of repeated assignable-from checks. // of repeated assignable-from checks.
if (this.customEditorCache == null) { if (this.customEditorCache == null) {
this.customEditorCache = new HashMap<Class, PropertyEditor>(); this.customEditorCache = new HashMap<Class<?>, PropertyEditor>();
} }
this.customEditorCache.put(requiredType, editor); this.customEditorCache.put(requiredType, editor);
} }
@ -438,7 +438,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @param propertyName the name of the property * @param propertyName the name of the property
* @return the property type, or <code>null</code> if not determinable * @return the property type, or <code>null</code> if not determinable
*/ */
protected Class guessPropertyTypeFromEditors(String propertyName) { protected Class<?> guessPropertyTypeFromEditors(String propertyName) {
if (this.customEditorsForPath != null) { if (this.customEditorsForPath != null) {
CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName); CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName);
if (editorHolder == null) { if (editorHolder == null) {
@ -467,7 +467,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
String actualPropertyName = String actualPropertyName =
(nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null); (nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null);
if (this.customEditors != null) { if (this.customEditors != null) {
for (Map.Entry<Class, PropertyEditor> entry : this.customEditors.entrySet()) { for (Map.Entry<Class<?>, PropertyEditor> entry : this.customEditors.entrySet()) {
target.registerCustomEditor(entry.getKey(), entry.getValue()); target.registerCustomEditor(entry.getKey(), entry.getValue());
} }
} }
@ -529,9 +529,9 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
private final PropertyEditor propertyEditor; private final PropertyEditor propertyEditor;
private final Class registeredType; private final Class<?> registeredType;
private CustomEditorHolder(PropertyEditor propertyEditor, Class registeredType) { private CustomEditorHolder(PropertyEditor propertyEditor, Class<?> registeredType) {
this.propertyEditor = propertyEditor; this.propertyEditor = propertyEditor;
this.registeredType = registeredType; this.registeredType = registeredType;
} }
@ -540,11 +540,11 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
return this.propertyEditor; return this.propertyEditor;
} }
private Class getRegisteredType() { private Class<?> getRegisteredType() {
return this.registeredType; return this.registeredType;
} }
private PropertyEditor getPropertyEditor(Class requiredType) { private PropertyEditor getPropertyEditor(Class<?> requiredType) {
// Special case: If no required type specified, which usually only happens for // Special case: If no required type specified, which usually only happens for
// Collection elements, or required type is not assignable to registered type, // Collection elements, or required type is not assignable to registered type,
// which usually only happens for generic properties of type Object - // which usually only happens for generic properties of type Object -

View File

@ -70,7 +70,7 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
* @see org.springframework.core.io.support.ResourcePatternResolver * @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.context.ApplicationContext * @see org.springframework.context.ApplicationContext
* @deprecated as of Spring 3.1 in favor of * @deprecated as of Spring 3.1 in favor of
* {@link ResourceEditorRegistrar#ResourceEditorRegistrar(ResourceLoader, Environment)} * {@link #ResourceEditorRegistrar(ResourceLoader, Environment)}
*/ */
@Deprecated @Deprecated
public ResourceEditorRegistrar(ResourceLoader resourceLoader) { public ResourceEditorRegistrar(ResourceLoader resourceLoader) {
@ -91,16 +91,19 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
/** /**
* Populate the given bean factory with the following resource editors: * Populate the given <code>registry</code> with the following resource editors:
* ResourceEditor, InputStreamEditor, FileEditor, URLEditor, ClassEditor, URIEditor. * ResourceEditor, InputStreamEditor, InputSourceEditor, FileEditor, URLEditor,
* <p>In case of a {@link org.springframework.core.io.support.ResourcePatternResolver}, * URIEditor, ClassEditor, ClassArrayEditor.
* <p>If this registrar has been configured with a {@link ResourcePatternResolver},
* a ResourceArrayPropertyEditor will be registered as well. * a ResourceArrayPropertyEditor will be registered as well.
* @see org.springframework.core.io.ResourceEditor * @see org.springframework.core.io.ResourceEditor
* @see org.springframework.beans.propertyeditors.InputStreamEditor * @see org.springframework.beans.propertyeditors.InputStreamEditor
* @see org.springframework.beans.propertyeditors.InputSourceEditor
* @see org.springframework.beans.propertyeditors.FileEditor * @see org.springframework.beans.propertyeditors.FileEditor
* @see org.springframework.beans.propertyeditors.URLEditor * @see org.springframework.beans.propertyeditors.URLEditor
* @see org.springframework.beans.propertyeditors.ClassEditor
* @see org.springframework.beans.propertyeditors.URIEditor * @see org.springframework.beans.propertyeditors.URIEditor
* @see org.springframework.beans.propertyeditors.ClassEditor
* @see org.springframework.beans.propertyeditors.ClassArrayEditor
* @see org.springframework.core.io.support.ResourceArrayPropertyEditor * @see org.springframework.core.io.support.ResourceArrayPropertyEditor
*/ */
public void registerCustomEditors(PropertyEditorRegistry registry) { public void registerCustomEditors(PropertyEditorRegistry registry) {
@ -126,7 +129,7 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
* Override default editor, if possible (since that's what we really mean to do here); * Override default editor, if possible (since that's what we really mean to do here);
* otherwise register as a custom editor. * otherwise register as a custom editor.
*/ */
private void doRegisterEditor(PropertyEditorRegistry registry, Class requiredType, PropertyEditor editor) { private void doRegisterEditor(PropertyEditorRegistry registry, Class<?> requiredType, PropertyEditor editor) {
if (registry instanceof PropertyEditorRegistrySupport) { if (registry instanceof PropertyEditorRegistrySupport) {
((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor); ((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor);
} }

View File

@ -84,8 +84,8 @@ import org.springframework.util.StringUtils;
* "<code>zip:</code>" in WebLogic, "<code>wsjar</code>" in WebSphere", etc.), * "<code>zip:</code>" in WebLogic, "<code>wsjar</code>" in WebSphere", etc.),
* then a <code>java.io.File</code> is obtained from it, and used to resolve the * then a <code>java.io.File</code> is obtained from it, and used to resolve the
* wildcard by walking the filesystem. In the case of a jar URL, the resolver * wildcard by walking the filesystem. In the case of a jar URL, the resolver
* either gets a <code>java.net.JarURLConnection</code> from it, or manually parse * either gets a <code>java.net.JarURLConnection</code> from it, or manually parses
* the jar URL, and then traverse the contents of the jar file, to resolve the * the jar URL, and then traverses the contents of the jar file, to resolve the
* wildcards. * wildcards.
* *
* <p><b>Implications on portability:</b> * <p><b>Implications on portability:</b>
@ -173,7 +173,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
static { static {
// Detect Equinox OSGi (e.g. on WebSphere 6.1) // Detect Equinox OSGi (e.g. on WebSphere 6.1)
try { try {
Class fileLocatorClass = PathMatchingResourcePatternResolver.class.getClassLoader().loadClass( Class<?> fileLocatorClass = PathMatchingResourcePatternResolver.class.getClassLoader().loadClass(
"org.eclipse.core.runtime.FileLocator"); "org.eclipse.core.runtime.FileLocator");
equinoxResolveMethod = fileLocatorClass.getMethod("resolve", URL.class); equinoxResolveMethod = fileLocatorClass.getMethod("resolve", URL.class);
logger.debug("Found Equinox FileLocator for OSGi bundle URL resolution"); logger.debug("Found Equinox FileLocator for OSGi bundle URL resolution");
@ -220,7 +220,6 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
this.resourceLoader = resourceLoader; this.resourceLoader = resourceLoader;
} }
/** /**
* Return the ResourceLoader that this pattern resolver works with. * Return the ResourceLoader that this pattern resolver works with.
*/ */
@ -286,7 +285,6 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
} }
} }
/** /**
* Find all class location resources with the given location via the ClassLoader. * Find all class location resources with the given location via the ClassLoader.
* @param location the absolute path within the classpath * @param location the absolute path within the classpath
@ -300,10 +298,10 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
if (path.startsWith("/")) { if (path.startsWith("/")) {
path = path.substring(1); path = path.substring(1);
} }
Enumeration resourceUrls = getClassLoader().getResources(path); Enumeration<URL> resourceUrls = getClassLoader().getResources(path);
Set<Resource> result = new LinkedHashSet<Resource>(16); Set<Resource> result = new LinkedHashSet<Resource>(16);
while (resourceUrls.hasMoreElements()) { while (resourceUrls.hasMoreElements()) {
URL url = (URL) resourceUrls.nextElement(); URL url = resourceUrls.nextElement();
result.add(convertClassLoaderURL(url)); result.add(convertClassLoaderURL(url));
} }
return result.toArray(new Resource[result.size()]); return result.toArray(new Resource[result.size()]);
@ -384,7 +382,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
* <p>The default implementation detects an Equinox OSGi "bundleresource:" * <p>The default implementation detects an Equinox OSGi "bundleresource:"
* / "bundleentry:" URL and resolves it into a standard jar file URL that * / "bundleentry:" URL and resolves it into a standard jar file URL that
* can be traversed using Spring's standard jar file traversal algorithm. * can be traversed using Spring's standard jar file traversal algorithm.
* @param original the resource to resolfe * @param original the resource to resolve
* @return the resolved resource (may be identical to the passed-in resource) * @return the resolved resource (may be identical to the passed-in resource)
* @throws IOException in case of resolution failure * @throws IOException in case of resolution failure
*/ */
@ -471,8 +469,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
rootEntryPath = rootEntryPath + "/"; rootEntryPath = rootEntryPath + "/";
} }
Set<Resource> result = new LinkedHashSet<Resource>(8); Set<Resource> result = new LinkedHashSet<Resource>(8);
for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) { for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = (JarEntry) entries.nextElement(); JarEntry entry = entries.nextElement();
String entryPath = entry.getName(); String entryPath = entry.getName();
if (entryPath.startsWith(rootEntryPath)) { if (entryPath.startsWith(rootEntryPath)) {
String relativePath = entryPath.substring(rootEntryPath.length()); String relativePath = entryPath.substring(rootEntryPath.length());
@ -604,7 +602,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
* Recursively retrieve files that match the given pattern, * Recursively retrieve files that match the given pattern,
* adding them to the given result list. * adding them to the given result list.
* @param fullPattern the pattern to match against, * @param fullPattern the pattern to match against,
* with preprended root directory path * with prepended root directory path
* @param dir the current directory * @param dir the current directory
* @param result the Set of matching File instances to add to * @param result the Set of matching File instances to add to
* @throws IOException if directory contents could not be retrieved * @throws IOException if directory contents could not be retrieved
@ -712,11 +710,11 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
return VfsPatternUtils.getVisitorAttribute(); return VfsPatternUtils.getVisitorAttribute();
} }
public Set<Resource> getResources() { public Set<Resource> getResources() {
return this.resources; return this.resources;
} }
@SuppressWarnings("unused")
public int size() { public int size() {
return this.resources.size(); return this.resources.size();
} }

View File

@ -37,9 +37,9 @@ import org.springframework.core.io.Resource;
* to <code>Resource</code> array properties. Can also translate a collection * to <code>Resource</code> array properties. Can also translate a collection
* or array of location patterns into a merged Resource array. * or array of location patterns into a merged Resource array.
* *
* <p>The path may contain <code>${...}</code> placeholders, * <p>A path may contain <code>${...}</code> placeholders, to be
* to be resolved as system properties: e.g. <code>${user.dir}</code>. * resolved as {@link org.springframework.core.env.Environment} properties:
* Unresolvable placeholder are ignored by default. * e.g. <code>${user.dir}</code>. Unresolvable placeholders are ignored by default.
* *
* <p>Delegates to a {@link ResourcePatternResolver}, * <p>Delegates to a {@link ResourcePatternResolver},
* by default using a {@link PathMatchingResourcePatternResolver}. * by default using a {@link PathMatchingResourcePatternResolver}.
@ -123,7 +123,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
/** /**
* Treat the given text as location pattern and convert it to a Resource array. * Treat the given text as a location pattern and convert it to a Resource array.
*/ */
@Override @Override
public void setAsText(String text) { public void setAsText(String text) {
@ -138,13 +138,13 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
} }
/** /**
* Treat the given value as collection or array and convert it to a Resource array. * Treat the given value as a collection or array and convert it to a Resource array.
* Considers String elements as location patterns, and takes Resource elements as-is. * Considers String elements as location patterns and takes Resource elements as-is.
*/ */
@Override @Override
public void setValue(Object value) throws IllegalArgumentException { public void setValue(Object value) throws IllegalArgumentException {
if (value instanceof Collection || (value instanceof Object[] && !(value instanceof Resource[]))) { if (value instanceof Collection || (value instanceof Object[] && !(value instanceof Resource[]))) {
Collection input = (value instanceof Collection ? (Collection) value : Arrays.asList((Object[]) value)); Collection<?> input = (value instanceof Collection ? (Collection<?>) value : Arrays.asList((Object[]) value));
List<Resource> merged = new ArrayList<Resource>(); List<Resource> merged = new ArrayList<Resource>();
for (Object element : input) { for (Object element : input) {
if (element instanceof String) { if (element instanceof String) {