|
1
|
|
/*
|
|
2
|
|
* Angkor Web Framework
|
|
3
|
|
*
|
|
4
|
|
* Distributable under LGPL license.
|
|
5
|
|
* See terms of license at gnu.org.
|
|
6
|
|
*/
|
|
7
|
|
package com.tirsen.angkor.widget;
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
/**
|
|
11
|
|
* A ModelProxy acts as the proxy for JavaBean instances which may or may not actually
|
|
12
|
|
* exist enabling them to be lazily evaluated only when a view actually requests the value
|
|
13
|
|
* of the JavaBean. Useful when creating views which should be bound to properties of JavaBeans
|
|
14
|
|
* but the view is not yet visible and the JavaBean is not yet instantiated. Also has a lot of
|
|
15
|
|
* utility methods for creating various models bound to the JavaBean so it may be useful even if
|
|
16
|
|
* the JavaBean actually exists. For this reason the name <code>ModelProxy</code> may be a little bit
|
|
17
|
|
* inaccurate, maybe <code>JavaBeanModel</code> may be better.
|
|
18
|
|
*
|
|
19
|
|
* <!-- $Id: ModelProxy.java,v 1.3 2002/10/09 21:37:37 tirsen Exp $ -->
|
|
20
|
|
*
|
|
21
|
|
* @author $Author: tirsen $
|
|
22
|
|
* @version $Revision: 1.3 $
|
|
23
|
|
*/
|
|
24
|
|
public class ModelProxy
|
|
25
|
|
{
|
|
26
|
|
private Object valueObject;
|
|
27
|
|
private ValueModel model;
|
|
28
|
|
private Class objectClass;
|
|
29
|
|
|
|
30
|
0
|
public ModelProxy(Class objectClass)
|
|
31
|
|
{
|
|
32
|
0
|
this.objectClass = objectClass;
|
|
33
|
|
}
|
|
34
|
|
|
|
35
|
0
|
public ModelProxy(ValueModel model)
|
|
36
|
|
{
|
|
37
|
0
|
this.model = model;
|
|
38
|
|
}
|
|
39
|
|
|
|
40
|
0
|
public void setValueObject(Object valueObject)
|
|
41
|
|
{
|
|
42
|
0
|
this.valueObject = valueObject;
|
|
43
|
|
}
|
|
44
|
|
|
|
45
|
0
|
public Object getObject()
|
|
46
|
|
{
|
|
47
|
0
|
Object object = valueObject;
|
|
48
|
0
|
if (object == null && model != null) object = model.getValue();
|
|
49
|
0
|
return object;
|
|
50
|
|
}
|
|
51
|
|
|
|
52
|
0
|
public Class getObjectClass()
|
|
53
|
|
{
|
|
54
|
0
|
Class klass = objectClass;
|
|
55
|
0
|
if (klass == null && valueObject != null) klass = valueObject.getClass();
|
|
56
|
0
|
if (klass == null && model != null) klass = model.getValueClass();
|
|
57
|
0
|
return klass;
|
|
58
|
|
}
|
|
59
|
|
|
|
60
|
0
|
public ValueModel getProperty(String property)
|
|
61
|
|
{
|
|
62
|
0
|
return new PropertyValueModel(this, property);
|
|
63
|
|
}
|
|
64
|
|
|
|
65
|
0
|
public ModelProxy getPropertyProxy(String property)
|
|
66
|
|
{
|
|
67
|
0
|
return new ModelProxy(getProperty(property));
|
|
68
|
|
}
|
|
69
|
|
}
|
|
70
|
|
|