KickJava   Java API By Example, From Geeks To Geeks.

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


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 DescriptionInterface for Servlet2.4 beans.
22  *
23  * @author Milan Kuchtiak
24  */

25
26 package org.netbeans.modules.j2ee.dd.impl.common;
27
28 import org.netbeans.modules.schema2beans.BaseBean;
29 import org.netbeans.modules.schema2beans.Version;
30 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
31 import org.netbeans.modules.j2ee.dd.api.common.DescriptionInterface;
32
33 public abstract class DescriptionBeanMultiple extends EnclosingBean implements DescriptionInterface {
34
35     public DescriptionBeanMultiple(java.util.Vector JavaDoc comps, Version version) {
36     super(comps, version);
37     }
38     // methods implemented by specific s2b beans
39
public void setDescription(int index, java.lang.String JavaDoc value){}
40     public String JavaDoc getDescription(int index){return null;}
41     public void setDescription(java.lang.String JavaDoc[] value){}
42     //public abstract java.lang.String[] getDescription();
43
public int sizeDescription(){return 0;}
44     public int addDescription(java.lang.String JavaDoc value){return 0;}
45     //public abstract int removeDescription(java.lang.String value);
46
public void setDescriptionXmlLang(int index, java.lang.String JavaDoc value){}
47     public String JavaDoc getDescriptionXmlLang(int index){return null;}
48     
49     public void setDescription(String JavaDoc locale, String JavaDoc description) throws VersionNotSupportedException {
50         if (description==null) removeDescriptionForLocale(locale);
51         else {
52             int size = sizeDescription();
53             boolean found=false;
54             for (int i=0;i<size;i++) {
55                 String JavaDoc loc=getDescriptionXmlLang(i);
56                 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
57                     found=true;
58                     setDescription(i, description);
59                     break;
60                 }
61             }
62             if (!found) {
63                 addDescription(description);
64                 if (locale!=null) setDescriptionXmlLang(size, locale.toLowerCase());
65             }
66         }
67     }
68     
69     public void setDescription(String JavaDoc description) {
70         try {
71             setDescription(null,description);
72         } catch (VersionNotSupportedException ex){}
73     }
74     
75     public void setAllDescriptions(java.util.Map JavaDoc descriptions) throws VersionNotSupportedException {
76         removeAllDescriptions();
77         if (descriptions!=null) {
78             java.util.Iterator JavaDoc keys = descriptions.keySet().iterator();
79             String JavaDoc[] newDescription = new String JavaDoc[descriptions.size()];
80             int i=0;
81             while (keys.hasNext()) {
82                 String JavaDoc key = (String JavaDoc) keys.next();
83                 addDescription((String JavaDoc)descriptions.get(key));
84                 setDescriptionXmlLang(i++, key);
85             }
86         }
87     }
88     
89     public String JavaDoc getDescription(String JavaDoc locale) throws VersionNotSupportedException {
90         for (int i=0;i<sizeDescription();i++) {
91             String JavaDoc loc=getDescriptionXmlLang(i);
92             if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) {
93                 return getDescription(i);
94             }
95         }
96         return null;
97     }
98     public String JavaDoc getDefaultDescription() {
99         try {
100             return getDescription(null);
101         } catch (VersionNotSupportedException ex){return null;}
102     }
103     public java.util.Map JavaDoc getAllDescriptions() {
104         java.util.Map JavaDoc map =new java.util.HashMap JavaDoc();
105         for (int i=0;i<sizeDescription();i++) {
106             String JavaDoc desc=getDescription(i);
107             String JavaDoc loc=getDescriptionXmlLang(i);
108             map.put(loc, desc);
109         }
110         return map;
111     }
112     
113     public void removeDescriptionForLocale(String JavaDoc locale) throws VersionNotSupportedException {
114         java.util.Map JavaDoc map = new java.util.HashMap JavaDoc();
115         for (int i=0;i<sizeDescription();i++) {
116             String JavaDoc desc=getDescription(i);
117             String JavaDoc loc=getDescriptionXmlLang(i);
118             if ((locale==null && loc!=null) || (locale!=null && !locale.equalsIgnoreCase(loc)))
119                 map.put(loc, desc);
120         }
121         setAllDescriptions(map);
122     }
123     
124     public void removeDescription() {
125         try {
126             removeDescriptionForLocale(null);
127         } catch (VersionNotSupportedException ex){}
128     }
129     public void removeAllDescriptions() {
130         setDescription(new String JavaDoc[]{});
131     }
132 }
133
Popular Tags