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 Inspector inspector = (Inspector) getPage(); 050 051 IPage inspectedPage = inspector.getInspectedPage(); 052 053 String pageName = inspectedPage.getPageName(); 054 055 PropertyPersistenceStrategySource source = getPropertySource(); 056 057 Collection properties = source.getAllStoredChanges(pageName); 058 059 // TODO: sorting 060 061 setProperties(new ArrayList(properties)); 062 } 063 064 /** 065 * Returns the name of the value's class, if the value is non-null. 066 */ 067 068 public String getValueClassName() 069 { 070 Object value = getChange().getNewValue(); 071 072 if (value == null) 073 return "<null>"; 074 075 return ClassFabUtils.getJavaClassName(value.getClass()); 076 } 077 }