polishing

This commit is contained in:
Mark Fisher
2010-11-13 12:47:35 -05:00
parent 3423ca2dd7
commit 969a160684
6 changed files with 38 additions and 23 deletions

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.util;
import java.beans.PropertyEditor;
@@ -28,22 +29,23 @@ import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.ConversionServiceFactory;
import org.springframework.expression.TypeConverter;
import org.springframework.util.CollectionUtils;
/**
*
* @author Dave Syer
* @author Oleg Zhurakousky
*
*/
public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware {
private SimpleTypeConverter delegate = new SimpleTypeConverter();
private static ConversionService defaultConversionService;
private ConversionService conversionService;
private volatile SimpleTypeConverter delegate = new SimpleTypeConverter();
private volatile ConversionService conversionService;
public BeanFactoryTypeConverter() {
synchronized (this) {
synchronized (BeanFactoryTypeConverter.class) {
if (defaultConversionService == null) {
defaultConversionService = ConversionServiceFactory.createDefaultConversionService();
}
@@ -55,6 +57,7 @@ public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware
this.conversionService = conversionService;
}
public void setConversionService(ConversionService conversionService) {
this.conversionService = conversionService;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.

View File

@@ -67,7 +67,6 @@ import org.springframework.util.StringUtils;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Dave Syer
*
* @since 2.0
*/
public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator {
@@ -86,6 +85,7 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
private final boolean canProcessMessageList;
public MessagingMethodInvokerHelper(Object targetObject, Method method, Class<?> expectedType,
boolean canProcessMessageList) {
this(targetObject, null, method, expectedType, canProcessMessageList);
@@ -114,6 +114,7 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
this(targetObject, annotationType, (String) null, expectedType, canProcessMessageList);
}
public T process(Message<?> message) throws Exception {
ParametersWrapper parameters = new ParametersWrapper(message);
return processInternal(parameters);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.util;
import java.io.ByteArrayOutputStream;
@@ -28,12 +29,12 @@ import org.springframework.util.ClassUtils;
* Utility to help generate UUID instances from generic objects.
*
* @author Dave Syer
*
*/
public class UUIDConverter implements Converter<Object, UUID> {
public static final String DEFAULT_CHARSET = "UTF-8";
/**
* Convert the input to a UUID using the convenience method
* {@link #getUUID(Object)}.
@@ -64,15 +65,12 @@ public class UUIDConverter implements Converter<Object, UUID> {
* @return a UUID constructed from the input
*/
public static UUID getUUID(Object input) {
if (input == null) {
return null;
}
if (input instanceof UUID) {
return (UUID) input;
}
if (input instanceof String) {
try {
return UUID.fromString((String) input);
@@ -86,7 +84,6 @@ public class UUIDConverter implements Converter<Object, UUID> {
}
}
}
if (ClassUtils.isPrimitiveOrWrapper(input.getClass())) {
try {
return UUID.nameUUIDFromBytes(input.toString().getBytes(DEFAULT_CHARSET));
@@ -95,18 +92,14 @@ public class UUIDConverter implements Converter<Object, UUID> {
throw new IllegalStateException("Cannot convert primitive using charset=" + DEFAULT_CHARSET, e);
}
}
byte[] bytes = serialize(input);
return UUID.nameUUIDFromBytes(bytes);
}
private static byte[] serialize(Object object) {
if (object == null) {
return null;
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
new ObjectOutputStream(stream).writeObject(object);
@@ -114,9 +107,7 @@ public class UUIDConverter implements Converter<Object, UUID> {
catch (IOException e) {
throw new IllegalArgumentException("Could not serialize object of type: " + object.getClass(), e);
}
return stream.toByteArray();
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.util;
import java.lang.reflect.Method;
@@ -13,16 +29,18 @@ import org.springframework.util.ReflectionUtils.MethodFilter;
*/
public class UniqueMethodFilter implements MethodFilter {
private List<Method> uniqueMethods = new ArrayList<Method>();
private final List<Method> uniqueMethods = new ArrayList<Method>();
public UniqueMethodFilter(Class<?> targetClass) {
ArrayList<Method> allMethods = new ArrayList<Method>(Arrays.asList(targetClass.getMethods()));
for (Method method : allMethods) {
uniqueMethods.add(org.springframework.util.ClassUtils.getMostSpecificMethod(method, targetClass));
this.uniqueMethods.add(org.springframework.util.ClassUtils.getMostSpecificMethod(method, targetClass));
}
}
public boolean matches(Method method) {
return uniqueMethods.contains(method);
return this.uniqueMethods.contains(method);
}
}

View File

@@ -31,6 +31,7 @@ public final class UpperBound {
public final Semaphore semaphore;
/**
* Create an UpperBound with the given capacity. If the given capacity is less than 1
* an infinite UpperBound is created.
@@ -39,6 +40,7 @@ public final class UpperBound {
this.semaphore = (capacity > 0) ? new Semaphore(capacity, true) : null;
}
/**
* Acquires a permit from the underlying semaphore if this UpperBound is bounded and returns
* true if it succeeds within the given timeout. If the timeout is less than 0, it will block