1 10 11 package org.mmbase.core; 12 13 import java.util.*; 14 import org.mmbase.bridge.Descriptor; 15 import org.mmbase.util.LocalizedString; 16 import org.mmbase.util.logging.*; 17 18 25 26 abstract public class AbstractDescriptor implements Descriptor, Cloneable { 27 28 private static final Logger log = Logging.getLoggerInstance(AbstractDescriptor.class); 29 30 protected String key; 31 protected LocalizedString description; 32 protected LocalizedString guiName; 33 34 protected AbstractDescriptor() {} 35 36 40 protected AbstractDescriptor(String name) { 41 key = name; 42 setGUIName(name); 43 setDescription(""); 44 } 45 46 51 protected AbstractDescriptor(String name, Descriptor descriptor, boolean cloneDataForRewrite) { 52 key = name; 53 if (cloneDataForRewrite) { 54 description = (LocalizedString)descriptor.getLocalizedDescription().clone(); 55 guiName = (LocalizedString)descriptor.getLocalizedGUIName().clone(); 56 } else { 57 description = (LocalizedString)descriptor.getLocalizedDescription(); 58 guiName = (LocalizedString)descriptor.getLocalizedGUIName(); 59 } 60 } 61 62 protected AbstractDescriptor(String name, Descriptor descriptor) { 63 this(name, descriptor, true); 64 } 65 66 67 73 protected Locale getDefaultLocale() { 74 return null; 75 } 76 77 81 public String getName() { 82 return key; 83 } 84 85 public String getDescription(Locale locale) { 86 if (description == null) description = new LocalizedString(key); 87 return description.get(locale == null ? getDefaultLocale() : locale); 88 } 89 90 public String getDescription() { 91 return getDescription(getDefaultLocale()); 92 } 93 94 public LocalizedString getLocalizedDescription() { 95 return description; 96 } 97 98 protected void setLocalizedDescription(LocalizedString description) { 99 this.description = description; 100 } 101 102 public void setDescription(String desc, Locale locale) { 103 if (description == null) description = new LocalizedString(key); 104 description.set(desc, locale); 105 } 106 107 public void setDescription(String desc) { 108 setDescription(desc, getDefaultLocale()); 109 } 110 111 112 118 public String getGUIName(Locale locale) { 119 if (guiName == null) guiName = new LocalizedString(key); 120 return guiName.get(locale == null ? getDefaultLocale() : locale); 121 } 122 123 129 public String getGUIName() { 130 return getGUIName(getDefaultLocale()); 131 } 132 133 public void setGUIName(String g, Locale locale) { 134 if (guiName == null) guiName = new LocalizedString(key); 135 guiName.set(g, locale); 136 } 137 138 public void setGUIName(String g) { 139 setGUIName(g, getDefaultLocale()); 140 } 141 142 public LocalizedString getLocalizedGUIName() { 143 return guiName; 144 } 145 146 protected void setLocalizedGUIName(LocalizedString value) { 147 guiName = value; 148 } 149 150 public String toString() { 151 return key; 152 } 153 154 public Object clone() throws CloneNotSupportedException { 155 return clone(getName() + ".clone"); 156 } 157 158 public Object clone(String name) throws CloneNotSupportedException { 159 AbstractDescriptor clone = (AbstractDescriptor)super.clone(); 160 clone.description = (LocalizedString)description.clone(); 161 clone.guiName = (LocalizedString)guiName.clone(); 162 if (name != null) { 163 clone.key = name; 164 clone.description.setKey(name); 165 clone.guiName.setKey(name); 166 } 167 return clone; 168 } 169 170 } 171 | Popular Tags |