You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2007/04/09 20:24:20 UTC
svn commit: r526864 - in
/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model:
AbstractPropertyModel.java CompoundPropertyModel.java IChainingModel.java
Author: jcompagner
Date: Mon Apr 9 11:24:19 2007
New Revision: 526864
URL: http://svn.apache.org/viewvc?view=rev&rev=526864
Log:
IChainingModel interface
Added:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/IChainingModel.java (with props)
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/AbstractPropertyModel.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/CompoundPropertyModel.java
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/AbstractPropertyModel.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/AbstractPropertyModel.java?view=diff&rev=526864&r1=526863&r2=526864
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/AbstractPropertyModel.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/AbstractPropertyModel.java Mon Apr 9 11:24:19 2007
@@ -31,7 +31,7 @@
* @author Eelco Hillenius
* @author Jonathan Locke
*/
-public abstract class AbstractPropertyModel implements IModel
+public abstract class AbstractPropertyModel implements IChainingModel
{
/** Any model object (which may or may not implement IModel) */
private Object target;
@@ -50,6 +50,23 @@
}
this.target = modelObject;
+ }
+
+ /**
+ * @see wicket.model.IChainingModel#getChainingModel()
+ */
+ public IModel getChainingModel()
+ {
+ if (target instanceof IModel) return (IModel)target;
+ return null;
+ }
+
+ /**
+ * @see wicket.model.IChainingModel#setChainingModel(wicket.model.IModel)
+ */
+ public void setChainingModel(IModel model)
+ {
+ target = model;
}
protected Object getTarget()
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/CompoundPropertyModel.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/CompoundPropertyModel.java?view=diff&rev=526864&r1=526863&r2=526864
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/CompoundPropertyModel.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/CompoundPropertyModel.java Mon Apr 9 11:24:19 2007
@@ -23,13 +23,17 @@
* A simple compound model which uses the component's name as the property
* expression to retrieve properties on the nested model object.
*
+ * CompoundPropertyModel is a chaining model so it will call get/setobject
+ * on the given object if the object is an instanceof IModel itself.
+ *
* @see wicket.model.IModel
* @see wicket.model.Model
* @see wicket.model.AbstractDetachableModel
+ * @see IChainingModel
*
* @author Jonathan Locke
*/
-public class CompoundPropertyModel implements IComponentInheritedModel
+public class CompoundPropertyModel implements IComponentInheritedModel, IChainingModel
{
private static final long serialVersionUID = 1L;
@@ -51,6 +55,10 @@
*/
public Object getObject()
{
+ if (target instanceof IModel)
+ {
+ return ((IModel)target).getObject();
+ }
return target;
}
@@ -59,7 +67,34 @@
*/
public void setObject(Object object)
{
- this.target = object;
+ if (target instanceof IModel)
+ {
+ ((IModel)target).setObject(object);
+ }
+ else
+ {
+ this.target = object;
+ }
+ }
+
+ /**
+ * @see wicket.model.IChainingModel#getChainingModel()
+ */
+ public IModel getChainingModel()
+ {
+ if (target instanceof IModel)
+ {
+ return (IModel)target;
+ }
+ return null;
+ }
+
+ /**
+ * @see wicket.model.IChainingModel#setChainingModel(wicket.model.IModel)
+ */
+ public void setChainingModel(IModel model)
+ {
+ target = model;
}
/**
@@ -67,7 +102,7 @@
*/
public void detach()
{
- if (target != null && target instanceof IModel)
+ if (target instanceof IModel)
{
((IModel)target).detach();
}
Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/IChainingModel.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/IChainingModel.java?view=auto&rev=526864
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/IChainingModel.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/IChainingModel.java Mon Apr 9 11:24:19 2007
@@ -0,0 +1,51 @@
+/*
+ * 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 wicket.model;
+
+/**
+ * Models who implement this interface will support chaining of IModels.
+ * getObject() of a IChainingModel should do something like:
+ * <pre>
+ * if ( object instanceof IModel) { return ((IModel)object).getObject()}
+ * else return object;
+ * </pre>
+ *
+ * ChainingModels should also take care that the internal model detach is called
+ * when detach is called on them.
+ *
+ * @author jcompagner
+ *
+ * @see CompoundPropertyModel
+ * @see AbstractPropertyModel
+ */
+public interface IChainingModel extends IModel
+{
+ /**
+ * Sets the model that is chained inside this model.
+ *
+ * @param model
+ */
+ public void setChainingModel(IModel model);
+
+ /**
+ * Returns the chained model if there is a chained model.
+ *
+ * @return The chained model
+ */
+ public IModel getChainingModel();
+
+}
Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/model/IChainingModel.java
------------------------------------------------------------------------------
svn:eol-style = native