1 18 19 package org.objectweb.kilim.model.services; 20 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 24 import org.objectweb.kilim.KilimException; 25 import org.objectweb.kilim.description.KILIM; 26 27 31 32 public class Annotations { 33 34 private HashMap externalServices; 35 36 39 public Annotations() { } 40 41 48 public void addAnnotation(String aName, Object xService) throws KilimException { 49 if (aName == null) { 50 throw new KilimException("attempt to add an annotation with a null name"); 51 } 52 if (xService == null) { 53 throw new KilimException("attempt to add a null annotation"); 54 } 55 if (externalServices == null) { 56 externalServices = new HashMap (); 57 } 58 externalServices.put(aName, xService); 59 } 60 61 66 public void removeAnnotation(String aName) throws KilimException { 67 if (aName == null) { 68 throw new KilimException("attempt to remove an annotation through a null name"); 69 } 70 if (externalServices == null) { 71 throw new KilimException("attempt to remove an unknown annotation " + aName); 72 } 73 Object result = externalServices.remove(aName); 74 if (result == null) { 75 throw new KilimException("attempt to remove an unknown annotation " + aName); 76 } 77 } 78 79 85 public Object getAnnotation(String aName) throws KilimException { 86 if (aName == null) { 87 throw new KilimException("attempt to get an external service with a null name from the instanciation strategy"); 88 } 89 if (externalServices == null) { 90 return null; 91 } 92 return externalServices.get(aName); 93 } 94 95 99 public Iterator getAnnotationNames() { 100 if (externalServices == null) { 101 return KILIM.EMPTY_ITERATOR; 102 } 103 return externalServices.keySet().iterator(); 104 } 105 } 106 | Popular Tags |