1 10 package org.mmbase.module.corebuilders; 11 12 import java.util.*; 13 14 import org.mmbase.datatypes.DataType; 15 import org.mmbase.bridge.NodeManager; 16 import org.mmbase.datatypes.DataTypes; 17 import org.mmbase.core.CoreField; 18 import org.mmbase.core.util.Fields; 19 import org.mmbase.storage.util.Index; 20 21 32 public class FieldDefs extends org.mmbase.core.CoreField { 33 34 public final static int DBSTATE_VIRTUAL = 0; 35 public final static int DBSTATE_PERSISTENT = 2; 36 public final static int DBSTATE_SYSTEM = 3; 37 38 public final static int DBSTATE_UNKNOWN = -1; 39 40 41 public final static int ORDER_CREATE = NodeManager.ORDER_CREATE; 42 public final static int ORDER_EDIT = NodeManager.ORDER_EDIT; 43 public final static int ORDER_LIST = NodeManager.ORDER_LIST; 44 public final static int ORDER_SEARCH = NodeManager.ORDER_SEARCH; 45 46 public FieldDefs(String name, int type, int listItemType, int state, DataType dataType ) { 47 super(name, type, listItemType, state, dataType); 48 } 49 50 59 public FieldDefs(String guiName, String guiType, int searchPos, int listPos, String name, int type) { 60 this(guiName, guiType, searchPos, listPos, name, type, -1, STATE_PERSISTENT); 61 } 62 63 74 public FieldDefs(String guiName, String guiType, int searchPos, int listPos, String name, int type, int guiPos, int state) { 75 super(name, type, TYPE_UNKNOWN, state, (DataType)DataTypes.getDataTypeInstance(guiType,type)); 76 setGUIName(guiName); 77 setSearchPosition(searchPos); 78 setEditPosition(guiPos); 79 setListPosition(listPos); 80 } 81 82 86 public String getDBName() { 87 return getName(); 88 } 89 90 96 public int getDBType() { 97 return getType(); 98 } 99 100 105 public int getDBSize() { 106 return getMaxLength(); 107 } 108 109 113 public boolean getDBNotNull() { 114 return getDataType().isRequired(); 115 } 116 117 122 public boolean isKey() { 123 return getParent() != null && getParent().getStorageConnector().isInIndex(Index.MAIN,this); 124 } 125 131 protected class LocaleToStringMap extends AbstractMap { 132 private final Map map; 133 public LocaleToStringMap(Map m) { 134 map = m; 135 } 136 public Set entrySet() { 137 return new AbstractSet() { 138 public Iterator iterator() { 139 return new Iterator() { 140 private final Iterator i = map.entrySet().iterator(); 141 public boolean hasNext() { 142 return i.hasNext(); 143 } 144 public void remove() { 145 throw new UnsupportedOperationException (""); 146 } 147 public Object next() { 148 final Map.Entry entry = (Map.Entry) i.next(); 149 return new Map.Entry() { 150 public Object getKey() { 151 return ((Locale) entry.getKey()).getLanguage(); 152 } 153 public Object getValue() { 154 return entry.getValue(); 155 } 156 public Object setValue(Object o) { 157 return entry.setValue(o); 158 } 159 }; 160 161 } 162 }; 163 } 164 public int size() { 165 return map.size(); 166 } 167 }; 168 } 169 } 170 171 174 public String getGUIName(String lang) { 175 return getGUIName(new Locale(lang, "")); 176 } 177 180 public Map getGUINames() { 181 return new LocaleToStringMap(getLocalizedGUIName().asMap()); 182 } 183 184 187 public Map getDescriptions() { 188 return new LocaleToStringMap(getLocalizedDescription().asMap()); 189 } 190 191 194 public String getDescription(String lang) { 195 return getDescription(new Locale(lang, "")); 196 } 197 198 201 public int getDBState() { 202 return getState(); 203 } 204 205 208 215 216 222 public void setGUIName(String lang, String value) { 223 setGUIName(value, new Locale(lang, "")); 224 } 225 226 232 public void setDescription(String lang, String value) { 233 setDescription(value, new Locale(lang, "")); 234 } 235 236 241 public void setDBSize(int value) { 242 setMaxLength(value); 243 } 244 245 246 251 public void setDBPos(int value) { 252 setStoragePosition(value); 253 } 254 255 258 public int getDBPos() { 259 return getStoragePosition(); 260 } 261 262 268 public void setGUIList(int value) { 269 setListPosition(value); 270 } 271 272 275 public int getGUIList() { 276 return getListPosition(); 277 } 278 279 285 public void setGUIPos(int value) { 286 setEditPosition(value); 287 } 288 289 292 public int getGUIPos() { 293 return getEditPosition(); 294 } 295 301 public void setGUISearch(int value) { 302 setSearchPosition(value); 303 } 304 305 308 public int getGUISearch() { 309 return getSearchPosition(); 310 } 311 312 317 public void setDBState(String value) { 318 setState(Fields.getState(value)); 319 } 320 321 324 public void setDBState(int i) { 325 setState(i); 326 } 327 328 333 public void setDBKey(boolean value) { 335 if (getParent() != null) { 336 getParent().getStorageConnector().addToIndex(Index.MAIN, this); 337 } 338 } 339 340 345 public void setDBNotNull(boolean value) { 346 getDataType().setRequired(value); 347 } 348 349 354 public static void sort(List fielddefs) { 355 Collections.sort(fielddefs); 356 } 357 358 364 public static void sort(List fielddefs, int order) { 365 Fields.sort(fielddefs, order); 366 } 367 368 } 369 | Popular Tags |