01: /*
02: * $Id: CompoundPropertyModel.java 459547 2006-02-28 07:50:57Z ivaynberg $
03: * $Revision: 459547 $ $Date: 2006-02-28 08:50:57 +0100 (Tue, 28 Feb 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.model;
19:
20: import wicket.Component;
21: import wicket.markup.html.form.FormComponent;
22:
23: /**
24: * A simple compound model which uses the component's name as the property
25: * expression to retrieve properties on the nested model object.
26: *
27: * @see wicket.model.IModel
28: * @see wicket.model.Model
29: * @see wicket.model.AbstractDetachableModel
30: *
31: * @author Jonathan Locke
32: */
33: public class CompoundPropertyModel extends AbstractPropertyModel
34: implements ICompoundModel {
35: private static final long serialVersionUID = 1L;
36:
37: /**
38: * Constructor
39: *
40: * @param model
41: * The model object, which may or may not implement IModel
42: */
43: public CompoundPropertyModel(final Object model) {
44: super (model);
45: }
46:
47: /**
48: * @see wicket.model.AbstractPropertyModel#propertyExpression(wicket.Component)
49: */
50: protected String propertyExpression(final Component component) {
51: if (component == null) {
52: return null;
53: }
54:
55: return component.getId();
56: }
57:
58: /**
59: * @see wicket.model.AbstractPropertyModel#propertyType(wicket.Component)
60: */
61: protected Class propertyType(final Component component) {
62: if (component instanceof FormComponent) {
63: return ((FormComponent) component).getType();
64: }
65: return null;
66: }
67:
68: /**
69: * @see java.lang.Object#toString()
70: */
71: public String toString() {
72: return new StringBuffer(super.toString()).toString();
73: }
74: }
|