Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-27 00:27:52 +00:00
parent 6bbc966a21
commit b0790bf5e7
248 changed files with 2374 additions and 3208 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -54,7 +54,7 @@ public class ContextSingletonBeanFactoryLocator extends SingletonBeanFactoryLoca
private static final String DEFAULT_RESOURCE_LOCATION = "classpath*:beanRefContext.xml";
/** The keyed singleton instances */
private static final Map instances = new HashMap();
private static final Map<String, BeanFactoryLocator> instances = new HashMap<String, BeanFactoryLocator>();
/**
@@ -101,7 +101,7 @@ public class ContextSingletonBeanFactoryLocator extends SingletonBeanFactoryLoca
logger.trace("ContextSingletonBeanFactoryLocator.getInstance(): instances.hashCode=" +
instances.hashCode() + ", instances=" + instances);
}
BeanFactoryLocator bfl = (BeanFactoryLocator) instances.get(resourceLocation);
BeanFactoryLocator bfl = instances.get(resourceLocation);
if (bfl == null) {
bfl = new ContextSingletonBeanFactoryLocator(resourceLocation);
instances.put(resourceLocation, bfl);

View File

@@ -17,6 +17,7 @@
package org.springframework.context.support;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -907,8 +908,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Implementation of ListableBeanFactory interface
//---------------------------------------------------------------------
public boolean containsBeanDefinition(String name) {
return getBeanFactory().containsBeanDefinition(name);
public boolean containsBeanDefinition(String beanName) {
return getBeanFactory().containsBeanDefinition(beanName);
}
public int getBeanDefinitionCount() {
@@ -937,6 +938,23 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
return getBeanFactory().getBeansOfType(type, includePrototypes, allowEagerInit);
}
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
throws BeansException {
return getBeanFactory().getBeansWithAnnotation(annotationType);
}
public Map<String, Object> getBeansWithAnnotation(
Class<? extends Annotation> annotationType, boolean includeNonSingletons, boolean allowEagerInit)
throws BeansException {
return getBeanFactory().getBeansWithAnnotation(annotationType, includeNonSingletons, allowEagerInit);
}
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType) {
return getBeanFactory().findAnnotationOnBean(beanName, annotationType);
}
//---------------------------------------------------------------------
// Implementation of HierarchicalBeanFactory interface

View File

@@ -51,7 +51,7 @@ class ContextTypeMatchClassLoader extends DecoratingClassLoader implements Smart
/** Cache for byte array per class name */
private final Map bytesCache = new HashMap();
private final Map<String, byte[]> bytesCache = new HashMap<String, byte[]>();
public ContextTypeMatchClassLoader(ClassLoader parent) {
@@ -96,7 +96,7 @@ class ContextTypeMatchClassLoader extends DecoratingClassLoader implements Smart
@Override
protected Class loadClassForOverriding(String name) throws ClassNotFoundException {
byte[] bytes = (byte[]) bytesCache.get(name);
byte[] bytes = bytesCache.get(name);
if (bytes == null) {
bytes = loadBytesForClass(name);
if (bytes != null) {

View File

@@ -48,7 +48,7 @@ public abstract class MessageSourceSupport {
* Used for passed-in default messages. MessageFormats for resolved
* codes are cached on a specific basis in subclasses.
*/
private final Map cachedMessageFormats = new HashMap();
private final Map<String, MessageFormat> cachedMessageFormats = new HashMap<String, MessageFormat>();
/**
@@ -94,7 +94,7 @@ public abstract class MessageSourceSupport {
}
MessageFormat messageFormat = null;
synchronized (this.cachedMessageFormats) {
messageFormat = (MessageFormat) this.cachedMessageFormats.get(msg);
messageFormat = this.cachedMessageFormats.get(msg);
if (messageFormat == null) {
messageFormat = createMessageFormat(msg, locale);
this.cachedMessageFormats.put(msg, messageFormat);

View File

@@ -117,8 +117,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
/** Cache to hold already loaded properties per filename */
private final Map<String, PropertiesHolder> cachedProperties = new HashMap<String, PropertiesHolder>();
/** Cache to hold merged loaded properties per basename */
private final Map cachedMergedProperties = new HashMap();
/** Cache to hold merged loaded properties per locale */
private final Map<Locale, PropertiesHolder> cachedMergedProperties = new HashMap<Locale, PropertiesHolder>();
/**
@@ -300,9 +300,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
}
else {
for (String basename : this.basenames) {
List filenames = calculateAllFilenames(basename, locale);
for (int j = 0; j < filenames.size(); j++) {
String filename = (String) filenames.get(j);
List<String> filenames = calculateAllFilenames(basename, locale);
for (String filename : filenames) {
PropertiesHolder propHolder = getProperties(filename);
MessageFormat result = propHolder.getMessageFormat(code, locale);
if (result != null) {
@@ -325,7 +324,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
*/
protected PropertiesHolder getMergedProperties(Locale locale) {
synchronized (this.cachedMergedProperties) {
PropertiesHolder mergedHolder = (PropertiesHolder) this.cachedMergedProperties.get(locale);
PropertiesHolder mergedHolder = this.cachedMergedProperties.get(locale);
if (mergedHolder != null) {
return mergedHolder;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -69,7 +69,8 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
* This allows for very efficient hash lookups, significantly faster
* than the ResourceBundle class's own cache.
*/
private final Map cachedResourceBundles = new HashMap();
private final Map<String, Map<Locale, ResourceBundle>> cachedResourceBundles =
new HashMap<String, Map<Locale, ResourceBundle>>();
/**
* Cache to hold already generated MessageFormats.
@@ -79,7 +80,8 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
* very efficient hash lookups without concatenated keys.
* @see #getMessageFormat
*/
private final Map cachedBundleMessageFormats = new HashMap();
private final Map<ResourceBundle, Map<String, Map<Locale, MessageFormat>>> cachedBundleMessageFormats =
new HashMap<ResourceBundle, Map<String, Map<Locale, MessageFormat>>>();
/**
@@ -200,9 +202,9 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
*/
protected ResourceBundle getResourceBundle(String basename, Locale locale) {
synchronized (this.cachedResourceBundles) {
Map localeMap = (Map) this.cachedResourceBundles.get(basename);
Map<Locale, ResourceBundle> localeMap = this.cachedResourceBundles.get(basename);
if (localeMap != null) {
ResourceBundle bundle = (ResourceBundle) localeMap.get(locale);
ResourceBundle bundle = localeMap.get(locale);
if (bundle != null) {
return bundle;
}
@@ -210,7 +212,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
try {
ResourceBundle bundle = doGetBundle(basename, locale);
if (localeMap == null) {
localeMap = new HashMap();
localeMap = new HashMap<Locale, ResourceBundle>();
this.cachedResourceBundles.put(basename, localeMap);
}
localeMap.put(locale, bundle);
@@ -254,12 +256,12 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
throws MissingResourceException {
synchronized (this.cachedBundleMessageFormats) {
Map codeMap = (Map) this.cachedBundleMessageFormats.get(bundle);
Map localeMap = null;
Map<String, Map<Locale, MessageFormat>> codeMap = this.cachedBundleMessageFormats.get(bundle);
Map<Locale, MessageFormat> localeMap = null;
if (codeMap != null) {
localeMap = (Map) codeMap.get(code);
localeMap = codeMap.get(code);
if (localeMap != null) {
MessageFormat result = (MessageFormat) localeMap.get(locale);
MessageFormat result = localeMap.get(locale);
if (result != null) {
return result;
}
@@ -269,11 +271,11 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
String msg = getStringOrNull(bundle, code);
if (msg != null) {
if (codeMap == null) {
codeMap = new HashMap();
codeMap = new HashMap<String, Map<Locale, MessageFormat>>();
this.cachedBundleMessageFormats.put(bundle, codeMap);
}
if (localeMap == null) {
localeMap = new HashMap();
localeMap = new HashMap<Locale, MessageFormat>();
codeMap.put(code, localeMap);
}
MessageFormat result = createMessageFormat(msg, locale);

View File

@@ -1,100 +0,0 @@
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.support;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
/**
* FactoryBean that creates a Map with String keys and Resource values from
* properties, interpreting passed-in String values as resource locations.
*
* <p>Extends PropertiesFactoryBean to inherit the capability of defining
* local properties and loading from properties files.
*
* <p>Implements the ResourceLoaderAware interface to automatically use
* the context ResourceLoader if running in an ApplicationContext.
* Uses DefaultResourceLoader else.
*
* @author Juergen Hoeller
* @author Keith Donald
* @since 1.0.2
* @see org.springframework.core.io.DefaultResourceLoader
*/
public class ResourceMapFactoryBean extends PropertiesFactoryBean implements ResourceLoaderAware {
private String resourceBasePath = "";
private ResourceLoader resourceLoader = new DefaultResourceLoader();
/**
* Set a base path to prepend to each resource location value
* in the properties file.
* <p>E.g.: resourceBasePath="/images", value="/test.gif"
* -> location="/images/test.gif"
*/
public void setResourceBasePath(String resourceBasePath) {
this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : "");
}
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
}
@Override
public Class getObjectType() {
return Map.class;
}
/**
* Create the Map instance, populated with keys and Resource values.
*/
@Override
protected Object createInstance() throws IOException {
Map resourceMap = new HashMap();
Properties props = mergeProperties();
for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {
String key = (String) en.nextElement();
String location = props.getProperty(key);
resourceMap.put(key, getResource(location));
}
return resourceMap;
}
/**
* Fetch the Resource handle for the given location,
* prepeding the resource base path.
* @param location the resource location
* @return the Resource handle
* @see org.springframework.core.io.ResourceLoader#getResource(String)
*/
protected Resource getResource(String location) {
return this.resourceLoader.getResource(this.resourceBasePath + location);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2005 the original author or authors.
* Copyright 2002-2008 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.
@@ -19,10 +19,8 @@ package org.springframework.jmx.export.assembler;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.management.modelmbean.ModelMBeanNotificationInfo;
import org.springframework.jmx.export.metadata.JmxMetadataUtils;
@@ -41,7 +39,8 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef
private ModelMBeanNotificationInfo[] notificationInfos;
private final Map notificationInfoMappings = new HashMap();
private final Map<String, ModelMBeanNotificationInfo[]> notificationInfoMappings =
new HashMap<String, ModelMBeanNotificationInfo[]>();
public void setNotificationInfos(ManagedNotification[] notificationInfos) {
@@ -53,13 +52,8 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef
this.notificationInfos = infos;
}
public void setNotificationInfoMappings(Map notificationInfoMappings) {
Iterator entries = notificationInfoMappings.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
if (!(entry.getKey() instanceof String)) {
throw new IllegalArgumentException("Property [notificationInfoMappings] only accepts Strings for Map keys");
}
public void setNotificationInfoMappings(Map<String, Object> notificationInfoMappings) {
for (Map.Entry<String, Object> entry : notificationInfoMappings.entrySet()) {
this.notificationInfoMappings.put(entry.getKey(), extractNotificationMetadata(entry.getValue()));
}
}
@@ -68,16 +62,13 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef
@Override
protected ModelMBeanNotificationInfo[] getNotificationInfo(Object managedBean, String beanKey) {
ModelMBeanNotificationInfo[] result = null;
if (StringUtils.hasText(beanKey)) {
result = (ModelMBeanNotificationInfo[]) this.notificationInfoMappings.get(beanKey);
result = this.notificationInfoMappings.get(beanKey);
}
if (result == null) {
result = this.notificationInfos;
}
return (result == null) ? new ModelMBeanNotificationInfo[0] : result;
return (result != null ? result : new ModelMBeanNotificationInfo[0]);
}
private ModelMBeanNotificationInfo[] extractNotificationMetadata(Object mapValue) {
@@ -87,9 +78,8 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef
}
else if (mapValue instanceof Collection) {
Collection col = (Collection) mapValue;
List result = new ArrayList();
for (Iterator iterator = col.iterator(); iterator.hasNext();) {
Object colValue = iterator.next();
List<ModelMBeanNotificationInfo> result = new ArrayList<ModelMBeanNotificationInfo>();
for (Object colValue : col) {
if (!(colValue instanceof ManagedNotification)) {
throw new IllegalArgumentException(
"Property 'notificationInfoMappings' only accepts ManagedNotifications for Map values");
@@ -97,7 +87,7 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef
ManagedNotification mn = (ManagedNotification) colValue;
result.add(JmxMetadataUtils.convertToModelMBeanNotificationInfo(mn));
}
return (ModelMBeanNotificationInfo[]) result.toArray(new ModelMBeanNotificationInfo[result.size()]);
return result.toArray(new ModelMBeanNotificationInfo[result.size()]);
}
else {
throw new IllegalArgumentException(

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2008 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.
@@ -88,10 +88,9 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI
*/
public void setManagedInterfaces(Class[] managedInterfaces) {
if (managedInterfaces != null) {
for (int x = 0; x < managedInterfaces.length; x++) {
if (!managedInterfaces[x].isInterface()) {
throw new IllegalArgumentException(
"Management interface [" + managedInterfaces[x].getName() + "] is no interface");
for (Class ifc : managedInterfaces) {
if (ifc.isInterface()) {
throw new IllegalArgumentException("Management interface [" + ifc.getName() + "] is no interface");
}
}
}
@@ -126,7 +125,7 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI
* @return the resolved interface mappings (with Class objects as values)
*/
private Map resolveInterfaceMappings(Properties mappings) {
Map resolvedMappings = new HashMap(mappings.size());
Map<String, Class[]> resolvedMappings = new HashMap<String, Class[]>(mappings.size());
for (Enumeration en = mappings.propertyNames(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] classNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
@@ -229,12 +228,10 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI
}
if (ifaces != null) {
for (int i = 0; i < ifaces.length; i++) {
Method[] methods = ifaces[i].getMethods();
for (int j = 0; j < methods.length; j++) {
Method ifaceMethod = methods[j];
if (ifaceMethod.getName().equals(method.getName()) &&
Arrays.equals(ifaceMethod.getParameterTypes(), method.getParameterTypes())) {
for (Class ifc : ifaces) {
for (Method ifcMethod : ifc.getMethods()) {
if (ifcMethod.getName().equals(method.getName()) &&
Arrays.equals(ifcMethod.getParameterTypes(), method.getParameterTypes())) {
return true;
}
}

View File

@@ -57,9 +57,9 @@ import org.springframework.util.StringUtils;
*/
public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBeanInfoAssembler {
private Set ignoredMethods;
private Set<String> ignoredMethods;
private Map ignoredMethodMappings;
private Map<String, Set<String>> ignoredMethodMappings;
/**
@@ -69,7 +69,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
* @see #setIgnoredMethodMappings(java.util.Properties)
*/
public void setIgnoredMethods(String[] ignoredMethodNames) {
this.ignoredMethods = new HashSet(Arrays.asList(ignoredMethodNames));
this.ignoredMethods = new HashSet<String>(Arrays.asList(ignoredMethodNames));
}
/**
@@ -80,11 +80,11 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
* Spring will check these mappings first.
*/
public void setIgnoredMethodMappings(Properties mappings) {
this.ignoredMethodMappings = new HashMap();
this.ignoredMethodMappings = new HashMap<String, Set<String>>();
for (Enumeration en = mappings.keys(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
this.ignoredMethodMappings.put(beanKey, new HashSet(Arrays.asList(methodNames)));
this.ignoredMethodMappings.put(beanKey, new HashSet<String>(Arrays.asList(methodNames)));
}
}
@@ -113,7 +113,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
*/
protected boolean isNotIgnored(Method method, String beanKey) {
if (this.ignoredMethodMappings != null) {
Set methodNames = (Set) this.ignoredMethodMappings.get(beanKey);
Set<String> methodNames = this.ignoredMethodMappings.get(beanKey);
if (methodNames != null) {
return !methodNames.contains(method.getName());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2005 the original author or authors.
* Copyright 2002-2008 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.
@@ -57,12 +57,12 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
/**
* Stores the set of method names to use for creating the management interface.
*/
private Set managedMethods;
private Set<String> managedMethods;
/**
* Stores the mappings of bean keys to an array of method names.
*/
private Map methodMappings;
private Map<String, Set<String>> methodMappings;
/**
@@ -73,7 +73,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
* @see #setMethodMappings
*/
public void setManagedMethods(String[] methodNames) {
this.managedMethods = new HashSet(Arrays.asList(methodNames));
this.managedMethods = new HashSet<String>(Arrays.asList(methodNames));
}
/**
@@ -84,11 +84,11 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
* @param mappings the mappins of bean keys to method names
*/
public void setMethodMappings(Properties mappings) {
this.methodMappings = new HashMap();
this.methodMappings = new HashMap<String, Set<String>>();
for (Enumeration en = mappings.keys(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
this.methodMappings.put(beanKey, new HashSet(Arrays.asList(methodNames)));
this.methodMappings.put(beanKey, new HashSet<String>(Arrays.asList(methodNames)));
}
}
@@ -110,7 +110,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
protected boolean isMatch(Method method, String beanKey) {
if (this.methodMappings != null) {
Set methodNames = (Set) this.methodMappings.get(beanKey);
Set<String> methodNames = this.methodMappings.get(beanKey);
if (methodNames != null) {
return methodNames.contains(method.getName());
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2002-2005 the original author or authors.
*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,21 +29,21 @@ import javax.naming.NamingException;
* interface, as JndiTemplate provides all usual JNDI operations via
* convenience methods.
*
* @author Rod Johnson
* @see JndiTemplate
* @see org.springframework.jdbc.core.JdbcTemplate
* @author Rod Johnson
*/
public interface JndiCallback {
public interface JndiCallback<T> {
/**
* Do something with the given JNDI context.
* Implementations don't need to worry about error handling
* <p>Implementations don't need to worry about error handling
* or cleanup, as the JndiTemplate class will handle this.
* @param ctx the current JNDI context
* @throws NamingException if thrown by JNDI methods
* @return a result object, or <code>null</code>
*/
Object doInContext(Context ctx) throws NamingException;
T doInContext(Context ctx) throws NamingException;
}

View File

@@ -87,10 +87,10 @@ public abstract class JndiLocatorSupport extends JndiAccessor {
* @throws NamingException if the JNDI lookup failed
* @see #setResourceRef
*/
protected Object lookup(String jndiName, Class requiredType) throws NamingException {
protected <T> T lookup(String jndiName, Class<T> requiredType) throws NamingException {
Assert.notNull(jndiName, "'jndiName' must not be null");
String convertedName = convertJndiName(jndiName);
Object jndiObject = null;
T jndiObject = null;
try {
jndiObject = getJndiTemplate().lookup(convertedName, requiredType);
}

View File

@@ -18,7 +18,6 @@ package org.springframework.jndi;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
@@ -82,7 +81,7 @@ public class JndiTemplate {
* @throws NamingException thrown by the callback implementation
* @see #createInitialContext
*/
public Object execute(JndiCallback contextCallback) throws NamingException {
public <T> T execute(JndiCallback<T> contextCallback) throws NamingException {
Context ctx = getContext();
try {
return contextCallback.doInContext(ctx);
@@ -174,13 +173,14 @@ public class JndiTemplate {
* @throws NamingException if there is no object with the given
* name bound to JNDI
*/
public Object lookup(String name, Class requiredType) throws NamingException {
@SuppressWarnings("unchecked")
public <T> T lookup(String name, Class<T> requiredType) throws NamingException {
Object jndiObject = lookup(name);
if (requiredType != null && !requiredType.isInstance(jndiObject)) {
throw new TypeMismatchNamingException(
name, requiredType, (jndiObject != null ? jndiObject.getClass() : null));
}
return jndiObject;
return (T) jndiObject;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -60,13 +60,13 @@ import org.springframework.jndi.TypeMismatchNamingException;
public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFactory {
/** JNDI names of resources that are known to be shareable, i.e. can be cached */
private final Set shareableResources = new HashSet();
private final Set<String> shareableResources = new HashSet<String>();
/** Cache of shareable singleton objects: bean name --> bean instance */
private final Map singletonObjects = new HashMap();
private final Map<String, Object> singletonObjects = new HashMap<String, Object>();
/** Cache of the types of nonshareable resources: bean name --> bean type */
private final Map resourceTypes = new HashMap();
private final Map<String, Class> resourceTypes = new HashMap<String, Class>();
public SimpleJndiBeanFactory() {
@@ -96,10 +96,10 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
public Object getBean(String name) throws BeansException {
return getBean(name, (Class) null);
return getBean(name, Object.class);
}
public Object getBean(String name, Class requiredType) throws BeansException {
public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
try {
if (isSingleton(name)) {
return doGetSingleton(name, requiredType);
@@ -170,7 +170,8 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
}
private Object doGetSingleton(String name, Class requiredType) throws NamingException {
@SuppressWarnings("unchecked")
private <T> T doGetSingleton(String name, Class<T> requiredType) throws NamingException {
synchronized (this.singletonObjects) {
if (this.singletonObjects.containsKey(name)) {
Object jndiObject = this.singletonObjects.get(name);
@@ -178,9 +179,9 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
throw new TypeMismatchNamingException(
convertJndiName(name), requiredType, (jndiObject != null ? jndiObject.getClass() : null));
}
return jndiObject;
return (T) jndiObject;
}
Object jndiObject = lookup(name, requiredType);
T jndiObject = lookup(name, requiredType);
this.singletonObjects.put(name, jndiObject);
return jndiObject;
}
@@ -194,7 +195,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
else {
synchronized (this.resourceTypes) {
if (this.resourceTypes.containsKey(name)) {
return (Class) this.resourceTypes.get(name);
return this.resourceTypes.get(name);
}
else {
Object jndiObject = lookup(name, null);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -55,7 +55,7 @@ public class RemoteInvocation implements Serializable {
private Object[] arguments;
private Map attributes;
private Map<String, Serializable> attributes;
/**
@@ -143,7 +143,7 @@ public class RemoteInvocation implements Serializable {
*/
public void addAttribute(String key, Serializable value) throws IllegalStateException {
if (this.attributes == null) {
this.attributes = new HashMap();
this.attributes = new HashMap<String, Serializable>();
}
if (this.attributes.containsKey(key)) {
throw new IllegalStateException("There is already an attribute with key '" + key + "' bound");
@@ -162,7 +162,7 @@ public class RemoteInvocation implements Serializable {
if (this.attributes == null) {
return null;
}
return (Serializable) this.attributes.get(key);
return this.attributes.get(key);
}
/**
@@ -172,7 +172,7 @@ public class RemoteInvocation implements Serializable {
* @see #addAttribute
* @see #getAttribute
*/
public void setAttributes(Map attributes) {
public void setAttributes(Map<String, Serializable> attributes) {
this.attributes = attributes;
}
@@ -183,7 +183,7 @@ public class RemoteInvocation implements Serializable {
* @see #addAttribute
* @see #getAttribute
*/
public Map getAttributes() {
public Map<String, Serializable> getAttributes() {
return this.attributes;
}

View File

@@ -34,7 +34,6 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.task.support.ConcurrentExecutorAdapter;
/**
* {@link org.springframework.beans.factory.FactoryBean} that creates a simple
@@ -120,7 +119,7 @@ public class SimpleHttpServerFactoryBean implements FactoryBean, InitializingBea
* @see com.sun.net.httpserver.HttpServer#setExecutor
*/
public void setTaskExecutor(TaskExecutor executor) {
this.executor = new ConcurrentExecutorAdapter(executor);
this.executor = executor;
}
/**

View File

@@ -42,16 +42,6 @@ import org.springframework.util.Assert;
*/
public class BindException extends Exception implements BindingResult {
/**
* Prefix for the name of the BindException instance in a model,
* followed by the object name.
* @deprecated in favor of <code>BindingResult.MODEL_KEY_PREFIX</code>
* @see BindingResult#MODEL_KEY_PREFIX
*/
@Deprecated
public static final String ERROR_KEY_PREFIX = BindException.class.getName() + ".";
private final BindingResult bindingResult;
@@ -208,7 +198,7 @@ public class BindException extends Exception implements BindingResult {
return this.bindingResult.getTarget();
}
public Map getModel() {
public Map<String, Object> getModel() {
return this.bindingResult.getModel();
}

View File

@@ -499,8 +499,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
*/
protected void checkAllowedFields(MutablePropertyValues mpvs) {
PropertyValue[] pvs = mpvs.getPropertyValues();
for (int i = 0; i < pvs.length; i++) {
PropertyValue pv = pvs[i];
for (PropertyValue pv : pvs) {
String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
if (!isAllowed(field)) {
mpvs.removePropertyValue(pv);
@@ -545,16 +544,14 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
protected void checkRequiredFields(MutablePropertyValues mpvs) {
String[] requiredFields = getRequiredFields();
if (!ObjectUtils.isEmpty(requiredFields)) {
Map propertyValues = new HashMap();
Map<String, PropertyValue> propertyValues = new HashMap<String, PropertyValue>();
PropertyValue[] pvs = mpvs.getPropertyValues();
for (int i = 0; i < pvs.length; i++) {
PropertyValue pv = pvs[i];
for (PropertyValue pv : pvs) {
String canonicalName = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
propertyValues.put(canonicalName, pv);
}
for (int i = 0; i < requiredFields.length; i++) {
String field = requiredFields[i];
PropertyValue pv = (PropertyValue) propertyValues.get(field);
for (String field : requiredFields) {
PropertyValue pv = propertyValues.get(field);
if (pv == null || pv.getValue() == null ||
(pv.getValue() instanceof String && !StringUtils.hasText((String) pv.getValue()))) {
// Use bind error processor to create FieldError.
@@ -589,9 +586,8 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
}
catch (PropertyBatchUpdateException ex) {
// Use bind error processor to create FieldErrors.
PropertyAccessException[] exs = ex.getPropertyAccessExceptions();
for (int i = 0; i < exs.length; i++) {
getBindingErrorProcessor().processPropertyAccessException(exs[i], getInternalBindingResult());
for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) {
getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult());
}
}
}