KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Containers > MetaInformation > AttributeInstanceListImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Hameau Fabien.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27
28
29 package org.objectweb.openccm.Containers.MetaInformation;
30
31 /**
32  * Manage the storage and acces to a given list of
33  * attribute instance objectsd
34  *
35  * @author <a HREF="hameau@lifl.fr">Hameau Fabien</a>
36  *
37  * @version 0.1
38  */

39
40 import org.objectweb.ccm.util.Table;
41 import org.omg.CORBA.LocalObject JavaDoc;
42 import org.omg.Components.InvalidName;
43
44 /**
45  * @author hameau
46  *
47
48  */

49 public class AttributeInstanceListImpl
50 extends LocalObject JavaDoc
51 implements AttributeInstanceList
52 {
53   // ==================================================================
54
//
55
// Internal states.
56
//
57
// ==================================================================
58

59   /** Internal representation of attribute instance MI */
60   private Table _attributes;
61   
62    public AttributeInstanceListImpl()
63    {
64      _attributes = new Table();
65    }
66
67   // ==================================================================
68
//
69
// Internal methods.
70
//
71
// ==================================================================
72

73   // NONE
74

75   //
76

77   // ==================================================================
78
//
79
// Public methods for ccm.Containers.MetaInformation::AttributeInstanceList.
80
//
81
// ==================================================================
82

83    public AttributeInstance
84    get_attribute_instance(String JavaDoc name)
85    throws InvalidName
86    {
87      AttributeInstance result = (AttributeInstance) _attributes.get(name);
88      if(result == null)
89        throw new InvalidName();
90      return result;
91    }
92
93    /* (non-Javadoc)
94     * @see org.objectweb.openccm.Containers.MetaInformation.AttributeInstanceListOperations#get_named_attribute_instances(java.lang.String[])
95     */

96    public AttributeInstance[]
97    get_named_attribute_instances(String JavaDoc[] names)
98    throws InvalidName
99    {
100      AttributeInstance[] result = new AttributeInstance[names.length];
101
102     // Iterate on all the connections.
103

104     int i = 0;
105     for(i=0;i<names.length;i++)
106     {
107       result[i] = (AttributeInstance)_attributes.get(names[i]);
108      
109       if(result[i] == null)
110       {
111         throw new InvalidName();
112       }
113      }
114    
115     return result;
116    }
117
118    /* (non-Javadoc)
119     * @see org.objectweb.openccm.Containers.MetaInformation.AttributeInstanceListOperations#get_all_attribute_instances()
120     */

121    public AttributeInstance[]
122    get_all_attribute_instances()
123    {
124      AttributeInstance[] result = new AttributeInstance[_attributes.size()];
125   
126       // Iterate on all the connections.
127
int idx = 0;
128       for(java.util.Enumeration JavaDoc elements = _attributes.elements(); elements.hasMoreElements(); )
129       {
130         AttributeInstance info = (AttributeInstance)elements.nextElement();
131           result[idx++] = info;
132       }
133       return result;
134    }
135
136    /* (non-Javadoc)
137     * @see org.objectweb.openccm.Containers.MetaInformation.AttributeInstanceListOperations#add_attribute_instance(org.objectweb.openccm.Containers.MetaInformation.AttributeInstance)
138     */

139    public void add_attribute_instance(AttributeInstance cpi)
140    {
141      String JavaDoc key = cpi.type_reference().name() + cpi.toString().substring(cpi.toString().lastIndexOf("@"));
142      
143      _attributes.put(key,cpi);
144     
145    }
146
147    /* (non-Javadoc)
148     * @see org.objectweb.openccm.Containers.MetaInformation.AttributeInstanceListOperations#remove_attribute_instance(java.lang.String)
149     */

150    public void remove_attribute_instance(String JavaDoc name)
151    throws InvalidName
152    {
153      Object JavaDoc result = _attributes.remove(name);
154     
155      if (result == null) throw new InvalidName();
156    }
157 }
158
Popular Tags