1 19 20 25 26 package org.netbeans.modules.j2ee.sun.share.config.ui; 27 28 import java.beans.*; 29 import java.lang.reflect.Method ; 30 import java.util.*; 31 32 import javax.enterprise.deploy.spi.DConfigBean ; 33 34 import org.openide.ErrorManager; 35 import org.openide.nodes.*; 36 import org.openide.util.Lookup; 37 38 import org.netbeans.modules.j2ee.sun.share.config.ConfigBeanStorage; 39 40 41 45 public class ConfigUtils { 46 47 static Map infoMap = new HashMap(); 48 49 public static BeanInfo createBeanInfo(Object bean) { 50 BeanInfo info; 51 if (bean == null) { 52 return null; 53 } 54 if(infoMap.containsKey(bean.getClass())) { 55 return (BeanInfo) infoMap.get(bean.getClass()); 56 } 57 try { 58 info = (BeanInfo) 63 bean.getClass().getClassLoader().loadClass(bean.getClass().getName() + "BeanInfo").newInstance(); 64 66 67 } catch ( Exception ie) { 68 info = new DefaultBeanInfo(bean.getClass()); 71 } 72 infoMap.put(bean.getClass(),info); 73 return info; 74 } 75 76 static BeanInfo createDefaultBeanInfo(Object bean) { 78 BeanInfo info = new DefaultBeanInfo(bean.getClass()); 79 infoMap.put(bean.getClass(),info); 80 return info; 81 } 82 83 public static Sheet.Set[] createSheets(Object bean) { 84 return null; 85 } 86 87 public static Sheet.Set createSheet(Object bean) { 88 Sheet.Set basic = new Sheet.Set(); 90 try { 91 BeanInfo info = null; 92 if (bean instanceof ConfigBeanStorage) { 93 info = createBeanInfo(((ConfigBeanStorage)bean).getConfigBean()); 94 } 95 else { 96 info = createBeanInfo(bean); 97 } 98 if(info == null) return basic; 99 PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); 100 if(descriptors == null) { 101 System.err.println("Beaninfo doesn't have property descriptors for " + bean.getClass() + " info " + info.getClass()); 102 107 Node.Property property = ConfigProperty.getBraindead(info.getBeanDescriptor()); 108 basic.put(property); 109 } 110 else 111 for(int i = 0; i < descriptors.length; i++) { 112 if(descriptors[i].isHidden()) continue; 113 if(descriptors[i].getName().equals("xpaths")) continue; 114 if(descriptors[i].getName().equals("standardDDBean")) continue; 115 DConfigBean dConfigBean = ((ConfigBeanStorage)bean).getConfigBean(); 117 Node.Property property = ConfigProperty.getProperty(dConfigBean,descriptors[i]); 118 basic.put(property); 120 } 121 } catch (Exception e) { 122 ErrorManager em = (ErrorManager) Lookup.getDefault().lookup(ErrorManager.class); 123 em.notify(e); 124 } 125 return basic; 128 } 129 130 public static Object getBeanPropertyValue(DConfigBean config, String propName) { 131 Class cls = config.getClass(); 132 StringBuffer name = new StringBuffer ("get"+propName); name.setCharAt(3,Character.toUpperCase(propName.charAt(0))); 134 try { 135 Method method = cls.getDeclaredMethod(name.toString(), new Class [0]); 136 method.setAccessible (true); 137 return method.invoke(config,new Object [0]); 138 } catch (Exception ex) { 139 org.openide.ErrorManager.getDefault().log(ErrorManager.USER, ex.toString()); 140 } 141 return null; 142 } 143 144 public static void setBeanPropertyValue(DConfigBean config, String propName, String value) { 145 Class cls = config.getClass(); 146 StringBuffer name = new StringBuffer ("set"+propName); name.setCharAt(3,Character.toUpperCase(propName.charAt(0))); 148 try { 149 Method method = cls.getDeclaredMethod(name.toString(), new Class [] { java.lang.String .class }); 150 method.setAccessible (true); 151 method.invoke(config, new Object [] { value }); 152 } catch (Exception ex) { 153 org.openide.ErrorManager.getDefault().log(ErrorManager.USER, ex.toString()); 154 } 155 }} 156 | Popular Tags |