2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
43
* Superclass that implements DisplayNameInterface and IconInterface for Servlet2.4 beans.
45
* @author Milan Kuchtiak
47
package org.netbeans.modules.j2ee.dd.impl.common;
49
import org.netbeans.modules.schema2beans.BaseBean;
50
import org.netbeans.modules.schema2beans.Version;
51
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
52
import org.netbeans.modules.j2ee.dd.api.common.IconInterface;
53
import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
54
import org.netbeans.modules.j2ee.dd.api.common.DisplayNameInterface;
56
public abstract class ComponentBeanMultiple extends DescriptionBeanMultiple implements DisplayNameInterface, IconInterface {
58
public ComponentBeanMultiple(java.util.Vector comps, Version version) {
59
super(comps, version);
61
// methods implemented by specific BaseBeans e.g. Servlet
62
public void setIcon(int index, org.netbeans.modules.j2ee.dd.api.common.Icon icon){}
63
public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon[] icons){}
64
public org.netbeans.modules.j2ee.dd.api.common.Icon getIcon(int i){return null;}
65
public org.netbeans.modules.j2ee.dd.api.common.Icon[] getIcon(){return null;}
66
public int sizeIcon(){return 0;}
67
public int addIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon){return 0;}
68
public int removeIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon){return 0;}
70
public abstract void setDisplayName(int index, java.lang.String value);
71
public abstract String getDisplayName(int index);
72
public abstract void setDisplayName(java.lang.String[] value);
73
//public abstract java.lang.String[] getDisplayName();
74
public abstract int sizeDisplayName();
75
public abstract int addDisplayName(java.lang.String value);
76
//public abstract int removeDisplayName(java.lang.String value);
77
public abstract void setDisplayNameXmlLang(int index, java.lang.String value);
78
public abstract String getDisplayNameXmlLang(int index);
80
public void setDisplayName(String locale, String displayName) throws VersionNotSupportedException {
81
if (displayName==null) removeDisplayNameForLocale(locale);
83
int size = sizeDisplayName();
85
for (int i=0;i<size;i++) {
86
String loc=getDisplayNameXmlLang(i);
87
if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
89
setDisplayName(i, displayName);
94
addDisplayName(displayName);
95
if (locale!=null) setDisplayNameXmlLang(size, locale.toLowerCase());
100
public void setDisplayName(String displayName) {
102
setDisplayName(null,displayName);
103
} catch (VersionNotSupportedException ex){}
106
public void setAllDisplayNames(java.util.Map displayNames) throws VersionNotSupportedException {
107
removeAllDisplayNames();
108
if (displayNames!=null) {
109
java.util.Iterator keys = displayNames.keySet().iterator();
110
String[] newDisplayName = new String[displayNames.size()];
112
while (keys.hasNext()) {
113
String key = (String) keys.next();
114
addDisplayName((String)displayNames.get(key));
115
setDisplayNameXmlLang(i++, key);
120
public String getDisplayName(String locale) throws VersionNotSupportedException {
121
for (int i=0;i<sizeDisplayName();i++) {
122
String loc=getDisplayNameXmlLang(i);
123
if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
124
return getDisplayName(i);
129
public String getDefaultDisplayName() {
131
return getDisplayName(null);
132
} catch (VersionNotSupportedException ex){return null;}
134
public java.util.Map getAllDisplayNames() {
135
java.util.Map map =new java.util.HashMap();
136
for (int i=0;i<sizeDisplayName();i++) {
137
String desc=getDisplayName(i);
138
String loc=getDisplayNameXmlLang(i);
144
public void removeDisplayNameForLocale(String locale) throws VersionNotSupportedException {
145
java.util.Map map = new java.util.HashMap();
146
for (int i=0;i<sizeDisplayName();i++) {
147
String desc=getDisplayName(i);
148
String loc=getDisplayNameXmlLang(i);
149
if ((locale==null && loc!=null) || (locale!=null && !locale.equalsIgnoreCase(loc)))
152
setAllDisplayNames(map);
155
public void removeDisplayName() {
157
removeDisplayNameForLocale(null);
158
} catch (VersionNotSupportedException ex){}
160
public void removeAllDisplayNames() {
161
setDisplayName(new String[]{});
165
public void setSmallIcon(String locale, String icon) throws VersionNotSupportedException {
166
setIcon(locale, icon, true);
168
public void setSmallIcon(String icon) {
170
setSmallIcon(null,icon);
171
} catch (VersionNotSupportedException ex){}
173
public void setLargeIcon(String locale, String icon) throws VersionNotSupportedException {
174
setIcon(locale, icon, false);
176
public void setLargeIcon(String icon) {
178
setLargeIcon(null,icon);
179
} catch (VersionNotSupportedException ex){}
181
public void setAllIcons(String[] locales, String[] smallIcons, String[] largeIcons) throws VersionNotSupportedException {
182
org.netbeans.modules.j2ee.dd.api.common.Icon[] newIcons = new org.netbeans.modules.j2ee.dd.api.common.Icon[locales.length];
183
for (int i=0;i<locales.length;i++) {
185
newIcons[i] = (org.netbeans.modules.j2ee.dd.api.common.Icon)createBean("Icon"); //NOI18N
186
if (smallIcons[i]!=null) newIcons[i].setSmallIcon(smallIcons[i]);
187
if (largeIcons[i]!=null) newIcons[i].setLargeIcon(largeIcons[i]);
188
if (locales[i]!=null) newIcons[i].setXmlLang(locales[i]);
189
} catch (ClassNotFoundException ex){}
194
public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon) {
195
if (icon==null) removeIcon();
197
org.netbeans.modules.j2ee.dd.api.common.Icon[] oldIcons = getIcon();
200
String locale = icon.getXmlLang();
201
for (int i=0;i<oldIcons.length;i++) {
202
String loc=oldIcons[i].getXmlLang();
203
if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
208
} catch (VersionNotSupportedException ex){}
215
public String getSmallIcon(String locale) throws VersionNotSupportedException {
216
return getIcon(locale,true);
218
public String getSmallIcon() {
220
return getSmallIcon(null);
221
} catch (VersionNotSupportedException ex){return null;}
223
public String getLargeIcon(String locale) throws VersionNotSupportedException {
224
return getIcon(locale,false);
226
public String getLargeIcon() {
228
return getLargeIcon(null);
229
} catch (VersionNotSupportedException ex){return null;}
231
public org.netbeans.modules.j2ee.dd.api.common.Icon getDefaultIcon() {
232
org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
233
for (int i=0;i<icons.length;i++) {
235
String loc=icons[i].getXmlLang();
236
if (loc==null) return icons[i];
237
} catch (VersionNotSupportedException ex){}
241
public java.util.Map getAllIcons() {
242
java.util.Map map =new java.util.HashMap();
243
org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
244
for (int i=0;i<icons.length;i++) {
245
String[] iconPair = new String[] {icons[i].getSmallIcon(),icons[i].getLargeIcon()};
248
loc=icons[i].getXmlLang();
249
} catch (VersionNotSupportedException ex){}
250
map.put(loc, iconPair);
255
public void removeSmallIcon(String locale) throws VersionNotSupportedException {
256
removeIcon(locale, true);
258
public void removeLargeIcon(String locale) throws VersionNotSupportedException {
259
removeIcon(locale, false);
261
public void removeIcon(String locale) throws VersionNotSupportedException {
262
org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
263
for (int i=0;i<icons.length;i++) {
264
String loc=icons[i].getXmlLang();
265
if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
266
removeIcon(icons[i]);
270
public void removeSmallIcon() {
272
removeSmallIcon(null);
273
} catch (VersionNotSupportedException ex){}
275
public void removeLargeIcon() {
277
removeLargeIcon(null);
278
} catch (VersionNotSupportedException ex){}
280
public void removeIcon() {
281
org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
282
for (int i=0;i<icons.length;i++) {
284
String loc=icons[i].getXmlLang();
285
if (loc==null) removeIcon(icons[i]);
286
} catch (VersionNotSupportedException ex){}
289
public void removeAllIcons() {
290
setIcon(new org.netbeans.modules.j2ee.dd.api.common.Icon[]{});
292
private void setIcon(String locale, String icon, boolean isSmall) throws VersionNotSupportedException {
294
if (isSmall) removeSmallIcon(locale);
295
else removeLargeIcon(locale);
298
org.netbeans.modules.j2ee.dd.api.common.Icon[] oldIcons = getIcon();
300
for (int i=0;i<oldIcons.length;i++) {
301
String loc=oldIcons[i].getXmlLang();
302
if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
304
if (isSmall) oldIcons[i].setSmallIcon(icon);
305
else oldIcons[i].setLargeIcon(icon);
311
org.netbeans.modules.j2ee.dd.api.common.Icon newIcon = (org.netbeans.modules.j2ee.dd.api.common.Icon)createBean("Icon"); //NOI18N
312
if (locale!=null) newIcon.setXmlLang(locale.toLowerCase());
313
if (isSmall) newIcon.setSmallIcon(icon);
314
else newIcon.setLargeIcon(icon);
316
} catch (ClassNotFoundException ex){}
320
private String getIcon(String locale, boolean isSmall) throws VersionNotSupportedException {
321
for (int i=0;i<sizeIcon();i++) {
322
org.netbeans.modules.j2ee.dd.api.common.Icon icon = getIcon(i);
323
String loc=icon.getXmlLang();
324
if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
325
if (isSmall) return icon.getSmallIcon();
326
else return icon.getLargeIcon();
332
public void removeIcon(String locale, boolean isSmall) throws VersionNotSupportedException {
333
org.netbeans.modules.j2ee.dd.api.common.Icon[] icons = getIcon();
334
java.util.List iconList = new java.util.ArrayList();
335
for (int i=0;i<icons.length;i++) {
336
String loc=icons[i].getXmlLang();
337
if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
339
icons[i].setSmallIcon(null);
340
if (icons[i].getLargeIcon()==null) iconList.add(icons[i]);
342
icons[i].setLargeIcon(null);
343
if (icons[i].getSmallIcon()==null) iconList.add(icons[i]);
347
java.util.Iterator it = iconList.iterator();
348
while(it.hasNext()) removeIcon((org.netbeans.modules.j2ee.dd.api.common.Icon)it.next());