Skip to content
Browse files

Merge commit 'eede862' into wicket-1.5

Conflicts:
	pom.xml
  • Loading branch information...
2 parents fb62ed5 + eede862 commit 09940b84110f272a498b0956740d17684d48f1c3 Carl-Eric Menzel committed Apr 3, 2012
View
2 pom.xml
@@ -15,7 +15,7 @@
</license>
</licenses>
<properties>
- <wicket.version>1.5.0</wicket.version>
+ <wicket.version>1.5.5</wicket.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.5.8</slf4j.version>
</properties>
View
38 src/main/java/de/wicketbuch/safemodel/SafeModel.java
@@ -295,19 +295,26 @@ private static void clear() {
@SuppressWarnings("unchecked")
private static <U> Class<U> reflectModelObjectType(final IModel<U> target) throws Error {
- final Method getObject;
- try {
- getObject = target.getClass().getMethod("getObject");
- } catch (final NoSuchMethodException e) {
- throw new Error();
- }
- final Type type = GenericTypeReflector.getExactReturnType(getObject, target.getClass());
- if (type instanceof Class) {
- return (Class<U>) type;
- } else if (type instanceof ParameterizedType) {
- return (Class<U>) ((ParameterizedType) type).getRawType();
+ final U targetObject = target.getObject();
+ if (targetObject == null) {
+ final Method getObject;
+ try {
+ getObject = target.getClass().getMethod("getObject");
+ } catch (final NoSuchMethodException e) {
+ throw new Error();
+ }
+ final Type type = GenericTypeReflector.getExactReturnType(getObject, target.getClass());
+ final Class<U> reflectedType;
+ if (type instanceof Class) {
+ reflectedType = (Class<U>) type;
+ } else if (type instanceof ParameterizedType) {
+ reflectedType = (Class<U>) ((ParameterizedType) type).getRawType();
+ } else {
+ throw new UnsupportedOperationException("don't know how to find the type");
+ }
+ return reflectedType; // can't do anything else here
} else {
- throw new UnsupportedOperationException("don't know how to find the type");
+ return (Class<U>) targetObject.getClass();
}
}
@@ -356,7 +363,12 @@ public Object invoke(final Invocation invocation) throws Throwable {
} else if (Object.class.equals(returnType)) {
return ClassImposteriser.INSTANCE.imposterise(BLOCKER, Object.class);
} else {
- return ClassImposteriser.INSTANCE.imposterise(BLOCKER, returnType);
+ try {
+ return ClassImposteriser.INSTANCE.imposterise(BLOCKER, returnType);
+ } catch (ClassCastException e) {
+ // some classloading problem in an appserver... maybe we can get by with just a null:
+ return null;
+ }
}
}
}
View
22 src/test/java/de/wicketbuch/safemodel/SafeModelTest.java
@@ -31,6 +31,7 @@
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
import org.apache.wicket.util.tester.WicketTester;
import org.jmock.api.Invocation;
import org.jmock.api.Invokable;
@@ -325,4 +326,25 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
IModel<Middle> model = model(fromService(mockedService).loadMid(42));
assertSame(expected, model.getObject());
}
+
+ public static class SomethingSerializable implements Serializable {
+ private String foo;
+
+ public String getFoo() {
+ return foo;
+ }
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+ }
+
+ @Test
+ public void nonreflectableModel() throws Exception {
+ final SomethingSerializable something = new SomethingSerializable();
+ something.setFoo("bar");
+ Model<SomethingSerializable> rootModel = new Model<SomethingSerializable>(something);
+ IModel<String> propmodel = model(from(rootModel).getFoo());
+ assertEquals("bar", propmodel.getObject());
+ }
}

0 comments on commit 09940b8

Please sign in to comment.
Something went wrong with that request. Please try again.