001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.contrib.inspector;
016
017 import java.util.ArrayList;
018 import java.util.Collection;
019 import java.util.List;
020
021 import org.apache.hivemind.service.ClassFabUtils;
022 import org.apache.tapestry.BaseComponent;
023 import org.apache.tapestry.IPage;
024 import org.apache.tapestry.event.PageBeginRenderListener;
025 import org.apache.tapestry.event.PageEvent;
026 import org.apache.tapestry.record.PropertyChange;
027 import org.apache.tapestry.record.PropertyPersistenceStrategySource;
028
029 /**
030 * Component of the {@link Inspector}page used to display the persisent properties of the page.
031 *
032 * @author Howard Lewis Ship
033 */
034
035 public abstract class ShowProperties extends BaseComponent implements PageBeginRenderListener
036 {
037
038 public abstract void setProperties(List properties);
039
040 public abstract PropertyChange getChange();
041
042 /** Injected. */
043
044 public abstract PropertyPersistenceStrategySource getPropertySource();
045
046 public void pageBeginRender(PageEvent event)
047 {
048 Inspector inspector = (Inspector) getPage();
049
050 IPage inspectedPage = inspector.getInspectedPage();
051
052 String pageName = inspectedPage.getPageName();
053
054 PropertyPersistenceStrategySource source = getPropertySource();
055
056 Collection properties = source.getAllStoredChanges(pageName);
057
058 // TODO: sorting
059
060 setProperties(new ArrayList(properties));
061 }
062
063 /**
064 * Returns the name of the value's class, if the value is non-null.
065 */
066
067 public String getValueClassName()
068 {
069 Object value = getChange().getNewValue();
070
071 if (value == null)
072 return "<null>";
073
074 return ClassFabUtils.getJavaClassName(value.getClass());
075 }
076 }