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.IRequestCycle; 025 import org.apache.tapestry.event.PageBeginRenderListener; 026 import org.apache.tapestry.event.PageEvent; 027 import org.apache.tapestry.record.PropertyChange; 028 import org.apache.tapestry.record.PropertyPersistenceStrategySource; 029 030 /** 031 * Component of the {@link Inspector}page used to display the persisent properties of the page. 032 * 033 * @author Howard Lewis Ship 034 */ 035 036 public abstract class ShowProperties extends BaseComponent implements PageBeginRenderListener 037 { 038 039 public abstract void setProperties(List properties); 040 041 public abstract PropertyChange getChange(); 042 043 /** Injected */ 044 045 public abstract PropertyPersistenceStrategySource getPropertySource(); 046 047 public void pageBeginRender(PageEvent event) 048 { 049 IRequestCycle cycle = event.getRequestCycle(); 050 051 Inspector inspector = (Inspector) getPage(); 052 053 IPage inspectedPage = inspector.getInspectedPage(); 054 055 String pageName = inspectedPage.getPageName(); 056 057 PropertyPersistenceStrategySource source = getPropertySource(); 058 059 Collection properties = source.getAllStoredChanges(pageName, cycle); 060 061 // TODO: sorting 062 063 setProperties(new ArrayList(properties)); 064 } 065 066 /** 067 * Returns the name of the value's class, if the value is non-null. 068 */ 069 070 public String getValueClassName() 071 { 072 Object value = getChange().getNewValue(); 073 074 if (value == null) 075 return "<null>"; 076 077 return ClassFabUtils.getJavaClassName(value.getClass()); 078 } 079 }