Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge commit 'eede862' into wicket-1.5

Conflicts:
	pom.xml
  • Loading branch information...
commit 09940b84110f272a498b0956740d17684d48f1c3 2 parents fb62ed5 + eede862
Carl-Eric Menzel authored
2  pom.xml
@@ -15,7 +15,7 @@
15 15 </license>
16 16 </licenses>
17 17 <properties>
18   - <wicket.version>1.5.0</wicket.version>
  18 + <wicket.version>1.5.5</wicket.version>
19 19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20 20 <slf4j.version>1.5.8</slf4j.version>
21 21 </properties>
38 src/main/java/de/wicketbuch/safemodel/SafeModel.java
@@ -295,19 +295,26 @@ private static void clear() {
295 295
296 296 @SuppressWarnings("unchecked")
297 297 private static <U> Class<U> reflectModelObjectType(final IModel<U> target) throws Error {
298   - final Method getObject;
299   - try {
300   - getObject = target.getClass().getMethod("getObject");
301   - } catch (final NoSuchMethodException e) {
302   - throw new Error();
303   - }
304   - final Type type = GenericTypeReflector.getExactReturnType(getObject, target.getClass());
305   - if (type instanceof Class) {
306   - return (Class<U>) type;
307   - } else if (type instanceof ParameterizedType) {
308   - return (Class<U>) ((ParameterizedType) type).getRawType();
  298 + final U targetObject = target.getObject();
  299 + if (targetObject == null) {
  300 + final Method getObject;
  301 + try {
  302 + getObject = target.getClass().getMethod("getObject");
  303 + } catch (final NoSuchMethodException e) {
  304 + throw new Error();
  305 + }
  306 + final Type type = GenericTypeReflector.getExactReturnType(getObject, target.getClass());
  307 + final Class<U> reflectedType;
  308 + if (type instanceof Class) {
  309 + reflectedType = (Class<U>) type;
  310 + } else if (type instanceof ParameterizedType) {
  311 + reflectedType = (Class<U>) ((ParameterizedType) type).getRawType();
  312 + } else {
  313 + throw new UnsupportedOperationException("don't know how to find the type");
  314 + }
  315 + return reflectedType; // can't do anything else here
309 316 } else {
310   - throw new UnsupportedOperationException("don't know how to find the type");
  317 + return (Class<U>) targetObject.getClass();
311 318 }
312 319 }
313 320
@@ -356,7 +363,12 @@ public Object invoke(final Invocation invocation) throws Throwable {
356 363 } else if (Object.class.equals(returnType)) {
357 364 return ClassImposteriser.INSTANCE.imposterise(BLOCKER, Object.class);
358 365 } else {
359   - return ClassImposteriser.INSTANCE.imposterise(BLOCKER, returnType);
  366 + try {
  367 + return ClassImposteriser.INSTANCE.imposterise(BLOCKER, returnType);
  368 + } catch (ClassCastException e) {
  369 + // some classloading problem in an appserver... maybe we can get by with just a null:
  370 + return null;
  371 + }
360 372 }
361 373 }
362 374 }
22 src/test/java/de/wicketbuch/safemodel/SafeModelTest.java
@@ -31,6 +31,7 @@
31 31
32 32 import org.apache.wicket.model.AbstractReadOnlyModel;
33 33 import org.apache.wicket.model.IModel;
  34 +import org.apache.wicket.model.Model;
34 35 import org.apache.wicket.util.tester.WicketTester;
35 36 import org.jmock.api.Invocation;
36 37 import org.jmock.api.Invokable;
@@ -325,4 +326,25 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
325 326 IModel<Middle> model = model(fromService(mockedService).loadMid(42));
326 327 assertSame(expected, model.getObject());
327 328 }
  329 +
  330 + public static class SomethingSerializable implements Serializable {
  331 + private String foo;
  332 +
  333 + public String getFoo() {
  334 + return foo;
  335 + }
  336 +
  337 + public void setFoo(String foo) {
  338 + this.foo = foo;
  339 + }
  340 + }
  341 +
  342 + @Test
  343 + public void nonreflectableModel() throws Exception {
  344 + final SomethingSerializable something = new SomethingSerializable();
  345 + something.setFoo("bar");
  346 + Model<SomethingSerializable> rootModel = new Model<SomethingSerializable>(something);
  347 + IModel<String> propmodel = model(from(rootModel).getFoo());
  348 + assertEquals("bar", propmodel.getObject());
  349 + }
328 350 }

0 comments on commit 09940b8

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