1 19 20 package org.netbeans.modules.xml.wsdl.ui.wsdl.util; 21 22 import java.lang.reflect.InvocationTargetException ; 23 import java.lang.reflect.Method ; 24 import org.openide.ErrorManager; 25 26 public class DisplayObject { 27 private Object mObj = null; 28 private String mMethodToGetDisplayName = null; 29 private String mDisplayName = null; 30 public DisplayObject (Object obj, String methodToGetDisplayName) { 31 mObj = obj; 32 mMethodToGetDisplayName = methodToGetDisplayName; 33 } 34 35 public DisplayObject(String displayName, Object value) { 36 mObj = value; 37 mDisplayName = displayName; 38 } 39 40 public Object getValue() { 41 return mObj; 42 } 43 44 @Override 45 public String toString() { 46 if (mDisplayName != null) { 47 return mDisplayName; 48 } 49 String str = ""; 50 if (mMethodToGetDisplayName != null) { 51 Class c = mObj.getClass(); 52 Class [] parameterTypes = new Class [] {String .class}; 53 Method getDisplayNameMethod; 54 Object [] arguments = new Object [] {}; 55 try { 56 getDisplayNameMethod = c.getMethod(mMethodToGetDisplayName, parameterTypes); 57 str = (String ) getDisplayNameMethod.invoke(mObj, arguments); 58 } catch (NoSuchMethodException e) { 59 ErrorManager.getDefault().notify(e); 60 } catch (IllegalAccessException e) { 61 ErrorManager.getDefault().notify(e); 62 } catch (InvocationTargetException e) { 63 ErrorManager.getDefault().notify(e); 64 } 65 } 66 return str; 67 68 } 69 } 70 | Popular Tags |