1 22 package org.jboss.metadata.spi.retrieval; 23 24 import java.lang.annotation.Annotation ; 25 26 import org.jboss.metadata.spi.MetaData; 27 28 34 public class MetaDataRetrievalToMetaDataBridge implements MetaData 35 { 36 37 private MetaDataRetrieval retrieval; 38 39 public MetaDataRetrievalToMetaDataBridge(MetaDataRetrieval retrieval) 40 { 41 if (retrieval == null) 42 throw new IllegalArgumentException ("Null retrieval"); 43 this.retrieval = retrieval; 44 } 45 46 public long getValidTime() 47 { 48 ValidTime validTime = retrieval.getValidTime(); 49 return validTime.getValidTime(); 50 } 51 52 public <T extends Annotation > T getAnnotation(Class <T> annotationType) 53 { 54 if (annotationType == null) 55 throw new IllegalArgumentException ("Null annotationType"); 56 AnnotationItem<T> item = retrieval.retrieveAnnotation(annotationType); 57 if (item == null) 58 return null; 59 return item.getValue(); 60 } 61 62 public Annotation [] getAnnotations() 63 { 64 AnnotationsItem item = retrieval.retrieveAnnotations(); 65 if (item == null) 66 return NO_ANNOTATIONS; 67 return item.getValue(); 68 } 69 70 public Annotation [] getLocalAnnotations() 71 { 72 AnnotationsItem item = retrieval.retrieveLocalAnnotations(); 73 if (item == null) 74 return NO_ANNOTATIONS; 75 return item.getValue(); 76 } 77 78 public Object [] getMetaData() 79 { 80 MetaDatasItem item = retrieval.retrieveMetaData(); 81 if (item == null) 82 return NO_METADATA; 83 return item.getValue(); 84 } 85 86 public Object [] getLocalMetaData() 87 { 88 MetaDatasItem item = retrieval.retrieveLocalMetaData(); 89 if (item == null) 90 return NO_METADATA; 91 return item.getValue(); 92 } 93 94 public <T> T getMetaData(Class <T> type) 95 { 96 if (type == null) 97 throw new IllegalArgumentException ("Null type"); 98 MetaDataItem<T> item = retrieval.retrieveMetaData(type); 99 if (item == null) 100 return null; 101 return item.getValue(); 102 } 103 104 public <T> T getMetaData(String name, Class <T> type) 105 { 106 if (name == null) 107 throw new IllegalArgumentException ("Null name"); 108 if (type == null) 109 throw new IllegalArgumentException ("Null type"); 110 MetaDataItem item = retrieval.retrieveMetaData(name); 111 if (item == null) 112 return null; 113 return type.cast(item.getValue()); 114 } 115 116 public Object getMetaData(String name) 117 { 118 if (name == null) 119 throw new IllegalArgumentException ("Null name"); 120 MetaDataItem item = retrieval.retrieveMetaData(name); 121 if (item == null) 122 return null; 123 return item.getValue(); 124 } 125 126 public boolean isAnnotationPresent(Class <? extends Annotation > annotationType) 127 { 128 return getAnnotation(annotationType) != null; 129 } 130 131 public boolean isMetaDataPresent(Class <?> type) 132 { 133 return getMetaData(type) != null; 134 } 135 136 public boolean isMetaDataPresent(String name, Class <?> type) 137 { 138 if (type == null) 139 throw new IllegalArgumentException ("Null type"); 140 Object value = getMetaData(name); 141 if (value == null) 142 return false; 143 return type.isInstance(value); 144 } 145 146 public boolean isMetaDataPresent(String name) 147 { 148 return getMetaData(name) != null; 149 } 150 151 156 protected MetaDataRetrieval getMetaDataRetrieval() 157 { 158 return retrieval; 159 } 160 } 161 | Popular Tags |