Polishing
This commit is contained in:
@@ -151,11 +151,6 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
this.beanFactory.setParentBeanFactory(getInternalParentBeanFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
super.setId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether it should be allowed to override bean definitions by registering
|
||||
* a different definition with the same name, automatically replacing the former.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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,21 +103,20 @@ public class Indexer extends SpelNodeImpl {
|
||||
@Override
|
||||
protected ValueRef getValueRef(ExpressionState state) throws EvaluationException {
|
||||
TypedValue context = state.getActiveContextObject();
|
||||
Object targetObject = context.getValue();
|
||||
Object target = context.getValue();
|
||||
TypeDescriptor targetDescriptor = context.getTypeDescriptor();
|
||||
TypedValue indexValue = null;
|
||||
Object index = null;
|
||||
TypedValue indexValue;
|
||||
Object index;
|
||||
|
||||
// This first part of the if clause prevents a 'double dereference' of
|
||||
// the property (SPR-5847)
|
||||
if (targetObject instanceof Map && (this.children[0] instanceof PropertyOrFieldReference)) {
|
||||
// This first part of the if clause prevents a 'double dereference' of the property (SPR-5847)
|
||||
if (target instanceof Map && (this.children[0] instanceof PropertyOrFieldReference)) {
|
||||
PropertyOrFieldReference reference = (PropertyOrFieldReference) this.children[0];
|
||||
index = reference.getName();
|
||||
indexValue = new TypedValue(index);
|
||||
}
|
||||
else {
|
||||
// In case the map key is unqualified, we want it evaluated against
|
||||
// the root object so temporarily push that on whilst evaluating the key
|
||||
// In case the map key is unqualified, we want it evaluated against the root object
|
||||
// so temporarily push that on whilst evaluating the key
|
||||
try {
|
||||
state.pushActiveContextObject(state.getRootContextObject());
|
||||
indexValue = this.children[0].getValueInternal(state);
|
||||
@@ -128,52 +127,53 @@ public class Indexer extends SpelNodeImpl {
|
||||
}
|
||||
}
|
||||
|
||||
// Raise a proper exception in case of a null target
|
||||
if (target == null) {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
|
||||
}
|
||||
|
||||
// Indexing into a Map
|
||||
if (targetObject instanceof Map) {
|
||||
if (target instanceof Map) {
|
||||
Object key = index;
|
||||
if (targetDescriptor.getMapKeyTypeDescriptor() != null) {
|
||||
key = state.convertValue(key, targetDescriptor.getMapKeyTypeDescriptor());
|
||||
}
|
||||
this.indexedType = IndexedType.MAP;
|
||||
return new MapIndexingValueRef(state.getTypeConverter(), (Map<?, ?>) targetObject, key, targetDescriptor);
|
||||
return new MapIndexingValueRef(state.getTypeConverter(), (Map<?, ?>) target, key, targetDescriptor);
|
||||
}
|
||||
|
||||
if (targetObject == null) {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
|
||||
}
|
||||
|
||||
// if the object is something that looks indexable by an integer,
|
||||
// If the object is something that looks indexable by an integer,
|
||||
// attempt to treat the index value as a number
|
||||
if (targetObject.getClass().isArray() || targetObject instanceof Collection || targetObject instanceof String) {
|
||||
if (target.getClass().isArray() || target instanceof Collection || target instanceof String) {
|
||||
int idx = (Integer) state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
|
||||
if (targetObject.getClass().isArray()) {
|
||||
if (target.getClass().isArray()) {
|
||||
this.indexedType = IndexedType.ARRAY;
|
||||
return new ArrayIndexingValueRef(state.getTypeConverter(), targetObject, idx, targetDescriptor);
|
||||
return new ArrayIndexingValueRef(state.getTypeConverter(), target, idx, targetDescriptor);
|
||||
}
|
||||
else if (targetObject instanceof Collection) {
|
||||
if (targetObject instanceof List) {
|
||||
else if (target instanceof Collection) {
|
||||
if (target instanceof List) {
|
||||
this.indexedType = IndexedType.LIST;
|
||||
}
|
||||
return new CollectionIndexingValueRef((Collection<?>) targetObject, idx, targetDescriptor,
|
||||
return new CollectionIndexingValueRef((Collection<?>) target, idx, targetDescriptor,
|
||||
state.getTypeConverter(), state.getConfiguration().isAutoGrowCollections(),
|
||||
state.getConfiguration().getMaximumAutoGrowSize());
|
||||
}
|
||||
else {
|
||||
this.indexedType = IndexedType.STRING;
|
||||
return new StringIndexingLValue((String) targetObject, idx, targetDescriptor);
|
||||
return new StringIndexingLValue((String) target, idx, targetDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
// Try and treat the index value as a property of the context object
|
||||
// TODO could call the conversion service to convert the value to a String
|
||||
// TODO: could call the conversion service to convert the value to a String
|
||||
if (String.class == indexValue.getTypeDescriptor().getType()) {
|
||||
this.indexedType = IndexedType.OBJECT;
|
||||
return new PropertyIndexingValueRef(targetObject, (String) indexValue.getValue(),
|
||||
state.getEvaluationContext(), targetDescriptor);
|
||||
return new PropertyIndexingValueRef(
|
||||
target, (String) index, state.getEvaluationContext(), targetDescriptor);
|
||||
}
|
||||
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
|
||||
targetDescriptor.toString());
|
||||
throw new SpelEvaluationException(
|
||||
getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,12 +188,10 @@ public class Indexer extends SpelNodeImpl {
|
||||
return (this.children[0] instanceof PropertyOrFieldReference || this.children[0].isCompilable());
|
||||
}
|
||||
else if (this.indexedType == IndexedType.OBJECT) {
|
||||
// If the string name is changing the accessor is clearly going to change (so compilation is not possible)
|
||||
if (this.cachedReadAccessor != null &&
|
||||
(this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) &&
|
||||
(getChild(0) instanceof StringLiteral)) {
|
||||
return true;
|
||||
}
|
||||
// If the string name is changing the accessor is clearly going to change (so no compilation possible)
|
||||
return (this.cachedReadAccessor != null &&
|
||||
this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor &&
|
||||
getChild(0) instanceof StringLiteral);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -271,7 +269,8 @@ public class Indexer extends SpelNodeImpl {
|
||||
this.children[0].generateCode(mv, cf);
|
||||
cf.exitCompilationScope();
|
||||
}
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
|
||||
mv.visitMethodInsn(
|
||||
INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
|
||||
}
|
||||
|
||||
else if (this.indexedType == IndexedType.OBJECT) {
|
||||
@@ -526,8 +525,9 @@ public class Indexer extends SpelNodeImpl {
|
||||
|
||||
private final TypeDescriptor targetObjectTypeDescriptor;
|
||||
|
||||
public PropertyIndexingValueRef(Object targetObject, String value, EvaluationContext evaluationContext,
|
||||
TypeDescriptor targetObjectTypeDescriptor) {
|
||||
public PropertyIndexingValueRef(Object targetObject, String value,
|
||||
EvaluationContext evaluationContext, TypeDescriptor targetObjectTypeDescriptor) {
|
||||
|
||||
this.targetObject = targetObject;
|
||||
this.name = value;
|
||||
this.evaluationContext = evaluationContext;
|
||||
@@ -569,11 +569,11 @@ public class Indexer extends SpelNodeImpl {
|
||||
}
|
||||
}
|
||||
catch (AccessException ex) {
|
||||
throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
|
||||
this.targetObjectTypeDescriptor.toString());
|
||||
throw new SpelEvaluationException(getStartPosition(), ex,
|
||||
SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString());
|
||||
}
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
|
||||
this.targetObjectTypeDescriptor.toString());
|
||||
throw new SpelEvaluationException(getStartPosition(),
|
||||
SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -629,11 +629,12 @@ public class Indexer extends SpelNodeImpl {
|
||||
|
||||
private final int maximumSize;
|
||||
|
||||
public CollectionIndexingValueRef(Collection collection, int index, TypeDescriptor collectionEntryTypeDescriptor,
|
||||
public CollectionIndexingValueRef(Collection collection, int index, TypeDescriptor collectionEntryDescriptor,
|
||||
TypeConverter typeConverter, boolean growCollection, int maximumSize) {
|
||||
|
||||
this.collection = collection;
|
||||
this.index = index;
|
||||
this.collectionEntryDescriptor = collectionEntryTypeDescriptor;
|
||||
this.collectionEntryDescriptor = collectionEntryDescriptor;
|
||||
this.typeConverter = typeConverter;
|
||||
this.growCollection = growCollection;
|
||||
this.maximumSize = maximumSize;
|
||||
@@ -684,13 +685,14 @@ public class Indexer extends SpelNodeImpl {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION);
|
||||
}
|
||||
if (this.collectionEntryDescriptor.getElementTypeDescriptor() == null) {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
|
||||
throw new SpelEvaluationException(
|
||||
getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
|
||||
}
|
||||
TypeDescriptor elementType = this.collectionEntryDescriptor.getElementTypeDescriptor();
|
||||
try {
|
||||
int newElements = this.index - this.collection.size();
|
||||
while (newElements >= 0) {
|
||||
(this.collection).add(elementType.getType().newInstance());
|
||||
this.collection.add(elementType.getType().newInstance());
|
||||
newElements--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -66,12 +66,14 @@ import org.springframework.util.ReflectionUtils;
|
||||
* always be configured as bean in the application context, in the first case
|
||||
* given to the service directly, in the second case to the prepared template.
|
||||
*
|
||||
* <p><b>NOTE: Hibernate access code can also be coded in plain Hibernate style.
|
||||
* Hence, for newly started projects, consider adopting the standard Hibernate
|
||||
* style of coding data access objects instead, based on
|
||||
* {@link SessionFactory#getCurrentSession()}.
|
||||
* This HibernateTemplate primarily exists as a migration helper for Hibernate 3
|
||||
* based data access code, to benefit from bug fixes in Hibernate 5.x.</b>
|
||||
* <p><b>NOTE: Hibernate access code can also be coded against the native Hibernate
|
||||
* {@link Session}. Hence, for newly started projects, consider adopting the standard
|
||||
* Hibernate style of coding against {@link SessionFactory#getCurrentSession()}.</b>
|
||||
* Alternatively, use {@link #execute(HibernateCallback)} with Java 8 lambda code blocks
|
||||
* against the callback-provided {@code Session} which results in elegant code as well,
|
||||
* decoupled from the Hibernate Session lifecycle. The remaining operations on this
|
||||
* HibernateTemplate primarily exist as a migration helper for older Hibernate 3.x/4.x
|
||||
* data access code in existing applications.</b>
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.2
|
||||
@@ -1168,6 +1170,34 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the given Criteria object, applying cache settings and/or
|
||||
* a transaction timeout.
|
||||
* @param criteria the Criteria object to prepare
|
||||
* @see #setCacheQueries
|
||||
* @see #setQueryCacheRegion
|
||||
*/
|
||||
protected void prepareCriteria(Criteria criteria) {
|
||||
if (isCacheQueries()) {
|
||||
criteria.setCacheable(true);
|
||||
if (getQueryCacheRegion() != null) {
|
||||
criteria.setCacheRegion(getQueryCacheRegion());
|
||||
}
|
||||
}
|
||||
if (getFetchSize() > 0) {
|
||||
criteria.setFetchSize(getFetchSize());
|
||||
}
|
||||
if (getMaxResults() > 0) {
|
||||
criteria.setMaxResults(getMaxResults());
|
||||
}
|
||||
|
||||
SessionHolder sessionHolder =
|
||||
(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
|
||||
if (sessionHolder != null && sessionHolder.hasTimeout()) {
|
||||
criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the given Query object, applying cache settings and/or
|
||||
* a transaction timeout.
|
||||
@@ -1197,34 +1227,6 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the given Criteria object, applying cache settings and/or
|
||||
* a transaction timeout.
|
||||
* @param criteria the Criteria object to prepare
|
||||
* @see #setCacheQueries
|
||||
* @see #setQueryCacheRegion
|
||||
*/
|
||||
protected void prepareCriteria(Criteria criteria) {
|
||||
if (isCacheQueries()) {
|
||||
criteria.setCacheable(true);
|
||||
if (getQueryCacheRegion() != null) {
|
||||
criteria.setCacheRegion(getQueryCacheRegion());
|
||||
}
|
||||
}
|
||||
if (getFetchSize() > 0) {
|
||||
criteria.setFetchSize(getFetchSize());
|
||||
}
|
||||
if (getMaxResults() > 0) {
|
||||
criteria.setMaxResults(getMaxResults());
|
||||
}
|
||||
|
||||
SessionHolder sessionHolder =
|
||||
(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
|
||||
if (sessionHolder != null && sessionHolder.hasTimeout()) {
|
||||
criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the given name parameter to the given Query object.
|
||||
* @param queryObject the Query object
|
||||
@@ -1285,12 +1287,12 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
|
||||
|
||||
// If return value is a Query or Criteria, apply transaction timeout.
|
||||
// Applies to createQuery, getNamedQuery, createCriteria.
|
||||
if (retVal instanceof org.hibernate.Query) {
|
||||
prepareQuery(((org.hibernate.Query) retVal));
|
||||
}
|
||||
if (retVal instanceof Criteria) {
|
||||
prepareCriteria(((Criteria) retVal));
|
||||
}
|
||||
else if (retVal instanceof org.hibernate.Query) {
|
||||
prepareQuery(((org.hibernate.Query) retVal));
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -506,16 +506,6 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpSession getSession() {
|
||||
return super.getSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSession(HttpSession session) {
|
||||
super.setSession(session);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -43,7 +43,8 @@ import org.springframework.util.comparator.CompoundComparator;
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sebastien Deleuze
|
||||
* @since 3.0
|
||||
* @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP 1.1: Semantics and Content, section 3.1.1.1</a>
|
||||
* @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.1.1">
|
||||
* HTTP 1.1: Semantics and Content, section 3.1.1.1</a>
|
||||
*/
|
||||
public class MediaType extends MimeType implements Serializable {
|
||||
|
||||
@@ -99,7 +100,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
/**
|
||||
* A String equivalent of {@link MediaType#APPLICATION_JSON_UTF8}.
|
||||
*/
|
||||
public final static String APPLICATION_JSON_UTF8_VALUE = APPLICATION_JSON_VALUE + ";charset=UTF-8";
|
||||
public final static String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";
|
||||
|
||||
/**
|
||||
* Public constant media type for {@code application/octet-stream}.
|
||||
@@ -250,7 +251,6 @@ public class MediaType extends MimeType implements Serializable {
|
||||
*/
|
||||
public final static String TEXT_XML_VALUE = "text/xml";
|
||||
|
||||
|
||||
private static final String PARAM_QUALITY_FACTOR = "q";
|
||||
|
||||
|
||||
@@ -376,28 +376,6 @@ public class MediaType extends MimeType implements Serializable {
|
||||
return (qualityFactory != null ? Double.parseDouble(unquote(qualityFactory)) : 1D);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether this {@code MediaType} includes the given media type.
|
||||
* <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, and {@code application/*+xml}
|
||||
* includes {@code application/soap+xml}, etc. This method is <b>not</b> symmetric.
|
||||
* @param other the reference media type with which to compare
|
||||
* @return {@code true} if this media type includes the given media type; {@code false} otherwise
|
||||
*/
|
||||
public boolean includes(MediaType other) {
|
||||
return super.includes(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether this {@code MediaType} is compatible with the given media type.
|
||||
* <p>For instance, {@code text/*} is compatible with {@code text/plain}, {@code text/html}, and vice versa.
|
||||
* In effect, this method is similar to {@link #includes(MediaType)}, except that it <b>is</b> symmetric.
|
||||
* @param other the reference media type with which to compare
|
||||
* @return {@code true} if this media type is compatible with the given media type; {@code false} otherwise
|
||||
*/
|
||||
public boolean isCompatibleWith(MediaType other) {
|
||||
return super.isCompatibleWith(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a replica of this instance with the quality value of the given MediaType.
|
||||
* @return the same instance if the given MediaType doesn't have a quality value, or a new one otherwise
|
||||
@@ -624,7 +602,8 @@ public class MediaType extends MimeType implements Serializable {
|
||||
else {
|
||||
int paramsSize1 = mediaType1.getParameters().size();
|
||||
int paramsSize2 = mediaType2.getParameters().size();
|
||||
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic
|
||||
// audio/basic;level=1 < audio/basic
|
||||
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -76,6 +76,7 @@ public class HandlerMappingIntrospector
|
||||
* Constructor that detects the configured {@code HandlerMapping}s in the
|
||||
* given {@code ApplicationContext} or falls back on
|
||||
* "DispatcherServlet.properties" like the {@code DispatcherServlet}.
|
||||
* @deprecated as of 4.3.12, in favor of {@link #setApplicationContext}
|
||||
*/
|
||||
@Deprecated
|
||||
public HandlerMappingIntrospector(ApplicationContext context) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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,7 @@ import org.springframework.web.socket.handler.BeanCreatingHandlerProvider;
|
||||
|
||||
/**
|
||||
* An implementation of {@link javax.websocket.server.ServerEndpointConfig} for use in
|
||||
* Spring applications. A {@link ServerEndpointRegistration} bean is detected by
|
||||
* Spring-based applications. A {@link ServerEndpointRegistration} bean is detected by
|
||||
* {@link ServerEndpointExporter} and registered with a Java WebSocket runtime at startup.
|
||||
*
|
||||
* <p>Class constructors accept a singleton {@link javax.websocket.Endpoint} instance
|
||||
@@ -44,10 +44,11 @@ import org.springframework.web.socket.handler.BeanCreatingHandlerProvider;
|
||||
* each client WebSocket connection.
|
||||
*
|
||||
* <p>This class also extends
|
||||
* {@link javax.websocket.server.ServerEndpointConfig.Configurator} to make it easier to
|
||||
* override methods for customizing the handshake process.
|
||||
* {@link javax.websocket.server.ServerEndpointConfig.Configurator} to make it easier
|
||||
* to override methods for customizing the handshake process.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.0
|
||||
* @see ServerEndpointExporter
|
||||
*/
|
||||
@@ -56,34 +57,20 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
|
||||
|
||||
private final String path;
|
||||
|
||||
private final BeanCreatingHandlerProvider<Endpoint> endpointProvider;
|
||||
|
||||
private final Endpoint endpoint;
|
||||
|
||||
private List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>();
|
||||
private final BeanCreatingHandlerProvider<Endpoint> endpointProvider;
|
||||
|
||||
private List<Class<? extends Decoder>> decoders = new ArrayList<Class<? extends Decoder>>();
|
||||
private List<String> subprotocols = new ArrayList<String>(0);
|
||||
|
||||
private List<String> protocols = new ArrayList<String>();
|
||||
private List<Extension> extensions = new ArrayList<Extension>(0);
|
||||
|
||||
private List<Extension> extensions = new ArrayList<Extension>();
|
||||
private List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>(0);
|
||||
|
||||
private final Map<String, Object> userProperties = new HashMap<String, Object>();
|
||||
private List<Class<? extends Decoder>> decoders = new ArrayList<Class<? extends Decoder>>(0);
|
||||
|
||||
private final Map<String, Object> userProperties = new HashMap<String, Object>(4);
|
||||
|
||||
/**
|
||||
* Create a new {@link ServerEndpointRegistration} instance from an
|
||||
* {@code javax.websocket.Endpoint} class.
|
||||
* @param path the endpoint path
|
||||
* @param endpointClass the endpoint class
|
||||
*/
|
||||
public ServerEndpointRegistration(String path, Class<? extends Endpoint> endpointClass) {
|
||||
Assert.hasText(path, "path must not be empty");
|
||||
Assert.notNull(endpointClass, "endpointClass must not be null");
|
||||
this.path = path;
|
||||
this.endpointProvider = new BeanCreatingHandlerProvider<Endpoint>(endpointClass);
|
||||
this.endpoint = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ServerEndpointRegistration} instance from an
|
||||
@@ -92,13 +79,29 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
|
||||
* @param endpoint the endpoint instance
|
||||
*/
|
||||
public ServerEndpointRegistration(String path, Endpoint endpoint) {
|
||||
Assert.hasText(path, "path must not be empty");
|
||||
Assert.notNull(endpoint, "endpoint must not be null");
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
Assert.notNull(endpoint, "Endpoint must not be null");
|
||||
this.path = path;
|
||||
this.endpointProvider = null;
|
||||
this.endpoint = endpoint;
|
||||
this.endpointProvider = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ServerEndpointRegistration} instance from an
|
||||
* {@code javax.websocket.Endpoint} class.
|
||||
* @param path the endpoint path
|
||||
* @param endpointClass the endpoint class
|
||||
*/
|
||||
public ServerEndpointRegistration(String path, Class<? extends Endpoint> endpointClass) {
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
Assert.notNull(endpointClass, "Endpoint Class must not be null");
|
||||
this.path = path;
|
||||
this.endpoint = null;
|
||||
this.endpointProvider = new BeanCreatingHandlerProvider<Endpoint>(endpointClass);
|
||||
}
|
||||
|
||||
|
||||
// ServerEndpointConfig implementation
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
@@ -114,13 +117,13 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
|
||||
return (this.endpoint != null) ? this.endpoint : this.endpointProvider.getHandler();
|
||||
}
|
||||
|
||||
public void setSubprotocols(List<String> protocols) {
|
||||
this.protocols = protocols;
|
||||
public void setSubprotocols(List<String> subprotocols) {
|
||||
this.subprotocols = subprotocols;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubprotocols() {
|
||||
return this.protocols;
|
||||
return this.subprotocols;
|
||||
}
|
||||
|
||||
public void setExtensions(List<Extension> extensions) {
|
||||
@@ -132,16 +135,6 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
|
||||
return this.extensions;
|
||||
}
|
||||
|
||||
public void setUserProperties(Map<String, Object> userProperties) {
|
||||
this.userProperties.clear();
|
||||
this.userProperties.putAll(userProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getUserProperties() {
|
||||
return this.userProperties;
|
||||
}
|
||||
|
||||
public void setEncoders(List<Class<? extends Encoder>> encoders) {
|
||||
this.encoders = encoders;
|
||||
}
|
||||
@@ -160,20 +153,23 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
|
||||
return this.decoders;
|
||||
}
|
||||
|
||||
public void setUserProperties(Map<String, Object> userProperties) {
|
||||
this.userProperties.clear();
|
||||
this.userProperties.putAll(userProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getUserProperties() {
|
||||
return this.userProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configurator getConfigurator() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (this.endpointProvider != null) {
|
||||
this.endpointProvider.setBeanFactory(beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Implementations of ServerEndpointConfig.Configurator
|
||||
// ServerEndpointConfig.Configurator implementation
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@@ -186,24 +182,19 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
|
||||
super.modifyHandshake(this, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkOrigin(String originHeaderValue) {
|
||||
return super.checkOrigin(originHeaderValue);
|
||||
}
|
||||
|
||||
// Remaining methods
|
||||
|
||||
@Override
|
||||
public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
|
||||
return super.getNegotiatedSubprotocol(supported, requested);
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (this.endpointProvider != null) {
|
||||
this.endpointProvider.setBeanFactory(beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) {
|
||||
return super.getNegotiatedExtensions(installed, requested);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ServerEndpointRegistration for path '" + getPath() + "': " + getEndpointClass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user