1 7 package org.jdesktop.swing.data; 8 9 import java.util.*; 10 11 12 15 public class DefaultMetaDataProvider implements MetaDataProvider { 16 17 private List fieldNames; 18 private Map metaData; 19 20 public DefaultMetaDataProvider() { 21 22 } 23 public DefaultMetaDataProvider(MetaDataProvider provider) { 24 this(provider.getMetaData()); 25 } 26 27 public DefaultMetaDataProvider(MetaData[] metaDatas) { 28 29 setMetaData(metaDatas); 30 } 31 public MetaData[] getMetaData() { 33 MetaData[] metaData = new MetaData[getFieldCount()]; 34 for (int i = 0; i < metaData.length; i++) { 35 metaData[i] = getMetaData(getFieldName(i)); 36 } 37 return metaData; 38 } 39 40 public MetaData getMetaData(String dataID) { 41 return (MetaData) getMetaDataMap().get(dataID); 42 } 43 44 public String [] getFieldNames() { 46 return (String []) getFieldNameList().toArray(new String [getFieldCount()]); 47 } 48 49 public int getFieldCount() { 50 return getFieldNameList().size(); 51 } 52 53 58 public String getFieldName(int index) { 59 return (String ) getFieldNameList().get(index); 60 } 61 62 public int getFieldIndex(String fieldName) { 63 for (int i = 0; i < getFieldCount(); i++) { 64 if (fieldName.equals(getFieldName(i))) { 65 return i; 66 } 67 } 68 return -1; 69 } 70 71 public boolean hasField(String fieldName) { 72 return getFieldNameList().contains(fieldName); 73 } 74 75 public void setMetaData(MetaData[] metaData) { 77 clear(); 78 for (int i = 0; i < metaData.length; i++) { 79 addField(metaData[i]); 80 } 81 } 82 83 public void setMetaData(List metaData) { 84 clear(); 85 for (Iterator iter = metaData.iterator(); iter.hasNext(); ) { 86 addField((MetaData) iter.next()); 87 } 88 } 89 90 public void addField(MetaData data) { 91 getFieldNameList().add(data.getName()); 92 getMetaDataMap().put(data.getName(), data); 93 } 94 95 public void clear() { 96 fieldNames = null; 97 metaData = null; 98 } 99 100 private List getFieldNameList() { 102 if (fieldNames == null) { 103 fieldNames = new ArrayList(); 104 } 105 return fieldNames; 106 } 107 108 private Map getMetaDataMap() { 109 if (metaData == null) { 110 metaData = new HashMap(); 111 } 112 return metaData; 113 } 114 } 115 | Popular Tags |