generified FactoryBeans and further Java 5 code style updates

This commit is contained in:
Juergen Hoeller 2009-02-25 00:34:22 +00:00
parent 555fa3b4c8
commit 160249c012
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");
* you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import org.springframework.util.StringUtils;
* @author Rob Harrop
* @since 2.0
*/
public class MethodLocatingFactoryBean implements FactoryBean, BeanFactoryAware {
public class MethodLocatingFactoryBean implements FactoryBean<Method>, BeanFactoryAware {
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;
}
public Class getObjectType() {
public Class<Method> getObjectType() {
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");
* you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import org.springframework.util.ClassUtils;
* @since 2.0
*/
public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
implements FactoryBean, BeanClassLoaderAware, InitializingBean {
implements FactoryBean<Object>, BeanClassLoaderAware, InitializingBean {
private Object target;
@ -196,7 +196,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
return this.proxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
if (this.proxy != null) {
return this.proxy.getClass();
}

View File

@ -89,7 +89,7 @@ import org.springframework.util.ObjectUtils;
* @see Advised
*/
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.
@ -256,7 +256,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
* a single one), the target bean type, or the TargetSource's target class.
* @see org.springframework.aop.TargetSource#getTargetClass
*/
public Class getObjectType() {
public Class<?> getObjectType() {
synchronized (this) {
if (this.singletonInstance != null) {
return this.singletonInstance.getClass();
@ -448,7 +448,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
else {
// If we get here, we need to add a named interceptor.
// We must check if it's a singleton or prototype.
Object advice = null;
Object advice;
if (this.singleton || this.beanFactory.isSingleton(name)) {
// Add the real Advisor/Advice to the chain.
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");
* you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ import org.springframework.util.ClassUtils;
* @since 2.0
* @see #setProxyTargetClass
*/
public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean, BeanFactoryAware {
public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<Object>, BeanFactoryAware {
/** The TargetSource that manages scoping */
private final SimpleBeanTargetSource scopedTargetSource = new SimpleBeanTargetSource();
@ -117,7 +117,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean,
return this.proxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
if (this.proxy != null) {
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");
* 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;
/**
* 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:
*
@ -52,7 +52,8 @@ import org.springframework.util.StringUtils;
* @since 1.1
* @see #setStaticField
*/
public class FieldRetrievingFactoryBean implements FactoryBean, BeanNameAware, BeanClassLoaderAware, InitializingBean {
public class FieldRetrievingFactoryBean
implements FactoryBean<Object>, BeanNameAware, BeanClassLoaderAware, InitializingBean {
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);
}

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");
* 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;
/**
* 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
* 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
@ -88,7 +88,7 @@ import org.springframework.util.ClassUtils;
* @since 21.11.2003
*/
public class MethodInvokingFactoryBean extends ArgumentConvertingMethodInvoker
implements FactoryBean, BeanClassLoaderAware, BeanFactoryAware, InitializingBean {
implements FactoryBean<Object>, BeanClassLoaderAware, BeanFactoryAware, InitializingBean {
private boolean singleton = true;
@ -196,7 +196,7 @@ public class MethodInvokingFactoryBean extends ArgumentConvertingMethodInvoker
* Return the type of object that this FactoryBean creates,
* or <code>null</code> if not known in advance.
*/
public Class getObjectType() {
public Class<?> getObjectType() {
if (!isPrepared()) {
// Not fully initialized yet -> return null to indicate "not known yet".
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");
* you may not use this file except in compliance with the License.
@ -81,7 +81,7 @@ import org.springframework.util.StringUtils;
* @see #setTargetBeanName
* @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);
@ -207,7 +207,7 @@ public class PropertyPathFactoryBean implements FactoryBean, BeanNameAware, Bean
return target.getPropertyValue(this.propertyPath);
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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;
/**
* A {@link org.springframework.beans.factory.FactoryBean} implementation that
* takes an interface which must have one or more methods with
* the signatures <code>MyType xxx()</code> or <code>MyType xxx(MyIdType id)</code>
* A {@link FactoryBean} implementation that takes an interface which must have one or more
* methods with 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>)
* and creates a dynamic proxy which implements that interface, delegating to an
* underlying {@link org.springframework.beans.factory.BeanFactory}.
@ -188,7 +187,7 @@ import org.springframework.util.StringUtils;
* @see #setServiceMappings
* @see ObjectFactoryCreatingFactoryBean
*/
public class ServiceLocatorFactoryBean implements FactoryBean, BeanFactoryAware, InitializingBean {
public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFactoryAware, InitializingBean {
private Class serviceLocatorInterface;
@ -328,7 +327,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFactoryAware,
return this.proxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
return this.serviceLocatorInterface;
}
@ -359,6 +358,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFactoryAware,
}
}
@SuppressWarnings("unchecked")
private Object invokeServiceLocatorMethod(Method method, Object[] args) throws Exception {
Class serviceLocatorMethodReturnType = getServiceLocatorMethodReturnType(method);
try {

View File

@ -53,7 +53,7 @@ import org.springframework.jndi.JndiLocatorSupport;
* @see commonj.timers.TimerListener
*/
public class TimerManagerFactoryBean extends JndiLocatorSupport
implements FactoryBean, InitializingBean, DisposableBean, Lifecycle {
implements FactoryBean<TimerManager>, InitializingBean, DisposableBean, Lifecycle {
private TimerManager timerManager;
@ -169,11 +169,11 @@ public class TimerManagerFactoryBean extends JndiLocatorSupport
// Implementation of FactoryBean interface
//---------------------------------------------------------------------
public Object getObject() {
public TimerManager getObject() {
return this.timerManager;
}
public Class getObjectType() {
public Class<? extends TimerManager> getObjectType() {
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");
* you may not use this file except in compliance with the License.
@ -70,7 +70,7 @@ import org.springframework.util.MethodInvoker;
* @see #setConcurrent
*/
public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethodInvoker
implements FactoryBean, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean {
implements FactoryBean<Object>, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean {
private String name;
@ -171,7 +171,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
String name = (this.name != null ? this.name : this.beanName);
// 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.
this.jobDetail = new JobDetail(name, this.group, jobClass);
@ -181,8 +181,8 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
// Register job listener names.
if (this.jobListenerNames != null) {
for (int i = 0; i < this.jobListenerNames.length; i++) {
this.jobDetail.addJobListener(this.jobListenerNames[i]);
for (String jobListenerName : this.jobListenerNames) {
this.jobDetail.addJobListener(jobListenerName);
}
}
@ -229,7 +229,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
return this.jobDetail;
}
public Class getObjectType() {
public Class<?> getObjectType() {
return JobDetail.class;
}

View File

@ -87,7 +87,7 @@ import org.springframework.util.CollectionUtils;
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/
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";
@ -665,11 +665,11 @@ public class SchedulerFactoryBean extends SchedulerAccessor
return this.scheduler;
}
public Object getObject() {
public Scheduler getObject() {
return this.scheduler;
}
public Class getObjectType() {
public Class<? extends Scheduler> getObjectType() {
return (this.scheduler != null) ? this.scheduler.getClass() : Scheduler.class;
}

View File

@ -1,12 +1,12 @@
/*
* 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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -51,7 +51,7 @@ import org.springframework.context.ResourceLoaderAware;
* @see org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
*/
public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationFactory
implements FactoryBean, InitializingBean, ResourceLoaderAware {
implements FactoryBean<Configuration>, InitializingBean, ResourceLoaderAware {
private Configuration configuration;
@ -61,11 +61,11 @@ public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationF
}
public Object getObject() {
public Configuration getObject() {
return this.configuration;
}
public Class getObjectType() {
public Class<? extends Configuration> getObjectType() {
return Configuration.class;
}

View File

@ -1,12 +1,12 @@
/*
* 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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,7 +48,7 @@ import org.springframework.context.ResourceLoaderAware;
* @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
*/
public class VelocityEngineFactoryBean extends VelocityEngineFactory
implements FactoryBean, InitializingBean, ResourceLoaderAware {
implements FactoryBean<VelocityEngine>, InitializingBean, ResourceLoaderAware {
private VelocityEngine velocityEngine;
@ -58,11 +58,11 @@ public class VelocityEngineFactoryBean extends VelocityEngineFactory
}
public Object getObject() {
public VelocityEngine getObject() {
return this.velocityEngine;
}
public Class getObjectType() {
public Class<? extends VelocityEngine> getObjectType() {
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");
* 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;
/**
* 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.
*
* <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on
@ -49,7 +49,7 @@ import org.springframework.util.ClassUtils;
* @see AbstractSlsbInvokerInterceptor#setCacheHome
*/
public class LocalStatelessSessionProxyFactoryBean extends LocalSlsbInvokerInterceptor
implements FactoryBean, BeanClassLoaderAware {
implements FactoryBean<Object>, BeanClassLoaderAware {
/** The business interface of the EJB we're proxying */
private Class businessInterface;
@ -95,7 +95,7 @@ public class LocalStatelessSessionProxyFactoryBean extends LocalSlsbInvokerInter
return this.proxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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;
/**
* 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.
*
* <p>See {@link org.springframework.jndi.JndiObjectLocator} for info on
@ -59,7 +59,7 @@ import org.springframework.util.ClassUtils;
* @see AbstractRemoteSlsbInvokerInterceptor#setRefreshHomeOnConnectFailure
*/
public class SimpleRemoteStatelessSessionProxyFactoryBean extends SimpleRemoteSlsbInvokerInterceptor
implements FactoryBean, BeanClassLoaderAware {
implements FactoryBean<Object>, BeanClassLoaderAware {
/** The business interface of the EJB we're proxying */
private Class businessInterface;
@ -109,7 +109,7 @@ public class SimpleRemoteStatelessSessionProxyFactoryBean extends SimpleRemoteSl
return this.proxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* you may not use this file except in compliance with the License.
@ -46,7 +46,7 @@ import org.springframework.util.ClassUtils;
* @see InvalidInvocationException
*/
public class MBeanProxyFactoryBean extends MBeanClientInterceptor
implements FactoryBean, BeanClassLoaderAware, InitializingBean {
implements FactoryBean<Object>, BeanClassLoaderAware, InitializingBean {
private Class proxyInterface;
@ -98,7 +98,7 @@ public class MBeanProxyFactoryBean extends MBeanClientInterceptor
return this.mbeanProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* you may not use this file except in compliance with the License.
@ -17,9 +17,9 @@
package org.springframework.jmx.support;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.management.JMException;
import javax.management.MBeanServer;
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.InitializingBean;
import org.springframework.jmx.JmxException;
import org.springframework.util.CollectionUtils;
/**
* <code>FactoryBean</code> that creates a JSR-160 <code>JMXConnectorServer</code>,
* optionally registers it with the <code>MBeanServer</code> and then starts it.
* {@link FactoryBean} that creates a JSR-160 {@link JMXConnectorServer},
* 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
* <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
*/
public class ConnectorServerFactoryBean extends MBeanRegistrationSupport
implements FactoryBean, InitializingBean, DisposableBean {
implements FactoryBean<JMXConnectorServer>, InitializingBean, DisposableBean {
/** The default service URL */
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 Map environment;
private Map<String, Object> environment = new HashMap<String, Object>();
private ObjectName objectName;
@ -83,15 +84,17 @@ public class ConnectorServerFactoryBean extends MBeanRegistrationSupport
* as <code>java.util.Properties</code> (String key/value pairs).
*/
public void setEnvironment(Properties environment) {
this.environment = environment;
CollectionUtils.mergePropertiesIntoMap(environment, this.environment);
}
/**
* Set the environment properties used to construct the <code>JMXConnector</code>
* as a <code>Map</code> of String keys and arbitrary Object values.
*/
public void setEnvironmentMap(Map environment) {
this.environment = environment;
public void setEnvironmentMap(Map<String, ?> 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;
}
public Class getObjectType() {
public Class<? extends JMXConnectorServer> getObjectType() {
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");
* 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.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
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.InitializingBean;
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>.
* Exposes the <code>MBeanServer</code> for bean references.
*
@ -49,11 +50,11 @@ import org.springframework.util.ClassUtils;
* @see org.springframework.jmx.access.NotificationListenerRegistrar#setServer
*/
public class MBeanServerConnectionFactoryBean
implements FactoryBean, BeanClassLoaderAware, InitializingBean, DisposableBean {
implements FactoryBean<MBeanServerConnection>, BeanClassLoaderAware, InitializingBean, DisposableBean {
private JMXServiceURL serviceUrl;
private Map environment;
private Map<String, Object> environment = new HashMap<String, Object>();
private boolean connectOnStartup = true;
@ -78,15 +79,17 @@ public class MBeanServerConnectionFactoryBean
* as <code>java.util.Properties</code> (String key/value pairs).
*/
public void setEnvironment(Properties environment) {
this.environment = environment;
CollectionUtils.mergePropertiesIntoMap(environment, this.environment);
}
/**
* Set the environment properties used to construct the <code>JMXConnector</code>
* as a <code>Map</code> of String keys and arbitrary Object values.
*/
public void setEnvironmentMap(Map environment) {
this.environment = environment;
public void setEnvironmentMap(Map<String, ?> environment) {
if (environment != null) {
this.environment.putAll(environment);
}
}
/**
@ -143,11 +146,11 @@ public class MBeanServerConnectionFactoryBean
}
public Object getObject() {
public MBeanServerConnection getObject() {
return this.connection;
}
public Class getObjectType() {
public Class<? extends MBeanServerConnection> getObjectType() {
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");
* 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;
/**
* 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}
* 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.
@ -51,7 +51,7 @@ import org.springframework.jmx.MBeanServerNotFoundException;
* @see MBeanServerConnectionFactoryBean
* @see ConnectorServerFactoryBean
*/
public class MBeanServerFactoryBean implements FactoryBean, InitializingBean, DisposableBean {
public class MBeanServerFactoryBean implements FactoryBean<MBeanServer>, InitializingBean, DisposableBean {
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;
}
public Class getObjectType() {
public Class<? extends MBeanServer> getObjectType() {
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");
* 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;
/**
* 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,
* available on WebSphere 5.1 and higher.
*
@ -42,7 +42,7 @@ import org.springframework.jmx.MBeanServerNotFoundException;
* @see javax.management.MBeanServer
* @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";
@ -60,10 +60,10 @@ public class WebSphereMBeanServerFactoryBean implements FactoryBean, Initializin
* this.mbeanServer = AdminServiceFactory.getMBeanFactory().getMBeanServer();
*/
Class adminServiceClass = getClass().getClassLoader().loadClass(ADMIN_SERVICE_FACTORY_CLASS);
Method getMBeanFactoryMethod = adminServiceClass.getMethod(GET_MBEAN_FACTORY_METHOD, new Class[0]);
Object mbeanFactory = getMBeanFactoryMethod.invoke(null, new Object[0]);
Method getMBeanServerMethod = mbeanFactory.getClass().getMethod(GET_MBEAN_SERVER_METHOD, new Class[0]);
this.mbeanServer = (MBeanServer) getMBeanServerMethod.invoke(mbeanFactory, new Object[0]);
Method getMBeanFactoryMethod = adminServiceClass.getMethod(GET_MBEAN_FACTORY_METHOD);
Object mbeanFactory = getMBeanFactoryMethod.invoke(null);
Method getMBeanServerMethod = mbeanFactory.getClass().getMethod(GET_MBEAN_SERVER_METHOD);
this.mbeanServer = (MBeanServer) getMBeanServerMethod.invoke(mbeanFactory);
}
catch (ClassNotFoundException 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;
}
public Class getObjectType() {
public Class<? extends MBeanServer> getObjectType() {
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");
* you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ import org.springframework.util.ClassUtils;
* @see #setCache
* @see JndiObjectTargetSource
*/
public class JndiObjectFactoryBean extends JndiObjectLocator implements FactoryBean, BeanClassLoaderAware {
public class JndiObjectFactoryBean extends JndiObjectLocator implements FactoryBean<Object>, BeanClassLoaderAware {
private Class[] proxyInterfaces;
@ -232,7 +232,7 @@ public class JndiObjectFactoryBean extends JndiObjectLocator implements FactoryB
return this.jndiObject;
}
public Class getObjectType() {
public Class<?> getObjectType() {
if (this.proxyInterfaces != null) {
if (this.proxyInterfaces.length == 1) {
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");
* 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;
/**
* 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
* (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 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();
@ -86,7 +87,7 @@ public class JndiRmiProxyFactoryBean extends JndiRmiClientInterceptor implements
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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;
/**
* FactoryBean for RMI proxies, supporting both conventional RMI services and
* RMI invokers. Exposes the proxied service for use as a bean reference,
* {@link FactoryBean} for RMI proxies, supporting both conventional RMI services
* and RMI invokers. Exposes the proxied service for use as a bean reference,
* using the specified service interface. Proxies will throw Spring's unchecked
* 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.httpinvoker.HttpInvokerProxyFactoryBean
*/
public class RmiProxyFactoryBean extends RmiClientInterceptor implements FactoryBean, BeanClassLoaderAware {
public class RmiProxyFactoryBean extends RmiClientInterceptor implements FactoryBean<Object>, BeanClassLoaderAware {
private Object serviceProxy;
@ -77,7 +77,7 @@ public class RmiProxyFactoryBean extends RmiClientInterceptor implements Factory
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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;
/**
* 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
* 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.LocateRegistry
*/
public class RmiRegistryFactoryBean implements FactoryBean, InitializingBean, DisposableBean {
public class RmiRegistryFactoryBean implements FactoryBean<Registry>, InitializingBean, DisposableBean {
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;
}
public Class getObjectType() {
public Class<? extends Registry> getObjectType() {
return (this.registry != null ? this.registry.getClass() : Registry.class);
}

View File

@ -1,12 +1,12 @@
/*
* 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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -22,19 +22,14 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.scheduling.support.MethodInvokingRunnable;
/**
* FactoryBean that exposes a TimerTask object that delegates
* job execution to a specified (static or non-static) method.
* Avoids the need to implement a one-line TimerTask that just
* invokes an existing business method.
* {@link FactoryBean} that exposes a {@link TimerTask} object which
* delegates job execution to a specified (static or non-static) method.
* Avoids the need to implement a one-line TimerTask that just invokes
* 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.
*
* <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
* @since 19.02.2004
* @see DelegatingTimerTask
@ -43,7 +38,7 @@ import org.springframework.scheduling.support.MethodInvokingRunnable;
* @see org.springframework.scheduling.support.MethodInvokingRunnable
* @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;
@ -55,11 +50,11 @@ public class MethodInvokingTimerTaskFactoryBean extends MethodInvokingRunnable i
}
public Object getObject() {
public TimerTask getObject() {
return this.timerTask;
}
public Class getObjectType() {
public Class<TimerTask> getObjectType() {
return TimerTask.class;
}

View File

@ -47,7 +47,7 @@ import org.springframework.util.StringUtils;
* @see java.util.Timer
* @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());
@ -141,11 +141,11 @@ public class TimerFactoryBean implements FactoryBean, BeanNameAware, Initializin
}
public Object getObject() {
public Timer getObject() {
return this.timer;
}
public Class getObjectType() {
public Class<? extends Timer> getObjectType() {
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");
* 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
* {@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 true convention name. View code should check for <code>null</code> rather
* 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");
* you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
package org.springframework.ui;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
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
* {@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 true convention name. View code should check for <code>null</code> rather
* 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) {
if (attributeValues != null) {
for (Iterator it = attributeValues.iterator(); it.hasNext();) {
addAttribute(it.next());
for (Object attributeValue : attributeValues) {
addAttribute(attributeValue);
}
}
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");
* 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;
@SuppressWarnings("serial")
public class TestProxyFactoryBean extends AbstractSingletonProxyFactoryBean
implements FactoryBean, BeanFactoryAware {
public class TestProxyFactoryBean extends AbstractSingletonProxyFactoryBean implements BeanFactoryAware {
@Override
protected Object createMainInterceptor() {
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");
* 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
*/
public class JmsInvokerProxyFactoryBean extends JmsInvokerClientInterceptor
implements FactoryBean, BeanClassLoaderAware {
implements FactoryBean<Object>, BeanClassLoaderAware {
private Class serviceInterface;
@ -81,7 +81,7 @@ public class JmsInvokerProxyFactoryBean extends JmsInvokerClientInterceptor
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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 org.springframework.jca.cci.connection.CciLocalTransactionManager
*/
public class LocalConnectionFactoryBean implements FactoryBean, InitializingBean {
public class LocalConnectionFactoryBean implements FactoryBean<Object>, InitializingBean {
private ManagedConnectionFactory managedConnectionFactory;
@ -126,7 +126,7 @@ public class LocalConnectionFactoryBean implements FactoryBean, InitializingBean
return this.connectionFactory;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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#stop()
*/
public class ResourceAdapterFactoryBean implements FactoryBean, InitializingBean, DisposableBean {
public class ResourceAdapterFactoryBean implements FactoryBean<ResourceAdapter>, InitializingBean, DisposableBean {
private ResourceAdapter resourceAdapter;
@ -124,11 +124,11 @@ public class ResourceAdapterFactoryBean implements FactoryBean, InitializingBean
}
public Object getObject() {
public ResourceAdapter getObject() {
return this.resourceAdapter;
}
public Class getObjectType() {
public Class<? extends ResourceAdapter> getObjectType() {
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");
* 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
*/
public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBean
implements FactoryBean, BeanFactoryAware {
implements BeanFactoryAware {
private final TransactionInterceptor transactionInterceptor = new TransactionInterceptor();
@ -174,8 +174,7 @@ public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBe
if (this.transactionInterceptor.getTransactionManager() == null &&
beanFactory instanceof ListableBeanFactory) {
ListableBeanFactory lbf = (ListableBeanFactory) beanFactory;
PlatformTransactionManager ptm = (PlatformTransactionManager)
BeanFactoryUtils.beanOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class);
PlatformTransactionManager ptm = BeanFactoryUtils.beanOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class);
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.
*
* <p/>The default implementation logs a warning, sends an HTTP 405 error and sets the "Allow" header. Alternatively, a
* fallback view could be chosen, or the HttpRequestMethodNotSupportedException could be rethrown as-is.
*
* @param ex the HttpRequestMethodNotSupportedException to be handled
* @param request current HTTP request
* <p>The default implementation logs a warning, sends an HTTP 405 error and sets the "Allow" header.
* Alternatively, a fallback view could be chosen, or the HttpRequestMethodNotSupportedException
* could be rethrown as-is.
* @param ex the HttpRequestMethodNotSupportedException to be handled
* @param request current HTTP request
* @param response current HTTP response
* @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
*/
protected ModelAndView handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException ex,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
protected ModelAndView handleHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException ex, HttpServletRequest request, HttpServletResponse response)
throws Exception {
pageNotFoundLogger.warn(ex.getMessage());
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
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");
* 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.
* 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)}.
*
* <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");
* 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;
/**
* FactoryBean for Burlap proxies. Exposes the proxied service for
* use as a bean reference, using the specified service interface.
* {@link FactoryBean} for Burlap proxies. Exposes the proxied service
* for use as a bean reference, using the specified service interface.
*
* <p>Burlap is a slim, XML-based RPC protocol.
* 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.rmi.RmiProxyFactoryBean
*/
public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements FactoryBean {
public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements FactoryBean<Object> {
private Object serviceProxy;
@ -56,7 +56,7 @@ public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements F
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
return getServiceInterface();
}

View File

@ -20,8 +20,8 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.FactoryBean;
/**
* FactoryBean for Hessian proxies. Exposes the proxied service for
* use as a bean reference, using the specified service interface.
* {@link FactoryBean} for Hessian proxies. Exposes the proxied service
* for use as a bean reference, using the specified service interface.
*
* <p>Hessian is a slim, binary RPC protocol.
* 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.rmi.RmiProxyFactoryBean
*/
public class HessianProxyFactoryBean extends HessianClientInterceptor implements FactoryBean {
public class HessianProxyFactoryBean extends HessianClientInterceptor implements FactoryBean<Object> {
private Object serviceProxy;
@ -56,7 +56,7 @@ public class HessianProxyFactoryBean extends HessianClientInterceptor implements
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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;
/**
* FactoryBean for HTTP invoker proxies. Exposes the proxied service for
* use as a bean reference, using the specified service interface.
* {@link FactoryBean} for HTTP invoker proxies. Exposes the proxied service
* 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.
* 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
*/
public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor
implements FactoryBean {
implements FactoryBean<Object> {
private Object serviceProxy;
@ -67,7 +67,7 @@ public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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;
/**
* {@link org.springframework.beans.factory.FactoryBean} for a specific port of a
* JAX-RPC service. Exposes a proxy for the port, to be used for bean references.
* {@link FactoryBean} for a specific port of a JAX-RPC service.
* Exposes a proxy for the port, to be used for bean references.
* Inherits configuration properties from {@link JaxRpcPortClientInterceptor}.
*
* <p>This factory is typically used with an RMI service interface. Alternatively,
@ -45,7 +45,7 @@ import org.springframework.util.ClassUtils;
* @see LocalJaxRpcServiceFactoryBean
*/
public class JaxRpcPortProxyFactoryBean extends JaxRpcPortClientInterceptor
implements FactoryBean, BeanClassLoaderAware {
implements FactoryBean<Object>, BeanClassLoaderAware {
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@ -77,7 +77,7 @@ public class JaxRpcPortProxyFactoryBean extends JaxRpcPortClientInterceptor
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ import org.springframework.beans.factory.InitializingBean;
* @see JaxRpcPortProxyFactoryBean
*/
public class LocalJaxRpcServiceFactoryBean extends LocalJaxRpcServiceFactory
implements FactoryBean, InitializingBean {
implements FactoryBean<Service>, InitializingBean {
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;
}
public Class getObjectType() {
public Class<? extends Service> getObjectType() {
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");
* you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import org.springframework.util.ClassUtils;
* @see LocalJaxWsServiceFactoryBean
*/
public class JaxWsPortProxyFactoryBean extends JaxWsPortClientInterceptor
implements FactoryBean, BeanClassLoaderAware {
implements FactoryBean<Object>, BeanClassLoaderAware {
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@ -62,7 +62,7 @@ public class JaxWsPortProxyFactoryBean extends JaxWsPortClientInterceptor
return this.serviceProxy;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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 JaxWsPortProxyFactoryBean
*/
public class LocalJaxWsServiceFactoryBean extends LocalJaxWsServiceFactory implements FactoryBean, InitializingBean {
public class LocalJaxWsServiceFactoryBean extends LocalJaxWsServiceFactory
implements FactoryBean<Service>, InitializingBean {
private Service service;
@ -44,11 +45,11 @@ public class LocalJaxWsServiceFactoryBean extends LocalJaxWsServiceFactory imple
this.service = createJaxWsService();
}
public Object getObject() throws Exception {
public Service getObject() {
return this.service;
}
public Class getObjectType() {
public Class<? extends Service> getObjectType() {
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");
* 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;
/**
* 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,
* effectively making it available as named Spring bean instance.
*
@ -36,7 +36,7 @@ import org.springframework.web.context.ServletContextAware;
* @since 1.1.4
* @see ServletContextParameterFactoryBean
*/
public class ServletContextAttributeFactoryBean implements FactoryBean, ServletContextAware {
public class ServletContextAttributeFactoryBean implements FactoryBean<Object>, ServletContextAware {
private String attributeName;
@ -65,7 +65,7 @@ public class ServletContextAttributeFactoryBean implements FactoryBean, ServletC
return this.attribute;
}
public Class getObjectType() {
public Class<?> getObjectType() {
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");
* 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;
/**
* 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
* callback interface. Allows for passing the ServletContext reference
* 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 ServletContextAttributeFactoryBean
*/
public class ServletContextFactoryBean implements FactoryBean, ServletContextAware {
public class ServletContextFactoryBean implements FactoryBean<ServletContext>, ServletContextAware {
private ServletContext servletContext;
@ -50,11 +50,11 @@ public class ServletContextFactoryBean implements FactoryBean, ServletContextAwa
}
public Object getObject() {
public ServletContext getObject() {
return this.servletContext;
}
public Class getObjectType() {
public Class<? extends ServletContext> getObjectType() {
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");
* 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;
/**
* 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>).
* Exposes that ServletContext init parameter when used as bean reference,
* effectively making it available as named Spring bean instance.
@ -31,7 +31,7 @@ import org.springframework.web.context.ServletContextAware;
* @since 1.2.4
* @see ServletContextAttributeFactoryBean
*/
public class ServletContextParameterFactoryBean implements FactoryBean, ServletContextAware {
public class ServletContextParameterFactoryBean implements FactoryBean<String>, ServletContextAware {
private String initParamName;
@ -56,11 +56,11 @@ public class ServletContextParameterFactoryBean implements FactoryBean, ServletC
}
public Object getObject() throws Exception {
public String getObject() {
return this.paramValue;
}
public Class getObjectType() {
public Class<String> getObjectType() {
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");
* 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;
/**
* Servlet 2.3/2.4 {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods, retrievable
* via {@link HttpServletRequest#getMethod()}. Since browsers currently only support GET and POST, a common technique -
* used by the Prototype library, for instance - is to use a normal POST with an additional hidden form field
* (<code>_method</code>) to pass the "real" HTTP method. This filter reads that parameter, and changes of {@link
* HttpServletRequestWrapper#getMethod()} accordingly.
* {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods,
* retrievable via {@link HttpServletRequest#getMethod()}. Since browsers currently only
* support GET and POST, a common technique - used by the Prototype library, for instance -
* is to use a normal POST with an additional hidden form field (<code>_method</code>)
* 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
* #setMethodParam(String) methodParam} property.
* <p>The name of the request parameter defaults to <code>_method</code>, but can be
* changed via the {@link #setMethodParam(String) methodParam} property.
*
* @author Arjen Poutsma
* @since 3.0
*/
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";
private String methodParam = DEFAULT_METHOD_PARAM;
/**
* Set the parameter name to look for HTTP methods.
*
* @see #DEFAULT_METHOD_PARAM
*/
public void setMethodParam(String methodParam) {
@ -59,8 +60,10 @@ public class HiddenHttpMethodFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
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);
filterChain.doFilter(wrapper, response);
}
@ -69,21 +72,23 @@ public class HiddenHttpMethodFilter extends OncePerRequestFilter {
}
}
/**
* Simple {@link HttpServletRequest} wrapper that returns the supplied method for {@link
* HttpServletRequest#getMethod()}.
* Simple {@link HttpServletRequest} wrapper that returns the supplied method for
* {@link HttpServletRequest#getMethod()}.
*/
private static class HttpMethodRequestWrapper extends HttpServletRequestWrapper {
private final String method;
private HttpMethodRequestWrapper(String method, HttpServletRequest request) {
public HttpMethodRequestWrapper(String method, HttpServletRequest request) {
super(request);
this.method = method;
}
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");
* 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;
/**
* Servlet 2.3/2.4 {@link javax.servlet.Filter} that generates an <code>ETag</code> value based on the content on the
* response. This ETag is compared to the <code>If-None-Match</code> header of the request. 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})
* is still rendered. As such, this filter only saves bandwith, not performance.
* {@link javax.servlet.Filter} that generates an <code>ETag</code> value based on the content
* on the response. This ETag is compared to the <code>If-None-Match</code> header of the request.
* If these headers are equal, the resonse content is not sent, but rather a 304 "Not Modified" status.
*
* <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 bandwidth, not server performance.
*
* @author Arjen Poutsma
* @since 3.0
@ -48,13 +48,15 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
private static String HEADER_IF_NONE_MATCH = "If-None-Match";
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
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);
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.
* <p/>
* <p/>Default implementation generates an MD5 hash.
*
* @param bytes the
* Generate the ETag header value from the given response body byte array.
* <p>The default implementation generates an MD5 hash.
* @param bytes the response bdoy as byte array
* @return the ETag header value
* @see Md5HashUtils
*/
@ -91,10 +91,11 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
return builder.toString();
}
/**
* {@link HttpServletRequest} wrapper that buffers all content written to the {@linkplain #getOutputStream() output
* stream} and {@linkplain #getWriter() writer}, and allows this content to be retrieved via a {@link #toByteArray()
* byte array}.
* {@link HttpServletRequest} wrapper that buffers all content written to the
* {@linkplain #getOutputStream() output stream} and {@linkplain #getWriter() writer},
* and allows this content to be retrieved via a {@link #toByteArray() byte array}.
*/
private static class ShallowEtagResponseWrapper extends HttpServletResponseWrapper {
@ -109,24 +110,25 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
}
@Override
public ServletOutputStream getOutputStream() throws IOException {
return outputStream;
public ServletOutputStream getOutputStream() {
return this.outputStream;
}
@Override
public PrintWriter getWriter() throws IOException {
if (writer == null) {
if (this.writer == null) {
String characterEncoding = getCharacterEncoding();
Writer targetWriter = (characterEncoding != null ?
new OutputStreamWriter(outputStream, characterEncoding) : new OutputStreamWriter(outputStream));
writer = new PrintWriter(targetWriter);
new OutputStreamWriter(this.outputStream, characterEncoding) :
new OutputStreamWriter(this.outputStream));
this.writer = new PrintWriter(targetWriter);
}
return writer;
return this.writer;
}
@Override
public void resetBuffer() {
content.reset();
this.content.reset();
}
@Override
@ -136,16 +138,16 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
}
private byte[] toByteArray() {
return content.toByteArray();
return this.content.toByteArray();
}
private class ResponseServletOutputStream extends ServletOutputStream {
@Override
public void write(int b) throws IOException {
content.write(b);
}
}
}

View File

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