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.record; 016 017 import org.apache.hivemind.util.Defense; 018 import org.apache.hivemind.util.ToStringBuilder; 019 020 /** 021 * Represents a change to a component on a page. 022 * 023 * @author Howard Lewis Ship 024 */ 025 026 public class PropertyChangeImpl implements PropertyChange 027 { 028 029 private String _componentPath; 030 031 private String _propertyName; 032 033 private Object _newValue; 034 035 public PropertyChangeImpl(String componentPath, String propertyName, 036 Object newValue) 037 { 038 Defense.notNull(propertyName, "propertyName"); 039 040 // TODO: This breaks some tests, but those tests are wrong. 041 // Defense.notNull(newValue, "newValue"); 042 043 _componentPath = componentPath; 044 _propertyName = propertyName; 045 _newValue = newValue; 046 } 047 048 /** 049 * The path to the component on the page, or null if the property is a 050 * property of the page. 051 */ 052 053 public String getComponentPath() 054 { 055 return _componentPath; 056 } 057 058 /** 059 * The new value for the property, which may be null. 060 */ 061 062 public Object getNewValue() 063 { 064 return _newValue; 065 } 066 067 /** 068 * The name of the property that changed. 069 */ 070 071 public String getPropertyName() 072 { 073 return _propertyName; 074 } 075 076 public String toString() 077 { 078 ToStringBuilder builder = new ToStringBuilder(this); 079 080 builder.append("componentPath", _componentPath); 081 builder.append("propertyName", _propertyName); 082 builder.append("newValue", _newValue); 083 084 return builder.toString(); 085 } 086 087 public boolean equals(Object object) 088 { 089 if (this == object) return true; 090 091 if (object == null || object.getClass() != this.getClass()) 092 return false; 093 094 PropertyChangeImpl other = (PropertyChangeImpl) object; 095 096 return same(_componentPath, other._componentPath) 097 && same(_propertyName, other._propertyName) 098 && same(_newValue, other._newValue); 099 } 100 101 private boolean same(Object o1, Object o2) 102 { 103 return o1 == o2 || (o1 != null && o1.equals(o2)); 104 } 105 }