KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > dd > impl > common > ComponentBeanSingle


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * Superclass that implements DisplayNameInterface and IconInterface for Ejb2.0 beans.
22  *
23  * @author Milan Kuchtiak
24  */

25 package org.netbeans.modules.j2ee.dd.impl.common;
26
27 import org.netbeans.modules.schema2beans.BaseBean;
28 import org.netbeans.modules.schema2beans.Version;
29 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
30 import org.netbeans.modules.j2ee.dd.api.common.IconInterface;
31 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
32 import org.netbeans.modules.j2ee.dd.api.common.DisplayNameInterface;
33
34 public abstract class ComponentBeanSingle extends DescriptionBeanSingle implements DisplayNameInterface, IconInterface {
35     
36     public ComponentBeanSingle(java.util.Vector JavaDoc comps, Version version) {
37     super(comps, version);
38     }
39     
40     // methods implemented in specific BaseBeans e.g. Servlet
41
public org.netbeans.modules.j2ee.dd.api.common.Icon getIcon(){return null;}
42     public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon){}
43     public abstract String JavaDoc getDisplayName();
44     public abstract void setDisplayName(String JavaDoc displayName);
45     
46     
47     public void setDisplayName(String JavaDoc locale, String JavaDoc displayName) throws VersionNotSupportedException {
48         if (locale==null) setDisplayName(displayName);
49         else throw new VersionNotSupportedException("2.0"); // NOI18N
50
}
51     
52     public void setAllDisplayNames(java.util.Map JavaDoc displayNames) throws VersionNotSupportedException {
53         throw new VersionNotSupportedException("2.0"); // NOI18N
54
}
55     
56     public String JavaDoc getDisplayName(String JavaDoc locale) throws VersionNotSupportedException {
57         if (locale==null) return getDisplayName();
58         else throw new VersionNotSupportedException("2.0"); // NOI18N
59
}
60     public String JavaDoc getDefaultDisplayName() {
61         return getDisplayName();
62     }
63     public java.util.Map JavaDoc getAllDisplayNames() {
64         java.util.Map JavaDoc map = new java.util.HashMap JavaDoc();
65         map.put(null, getDisplayName());
66         return map;
67     }
68     
69     public void removeDisplayNameForLocale(String JavaDoc locale) throws VersionNotSupportedException {
70         if (locale==null) setDisplayName(null);
71         else throw new VersionNotSupportedException("2.0"); // NOI18N
72
}
73     public void removeDisplayName() {
74         setDisplayName(null);
75     }
76     public void removeAllDisplayNames() {
77         setDisplayName(null);
78     }
79
80     // setters
81
public void setSmallIcon(String JavaDoc locale, String JavaDoc icon) throws VersionNotSupportedException {
82         if (locale==null) setSmallIcon(icon);
83         else throw new VersionNotSupportedException("2.0"); // NOI18N
84
}
85     public void setSmallIcon(String JavaDoc icon) {
86         setIcon(icon, true);
87     }
88     public void setLargeIcon(String JavaDoc locale, String JavaDoc icon) throws VersionNotSupportedException {
89         if (locale==null) setLargeIcon(icon);
90         else throw new VersionNotSupportedException("2.0"); // NOI18N
91
}
92     public void setLargeIcon(String JavaDoc icon) {
93         setIcon(icon, false);
94     }
95     public void setAllIcons(String JavaDoc[] locales, String JavaDoc[] smallIcons, String JavaDoc[] largeIcons) throws VersionNotSupportedException {
96         throw new VersionNotSupportedException("2.0"); // NOI18N
97
}
98     // getters
99
public String JavaDoc getSmallIcon(String JavaDoc locale) throws VersionNotSupportedException {
100         if (locale==null) return getSmallIcon();
101         else throw new VersionNotSupportedException("2.0"); // NOI18N
102
}
103     public String JavaDoc getSmallIcon() {
104         org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon();
105         if (icon==null) return null;
106         else return icon.getSmallIcon();
107     }
108     public String JavaDoc getLargeIcon(String JavaDoc locale) throws VersionNotSupportedException {
109         if (locale==null) return getLargeIcon();
110         else throw new VersionNotSupportedException("2.0"); // NOI18N
111
}
112     public String JavaDoc getLargeIcon() {
113         org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon();
114         if (icon==null) return null;
115         else return icon.getLargeIcon();
116     }
117     public org.netbeans.modules.j2ee.dd.api.common.Icon getDefaultIcon() {
118         return getIcon();
119     }
120     public java.util.Map JavaDoc getAllIcons() {
121         java.util.Map JavaDoc map = new java.util.HashMap JavaDoc();
122         org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon();
123         if (icon!=null) {
124             String JavaDoc[] icons = new String JavaDoc[]{icon.getSmallIcon(),icon.getLargeIcon()};
125             map.put(null, icons);
126         }
127         return map;
128     }
129     // removers
130
public void removeSmallIcon(String JavaDoc locale) throws VersionNotSupportedException {
131         if (locale==null) removeSmallIcon();
132         else throw new VersionNotSupportedException("2.0"); // NOI18N
133
}
134     public void removeLargeIcon(String JavaDoc locale) throws VersionNotSupportedException {
135         if (locale==null) removeLargeIcon();
136         else throw new VersionNotSupportedException("2.0"); // NOI18N
137
}
138     public void removeIcon(String JavaDoc locale) throws VersionNotSupportedException {
139         if (locale==null) removeIcon();
140         else throw new VersionNotSupportedException("2.0"); // NOI18N
141
}
142     public void removeSmallIcon() {
143         org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon();
144         if (icon!=null) {
145             icon.setSmallIcon(null);
146             if (icon.getLargeIcon()==null) setIcon(null);
147         }
148     }
149     public void removeLargeIcon() {
150         org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon();
151         if (icon!=null) {
152             icon.setLargeIcon(null);
153             if (icon.getSmallIcon()==null) setIcon(null);
154         }
155     }
156     public void removeIcon() {
157         setIcon(null);
158     }
159     public void removeAllIcons() {
160         setIcon(null);
161     }
162     // universal method for setting icon
163
private void setIcon(String JavaDoc icon, boolean isSmall) {
164         org.netbeans.modules.j2ee.dd.api.common.Icon oldIcon = getIcon();
165         if (oldIcon==null) {
166             if (icon!=null) {
167                 try {
168                     org.netbeans.modules.j2ee.dd.api.common.Icon newIcon = (org.netbeans.modules.j2ee.dd.api.common.Icon) createBean("Icon");
169                     if (isSmall) newIcon.setSmallIcon(icon);
170                     else newIcon.setLargeIcon(icon);
171                     setIcon(newIcon);
172                 } catch(ClassNotFoundException JavaDoc ex){}
173             }
174         } else {
175             if (icon==null) {
176                 if (isSmall) {
177                     oldIcon.setSmallIcon(null);
178                     if (oldIcon.getLargeIcon()==null) setIcon(null);
179                 } else {
180                     oldIcon.setLargeIcon(null);
181                     if (oldIcon.getSmallIcon()==null) setIcon(null);
182                 }
183             } else {
184                 if (isSmall) oldIcon.setSmallIcon(icon);
185                 else oldIcon.setLargeIcon(icon);
186             }
187         }
188     }
189 }
190
Popular Tags