KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > wsdl > util > DisplayObject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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