KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > model > services > Annotations


1 /**
2  * Copyright (C) 2002 Kelua SA
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package org.objectweb.kilim.model.services;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import org.objectweb.kilim.KilimException;
25 import org.objectweb.kilim.description.KILIM;
26
27 /**
28  * Thids class is a simple container for annotations (i.e. a couple made of a name and a value).
29  * @author horn
30  */

31
32 public class Annotations {
33
34     private HashMap JavaDoc externalServices;
35     
36     /**
37      * @see java.lang.Object#Object()
38      */

39     public Annotations() { }
40         
41     /**
42      * adds a new annotation
43      * @param aName : the name of the annotation to be added.
44      * @param xService : the reference of the object offering the annotation
45      * @throws KilimException : the exception is generated if the name or the reference is null or if the annotation
46      * has already been added (It should be removed first).
47      */

48     public void addAnnotation(String JavaDoc aName, Object JavaDoc 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 JavaDoc();
57         }
58         externalServices.put(aName, xService);
59     }
60     
61     /**
62      * removes an annotation
63      * @param aName : the name of the annotation to be removed.
64      * @throws KilimException : the exception is generated if the name is null or if the annotation name is unknown.
65      */

66     public void removeAnnotation(String JavaDoc 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 JavaDoc result = externalServices.remove(aName);
74         if (result == null) {
75             throw new KilimException("attempt to remove an unknown annotation " + aName);
76         }
77     }
78     
79     /**
80      * returns an annotation.
81      * @param aName : the name of the annotation to be returned.
82      * @return Object : the reference of the object offering the annotation.
83      * @throws KilimException : the exception is generated if the name is null.
84      */

85     public Object JavaDoc getAnnotation(String JavaDoc 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     /**
96      * returns an iterator containing the names of all the currently added annotations.
97      * @return Iterator
98      */

99     public Iterator JavaDoc getAnnotationNames() {
100         if (externalServices == null) {
101             return KILIM.EMPTY_ITERATOR;
102         }
103         return externalServices.keySet().iterator();
104     }
105 }
106
Popular Tags