KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > util > SessionObjectHashtable


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

23 package org.objectweb.clif.scenario.util.isac.util;
24
25 import java.util.Enumeration JavaDoc;
26 import java.util.Hashtable JavaDoc;
27
28 import org.objectweb.clif.scenario.util.isac.exception.IsacRuntimeException;
29
30 /**
31  * Create specifics hashtable which override clone method, in order to clone
32  * values and not references All the elements putted in the class must
33  * implements the SessionObjectAction interface This kind of hashtable permit to
34  * reset all elements of the table too and close all elements of the table.
35  *
36  * @author JC Meillaud
37  * @author A Peyrard
38  */

39 public class SessionObjectHashtable extends Hashtable JavaDoc {
40     /**
41      * Constructor, build a ne cloneable hashtable All the object which are
42      * containing in this class must implements CloneableObject interface
43      */

44     public SessionObjectHashtable() {
45         super();
46     }
47
48     /**
49      * @see java.lang.Object#clone()
50      */

51     public synchronized Object JavaDoc clone() {
52         try {
53             SessionObjectHashtable clone = new SessionObjectHashtable();
54             Enumeration JavaDoc keys = this.keys();
55             Enumeration JavaDoc elems = this.elements();
56             while (keys.hasMoreElements()) {
57                 Object JavaDoc key = keys.nextElement();
58                 Object JavaDoc cloneableValue = ((SessionObjectAction) elems
59                         .nextElement()).createNewSessionObject();
60                 // put the object in the cloned hashtable
61
clone.put(key, cloneableValue);
62             }
63             return clone;
64         } catch (ClassCastException JavaDoc cce) {
65             throw new IsacRuntimeException(
66                     "This hashtable must only contains object which implements SessionObjectAction interface", cce);
67         }
68     }
69
70     /**
71      * This method will call the reset method on all containing objects
72      */

73     public void reset() {
74         try {
75             Enumeration JavaDoc e = this.elements();
76             while (e.hasMoreElements()) {
77                 ((SessionObjectAction) e.nextElement()).reset();
78             }
79         } catch (ClassCastException JavaDoc cce) {
80             throw new IsacRuntimeException(
81                     "This hashtable must only contains object which implements SessionObjectAction interface",cce);
82         }
83     }
84
85     /**
86      * This method will call the close method on all objects
87      */

88     public void close() {
89         try {
90             Enumeration JavaDoc e = this.elements();
91             while (e.hasMoreElements()) {
92                 ((SessionObjectAction) e.nextElement()).close();
93             }
94         } catch (ClassCastException JavaDoc cce) {
95             throw new IsacRuntimeException(
96                     "This hashtable must only contains object which implements SessionObjectAction interface",cce);
97         }
98     }
99 }
Popular Tags