generified FactoryBeans and further Java 5 code style updates

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@686 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2009-02-25 00:34:22 +00:00
parent 5ad5303398
commit f6c70c07c5
48 changed files with 346 additions and 335 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import org.springframework.util.StringUtils;
* @author Rob Harrop * @author Rob Harrop
* @since 2.0 * @since 2.0
*/ */
public class MethodLocatingFactoryBean implements FactoryBean, BeanFactoryAware { public class MethodLocatingFactoryBean implements FactoryBean<Method>, BeanFactoryAware {
private String targetBeanName; private String targetBeanName;
@ -78,11 +78,11 @@ public class MethodLocatingFactoryBean implements FactoryBean, BeanFactoryAware
} }
public Object getObject() throws Exception { public Method getObject() throws Exception {
return this.method; return this.method;
} }
public Class getObjectType() { public Class<Method> getObjectType() {
return Method.class; return Method.class;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import org.springframework.util.ClassUtils;
* @since 2.0 * @since 2.0
*/ */
public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
implements FactoryBean, BeanClassLoaderAware, InitializingBean { implements FactoryBean<Object>, BeanClassLoaderAware, InitializingBean {
private Object target; private Object target;
@ -196,7 +196,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
return this.proxy; return this.proxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
if (this.proxy != null) { if (this.proxy != null) {
return this.proxy.getClass(); return this.proxy.getClass();
} }

View File

@ -89,7 +89,7 @@ import org.springframework.util.ObjectUtils;
* @see Advised * @see Advised
*/ */
public class ProxyFactoryBean extends ProxyCreatorSupport public class ProxyFactoryBean extends ProxyCreatorSupport
implements FactoryBean, BeanClassLoaderAware, BeanFactoryAware { implements FactoryBean<Object>, BeanClassLoaderAware, BeanFactoryAware {
/** /**
* This suffix in a value in an interceptor list indicates to expand globals. * This suffix in a value in an interceptor list indicates to expand globals.
@ -256,7 +256,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
* a single one), the target bean type, or the TargetSource's target class. * a single one), the target bean type, or the TargetSource's target class.
* @see org.springframework.aop.TargetSource#getTargetClass * @see org.springframework.aop.TargetSource#getTargetClass
*/ */
public Class getObjectType() { public Class<?> getObjectType() {
synchronized (this) { synchronized (this) {
if (this.singletonInstance != null) { if (this.singletonInstance != null) {
return this.singletonInstance.getClass(); return this.singletonInstance.getClass();
@ -448,7 +448,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
else { else {
// If we get here, we need to add a named interceptor. // If we get here, we need to add a named interceptor.
// We must check if it's a singleton or prototype. // We must check if it's a singleton or prototype.
Object advice = null; Object advice;
if (this.singleton || this.beanFactory.isSingleton(name)) { if (this.singleton || this.beanFactory.isSingleton(name)) {
// Add the real Advisor/Advice to the chain. // Add the real Advisor/Advice to the chain.
advice = this.beanFactory.getBean(name); advice = this.beanFactory.getBean(name);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ import org.springframework.util.ClassUtils;
* @since 2.0 * @since 2.0
* @see #setProxyTargetClass * @see #setProxyTargetClass
*/ */
public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean, BeanFactoryAware { public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<Object>, BeanFactoryAware {
/** The TargetSource that manages scoping */ /** The TargetSource that manages scoping */
private final SimpleBeanTargetSource scopedTargetSource = new SimpleBeanTargetSource(); private final SimpleBeanTargetSource scopedTargetSource = new SimpleBeanTargetSource();
@ -117,7 +117,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean,
return this.proxy; return this.proxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
if (this.proxy != null) { if (this.proxy != null) {
return this.proxy.getClass(); return this.proxy.getClass();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* FactoryBean which retrieves a static or non-static field value. * {@link FactoryBean} which retrieves a static or non-static field value.
* *
* <p>Typically used for retrieving public static final constants. Usage example: * <p>Typically used for retrieving public static final constants. Usage example:
* *
@ -52,7 +52,8 @@ import org.springframework.util.StringUtils;
* @since 1.1 * @since 1.1
* @see #setStaticField * @see #setStaticField
*/ */
public class FieldRetrievingFactoryBean implements FactoryBean, BeanNameAware, BeanClassLoaderAware, InitializingBean { public class FieldRetrievingFactoryBean
implements FactoryBean<Object>, BeanNameAware, BeanClassLoaderAware, InitializingBean {
private Class targetClass; private Class targetClass;
@ -205,7 +206,7 @@ public class FieldRetrievingFactoryBean implements FactoryBean, BeanNameAware, B
} }
} }
public Class getObjectType() { public Class<?> getObjectType() {
return (this.fieldObject != null ? this.fieldObject.getType() : null); return (this.fieldObject != null ? this.fieldObject.getType() : null);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import org.springframework.beans.support.ArgumentConvertingMethodInvoker;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
* FactoryBean which returns a value which is the result of a static or instance * {@link FactoryBean} which returns a value which is the result of a static or instance
* method invocation. For most use cases it is better to just use the container's * method invocation. For most use cases it is better to just use the container's
* built-in factory method support for the same purpose, since that is smarter at * built-in factory method support for the same purpose, since that is smarter at
* converting arguments. This factory bean is still useful though when you need to * converting arguments. This factory bean is still useful though when you need to
@ -88,7 +88,7 @@ import org.springframework.util.ClassUtils;
* @since 21.11.2003 * @since 21.11.2003
*/ */
public class MethodInvokingFactoryBean extends ArgumentConvertingMethodInvoker public class MethodInvokingFactoryBean extends ArgumentConvertingMethodInvoker
implements FactoryBean, BeanClassLoaderAware, BeanFactoryAware, InitializingBean { implements FactoryBean<Object>, BeanClassLoaderAware, BeanFactoryAware, InitializingBean {
private boolean singleton = true; private boolean singleton = true;
@ -196,7 +196,7 @@ public class MethodInvokingFactoryBean extends ArgumentConvertingMethodInvoker
* Return the type of object that this FactoryBean creates, * Return the type of object that this FactoryBean creates,
* or <code>null</code> if not known in advance. * or <code>null</code> if not known in advance.
*/ */
public Class getObjectType() { public Class<?> getObjectType() {
if (!isPrepared()) { if (!isPrepared()) {
// Not fully initialized yet -> return null to indicate "not known yet". // Not fully initialized yet -> return null to indicate "not known yet".
return null; return null;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -81,7 +81,7 @@ import org.springframework.util.StringUtils;
* @see #setTargetBeanName * @see #setTargetBeanName
* @see #setPropertyPath * @see #setPropertyPath
*/ */
public class PropertyPathFactoryBean implements FactoryBean, BeanNameAware, BeanFactoryAware { public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAware, BeanFactoryAware {
private static final Log logger = LogFactory.getLog(PropertyPathFactoryBean.class); private static final Log logger = LogFactory.getLog(PropertyPathFactoryBean.class);
@ -207,7 +207,7 @@ public class PropertyPathFactoryBean implements FactoryBean, BeanNameAware, Bean
return target.getPropertyValue(this.propertyPath); return target.getPropertyValue(this.propertyPath);
} }
public Class getObjectType() { public Class<?> getObjectType() {
return this.resultType; return this.resultType;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,9 +35,8 @@ import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* A {@link org.springframework.beans.factory.FactoryBean} implementation that * A {@link FactoryBean} implementation that takes an interface which must have one or more
* takes an interface which must have one or more methods with * methods with the signatures <code>MyType xxx()</code> or <code>MyType xxx(MyIdType id)</code>
* the signatures <code>MyType xxx()</code> or <code>MyType xxx(MyIdType id)</code>
* (typically, <code>MyService getService()</code> or <code>MyService getService(String id)</code>) * (typically, <code>MyService getService()</code> or <code>MyService getService(String id)</code>)
* and creates a dynamic proxy which implements that interface, delegating to an * and creates a dynamic proxy which implements that interface, delegating to an
* underlying {@link org.springframework.beans.factory.BeanFactory}. * underlying {@link org.springframework.beans.factory.BeanFactory}.
@ -188,7 +187,7 @@ import org.springframework.util.StringUtils;
* @see #setServiceMappings * @see #setServiceMappings
* @see ObjectFactoryCreatingFactoryBean * @see ObjectFactoryCreatingFactoryBean
*/ */
public class ServiceLocatorFactoryBean implements FactoryBean, BeanFactoryAware, InitializingBean { public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFactoryAware, InitializingBean {
private Class serviceLocatorInterface; private Class serviceLocatorInterface;
@ -328,7 +327,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFactoryAware,
return this.proxy; return this.proxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return this.serviceLocatorInterface; return this.serviceLocatorInterface;
} }
@ -359,6 +358,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFactoryAware,
} }
} }
@SuppressWarnings("unchecked")
private Object invokeServiceLocatorMethod(Method method, Object[] args) throws Exception { private Object invokeServiceLocatorMethod(Method method, Object[] args) throws Exception {
Class serviceLocatorMethodReturnType = getServiceLocatorMethodReturnType(method); Class serviceLocatorMethodReturnType = getServiceLocatorMethodReturnType(method);
try { try {

View File

@ -53,7 +53,7 @@ import org.springframework.jndi.JndiLocatorSupport;
* @see commonj.timers.TimerListener * @see commonj.timers.TimerListener
*/ */
public class TimerManagerFactoryBean extends JndiLocatorSupport public class TimerManagerFactoryBean extends JndiLocatorSupport
implements FactoryBean, InitializingBean, DisposableBean, Lifecycle { implements FactoryBean<TimerManager>, InitializingBean, DisposableBean, Lifecycle {
private TimerManager timerManager; private TimerManager timerManager;
@ -169,11 +169,11 @@ public class TimerManagerFactoryBean extends JndiLocatorSupport
// Implementation of FactoryBean interface // Implementation of FactoryBean interface
//--------------------------------------------------------------------- //---------------------------------------------------------------------
public Object getObject() { public TimerManager getObject() {
return this.timerManager; return this.timerManager;
} }
public Class getObjectType() { public Class<? extends TimerManager> getObjectType() {
return (this.timerManager != null ? this.timerManager.getClass() : TimerManager.class); return (this.timerManager != null ? this.timerManager.getClass() : TimerManager.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -70,7 +70,7 @@ import org.springframework.util.MethodInvoker;
* @see #setConcurrent * @see #setConcurrent
*/ */
public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethodInvoker public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethodInvoker
implements FactoryBean, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean { implements FactoryBean<Object>, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean {
private String name; private String name;
@ -171,7 +171,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
String name = (this.name != null ? this.name : this.beanName); String name = (this.name != null ? this.name : this.beanName);
// Consider the concurrent flag to choose between stateful and stateless job. // Consider the concurrent flag to choose between stateful and stateless job.
Class jobClass = (this.concurrent ? (Class) MethodInvokingJob.class : StatefulMethodInvokingJob.class); Class jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);
// Build JobDetail instance. // Build JobDetail instance.
this.jobDetail = new JobDetail(name, this.group, jobClass); this.jobDetail = new JobDetail(name, this.group, jobClass);
@ -181,8 +181,8 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
// Register job listener names. // Register job listener names.
if (this.jobListenerNames != null) { if (this.jobListenerNames != null) {
for (int i = 0; i < this.jobListenerNames.length; i++) { for (String jobListenerName : this.jobListenerNames) {
this.jobDetail.addJobListener(this.jobListenerNames[i]); this.jobDetail.addJobListener(jobListenerName);
} }
} }
@ -229,7 +229,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
return this.jobDetail; return this.jobDetail;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return JobDetail.class; return JobDetail.class;
} }

View File

@ -87,7 +87,7 @@ import org.springframework.util.CollectionUtils;
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/ */
public class SchedulerFactoryBean extends SchedulerAccessor public class SchedulerFactoryBean extends SchedulerAccessor
implements FactoryBean, BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean, Lifecycle { implements FactoryBean<Scheduler>, BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean, Lifecycle {
public static final String PROP_THREAD_COUNT = "org.quartz.threadPool.threadCount"; public static final String PROP_THREAD_COUNT = "org.quartz.threadPool.threadCount";
@ -665,11 +665,11 @@ public class SchedulerFactoryBean extends SchedulerAccessor
return this.scheduler; return this.scheduler;
} }
public Object getObject() { public Scheduler getObject() {
return this.scheduler; return this.scheduler;
} }
public Class getObjectType() { public Class<? extends Scheduler> getObjectType() {
return (this.scheduler != null) ? this.scheduler.getClass() : Scheduler.class; return (this.scheduler != null) ? this.scheduler.getClass() : Scheduler.class;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,7 +51,7 @@ import org.springframework.context.ResourceLoaderAware;
* @see org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer * @see org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
*/ */
public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationFactory public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationFactory
implements FactoryBean, InitializingBean, ResourceLoaderAware { implements FactoryBean<Configuration>, InitializingBean, ResourceLoaderAware {
private Configuration configuration; private Configuration configuration;
@ -61,11 +61,11 @@ public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationF
} }
public Object getObject() { public Configuration getObject() {
return this.configuration; return this.configuration;
} }
public Class getObjectType() { public Class<? extends Configuration> getObjectType() {
return Configuration.class; return Configuration.class;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ import org.springframework.context.ResourceLoaderAware;
* @see org.springframework.web.servlet.view.velocity.VelocityConfigurer * @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
*/ */
public class VelocityEngineFactoryBean extends VelocityEngineFactory public class VelocityEngineFactoryBean extends VelocityEngineFactory
implements FactoryBean, InitializingBean, ResourceLoaderAware { implements FactoryBean<VelocityEngine>, InitializingBean, ResourceLoaderAware {
private VelocityEngine velocityEngine; private VelocityEngine velocityEngine;
@ -58,11 +58,11 @@ public class VelocityEngineFactoryBean extends VelocityEngineFactory
} }
public Object getObject() { public VelocityEngine getObject() {
return this.velocityEngine; return this.velocityEngine;
} }
public Class getObjectType() { public Class<? extends VelocityEngine> getObjectType() {
return VelocityEngine.class; return VelocityEngine.class;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
* Convenient factory for local Stateless Session Bean (SLSB) proxies. * Convenient {@link FactoryBean} for local Stateless Session Bean (SLSB) proxies.
* Designed for EJB 2.x, but works for EJB 3 Session Beans as well. * Designed for EJB 2.x, but works for EJB 3 Session Beans as well.
* *
* <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on * <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on
@ -49,7 +49,7 @@ import org.springframework.util.ClassUtils;
* @see AbstractSlsbInvokerInterceptor#setCacheHome * @see AbstractSlsbInvokerInterceptor#setCacheHome
*/ */
public class LocalStatelessSessionProxyFactoryBean extends LocalSlsbInvokerInterceptor public class LocalStatelessSessionProxyFactoryBean extends LocalSlsbInvokerInterceptor
implements FactoryBean, BeanClassLoaderAware { implements FactoryBean<Object>, BeanClassLoaderAware {
/** The business interface of the EJB we're proxying */ /** The business interface of the EJB we're proxying */
private Class businessInterface; private Class businessInterface;
@ -95,7 +95,7 @@ public class LocalStatelessSessionProxyFactoryBean extends LocalSlsbInvokerInter
return this.proxy; return this.proxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return this.businessInterface; return this.businessInterface;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
* Convenient factory for remote SLSB proxies. * Convenient {@link FactoryBean} for remote SLSB proxies.
* Designed for EJB 2.x, but works for EJB 3 Session Beans as well. * Designed for EJB 2.x, but works for EJB 3 Session Beans as well.
* *
* <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on * <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on
@ -59,7 +59,7 @@ import org.springframework.util.ClassUtils;
* @see AbstractRemoteSlsbInvokerInterceptor#setRefreshHomeOnConnectFailure * @see AbstractRemoteSlsbInvokerInterceptor#setRefreshHomeOnConnectFailure
*/ */
public class SimpleRemoteStatelessSessionProxyFactoryBean extends SimpleRemoteSlsbInvokerInterceptor public class SimpleRemoteStatelessSessionProxyFactoryBean extends SimpleRemoteSlsbInvokerInterceptor
implements FactoryBean, BeanClassLoaderAware { implements FactoryBean<Object>, BeanClassLoaderAware {
/** The business interface of the EJB we're proxying */ /** The business interface of the EJB we're proxying */
private Class businessInterface; private Class businessInterface;
@ -109,7 +109,7 @@ public class SimpleRemoteStatelessSessionProxyFactoryBean extends SimpleRemoteSl
return this.proxy; return this.proxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return this.businessInterface; return this.businessInterface;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,7 +46,7 @@ import org.springframework.util.ClassUtils;
* @see InvalidInvocationException * @see InvalidInvocationException
*/ */
public class MBeanProxyFactoryBean extends MBeanClientInterceptor public class MBeanProxyFactoryBean extends MBeanClientInterceptor
implements FactoryBean, BeanClassLoaderAware, InitializingBean { implements FactoryBean<Object>, BeanClassLoaderAware, InitializingBean {
private Class proxyInterface; private Class proxyInterface;
@ -98,7 +98,7 @@ public class MBeanProxyFactoryBean extends MBeanClientInterceptor
return this.mbeanProxy; return this.mbeanProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return this.proxyInterface; return this.proxyInterface;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,9 +17,9 @@
package org.springframework.jmx.support; package org.springframework.jmx.support;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.management.JMException; import javax.management.JMException;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException; import javax.management.MalformedObjectNameException;
@ -32,10 +32,11 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.jmx.JmxException; import org.springframework.jmx.JmxException;
import org.springframework.util.CollectionUtils;
/** /**
* <code>FactoryBean</code> that creates a JSR-160 <code>JMXConnectorServer</code>, * {@link FactoryBean} that creates a JSR-160 {@link JMXConnectorServer},
* optionally registers it with the <code>MBeanServer</code> and then starts it. * optionally registers it with the {@link MBeanServer} and then starts it.
* *
* <p>The <code>JMXConnectorServer</code> can be started in a separate thread by setting the * <p>The <code>JMXConnectorServer</code> can be started in a separate thread by setting the
* <code>threaded</code> property to <code>true</code>. You can configure this thread to be a * <code>threaded</code> property to <code>true</code>. You can configure this thread to be a
@ -52,7 +53,7 @@ import org.springframework.jmx.JmxException;
* @see MBeanServer * @see MBeanServer
*/ */
public class ConnectorServerFactoryBean extends MBeanRegistrationSupport public class ConnectorServerFactoryBean extends MBeanRegistrationSupport
implements FactoryBean, InitializingBean, DisposableBean { implements FactoryBean<JMXConnectorServer>, InitializingBean, DisposableBean {
/** The default service URL */ /** The default service URL */
public static final String DEFAULT_SERVICE_URL = "service:jmx:jmxmp://localhost:9875"; public static final String DEFAULT_SERVICE_URL = "service:jmx:jmxmp://localhost:9875";
@ -60,7 +61,7 @@ public class ConnectorServerFactoryBean extends MBeanRegistrationSupport
private String serviceUrl = DEFAULT_SERVICE_URL; private String serviceUrl = DEFAULT_SERVICE_URL;
private Map environment; private Map<String, Object> environment = new HashMap<String, Object>();
private ObjectName objectName; private ObjectName objectName;
@ -83,15 +84,17 @@ public class ConnectorServerFactoryBean extends MBeanRegistrationSupport
* as <code>java.util.Properties</code> (String key/value pairs). * as <code>java.util.Properties</code> (String key/value pairs).
*/ */
public void setEnvironment(Properties environment) { public void setEnvironment(Properties environment) {
this.environment = environment; CollectionUtils.mergePropertiesIntoMap(environment, this.environment);
} }
/** /**
* Set the environment properties used to construct the <code>JMXConnector</code> * Set the environment properties used to construct the <code>JMXConnector</code>
* as a <code>Map</code> of String keys and arbitrary Object values. * as a <code>Map</code> of String keys and arbitrary Object values.
*/ */
public void setEnvironmentMap(Map environment) { public void setEnvironmentMap(Map<String, ?> environment) {
this.environment = environment; if (environment != null) {
this.environment.putAll(environment);
}
} }
/** /**
@ -182,11 +185,11 @@ public class ConnectorServerFactoryBean extends MBeanRegistrationSupport
} }
public Object getObject() { public JMXConnectorServer getObject() {
return this.connectorServer; return this.connectorServer;
} }
public Class getObjectType() { public Class<? extends JMXConnectorServer> getObjectType() {
return (this.connectorServer != null ? this.connectorServer.getClass() : JMXConnectorServer.class); return (this.connectorServer != null ? this.connectorServer.getClass() : JMXConnectorServer.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,9 +18,9 @@ package org.springframework.jmx.support;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.management.MBeanServerConnection; import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXConnectorFactory;
@ -34,9 +34,10 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
/** /**
* <code>FactoryBean</code> that creates a JMX 1.2 <code>MBeanServerConnection</code> * {@link FactoryBean} that creates a JMX 1.2 <code>MBeanServerConnection</code>
* to a remote <code>MBeanServer</code> exposed via a <code>JMXServerConnector</code>. * to a remote <code>MBeanServer</code> exposed via a <code>JMXServerConnector</code>.
* Exposes the <code>MBeanServer</code> for bean references. * Exposes the <code>MBeanServer</code> for bean references.
* *
@ -49,11 +50,11 @@ import org.springframework.util.ClassUtils;
* @see org.springframework.jmx.access.NotificationListenerRegistrar#setServer * @see org.springframework.jmx.access.NotificationListenerRegistrar#setServer
*/ */
public class MBeanServerConnectionFactoryBean public class MBeanServerConnectionFactoryBean
implements FactoryBean, BeanClassLoaderAware, InitializingBean, DisposableBean { implements FactoryBean<MBeanServerConnection>, BeanClassLoaderAware, InitializingBean, DisposableBean {
private JMXServiceURL serviceUrl; private JMXServiceURL serviceUrl;
private Map environment; private Map<String, Object> environment = new HashMap<String, Object>();
private boolean connectOnStartup = true; private boolean connectOnStartup = true;
@ -78,15 +79,17 @@ public class MBeanServerConnectionFactoryBean
* as <code>java.util.Properties</code> (String key/value pairs). * as <code>java.util.Properties</code> (String key/value pairs).
*/ */
public void setEnvironment(Properties environment) { public void setEnvironment(Properties environment) {
this.environment = environment; CollectionUtils.mergePropertiesIntoMap(environment, this.environment);
} }
/** /**
* Set the environment properties used to construct the <code>JMXConnector</code> * Set the environment properties used to construct the <code>JMXConnector</code>
* as a <code>Map</code> of String keys and arbitrary Object values. * as a <code>Map</code> of String keys and arbitrary Object values.
*/ */
public void setEnvironmentMap(Map environment) { public void setEnvironmentMap(Map<String, ?> environment) {
this.environment = environment; if (environment != null) {
this.environment.putAll(environment);
}
} }
/** /**
@ -143,11 +146,11 @@ public class MBeanServerConnectionFactoryBean
} }
public Object getObject() { public MBeanServerConnection getObject() {
return this.connection; return this.connection;
} }
public Class getObjectType() { public Class<? extends MBeanServerConnection> getObjectType() {
return (this.connection != null ? this.connection.getClass() : MBeanServerConnection.class); return (this.connection != null ? this.connection.getClass() : MBeanServerConnection.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,7 +28,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.jmx.MBeanServerNotFoundException; import org.springframework.jmx.MBeanServerNotFoundException;
/** /**
* FactoryBean that obtains an {@link javax.management.MBeanServer} reference * {@link FactoryBean} that obtains an {@link javax.management.MBeanServer} reference
* through the standard JMX 1.2 {@link javax.management.MBeanServerFactory} * through the standard JMX 1.2 {@link javax.management.MBeanServerFactory}
* API (which is available on JDK 1.5 or as part of a JMX 1.2 provider). * API (which is available on JDK 1.5 or as part of a JMX 1.2 provider).
* Exposes the <code>MBeanServer</code> for bean references. * Exposes the <code>MBeanServer</code> for bean references.
@ -51,7 +51,7 @@ import org.springframework.jmx.MBeanServerNotFoundException;
* @see MBeanServerConnectionFactoryBean * @see MBeanServerConnectionFactoryBean
* @see ConnectorServerFactoryBean * @see ConnectorServerFactoryBean
*/ */
public class MBeanServerFactoryBean implements FactoryBean, InitializingBean, DisposableBean { public class MBeanServerFactoryBean implements FactoryBean<MBeanServer>, InitializingBean, DisposableBean {
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());
@ -178,11 +178,11 @@ public class MBeanServerFactoryBean implements FactoryBean, InitializingBean, Di
} }
public Object getObject() { public MBeanServer getObject() {
return this.server; return this.server;
} }
public Class getObjectType() { public Class<? extends MBeanServer> getObjectType() {
return (this.server != null ? this.server.getClass() : MBeanServer.class); return (this.server != null ? this.server.getClass() : MBeanServer.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,7 +26,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.jmx.MBeanServerNotFoundException; import org.springframework.jmx.MBeanServerNotFoundException;
/** /**
* FactoryBean that obtains a WebSphere {@link javax.management.MBeanServer} * {@link FactoryBean} that obtains a WebSphere {@link javax.management.MBeanServer}
* reference through WebSphere's proprietary <code>AdminServiceFactory</code> API, * reference through WebSphere's proprietary <code>AdminServiceFactory</code> API,
* available on WebSphere 5.1 and higher. * available on WebSphere 5.1 and higher.
* *
@ -42,7 +42,7 @@ import org.springframework.jmx.MBeanServerNotFoundException;
* @see javax.management.MBeanServer * @see javax.management.MBeanServer
* @see MBeanServerFactoryBean * @see MBeanServerFactoryBean
*/ */
public class WebSphereMBeanServerFactoryBean implements FactoryBean, InitializingBean { public class WebSphereMBeanServerFactoryBean implements FactoryBean<MBeanServer>, InitializingBean {
private static final String ADMIN_SERVICE_FACTORY_CLASS = "com.ibm.websphere.management.AdminServiceFactory"; private static final String ADMIN_SERVICE_FACTORY_CLASS = "com.ibm.websphere.management.AdminServiceFactory";
@ -60,10 +60,10 @@ public class WebSphereMBeanServerFactoryBean implements FactoryBean, Initializin
* this.mbeanServer = AdminServiceFactory.getMBeanFactory().getMBeanServer(); * this.mbeanServer = AdminServiceFactory.getMBeanFactory().getMBeanServer();
*/ */
Class adminServiceClass = getClass().getClassLoader().loadClass(ADMIN_SERVICE_FACTORY_CLASS); Class adminServiceClass = getClass().getClassLoader().loadClass(ADMIN_SERVICE_FACTORY_CLASS);
Method getMBeanFactoryMethod = adminServiceClass.getMethod(GET_MBEAN_FACTORY_METHOD, new Class[0]); Method getMBeanFactoryMethod = adminServiceClass.getMethod(GET_MBEAN_FACTORY_METHOD);
Object mbeanFactory = getMBeanFactoryMethod.invoke(null, new Object[0]); Object mbeanFactory = getMBeanFactoryMethod.invoke(null);
Method getMBeanServerMethod = mbeanFactory.getClass().getMethod(GET_MBEAN_SERVER_METHOD, new Class[0]); Method getMBeanServerMethod = mbeanFactory.getClass().getMethod(GET_MBEAN_SERVER_METHOD);
this.mbeanServer = (MBeanServer) getMBeanServerMethod.invoke(mbeanFactory, new Object[0]); this.mbeanServer = (MBeanServer) getMBeanServerMethod.invoke(mbeanFactory);
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
throw new MBeanServerNotFoundException("Could not find WebSphere's AdminServiceFactory class", ex); throw new MBeanServerNotFoundException("Could not find WebSphere's AdminServiceFactory class", ex);
@ -79,11 +79,11 @@ public class WebSphereMBeanServerFactoryBean implements FactoryBean, Initializin
} }
public Object getObject() { public MBeanServer getObject() {
return this.mbeanServer; return this.mbeanServer;
} }
public Class getObjectType() { public Class<? extends MBeanServer> getObjectType() {
return (this.mbeanServer != null ? this.mbeanServer.getClass() : MBeanServer.class); return (this.mbeanServer != null ? this.mbeanServer.getClass() : MBeanServer.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ import org.springframework.util.ClassUtils;
* @see #setCache * @see #setCache
* @see JndiObjectTargetSource * @see JndiObjectTargetSource
*/ */
public class JndiObjectFactoryBean extends JndiObjectLocator implements FactoryBean, BeanClassLoaderAware { public class JndiObjectFactoryBean extends JndiObjectLocator implements FactoryBean<Object>, BeanClassLoaderAware {
private Class[] proxyInterfaces; private Class[] proxyInterfaces;
@ -232,7 +232,7 @@ public class JndiObjectFactoryBean extends JndiObjectLocator implements FactoryB
return this.jndiObject; return this.jndiObject;
} }
public Class getObjectType() { public Class<?> getObjectType() {
if (this.proxyInterfaces != null) { if (this.proxyInterfaces != null) {
if (this.proxyInterfaces.length == 1) { if (this.proxyInterfaces.length == 1) {
return this.proxyInterfaces[0]; return this.proxyInterfaces[0];

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
* Factory bean for RMI proxies from JNDI. * {@link FactoryBean} for RMI proxies from JNDI.
* *
* <p>Typically used for RMI-IIOP (CORBA), but can also be used for EJB home objects * <p>Typically used for RMI-IIOP (CORBA), but can also be used for EJB home objects
* (for example, a Stateful Session Bean home). In contrast to a plain JNDI lookup, * (for example, a Stateful Session Bean home). In contrast to a plain JNDI lookup,
@ -61,7 +61,8 @@ import org.springframework.util.ClassUtils;
* @see java.rmi.Remote * @see java.rmi.Remote
* @see javax.rmi.PortableRemoteObject#narrow * @see javax.rmi.PortableRemoteObject#narrow
*/ */
public class JndiRmiProxyFactoryBean extends JndiRmiClientInterceptor implements FactoryBean, BeanClassLoaderAware { public class JndiRmiProxyFactoryBean extends JndiRmiClientInterceptor
implements FactoryBean<Object>, BeanClassLoaderAware {
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@ -86,7 +87,7 @@ public class JndiRmiProxyFactoryBean extends JndiRmiClientInterceptor implements
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return getServiceInterface(); return getServiceInterface();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,8 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
/** /**
* FactoryBean for RMI proxies, supporting both conventional RMI services and * {@link FactoryBean} for RMI proxies, supporting both conventional RMI services
* RMI invokers. Exposes the proxied service for use as a bean reference, * and RMI invokers. Exposes the proxied service for use as a bean reference,
* using the specified service interface. Proxies will throw Spring's unchecked * using the specified service interface. Proxies will throw Spring's unchecked
* RemoteAccessException on remote invocation failure instead of RMI's RemoteException. * RemoteAccessException on remote invocation failure instead of RMI's RemoteException.
* *
@ -58,7 +58,7 @@ import org.springframework.beans.factory.FactoryBean;
* @see org.springframework.remoting.caucho.BurlapProxyFactoryBean * @see org.springframework.remoting.caucho.BurlapProxyFactoryBean
* @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean * @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
*/ */
public class RmiProxyFactoryBean extends RmiClientInterceptor implements FactoryBean, BeanClassLoaderAware { public class RmiProxyFactoryBean extends RmiClientInterceptor implements FactoryBean<Object>, BeanClassLoaderAware {
private Object serviceProxy; private Object serviceProxy;
@ -77,7 +77,7 @@ public class RmiProxyFactoryBean extends RmiClientInterceptor implements Factory
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return getServiceInterface(); return getServiceInterface();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
/** /**
* FactoryBean that locates a {@link java.rmi.registry.Registry} and * {@link FactoryBean} that locates a {@link java.rmi.registry.Registry} and
* exposes it for bean references. Can also create a local RMI registry * exposes it for bean references. Can also create a local RMI registry
* on the fly if none exists already. * on the fly if none exists already.
* *
@ -60,7 +60,7 @@ import org.springframework.beans.factory.InitializingBean;
* @see java.rmi.registry.Registry * @see java.rmi.registry.Registry
* @see java.rmi.registry.LocateRegistry * @see java.rmi.registry.LocateRegistry
*/ */
public class RmiRegistryFactoryBean implements FactoryBean, InitializingBean, DisposableBean { public class RmiRegistryFactoryBean implements FactoryBean<Registry>, InitializingBean, DisposableBean {
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());
@ -278,11 +278,11 @@ public class RmiRegistryFactoryBean implements FactoryBean, InitializingBean, Di
} }
public Object getObject() throws Exception { public Registry getObject() throws Exception {
return this.registry; return this.registry;
} }
public Class getObjectType() { public Class<? extends Registry> getObjectType() {
return (this.registry != null ? this.registry.getClass() : Registry.class); return (this.registry != null ? this.registry.getClass() : Registry.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,19 +22,14 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.scheduling.support.MethodInvokingRunnable; import org.springframework.scheduling.support.MethodInvokingRunnable;
/** /**
* FactoryBean that exposes a TimerTask object that delegates * {@link FactoryBean} that exposes a {@link TimerTask} object which
* job execution to a specified (static or non-static) method. * delegates job execution to a specified (static or non-static) method.
* Avoids the need to implement a one-line TimerTask that just * Avoids the need to implement a one-line TimerTask that just invokes
* invokes an existing business method. * an existing business method.
* *
* <p>Derives from MethodInvokingRunnable to share common properties * <p>Derives from {@link MethodInvokingRunnable} to share common properties
* and behavior, effectively providing a TimerTask adapter for it. * and behavior, effectively providing a TimerTask adapter for it.
* *
* <p>Often used to populate a ScheduledTimerTask object with a specific
* reflective method invocation. Note that you can alternatively populate
* a ScheduledTimerTask object with a plain MethodInvokingRunnable instance
* as well (as of Spring 1.2.4), without the need for this special FactoryBean.
*
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 19.02.2004 * @since 19.02.2004
* @see DelegatingTimerTask * @see DelegatingTimerTask
@ -43,7 +38,7 @@ import org.springframework.scheduling.support.MethodInvokingRunnable;
* @see org.springframework.scheduling.support.MethodInvokingRunnable * @see org.springframework.scheduling.support.MethodInvokingRunnable
* @see org.springframework.beans.factory.config.MethodInvokingFactoryBean * @see org.springframework.beans.factory.config.MethodInvokingFactoryBean
*/ */
public class MethodInvokingTimerTaskFactoryBean extends MethodInvokingRunnable implements FactoryBean { public class MethodInvokingTimerTaskFactoryBean extends MethodInvokingRunnable implements FactoryBean<TimerTask> {
private TimerTask timerTask; private TimerTask timerTask;
@ -55,11 +50,11 @@ public class MethodInvokingTimerTaskFactoryBean extends MethodInvokingRunnable i
} }
public Object getObject() { public TimerTask getObject() {
return this.timerTask; return this.timerTask;
} }
public Class getObjectType() { public Class<TimerTask> getObjectType() {
return TimerTask.class; return TimerTask.class;
} }

View File

@ -47,7 +47,7 @@ import org.springframework.util.StringUtils;
* @see java.util.Timer * @see java.util.Timer
* @see java.util.TimerTask * @see java.util.TimerTask
*/ */
public class TimerFactoryBean implements FactoryBean, BeanNameAware, InitializingBean, DisposableBean { public class TimerFactoryBean implements FactoryBean<Timer>, BeanNameAware, InitializingBean, DisposableBean {
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());
@ -141,11 +141,11 @@ public class TimerFactoryBean implements FactoryBean, BeanNameAware, Initializin
} }
public Object getObject() { public Timer getObject() {
return this.timer; return this.timer;
} }
public Class getObjectType() { public Class<? extends Timer> getObjectType() {
return Timer.class; return Timer.class;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,7 @@ public interface Model {
/** /**
* Add the supplied attribute to this <code>Map</code> using a * Add the supplied attribute to this <code>Map</code> using a
* {@link org.springframework.core.Conventions#getVariableName generated name}. * {@link org.springframework.core.Conventions#getVariableName generated name}.
* <p/><emphasis>Note: Empty {@link java.util.Collection Collections} are not added to * <p><emphasis>Note: Empty {@link java.util.Collection Collections} are not added to
* the model when using this method because we cannot correctly determine * the model when using this method because we cannot correctly determine
* the true convention name. View code should check for <code>null</code> rather * the true convention name. View code should check for <code>null</code> rather
* than for empty collections as is already done by JSTL tags.</emphasis> * than for empty collections as is already done by JSTL tags.</emphasis>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
package org.springframework.ui; package org.springframework.ui;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -81,7 +80,7 @@ public class ModelMap extends LinkedHashMap<String, Object> {
/** /**
* Add the supplied attribute to this <code>Map</code> using a * Add the supplied attribute to this <code>Map</code> using a
* {@link org.springframework.core.Conventions#getVariableName generated name}. * {@link org.springframework.core.Conventions#getVariableName generated name}.
* <p/><emphasis>Note: Empty {@link Collection Collections} are not added to * <p><emphasis>Note: Empty {@link Collection Collections} are not added to
* the model when using this method because we cannot correctly determine * the model when using this method because we cannot correctly determine
* the true convention name. View code should check for <code>null</code> rather * the true convention name. View code should check for <code>null</code> rather
* than for empty collections as is already done by JSTL tags.</emphasis> * than for empty collections as is already done by JSTL tags.</emphasis>
@ -102,8 +101,8 @@ public class ModelMap extends LinkedHashMap<String, Object> {
*/ */
public ModelMap addAllAttributes(Collection<?> attributeValues) { public ModelMap addAllAttributes(Collection<?> attributeValues) {
if (attributeValues != null) { if (attributeValues != null) {
for (Iterator it = attributeValues.iterator(); it.hasNext();) { for (Object attributeValue : attributeValues) {
addAttribute(it.next()); addAttribute(attributeValue);
} }
} }
return this; return this;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,15 +23,14 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class TestProxyFactoryBean extends AbstractSingletonProxyFactoryBean public class TestProxyFactoryBean extends AbstractSingletonProxyFactoryBean implements BeanFactoryAware {
implements FactoryBean, BeanFactoryAware {
@Override @Override
protected Object createMainInterceptor() { protected Object createMainInterceptor() {
return new NoOpAdvice(); return new NoOpAdvice();
} }
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { public void setBeanFactory(BeanFactory beanFactory) {
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ import org.springframework.util.ClassUtils;
* @see org.springframework.jms.remoting.JmsInvokerServiceExporter * @see org.springframework.jms.remoting.JmsInvokerServiceExporter
*/ */
public class JmsInvokerProxyFactoryBean extends JmsInvokerClientInterceptor public class JmsInvokerProxyFactoryBean extends JmsInvokerClientInterceptor
implements FactoryBean, BeanClassLoaderAware { implements FactoryBean<Object>, BeanClassLoaderAware {
private Class serviceInterface; private Class serviceInterface;
@ -81,7 +81,7 @@ public class JmsInvokerProxyFactoryBean extends JmsInvokerClientInterceptor
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return this.serviceInterface; return this.serviceInterface;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -68,7 +68,7 @@ import org.springframework.beans.factory.InitializingBean;
* @see javax.resource.cci.Connection#getLocalTransaction * @see javax.resource.cci.Connection#getLocalTransaction
* @see org.springframework.jca.cci.connection.CciLocalTransactionManager * @see org.springframework.jca.cci.connection.CciLocalTransactionManager
*/ */
public class LocalConnectionFactoryBean implements FactoryBean, InitializingBean { public class LocalConnectionFactoryBean implements FactoryBean<Object>, InitializingBean {
private ManagedConnectionFactory managedConnectionFactory; private ManagedConnectionFactory managedConnectionFactory;
@ -126,7 +126,7 @@ public class LocalConnectionFactoryBean implements FactoryBean, InitializingBean
return this.connectionFactory; return this.connectionFactory;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return (this.connectionFactory != null ? this.connectionFactory.getClass() : null); return (this.connectionFactory != null ? this.connectionFactory.getClass() : null);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ import org.springframework.util.Assert;
* @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext) * @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext)
* @see javax.resource.spi.ResourceAdapter#stop() * @see javax.resource.spi.ResourceAdapter#stop()
*/ */
public class ResourceAdapterFactoryBean implements FactoryBean, InitializingBean, DisposableBean { public class ResourceAdapterFactoryBean implements FactoryBean<ResourceAdapter>, InitializingBean, DisposableBean {
private ResourceAdapter resourceAdapter; private ResourceAdapter resourceAdapter;
@ -124,11 +124,11 @@ public class ResourceAdapterFactoryBean implements FactoryBean, InitializingBean
} }
public Object getObject() { public ResourceAdapter getObject() {
return this.resourceAdapter; return this.resourceAdapter;
} }
public Class getObjectType() { public Class<? extends ResourceAdapter> getObjectType() {
return (this.resourceAdapter != null ? this.resourceAdapter.getClass() : ResourceAdapter.class); return (this.resourceAdapter != null ? this.resourceAdapter.getClass() : ResourceAdapter.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -103,7 +103,7 @@ import org.springframework.transaction.PlatformTransactionManager;
* @see org.springframework.aop.framework.ProxyFactoryBean * @see org.springframework.aop.framework.ProxyFactoryBean
*/ */
public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBean public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBean
implements FactoryBean, BeanFactoryAware { implements BeanFactoryAware {
private final TransactionInterceptor transactionInterceptor = new TransactionInterceptor(); private final TransactionInterceptor transactionInterceptor = new TransactionInterceptor();
@ -174,8 +174,7 @@ public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBe
if (this.transactionInterceptor.getTransactionManager() == null && if (this.transactionInterceptor.getTransactionManager() == null &&
beanFactory instanceof ListableBeanFactory) { beanFactory instanceof ListableBeanFactory) {
ListableBeanFactory lbf = (ListableBeanFactory) beanFactory; ListableBeanFactory lbf = (ListableBeanFactory) beanFactory;
PlatformTransactionManager ptm = (PlatformTransactionManager) PlatformTransactionManager ptm = BeanFactoryUtils.beanOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class);
BeanFactoryUtils.beanOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class);
this.transactionInterceptor.setTransactionManager(ptm); this.transactionInterceptor.setTransactionManager(ptm);
} }
} }

View File

@ -375,19 +375,19 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
/** /**
* Handle the case where no request handler method was found for the particular HTTP request method. * Handle the case where no request handler method was found for the particular HTTP request method.
* * <p>The default implementation logs a warning, sends an HTTP 405 error and sets the "Allow" header.
* <p/>The default implementation logs a warning, sends an HTTP 405 error and sets the "Allow" header. Alternatively, a * Alternatively, a fallback view could be chosen, or the HttpRequestMethodNotSupportedException
* fallback view could be chosen, or the HttpRequestMethodNotSupportedException could be rethrown as-is. * could be rethrown as-is.
*
* @param ex the HttpRequestMethodNotSupportedException to be handled * @param ex the HttpRequestMethodNotSupportedException to be handled
* @param request current HTTP request * @param request current HTTP request
* @param response current HTTP response * @param response current HTTP response
* @return a ModelAndView to render, or <code>null</code> if handled directly * @return a ModelAndView to render, or <code>null</code> if handled directly
* @throws Exception an Exception that should be thrown as result of the servlet request * @throws Exception an Exception that should be thrown as result of the servlet request
*/ */
protected ModelAndView handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException ex, protected ModelAndView handleHttpRequestMethodNotSupportedException(
HttpServletRequest request, HttpRequestMethodNotSupportedException ex, HttpServletRequest request, HttpServletResponse response)
HttpServletResponse response) throws Exception { throws Exception {
pageNotFoundLogger.warn(ex.getMessage()); pageNotFoundLogger.warn(ex.getMessage());
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
response.addHeader("Allow", StringUtils.arrayToDelimitedString(ex.getSupportedMethods(), ", ")); response.addHeader("Allow", StringUtils.arrayToDelimitedString(ex.getSupportedMethods(), ", "));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,7 +32,7 @@ import com.sun.syndication.feed.rss.Item;
* <p>Application-specific view classes will extend this class. * <p>Application-specific view classes will extend this class.
* The view will be held in the subclass itself, not in a template. * The view will be held in the subclass itself, not in a template.
* *
* <p/>Main entry points are the {@link #buildFeedMetadata(Map, WireFeed , HttpServletRequest)} * <p>Main entry points are the {@link #buildFeedMetadata(Map, WireFeed , HttpServletRequest)}
* and {@link #buildFeedItems(Map, HttpServletRequest, HttpServletResponse)}. * and {@link #buildFeedItems(Map, HttpServletRequest, HttpServletResponse)}.
* *
* <p>Thanks to Jettro Coenradie and Sergio Bossa for the original feed view prototype! * <p>Thanks to Jettro Coenradie and Sergio Bossa for the original feed view prototype!

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,8 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
/** /**
* FactoryBean for Burlap proxies. Exposes the proxied service for * {@link FactoryBean} for Burlap proxies. Exposes the proxied service
* use as a bean reference, using the specified service interface. * for use as a bean reference, using the specified service interface.
* *
* <p>Burlap is a slim, XML-based RPC protocol. * <p>Burlap is a slim, XML-based RPC protocol.
* For information on Burlap, see the * For information on Burlap, see the
@ -40,7 +40,7 @@ import org.springframework.beans.factory.FactoryBean;
* @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean * @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
* @see org.springframework.remoting.rmi.RmiProxyFactoryBean * @see org.springframework.remoting.rmi.RmiProxyFactoryBean
*/ */
public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements FactoryBean { public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements FactoryBean<Object> {
private Object serviceProxy; private Object serviceProxy;
@ -56,7 +56,7 @@ public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements F
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return getServiceInterface(); return getServiceInterface();
} }

View File

@ -20,8 +20,8 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
/** /**
* FactoryBean for Hessian proxies. Exposes the proxied service for * {@link FactoryBean} for Hessian proxies. Exposes the proxied service
* use as a bean reference, using the specified service interface. * for use as a bean reference, using the specified service interface.
* *
* <p>Hessian is a slim, binary RPC protocol. * <p>Hessian is a slim, binary RPC protocol.
* For information on Hessian, see the * For information on Hessian, see the
@ -40,7 +40,7 @@ import org.springframework.beans.factory.FactoryBean;
* @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean * @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
* @see org.springframework.remoting.rmi.RmiProxyFactoryBean * @see org.springframework.remoting.rmi.RmiProxyFactoryBean
*/ */
public class HessianProxyFactoryBean extends HessianClientInterceptor implements FactoryBean { public class HessianProxyFactoryBean extends HessianClientInterceptor implements FactoryBean<Object> {
private Object serviceProxy; private Object serviceProxy;
@ -56,7 +56,7 @@ public class HessianProxyFactoryBean extends HessianClientInterceptor implements
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return getServiceInterface(); return getServiceInterface();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,8 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
/** /**
* FactoryBean for HTTP invoker proxies. Exposes the proxied service for * {@link FactoryBean} for HTTP invoker proxies. Exposes the proxied service
* use as a bean reference, using the specified service interface. * for use as a bean reference, using the specified service interface.
* *
* <p>The service URL must be an HTTP URL exposing an HTTP invoker service. * <p>The service URL must be an HTTP URL exposing an HTTP invoker service.
* Optionally, a codebase URL can be specified for on-demand dynamic code download * Optionally, a codebase URL can be specified for on-demand dynamic code download
@ -48,7 +48,7 @@ import org.springframework.beans.factory.FactoryBean;
* @see org.springframework.remoting.caucho.BurlapProxyFactoryBean * @see org.springframework.remoting.caucho.BurlapProxyFactoryBean
*/ */
public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor
implements FactoryBean { implements FactoryBean<Object> {
private Object serviceProxy; private Object serviceProxy;
@ -67,7 +67,7 @@ public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return getServiceInterface(); return getServiceInterface();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,8 +22,8 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
* {@link org.springframework.beans.factory.FactoryBean} for a specific port of a * {@link FactoryBean} for a specific port of a JAX-RPC service.
* JAX-RPC service. Exposes a proxy for the port, to be used for bean references. * Exposes a proxy for the port, to be used for bean references.
* Inherits configuration properties from {@link JaxRpcPortClientInterceptor}. * Inherits configuration properties from {@link JaxRpcPortClientInterceptor}.
* *
* <p>This factory is typically used with an RMI service interface. Alternatively, * <p>This factory is typically used with an RMI service interface. Alternatively,
@ -45,7 +45,7 @@ import org.springframework.util.ClassUtils;
* @see LocalJaxRpcServiceFactoryBean * @see LocalJaxRpcServiceFactoryBean
*/ */
public class JaxRpcPortProxyFactoryBean extends JaxRpcPortClientInterceptor public class JaxRpcPortProxyFactoryBean extends JaxRpcPortClientInterceptor
implements FactoryBean, BeanClassLoaderAware { implements FactoryBean<Object>, BeanClassLoaderAware {
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@ -77,7 +77,7 @@ public class JaxRpcPortProxyFactoryBean extends JaxRpcPortClientInterceptor
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return getServiceInterface(); return getServiceInterface();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ import org.springframework.beans.factory.InitializingBean;
* @see JaxRpcPortProxyFactoryBean * @see JaxRpcPortProxyFactoryBean
*/ */
public class LocalJaxRpcServiceFactoryBean extends LocalJaxRpcServiceFactory public class LocalJaxRpcServiceFactoryBean extends LocalJaxRpcServiceFactory
implements FactoryBean, InitializingBean { implements FactoryBean<Service>, InitializingBean {
private Service service; private Service service;
@ -47,11 +47,11 @@ public class LocalJaxRpcServiceFactoryBean extends LocalJaxRpcServiceFactory
} }
public Object getObject() throws Exception { public Service getObject() throws Exception {
return this.service; return this.service;
} }
public Class getObjectType() { public Class<? extends Service> getObjectType() {
return (this.service != null ? this.service.getClass() : Service.class); return (this.service != null ? this.service.getClass() : Service.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import org.springframework.util.ClassUtils;
* @see LocalJaxWsServiceFactoryBean * @see LocalJaxWsServiceFactoryBean
*/ */
public class JaxWsPortProxyFactoryBean extends JaxWsPortClientInterceptor public class JaxWsPortProxyFactoryBean extends JaxWsPortClientInterceptor
implements FactoryBean, BeanClassLoaderAware { implements FactoryBean<Object>, BeanClassLoaderAware {
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@ -62,7 +62,7 @@ public class JaxWsPortProxyFactoryBean extends JaxWsPortClientInterceptor
return this.serviceProxy; return this.serviceProxy;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return getServiceInterface(); return getServiceInterface();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,7 +35,8 @@ import org.springframework.beans.factory.InitializingBean;
* @see org.springframework.jndi.JndiObjectFactoryBean * @see org.springframework.jndi.JndiObjectFactoryBean
* @see JaxWsPortProxyFactoryBean * @see JaxWsPortProxyFactoryBean
*/ */
public class LocalJaxWsServiceFactoryBean extends LocalJaxWsServiceFactory implements FactoryBean, InitializingBean { public class LocalJaxWsServiceFactoryBean extends LocalJaxWsServiceFactory
implements FactoryBean<Service>, InitializingBean {
private Service service; private Service service;
@ -44,11 +45,11 @@ public class LocalJaxWsServiceFactoryBean extends LocalJaxWsServiceFactory imple
this.service = createJaxWsService(); this.service = createJaxWsService();
} }
public Object getObject() throws Exception { public Service getObject() {
return this.service; return this.service;
} }
public Class getObjectType() { public Class<? extends Service> getObjectType() {
return (this.service != null ? this.service.getClass() : Service.class); return (this.service != null ? this.service.getClass() : Service.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.ServletContextAware;
/** /**
* FactoryBean that fetches a specific, existing ServletContext attribute. * {@link FactoryBean} that fetches a specific, existing ServletContext attribute.
* Exposes that ServletContext attribute when used as bean reference, * Exposes that ServletContext attribute when used as bean reference,
* effectively making it available as named Spring bean instance. * effectively making it available as named Spring bean instance.
* *
@ -36,7 +36,7 @@ import org.springframework.web.context.ServletContextAware;
* @since 1.1.4 * @since 1.1.4
* @see ServletContextParameterFactoryBean * @see ServletContextParameterFactoryBean
*/ */
public class ServletContextAttributeFactoryBean implements FactoryBean, ServletContextAware { public class ServletContextAttributeFactoryBean implements FactoryBean<Object>, ServletContextAware {
private String attributeName; private String attributeName;
@ -65,7 +65,7 @@ public class ServletContextAttributeFactoryBean implements FactoryBean, ServletC
return this.attribute; return this.attribute;
} }
public Class getObjectType() { public Class<?> getObjectType() {
return (this.attribute != null ? this.attribute.getClass() : null); return (this.attribute != null ? this.attribute.getClass() : null);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.ServletContextAware;
/** /**
* Simple FactoryBean that exposes the ServletContext for bean references. * {@link FactoryBean} that exposes the ServletContext for bean references.
* Can be used as alternative to implementing the ServletContextAware * Can be used as alternative to implementing the ServletContextAware
* callback interface. Allows for passing the ServletContext reference * callback interface. Allows for passing the ServletContext reference
* to a constructor argument or any custom bean property. * to a constructor argument or any custom bean property.
@ -40,7 +40,7 @@ import org.springframework.web.context.ServletContextAware;
* @see org.springframework.web.context.ServletContextAware * @see org.springframework.web.context.ServletContextAware
* @see ServletContextAttributeFactoryBean * @see ServletContextAttributeFactoryBean
*/ */
public class ServletContextFactoryBean implements FactoryBean, ServletContextAware { public class ServletContextFactoryBean implements FactoryBean<ServletContext>, ServletContextAware {
private ServletContext servletContext; private ServletContext servletContext;
@ -50,11 +50,11 @@ public class ServletContextFactoryBean implements FactoryBean, ServletContextAwa
} }
public Object getObject() { public ServletContext getObject() {
return this.servletContext; return this.servletContext;
} }
public Class getObjectType() { public Class<? extends ServletContext> getObjectType() {
return (this.servletContext != null ? this.servletContext.getClass() : ServletContext.class); return (this.servletContext != null ? this.servletContext.getClass() : ServletContext.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.ServletContextAware;
/** /**
* FactoryBean that retrieves a specific ServletContext init parameter * {@link FactoryBean} that retrieves a specific ServletContext init parameter
* (that is, a "context-param" defined in <code>web.xml</code>). * (that is, a "context-param" defined in <code>web.xml</code>).
* Exposes that ServletContext init parameter when used as bean reference, * Exposes that ServletContext init parameter when used as bean reference,
* effectively making it available as named Spring bean instance. * effectively making it available as named Spring bean instance.
@ -31,7 +31,7 @@ import org.springframework.web.context.ServletContextAware;
* @since 1.2.4 * @since 1.2.4
* @see ServletContextAttributeFactoryBean * @see ServletContextAttributeFactoryBean
*/ */
public class ServletContextParameterFactoryBean implements FactoryBean, ServletContextAware { public class ServletContextParameterFactoryBean implements FactoryBean<String>, ServletContextAware {
private String initParamName; private String initParamName;
@ -56,11 +56,11 @@ public class ServletContextParameterFactoryBean implements FactoryBean, ServletC
} }
public Object getObject() throws Exception { public String getObject() {
return this.paramValue; return this.paramValue;
} }
public Class getObjectType() { public Class<String> getObjectType() {
return String.class; return String.class;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,28 +28,29 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* Servlet 2.3/2.4 {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods, retrievable * {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods,
* via {@link HttpServletRequest#getMethod()}. Since browsers currently only support GET and POST, a common technique - * retrievable via {@link HttpServletRequest#getMethod()}. Since browsers currently only
* used by the Prototype library, for instance - is to use a normal POST with an additional hidden form field * support GET and POST, a common technique - used by the Prototype library, for instance -
* (<code>_method</code>) to pass the "real" HTTP method. This filter reads that parameter, and changes of {@link * is to use a normal POST with an additional hidden form field (<code>_method</code>)
* HttpServletRequestWrapper#getMethod()} accordingly. * to pass the "real" HTTP method. This filter reads that parameter, and changes of
* {@link HttpServletRequestWrapper#getMethod()} accordingly.
* *
* <p/>The name of the request parameter defaults to <code>_method</code>, but can be changed via the {@link * <p>The name of the request parameter defaults to <code>_method</code>, but can be
* #setMethodParam(String) methodParam} property. * changed via the {@link #setMethodParam(String) methodParam} property.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0 * @since 3.0
*/ */
public class HiddenHttpMethodFilter extends OncePerRequestFilter { public class HiddenHttpMethodFilter extends OncePerRequestFilter {
/** Default method parameter, i.e. <code>_method</code>. */ /** Default method parameter: <code>_method</code> */
public static final String DEFAULT_METHOD_PARAM = "_method"; public static final String DEFAULT_METHOD_PARAM = "_method";
private String methodParam = DEFAULT_METHOD_PARAM; private String methodParam = DEFAULT_METHOD_PARAM;
/** /**
* Set the parameter name to look for HTTP methods. * Set the parameter name to look for HTTP methods.
*
* @see #DEFAULT_METHOD_PARAM * @see #DEFAULT_METHOD_PARAM
*/ */
public void setMethodParam(String methodParam) { public void setMethodParam(String methodParam) {
@ -59,8 +60,10 @@ public class HiddenHttpMethodFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException { throws ServletException, IOException {
if ("POST".equals(request.getMethod()) && StringUtils.hasLength(request.getParameter(methodParam))) {
String method = request.getParameter(methodParam).toUpperCase(Locale.ENGLISH); String paramValue = request.getParameter(this.methodParam);
if ("POST".equals(request.getMethod()) && StringUtils.hasLength(paramValue)) {
String method = paramValue.toUpperCase(Locale.ENGLISH);
HttpServletRequest wrapper = new HttpMethodRequestWrapper(method, request); HttpServletRequest wrapper = new HttpMethodRequestWrapper(method, request);
filterChain.doFilter(wrapper, response); filterChain.doFilter(wrapper, response);
} }
@ -69,21 +72,23 @@ public class HiddenHttpMethodFilter extends OncePerRequestFilter {
} }
} }
/** /**
* Simple {@link HttpServletRequest} wrapper that returns the supplied method for {@link * Simple {@link HttpServletRequest} wrapper that returns the supplied method for
* HttpServletRequest#getMethod()}. * {@link HttpServletRequest#getMethod()}.
*/ */
private static class HttpMethodRequestWrapper extends HttpServletRequestWrapper { private static class HttpMethodRequestWrapper extends HttpServletRequestWrapper {
private final String method; private final String method;
private HttpMethodRequestWrapper(String method, HttpServletRequest request) { public HttpMethodRequestWrapper(String method, HttpServletRequest request) {
super(request); super(request);
this.method = method; this.method = method;
} }
public String getMethod() { public String getMethod() {
return method; return this.method;
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,12 +32,12 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.util.Md5HashUtils; import org.springframework.util.Md5HashUtils;
/** /**
* Servlet 2.3/2.4 {@link javax.servlet.Filter} that generates an <code>ETag</code> value based on the content on the * {@link javax.servlet.Filter} that generates an <code>ETag</code> value based on the content
* response. This ETag is compared to the <code>If-None-Match</code> header of the request. If these headers are equal, * on the response. This ETag is compared to the <code>If-None-Match</code> header of the request.
* the resonse content is not sent, but rather a 304 "Not Modified" status. * If these headers are equal, the resonse content is not sent, but rather a 304 "Not Modified" status.
* <p/> *
* <p/>Since the ETag is based on the response content, the response (or {@link org.springframework.web.servlet.View}) * <p>Since the ETag is based on the response content, the response (or {@link org.springframework.web.servlet.View})
* is still rendered. As such, this filter only saves bandwith, not performance. * is still rendered. As such, this filter only saves bandwidth, not server performance.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0 * @since 3.0
@ -48,13 +48,15 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
private static String HEADER_IF_NONE_MATCH = "If-None-Match"; private static String HEADER_IF_NONE_MATCH = "If-None-Match";
@Override @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException { throws ServletException, IOException {
ShallowEtagResponseWrapper wrapper = new ShallowEtagResponseWrapper(response);
filterChain.doFilter(request, wrapper);
byte[] body = wrapper.toByteArray(); ShallowEtagResponseWrapper responseWrapper = new ShallowEtagResponseWrapper(response);
filterChain.doFilter(request, responseWrapper);
byte[] body = responseWrapper.toByteArray();
String responseETag = generateETagHeaderValue(body); String responseETag = generateETagHeaderValue(body);
response.setHeader(HEADER_ETAG, responseETag); response.setHeader(HEADER_ETAG, responseETag);
@ -76,11 +78,9 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
} }
/** /**
* Generates the ETag header value from the given response body bytes array. * Generate the ETag header value from the given response body byte array.
* <p/> * <p>The default implementation generates an MD5 hash.
* <p/>Default implementation generates an MD5 hash. * @param bytes the response bdoy as byte array
*
* @param bytes the
* @return the ETag header value * @return the ETag header value
* @see Md5HashUtils * @see Md5HashUtils
*/ */
@ -91,10 +91,11 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
return builder.toString(); return builder.toString();
} }
/** /**
* {@link HttpServletRequest} wrapper that buffers all content written to the {@linkplain #getOutputStream() output * {@link HttpServletRequest} wrapper that buffers all content written to the
* stream} and {@linkplain #getWriter() writer}, and allows this content to be retrieved via a {@link #toByteArray() * {@linkplain #getOutputStream() output stream} and {@linkplain #getWriter() writer},
* byte array}. * and allows this content to be retrieved via a {@link #toByteArray() byte array}.
*/ */
private static class ShallowEtagResponseWrapper extends HttpServletResponseWrapper { private static class ShallowEtagResponseWrapper extends HttpServletResponseWrapper {
@ -109,24 +110,25 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
} }
@Override @Override
public ServletOutputStream getOutputStream() throws IOException { public ServletOutputStream getOutputStream() {
return outputStream; return this.outputStream;
} }
@Override @Override
public PrintWriter getWriter() throws IOException { public PrintWriter getWriter() throws IOException {
if (writer == null) { if (this.writer == null) {
String characterEncoding = getCharacterEncoding(); String characterEncoding = getCharacterEncoding();
Writer targetWriter = (characterEncoding != null ? Writer targetWriter = (characterEncoding != null ?
new OutputStreamWriter(outputStream, characterEncoding) : new OutputStreamWriter(outputStream)); new OutputStreamWriter(this.outputStream, characterEncoding) :
writer = new PrintWriter(targetWriter); new OutputStreamWriter(this.outputStream));
this.writer = new PrintWriter(targetWriter);
} }
return writer; return this.writer;
} }
@Override @Override
public void resetBuffer() { public void resetBuffer() {
content.reset(); this.content.reset();
} }
@Override @Override
@ -136,16 +138,16 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
} }
private byte[] toByteArray() { private byte[] toByteArray() {
return content.toByteArray(); return this.content.toByteArray();
} }
private class ResponseServletOutputStream extends ServletOutputStream { private class ResponseServletOutputStream extends ServletOutputStream {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
content.write(b); content.write(b);
} }
} }
} }

View File

@ -29,15 +29,16 @@ import java.util.regex.Pattern;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Represents a URI template. An URI template is a URI-like string that contained variables marked of in braces * Represents a URI template. An URI template is a URI-like String that contained variables
* (<code>{</code>, <code>}</code>), which can be expanded to produce a URI. * marked of in braces (<code>{</code>, <code>}</code>), which can be expanded to produce a URI.
* <p/> * <p>See {@link #expand(Map)}, {@link #expand(String[])}, and {@link #match(String)} for example usages.
* See {@link #expand(Map)}, {@link #expand(String[])}, and {@link #match(String)} for example usages. *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0
* @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a> * @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a>
* @since 3.0 * @since 3.0
*/ */
public final class UriTemplate { public class UriTemplate {
/** /**
* Captures URI template variable names. * Captures URI template variable names.
@ -49,15 +50,17 @@ public final class UriTemplate {
*/ */
private static final String VALUE_REGEX = "(.*)"; private static final String VALUE_REGEX = "(.*)";
private final List<String> variableNames; private final List<String> variableNames;
private final Pattern matchPattern; private final Pattern matchPattern;
private final String uriTemplate; private final String uriTemplate;
/** /**
* Constructs a new {@link UriTemplate} with the given string. * Construct a new {@link UriTemplate} with the given URI String.
* @param uriTemplate the uri template string * @param uriTemplate the URI template string
*/ */
public UriTemplate(String uriTemplate) { public UriTemplate(String uriTemplate) {
Parser parser = new Parser(uriTemplate); Parser parser = new Parser(uriTemplate);
@ -66,19 +69,20 @@ public final class UriTemplate {
this.matchPattern = parser.getMatchPattern(); this.matchPattern = parser.getMatchPattern();
} }
/** /**
* Returns the names of the variables in the template, in order. * Return the names of the variables in the template, in order.
* @return the template variable names * @return the template variable names
*/ */
public List<String> getVariableNames() { public final List<String> getVariableNames() {
return variableNames; return this.variableNames;
} }
/** /**
* Given the map of variables, expands this template into a URI string. The map keys represent variable names, the * Given the Map of variables, expands this template into a URI.
* map values variable values. The order of variables is not significant. * The Map keys represent variable names, the Map values variable values.
* <p/> * The order of variables is not significant.
* Example: * <p>Example:
* <pre> * <pre>
* UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); * UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
* Map&lt;String, String&gt; uriVariables = new HashMap&lt;String, String&gt;(); * Map&lt;String, String&gt; uriVariables = new HashMap&lt;String, String&gt;();
@ -87,57 +91,58 @@ public final class UriTemplate {
* System.out.println(template.expand(uriVariables)); * System.out.println(template.expand(uriVariables));
* </pre> * </pre>
* will print: <blockquote><code>http://example.com/hotels/1/bookings/42</code></blockquote> * will print: <blockquote><code>http://example.com/hotels/1/bookings/42</code></blockquote>
* @param uriVariables the map of uri variables * @param uriVariables the map of URI variables
* @return the expanded uri * @return the expanded URI
* @throws IllegalArgumentException if <code>uriVariables</code> is <code>null</code>; or if it does not contain * @throws IllegalArgumentException if <code>uriVariables</code> is <code>null</code>;
* values for all the variable names * or if it does not contain values for all the variable names
*/ */
public URI expand(Map<String, String> uriVariables) { public URI expand(Map<String, String> uriVariables) {
Assert.notNull(uriVariables, "'uriVariables' must not be null"); Assert.notNull(uriVariables, "'uriVariables' must not be null");
String[] values = new String[variableNames.size()]; String[] values = new String[this.variableNames.size()];
for (int i = 0; i < variableNames.size(); i++) { for (int i = 0; i < this.variableNames.size(); i++) {
String name = variableNames.get(i); String name = this.variableNames.get(i);
Assert.isTrue(uriVariables.containsKey(name), "'uriVariables' has no value for [" + name + "]"); if (!uriVariables.containsKey(name)) {
throw new IllegalArgumentException("'uriVariables' Map has no value for '" + name + "'");
}
values[i] = uriVariables.get(name); values[i] = uriVariables.get(name);
} }
return expand(values); return expand(values);
} }
/** /**
* Given an array of variables, expands this template into a URI string. The array represent variable values. The * Given an array of variables, expand this template into a full URI.
* order of variables is significant. * The array represent variable values. The order of variables is significant.
* <p/> * <p>Example:
* Example: * <pre class="code>
* <pre>
* UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); * UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
* System.out.println(template.expand("1", "42)); * System.out.println(template.expand("1", "42));
* </pre> * </pre>
* will print: <blockquote><code>http://example.com/hotels/1/bookings/42</code></blockquote> * will print: <blockquote><code>http://example.com/hotels/1/bookings/42</code></blockquote>
* @param uriVariableValues the array of uri variables * @param uriVariableValues the array of URI variables
* @return the expanded uri * @return the expanded URI
* @throws IllegalArgumentException if <code>uriVariables</code> is <code>null</code>; or if it does not contain * @throws IllegalArgumentException if <code>uriVariables</code> is <code>null</code>;
* sufficient variables * or if it does not contain sufficient variables
*/ */
public URI expand(String... uriVariableValues) { public URI expand(String... uriVariableValues) {
Assert.notNull(uriVariableValues, "'uriVariableValues' must not be null"); Assert.notNull(uriVariableValues, "'uriVariableValues' must not be null");
if (uriVariableValues.length != variableNames.size()) { if (uriVariableValues.length != this.variableNames.size()) {
throw new IllegalArgumentException( throw new IllegalArgumentException("Invalid amount of variables values in [" +
"Invalid amount of variables values in [" + uriTemplate + "]: expected " + variableNames.size() + this.uriTemplate + "]: expected " + this.variableNames.size() +
"; got " + uriVariableValues.length); "; got " + uriVariableValues.length);
} }
Matcher m = NAMES_PATTERN.matcher(uriTemplate); Matcher matcher = NAMES_PATTERN.matcher(this.uriTemplate);
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
int i = 0; int i = 0;
while (m.find()) { while (matcher.find()) {
String uriVariable = uriVariableValues[i++]; String uriVariable = uriVariableValues[i++];
m.appendReplacement(buffer, uriVariable); matcher.appendReplacement(buffer, uriVariable);
} }
m.appendTail(buffer); matcher.appendTail(buffer);
return encodeUri(buffer.toString()); return encodeUri(buffer.toString());
} }
/** /**
* Indicates whether the given URI matches this template. * Indicate whether the given URI matches this template.
* @param uri the URI to match to * @param uri the URI to match to
* @return <code>true</code> if it matches; <code>false</code> otherwise * @return <code>true</code> if it matches; <code>false</code> otherwise
*/ */
@ -145,16 +150,15 @@ public final class UriTemplate {
if (uri == null) { if (uri == null) {
return false; return false;
} }
Matcher m = matchPattern.matcher(uri); Matcher matcher = this.matchPattern.matcher(uri);
return m.matches(); return matcher.matches();
} }
/** /**
* Matches the given URI to a map of variable values. Keys in the returned map are variable names, values are * Match the given URI to a map of variable values. Keys in the returned map are
* variable values, as occurred in the given URI. * variable names, values are variable values, as occurred in the given URI.
* <p/> * <p>Example:
* Example: * <pre class="code">
* <pre>
* UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); * UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
* System.out.println(template.match("http://example.com/hotels/1/bookings/42")); * System.out.println(template.match("http://example.com/hotels/1/bookings/42"));
* </pre> * </pre>
@ -164,18 +168,24 @@ public final class UriTemplate {
*/ */
public Map<String, String> match(String uri) { public Map<String, String> match(String uri) {
Assert.notNull(uri, "'uri' must not be null"); Assert.notNull(uri, "'uri' must not be null");
Map<String, String> result = new LinkedHashMap<String, String>(variableNames.size()); Map<String, String> result = new LinkedHashMap<String, String>(this.variableNames.size());
Matcher m = matchPattern.matcher(uri); Matcher matcher = this.matchPattern.matcher(uri);
if (m.find()) { if (matcher.find()) {
for (int i = 1; i <= m.groupCount(); i++) { for (int i = 1; i <= matcher.groupCount(); i++) {
String name = variableNames.get(i - 1); String name = this.variableNames.get(i - 1);
String value = m.group(i); String value = matcher.group(i);
result.put(name, value); result.put(name, value);
} }
} }
return result; return result;
} }
@Override
public String toString() {
return this.uriTemplate;
}
private static URI encodeUri(String uri) { private static URI encodeUri(String uri) {
try { try {
int idx = uri.indexOf(':'); int idx = uri.indexOf(':');
@ -190,41 +200,35 @@ public final class UriTemplate {
} }
return result; return result;
} }
catch (URISyntaxException e) { catch (URISyntaxException ex) {
throw new IllegalArgumentException("Could not create URI from [" + uri + "]"); throw new IllegalArgumentException("Could not create URI from [" + uri + "]: " + ex);
} }
} }
@Override
public String toString() {
return uriTemplate;
}
/** /**
* Static inner class to parse uri template strings into a matching regular expression. * Static inner class to parse uri template strings into a matching regular expression.
*/ */
private static class Parser { private static class Parser {
private List<String> variableNames = new LinkedList<String>(); private final List<String> variableNames = new LinkedList<String>();
private StringBuilder patternBuilder = new StringBuilder(); private final StringBuilder patternBuilder = new StringBuilder();
private Parser(String uriTemplate) { private Parser(String uriTemplate) {
Assert.hasText(uriTemplate, "'uriTemplate' must not be null"); Assert.hasText(uriTemplate, "'uriTemplate' must not be null");
Matcher m = NAMES_PATTERN.matcher(uriTemplate); Matcher m = NAMES_PATTERN.matcher(uriTemplate);
int end = 0; int end = 0;
while (m.find()) { while (m.find()) {
patternBuilder.append(encodeAndQuote(uriTemplate, end, m.start())); this.patternBuilder.append(encodeAndQuote(uriTemplate, end, m.start()));
patternBuilder.append(VALUE_REGEX); this.patternBuilder.append(VALUE_REGEX);
variableNames.add(m.group(1)); this.variableNames.add(m.group(1));
end = m.end(); end = m.end();
} }
patternBuilder.append(encodeAndQuote(uriTemplate, end, uriTemplate.length())); this.patternBuilder.append(encodeAndQuote(uriTemplate, end, uriTemplate.length()));
int lastIdx = this.patternBuilder.length() - 1;
int lastIdx = patternBuilder.length() - 1; if (lastIdx >= 0 && this.patternBuilder.charAt(lastIdx) == '/') {
if (lastIdx >= 0 && patternBuilder.charAt(lastIdx) == '/') { this.patternBuilder.deleteCharAt(lastIdx);
patternBuilder.deleteCharAt(lastIdx);
} }
} }
@ -238,13 +242,12 @@ public final class UriTemplate {
private List<String> getVariableNames() { private List<String> getVariableNames() {
return Collections.unmodifiableList(variableNames); return Collections.unmodifiableList(this.variableNames);
} }
private Pattern getMatchPattern() { private Pattern getMatchPattern() {
return Pattern.compile(patternBuilder.toString()); return Pattern.compile(this.patternBuilder.toString());
} }
} }
} }