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