Author: dashorst Date: Wed Jun 6 14:00:47 2007 New Revision: 544951 URL: http://svn.apache.org/viewvc?view=rev&rev=544951 Log: WICKET-621 Detaching of nested objects is now based on IDetachable instead of IModel
Added: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/ModelDetachTest.java (with props) Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java?view=diff&rev=544951&r1=544950&r2=544951 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java Wed Jun 6 14:00:47 2007 @@ -67,10 +67,10 @@ */ public void detach() { - // Detach nested object if it's an IModel - if (target instanceof IModel) + // Detach nested object if it's a detachable + if (target instanceof IDetachable) { - ((IModel)target).detach(); + ((IDetachable)target).detach(); } } Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java?view=diff&rev=544951&r1=544950&r2=544951 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/CompoundPropertyModel.java Wed Jun 6 14:00:47 2007 @@ -102,9 +102,9 @@ */ public void detach() { - if (target instanceof IModel) + if (target instanceof IDetachable) { - ((IModel)target).detach(); + ((IDetachable)target).detach(); } } Added: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/ModelDetachTest.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/ModelDetachTest.java?view=auto&rev=544951 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/ModelDetachTest.java (added) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/ModelDetachTest.java Wed Jun 6 14:00:47 2007 @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.wicket.model; + +import junit.framework.TestCase; + +/** + * Tests the detach behavior for compatibility with IDetachable nested objects, + * ensuring that the detach method is called for those nested objects. + */ +public class ModelDetachTest extends TestCase +{ + class Detachable implements IDetachable + { + private static final long serialVersionUID = 1L; + + private boolean detached = false; + + public void detach() + { + detached = true; + } + } + + /** + * Performs the nested test for CompoundPropertyModel. + */ + public void testCompoundPropertyModelDetach() + { + Detachable detachable = new Detachable(); + IModel model = new CompoundPropertyModel(detachable); + model.detach(); + assertTrue(detachable.detached); + } + + /** + * Performs the nested test for BoundCompoundPropertyModel. + */ + public void testBoundCompoundPropertyModelDetach() + { + Detachable detachable = new Detachable(); + IModel model = new BoundCompoundPropertyModel(detachable); + model.detach(); + assertTrue(detachable.detached); + } + + /** + * Performs the nested test for AbstractPropertyModel. + */ + public void testAbstractPropertyModelDetach() + { + Detachable detachable = new Detachable(); + IModel model = new AbstractPropertyModel(detachable) + { + private static final long serialVersionUID = 1L; + + protected String propertyExpression() + { + return null; + } + }; + model.detach(); + assertTrue(detachable.detached); + } + + /** + * Performs the nested test for PropertyModel. + */ + public void testPropertyModelDetach() + { + Detachable detachable = new Detachable(); + IModel model = new PropertyModel(detachable, "foo"); + model.detach(); + assertTrue(detachable.detached); + } +} Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/ModelDetachTest.java ------------------------------------------------------------------------------ svn:eol-style = native