1 16 package org.apache.catalina.storeconfig; 17 18 import java.beans.IndexedPropertyDescriptor ; 19 import java.beans.IntrospectionException ; 20 import java.beans.Introspector ; 21 import java.beans.PropertyDescriptor ; 22 import java.io.PrintWriter ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import org.apache.catalina.cluster.tcp.ReplicationTransmitter; 28 import org.apache.tomcat.util.IntrospectionUtils; 29 30 36 public class ReplicationTransmitterStoreAppender extends StoreAppender { 37 38 53 public void printAttributes(PrintWriter writer, int indent, 54 boolean include, Object bean, StoreDescription desc) 55 throws Exception { 56 57 String className = bean.getClass().getName(); 59 60 if (include && desc != null && !desc.isStandard()) { 62 writer.print(" className=\""); 63 writer.print(bean.getClass().getName()); 64 writer.print("\""); 65 } 66 67 List propertyKeys = getPropertyKeys((ReplicationTransmitter) bean); 68 Object bean2 = defaultInstance(bean); 70 for (Iterator propertyIterator = propertyKeys.iterator(); propertyIterator 71 .hasNext();) { 72 String key = (String ) propertyIterator.next(); 73 Object value = (Object ) IntrospectionUtils.getProperty(bean, key); 74 75 if (desc.isTransientAttribute(key)) { 76 continue; } 78 if (value == null) { 79 continue; } 81 if (!isPersistable(value.getClass())) { 82 continue; 83 } 84 Object value2 = IntrospectionUtils.getProperty(bean2, key); 85 if (value.equals(value2)) { 86 continue; 88 } 89 if (isPrintValue(bean, bean2, key, desc)) 90 printValue(writer, indent, key, value); 91 } 92 } 93 94 101 protected List getPropertyKeys(ReplicationTransmitter bean) 102 throws IntrospectionException { 103 ArrayList propertyKeys = new ArrayList (); 104 PropertyDescriptor descriptors[] = Introspector.getBeanInfo( 106 bean.getClass()).getPropertyDescriptors(); 107 if (descriptors == null) { 108 descriptors = new PropertyDescriptor [0]; 109 } 110 for (int i = 0; i < descriptors.length; i++) { 111 if (descriptors[i] instanceof IndexedPropertyDescriptor ) { 112 continue; } 114 if (!isPersistable(descriptors[i].getPropertyType()) 115 || (descriptors[i].getReadMethod() == null) 116 || (descriptors[i].getWriteMethod() == null)) { 117 continue; } 119 propertyKeys.add(descriptors[i].getName()); 120 } 121 for (Iterator propertyIterator = bean.getPropertyNames(); propertyIterator 122 .hasNext();) { 123 Object key = propertyIterator.next(); 124 if (propertyKeys.contains(key)) 125 continue; 126 if ("className".equals(key)) 127 continue; 128 propertyKeys.add(key); 129 } 130 return propertyKeys; 131 } 132 133 } | Popular Tags |