1 11 12 package org.jivesoftware.util; 13 14 import java.beans.*; 15 import java.util.Enumeration ; 16 import java.util.Locale ; 17 import java.util.ResourceBundle ; 18 19 26 public abstract class JiveBeanInfo implements BeanInfo { 27 28 private ResourceBundle bundle; 29 30 public JiveBeanInfo() { 31 Locale currentLocale = JiveGlobals.getLocale(); 33 try { 34 bundle = ResourceBundle.getBundle("bean_" + getName(), 35 currentLocale); 36 } 37 catch (Exception e) { 38 } 40 } 41 42 47 public abstract String [] getPropertyNames(); 48 49 54 public abstract Class getBeanClass(); 55 56 64 public abstract String getName(); 65 66 68 public BeanDescriptor getBeanDescriptor() { 69 BeanDescriptor descriptor = new BeanDescriptor(getBeanClass()); 70 try { 71 String displayName = bundle.getString("displayName"); 73 if (displayName != null) { 74 descriptor.setDisplayName(displayName); 75 } 76 String shortDescription = bundle.getString("shortDescription"); 77 if (shortDescription != null) { 78 descriptor.setShortDescription(shortDescription); 79 } 80 Enumeration enumeration = bundle.getKeys(); 82 while (enumeration.hasMoreElements()) { 83 String key = (String )enumeration.nextElement(); 84 String value = bundle.getString(key); 85 if (value != null) { 86 descriptor.setValue(key, value); 87 } 88 } 89 } 90 catch (Exception e) { 91 } 94 return descriptor; 95 } 96 97 public PropertyDescriptor[] getPropertyDescriptors() { 98 Class beanClass = getBeanClass(); 99 String [] properties = getPropertyNames(); 100 101 PropertyDescriptor[] descriptors = new PropertyDescriptor[properties.length]; 102 try { 103 for (int i = 0; i < descriptors.length; i++) { 106 PropertyDescriptor newDescriptor = 107 new PropertyDescriptor(properties[i], beanClass); 108 if (bundle != null) { 109 newDescriptor.setDisplayName(bundle.getString(properties[i] + ".displayName")); 110 newDescriptor.setShortDescription(bundle.getString(properties[i] + ".shortDescription")); 111 } 112 descriptors[i] = newDescriptor; 113 } 114 return descriptors; 115 } 116 catch (IntrospectionException ie) { 117 Log.error(ie); 118 throw new Error (ie.toString()); 119 } 120 } 121 122 public int getDefaultPropertyIndex() { 123 return -1; 124 } 125 126 public EventSetDescriptor[] getEventSetDescriptors() { 127 return null; 128 } 129 130 public int getDefaultEventIndex() { 131 return -1; 132 } 133 134 public MethodDescriptor[] getMethodDescriptors() { 135 return null; 136 } 137 138 public BeanInfo[] getAdditionalBeanInfo() { 139 return null; 140 } 141 142 public java.awt.Image getIcon(int iconKind) { 143 return null; 144 } 145 } | Popular Tags |