back to jdk 1.4; removed warnings; added two way executor

This commit is contained in:
Keith Donald
2009-02-13 20:57:26 +00:00
parent bae262b84b
commit 680002fafd
5 changed files with 87 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
#Thu Feb 12 13:53:33 EST 2009
#Fri Feb 13 15:52:19 EST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
@@ -9,22 +9,22 @@ org.eclipse.jdt.core.codeComplete.localSuffixes=
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
@@ -79,7 +79,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.3
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16

View File

@@ -36,8 +36,7 @@ public class CollectionToCollection implements Converter {
/**
* Creates a new collection-to-collection converter
* @param conversionService a specific converter to use to convert collection elements added to the target
* collection
* @param elementConverter a specific converter to use to convert collection elements added to the target collection
*/
public CollectionToCollection(ConversionExecutor elementConverter) {
this.elementConverter = elementConverter;

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2004-2007 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.binding.convert.service;
import org.springframework.binding.convert.ConversionExecutionException;
import org.springframework.binding.convert.ConversionExecutor;
import org.springframework.binding.convert.converters.TwoWayConverter;
/**
* A special conversion executor used by {@link DefaultConversionService} that can dynamically resolve whether to do a
* forward or "reverse" conversion using a {@link TwoWayConverter} based on the type of the object passed in.
*
* Used in conjunction with custom converters to support dynamic conversion of collection elements.
*/
class TwoWayCapableConversionExecutor implements ConversionExecutor {
private Class sourceClass;
private Class targetClass;
private TwoWayConverter converter;
/**
* Creates a new two way conversion executor.
* @param sourceClass the source class to convert to (or from)
* @param targetClass the target class to convert from (or to)
* @param converter the two way converter
*/
public TwoWayCapableConversionExecutor(Class sourceClass, Class targetClass, TwoWayConverter converter) {
this.sourceClass = sourceClass;
this.targetClass = targetClass;
this.converter = converter;
}
public Class getSourceClass() {
return sourceClass;
}
public Class getTargetClass() {
return targetClass;
}
public Object execute(Object source) throws ConversionExecutionException {
if (source == null || converter.getSourceClass().isInstance(source)) {
try {
return converter.convertSourceToTargetClass(source, targetClass);
} catch (Exception e) {
throw new ConversionExecutionException(source, getSourceClass(), getTargetClass(), e);
}
} else if (converter.getTargetClass().isInstance(source)) {
try {
return converter.convertTargetToSourceClass(source, sourceClass);
} catch (Exception e) {
throw new ConversionExecutionException(source, converter.getTargetClass(), getSourceClass(), e);
}
} else {
throw new ConversionExecutionException(source, getSourceClass(), getTargetClass(), "Source object "
+ source + " to convert is expected to be an instance of [" + converter.getSourceClass().getName()
+ "] or [" + converter.getTargetClass().getName() + "]");
}
}
}

View File

@@ -316,7 +316,7 @@ public class DefaultConversionServiceTests extends TestCase {
DefaultConversionService service = new DefaultConversionService();
service.addConverter("princy", new CustomTwoWayConverter());
try {
ConversionExecutor executor = service.getConversionExecutor("princy", Integer.class, Principal[].class);
service.getConversionExecutor("princy", Integer.class, Principal[].class);
fail("Should have failed");
} catch (ConversionExecutorNotFoundException e) {
@@ -336,7 +336,7 @@ public class DefaultConversionServiceTests extends TestCase {
service.addConverter("princy", new CustomTwoWayConverter());
ConversionExecutor executor = service.getConversionExecutor("princy", Integer.class, List.class);
try {
List list = (List) executor.execute(new Integer(1));
executor.execute(new Integer(1));
fail("Should have failed");
} catch (ConversionExecutionException e) {
@@ -397,7 +397,7 @@ public class DefaultConversionServiceTests extends TestCase {
List princyList = new ArrayList();
princyList.add(new Integer(1));
try {
List list = (List) executor.execute(princyList);
executor.execute(princyList);
fail("Should have failed");
} catch (ConversionExecutionException e) {

View File

@@ -42,7 +42,6 @@ public class DefaultMessageContextTests extends TestCase {
assertEquals("Hello world fallback!", messages[0].getText());
assertEquals(Severity.ERROR, messages[0].getSeverity());
assertEquals(null, messages[0].getSource());
assertTrue(context instanceof StateManageableMessageContext);
}
public void testResolveMessageWithArgs() {
@@ -53,7 +52,6 @@ public class DefaultMessageContextTests extends TestCase {
assertEquals("Hello world Keith!", messages[0].getText());
assertEquals(Severity.ERROR, messages[0].getSeverity());
assertEquals(this, messages[0].getSource());
assertTrue(context instanceof StateManageableMessageContext);
}
public void testResolveMessageWithMultipleCodes() {
@@ -64,7 +62,6 @@ public class DefaultMessageContextTests extends TestCase {
assertEquals("Hello world Keith!", messages[0].getText());
assertEquals(Severity.ERROR, messages[0].getSeverity());
assertEquals(this, messages[0].getSource());
assertTrue(context instanceof StateManageableMessageContext);
}
public void testSaveRestoreMessages() {
@@ -73,12 +70,11 @@ public class DefaultMessageContextTests extends TestCase {
context.addMessage(new MessageBuilder().warning().source(this).code("message").build());
assertEquals(2, context.getMessagesBySource(null).length);
assertEquals(1, context.getMessagesBySource(this).length);
assertTrue(context instanceof StateManageableMessageContext);
StateManageableMessageContext manageable = (StateManageableMessageContext) context;
StateManageableMessageContext manageable = context;
Serializable messages = manageable.createMessagesMemento();
context = new DefaultMessageContext(context.getMessageSource());
assertEquals(0, context.getAllMessages().length);
manageable = (StateManageableMessageContext) context;
manageable = context;
manageable.restoreMessages(messages);
assertEquals(2, context.getMessagesBySource(null).length);
assertEquals(1, context.getMessagesBySource(this).length);