/* * ContainerOrganizer.java - Organizes containers for a particular type * * Copyright (c) 1996 Chuck McManis, All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. * * CHUCK MCMANIS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. CHUCK MCMANIS * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT * OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ import java.util.Dictionary; /** * This class provides the frame work for a mixin. We supply custom * implementations for the abstract methods, mix it into the container * and then the container is customized for our object types. */ public abstract class ContainerOrganizer { Dictionary localContainer; /** * Set the container this organizer is organizing. * Useful for call backs into the dictionary if need be. */ public void setDict(Dictionary d) { if (localContainer != null) { throw new RuntimeException("Overwriting container not allowed."); } localContainer = d; } /** * Given a simple object for the key, verify its type and * if necessary convert it to a new type. Can throw an * exception if the key is completely bogus. */ public abstract Object keyForObject(Object o); /** * Verify that object 'obj' is of the correct type for this * container, if the boolean 'ex' is true, throw a runtime * exception if the type is not valid. Return a validity * indication. */ public abstract boolean verifyType(Object obj, boolean ex); /** * Verify that 'obj' is a valid type for this container and * throw a runtime exception if it is not, this will never * return 'false'. */ public boolean verifyType(Object o) { return verifyType(o, true); } /** * Returns true if both keys are equivalent. */ public boolean equalKeys(Object k1, Object k2) { return compareKeys(k1, k2) == 0; } /** * Compare the two key values, return an indication of their * relative value. */ public abstract int compareKeys(Object k1, Object k2); }