001: /*
002: * $Id: IModel.java 458456 2006-01-02 07:37:31Z jonl $ $Revision:
003: * 1.10 $ $Date: 2006-01-02 08:37:31 +0100 (Mon, 02 Jan 2006) $
004: *
005: * ==============================================================================
006: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007: * use this file except in compliance with the License. You may obtain a copy of
008: * the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.model;
019:
020: import wicket.Component;
021:
022: /**
023: * A IModel wraps the actual model Object used by a Component. IModel
024: * implementations are used as a facade for the real model so that users have
025: * control over the actual persistence strategy. Note that objects implementing
026: * this interface will be stored in the Session. Hence, you should use
027: * (non-transient) instance variables sparingly.
028: * <ul>
029: * <li><b>Basic Models </b>- To implement a basic (non-detachable) model which
030: * holds its entire state in the Session, you can either subclass
031: * {@link AbstractModel}, or use the simple model wrapper {@link Model}
032: * directly.
033: *
034: * <li><b>Detachable Models </b>- IModel inherits a hook,
035: * {@link IDetachable#detach()}, so that interface implementers can detach
036: * transient information when a model is no longer being actively used by the
037: * framework. This reduces memory use and reduces the expense of replicating the
038: * model in a clustered server environment. To implement a detachable model, you
039: * should generally extend {@link wicket.model.AbstractDetachableModel}instead
040: * of implementing IModel directly.
041: *
042: * <li><b>Nested Models </b>- IModels can be nested and the innermost model is
043: * also known as the "root" model since it is the model on which the outer
044: * models rely. The getNestedModel() method on IModel gets any nested model
045: * within the given model. This allows Component.sameRootModel() to compare two
046: * models to see if they both have the same root model (the same most nested
047: * model).
048: * <p>
049: * For example, a Form might have a Person model and then a TextField might have
050: * a PropertyModel which is the "name" property of the Person model. In this
051: * case, PropertyModel will implement getNestedModel(), returning the Person
052: * model which is the root model of the property model.
053: *
054: * <li><b>Property Models </b>- The AbstractPropertyModel class provides
055: * default functionality for property models. A property model provides access
056: * to a particular property of its wrapped model.
057: *
058: * <li><b>Compound Property Models </b>- The IModel interface is parameterized
059: * by Component, allowing a model to be shared among several Components. When
060: * the {@link IModel#getObject(Component)}method is called, the value returned
061: * will depend on the Component which is asking for the value. Likewise, the
062: * {@link IModel#setObject(Component, Object)}method sets a different property
063: * depending on which Component is doing the setting. For more information on
064: * CompoundPropertyModels and model inheritance, see
065: * {@link wicket.model.CompoundPropertyModel}and {@link wicket.Page}.
066: * </ul>
067: *
068: * @see wicket.Component#sameRootModel(wicket.Component)
069: * @see wicket.Component#sameRootModel(IModel)
070: *
071: * @author Chris Turner
072: * @author Eelco Hillenius
073: * @author Jonathan Locke
074: */
075: public interface IModel extends IDetachable {
076: /**
077: * Gets the nested model.
078: *
079: * @return The nested model object.
080: */
081: IModel getNestedModel();
082:
083: /**
084: * Gets the model object.
085: *
086: * @param component
087: * The component which wants to get a model Object
088: *
089: * @return The model object
090: */
091: Object getObject(final Component component);
092:
093: /**
094: * Sets the model object.
095: *
096: * @param component
097: * The component which wants to set a new model Object
098: *
099: * @param object
100: * The model object
101: */
102: void setObject(final Component component, final Object object);
103: }
|