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