KickJava   Java API By Example, From Geeks To Geeks.

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


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.LinkedHashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import org.objectweb.kilim.KilimException;
25 import org.objectweb.kilim.description.KILIM;
26
27 /**
28  * This class was initially dedicated to the definition of instanciation strategies. It has been generalized to
29  * be a generic container for any external references which may be accessed through a kilim component.
30  * @author horn
31  */

32
33 public class ExternalValueReferences {
34     private LinkedHashMap JavaDoc externalReferences;
35     
36     /**
37      * @see java.lang.Object#Object()
38      */

39     public ExternalValueReferences() { }
40     
41     /**
42      *This method adds a new external reference.
43      * @param aName : the name of the external reference.
44      * @param aObject : the referenced object.
45      * @throws KilimException : generated if aName is null.
46      */

47     public void addExternalValueReference(String JavaDoc aName, Object JavaDoc aObject) throws KilimException {
48         if (aName == null) {
49             throw new KilimException("attempt to add an external reference with a null name in the external value mapper");
50         }
51         
52         if (aObject == null) {
53             throw new KilimException("attempt to add an null external reference in the external value mapper");
54         }
55         if (externalReferences == null) {
56             externalReferences = new LinkedHashMap JavaDoc();
57         }
58         externalReferences.put(aName, aObject);
59     }
60     
61     /**
62      * removes an external reference.
63      * @param aName : the name of the reference to be removed.
64      * @throws KilimException : generated if aName is null.
65      */

66     public void removeExternalValueReference(String JavaDoc aName) throws KilimException {
67         if (aName == null) {
68             throw new KilimException("attempt to add an external reference with a null name in the external value mapper");
69         }
70         if (externalReferences == null) {
71             return;
72         }
73         externalReferences.remove(aName);
74     }
75
76     /**
77      * returns an external reference.
78      * @param aName : the name of the external reference
79      * @return Object : the referenced object
80      * @throws KilimException : generated if aName is null.
81      */

82     public Object JavaDoc getExternalValueReference(String JavaDoc aName) throws KilimException {
83         if (aName == null) {
84             throw new KilimException("attempt to add an external reference with a null name in the iexternal value mapper");
85         }
86         if (externalReferences == null) {
87             return null;
88         }
89         return externalReferences.get(aName);
90     }
91     
92         /**
93          * returns as an iterator the names of known external references.
94          * @return Iterator
95          */

96         public Iterator JavaDoc getExternalReferenceNames() {
97         if (externalReferences == null) {
98             return KILIM.EMPTY_ITERATOR;
99         }
100         return externalReferences.keySet().iterator();
101     }
102 }
103
Popular Tags