1 /** 2 * Redistribution and use of this software and associated documentation ("Software"), with or 3 * without modification, are permitted provided that the following conditions are met: 4 * 5 * 1. Redistributions of source code must retain copyright statements and notices. Redistributions 6 * must also contain a copy of this document. 7 * 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided with 10 * the distribution. 11 * 12 * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software 13 * without prior written permission of Intalio, Inc. For written permission, please contact 14 * info@exolab.org. 15 * 16 * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in 17 * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of 18 * Intalio, Inc. 19 * 20 * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/). 21 * 22 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS 25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Copyright 2002 (C) Intalio, Inc. All Rights Reserved. 32 * 33 * $Id$ 34 */ 35 36 37 package org.exolab.castor.mapping; 38 39 40 import java.util.Enumeration; 41 42 43 /** 44 * A Map handler for adding and retreiving key-value pairs from A map. A map handler is instantiated 45 * only once, must be thread safe and not use any synchronization. 46 * 47 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a> 48 * @version $Revision$ $Date: 2004-02-13 14:34:10 -0700 (Fri, 13 Feb 2004) $ 49 */ 50 public interface MapHandler { 51 52 /** 53 * Creates a new Instance of the map represented by this MapHandler. 54 * 55 * @return the new map. 56 */ 57 public Object create(); 58 59 /** 60 * Adds the given key-value pair to the map. Keys must be unique. Adding a key-value pair to the 61 * map, when an existing association for that key already exists will cause the existing 62 * association to be overwritten. 63 * 64 * The map is provided as a parameter and is returned as the return value if the returned map is a 65 * different object. That way the handler can create a new map if necessary. 66 * 67 * @param map the map, null if no map has been created yet. 68 * @param key the key for the object. 69 * @param object the object to add to the map. 70 * @return The map with the new object if a different instance than the <tt>map</tt> parameter, 71 * null otherwise 72 * @throws ClassCastException The MapHandler does not support maps of the given type. 73 */ 74 public Object put(Object map, Object key, Object object) throws ClassCastException; 75 76 77 /** 78 * Returns an enumeration of all the objects in the Map. 79 * 80 * @param map The map instance for which to return the enumeration of elements for. 81 * @return An enumeration of all the elements in the Map. 82 * @throws ClassCastException The MapHandler does not support collections of this type 83 */ 84 public Enumeration elements(Object map) throws ClassCastException; 85 86 /** 87 * Returns an enumeration of all the keys in the Map. 88 * 89 * @param map The map instance for which to return the enumeration of keys. 90 * @return An enumeration of all the keys in the Map. 91 * @throws ClassCastException The MapHandler does not support collections of this type 92 */ 93 public Enumeration keys(Object map) throws ClassCastException; 94 95 96 /** 97 * Returns the number of elements (key-value) in the map. 98 * 99 * @param map the map. 100 * @return Number of key-value associations in the Map 101 * @throws ClassCastException The MapHandler does not support collections of the given type. 102 */ 103 public int size(Object map) throws ClassCastException; 104 105 106 /** 107 * Clears the map of all key-value pairs. 108 * 109 * @param map the map to clear. 110 * @throws ClassCastException The MapHandler does not support collections of the given type. 111 */ 112 public void clear(Object map) throws ClassCastException; 113 114 /** 115 * Returns the object associated with the given key. 116 * 117 * @param map the map to return the object from. 118 * @param key the key for the object. 119 * @return the object associated with the given key, or null if no association was found in the 120 * given map. 121 * @throws ClassCastException The MapHandler does not support maps of the given type. 122 */ 123 public Object get(Object map, Object key) throws ClassCastException; 124 125 } // -- MapHandler 126 127