01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.model;
18:
19: import org.apache.wicket.Component;
20:
21: /**
22: * Models that wish to substitute themselves with a wrapper when they are bound
23: * to a component (either through IModel parameter in a constructor or via a
24: * call to {@link Component#setModel(IModel)}) should implement this interface.
25: * One reason for a model to want to do this is if it needs to be aware of the
26: * component it is bound to.
27: *
28: * The algorithm wicket employs is similar to this:
29: *
30: * <pre>
31: * void Component.setModel(IModel model)
32: * {
33: * if (model instanceof IComponentAssignedModel)
34: * {
35: * this.model = ((IComponentAssignedModel)model).wrapOnAssignment(this);
36: * }
37: * else
38: * {
39: * this.model = model;
40: * }
41: * }
42: * </pre>
43: *
44: * For an example see {@link ResourceModel}
45: *
46: * @author jcompagner
47: * @author Igor Vaynberg (ivaynberg)
48: */
49: public interface IComponentAssignedModel extends IModel {
50: /**
51: * This method is called when the component gets its model assigned.
52: *
53: * WARNING: Because the model can be assigned in the constructor of
54: * component this method can also be called with a 'this' of a component
55: * that is not fully constructed yet.
56: *
57: * @param component
58: * @return The WrapModel that wraps this model
59: */
60: IWrapModel wrapOnAssignment(Component component);
61: }
|