1 22 package org.jboss.metadata.spi.retrieval.cummulative; 23 24 import java.util.HashSet ; 25 import java.util.List ; 26 import java.util.Set ; 27 28 import org.jboss.metadata.spi.context.MetaDataContext; 29 import org.jboss.metadata.spi.retrieval.MetaDataItem; 30 import org.jboss.metadata.spi.retrieval.MetaDataRetrieval; 31 import org.jboss.metadata.spi.retrieval.MetaDatasItem; 32 import org.jboss.metadata.spi.retrieval.simple.SimpleMetaDatasItem; 33 34 40 public class CummulativeMetaDatasItem extends SimpleMetaDatasItem 41 { 42 43 private MetaDataContext context; 44 45 46 private boolean includeParent; 47 48 49 private long validTime; 50 51 57 public CummulativeMetaDatasItem(MetaDataContext context, boolean includeParent) 58 { 59 if (context == null) 60 throw new IllegalArgumentException ("Null context"); 61 62 this.context = context; 63 this.includeParent = includeParent; 64 init(context.getValidTime().getValidTime()); 65 } 66 67 public Object [] getValue() 68 { 69 checkValid(); 70 return super.getValue(); 71 } 72 73 public MetaDataItem[] getMetaDatas() 74 { 75 checkValid(); 76 return super.getMetaDatas(); 77 } 78 79 public boolean isCachable() 80 { 81 return true; 82 } 83 84 public boolean isValid() 85 { 86 return true; 87 } 88 89 92 protected void checkValid() 93 { 94 MetaDataItem[] items = super.getMetaDatas(); 95 boolean valid = (items != null); 96 97 long newValidTime = context.getValidTime().getValidTime(); 98 if (validTime < newValidTime) 99 valid = false; 100 101 if (items != null) 102 { 103 for (MetaDataItem item : items) 104 { 105 if (item.isValid() == false) 106 valid = false; 107 } 108 } 109 110 if (valid == false) 111 init(newValidTime); 112 } 113 114 119 protected void init(long validTime) 120 { 121 Set <MetaDataItem> temp = null; 122 123 List <MetaDataRetrieval> retrievals; 124 125 if (includeParent) 126 retrievals = context.getRetrievals(); 127 else 128 retrievals = context.getLocalRetrievals(); 129 130 for (MetaDataRetrieval retrieval : retrievals) 131 { 132 MetaDatasItem item = retrieval.retrieveMetaData(); 133 if (item != null) 134 { 135 MetaDataItem[] items = item.getMetaDatas(); 136 for (MetaDataItem it : items) 137 { 138 if (temp == null) 139 temp = new HashSet <MetaDataItem>(); 140 temp.add(it); 141 } 142 } 143 } 144 145 MetaDataItem[] items = NO_META_DATA_ITEMS; 146 if (temp != null) 147 items = temp.toArray(new MetaDataItem[temp.size()]); 148 setMetaDataItems(items); 149 this.validTime = validTime; 150 } 151 } 152 | Popular Tags |