KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > inspector > ShowProperties


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.contrib.inspector;
16
17 import java.util.Collections JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.apache.hivemind.service.ClassFabUtils;
21 import org.apache.tapestry.BaseComponent;
22 import org.apache.tapestry.IPage;
23 import org.apache.tapestry.engine.IPageRecorder;
24 import org.apache.tapestry.event.PageEvent;
25 import org.apache.tapestry.event.PageRenderListener;
26 import org.apache.tapestry.record.PropertyChange;
27
28 /**
29  * Component of the {@link Inspector}page used to display the persisent properties of the page.
30  *
31  * @author Howard Lewis Ship
32  */

33
34 public abstract class ShowProperties extends BaseComponent implements PageRenderListener
35 {
36     private List JavaDoc _properties;
37
38     private PropertyChange _change;
39
40     private IPage _inspectedPage;
41
42     /**
43      * Does nothing.
44      *
45      * @since 1.0.5
46      */

47
48     public void pageBeginRender(PageEvent event)
49     {
50     }
51
52     /**
53      * @since 1.0.5
54      */

55
56     public void pageEndRender(PageEvent event)
57     {
58         _properties = null;
59         _change = null;
60         _inspectedPage = null;
61     }
62
63     private void buildProperties()
64     {
65         Inspector inspector = (Inspector) getPage();
66
67         _inspectedPage = inspector.getInspectedPage();
68
69         // IEngine engine = getPage().getEngine();
70
IPageRecorder recorder = null;
71
72         // TODO: This is going to blow up with UnsupportedOperationException
73
// engine.getPageRecorder(_inspectedPage.getPageName(), inspector.getRequestCycle());
74

75         // No page recorder? No properties.
76

77         if (recorder == null)
78         {
79             _properties = Collections.EMPTY_LIST;
80             return;
81         }
82
83         _properties = Collections.EMPTY_LIST;
84
85         // The getChanges() method was removed
86
// from IPageRecorder in release 4.0
87
// new ArrayList(recorder.getChanges());
88
}
89
90     /**
91      * Returns a {@link List}of {@link PropertyChange}objects.
92      * <p>
93      * Sort order is not defined.
94      */

95
96     public List JavaDoc getProperties()
97     {
98         if (_properties == null)
99             buildProperties();
100
101         return _properties;
102     }
103
104     public void setChange(PropertyChange value)
105     {
106         _change = value;
107     }
108
109     public PropertyChange getChange()
110     {
111         return _change;
112     }
113
114     /**
115      * Returns the name of the value's class, if the value is non-null.
116      */

117
118     public String JavaDoc getValueClassName()
119     {
120         Object JavaDoc value;
121
122         value = _change.getNewValue();
123
124         if (value == null)
125             return "<null>";
126
127         return ClassFabUtils.getJavaClassName(value.getClass());
128     }
129 }
Popular Tags