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 2004 (C) Intalio, Inc. All Rights Reserved. 32 * 33 * $Id$ 34 */ 35 package org.exolab.castor.xml.handlers; 36 37 import org.exolab.castor.mapping.FieldHandlerFactory; 38 import org.exolab.castor.mapping.GeneralizedFieldHandler; 39 import org.exolab.castor.mapping.MappingException; 40 41 /** 42 * The default FieldHandlerFactory implementation. Used by the Introspector. This implementation 43 * only supports java.sql.Time and java.sql.Timestamp. 44 * 45 * @author <a href="kvisco@intalio.com">Keith Visco</a> 46 * @version $Revision$ $Date: 2004-04-08 22:44:47 -0600 (Thu, 08 Apr 2004) $ 47 */ 48 public class DefaultFieldHandlerFactory extends FieldHandlerFactory { 49 50 /** The array of supported classes. */ 51 private static final Class[] SUPPORTED_CLASSES = 52 new Class[] {java.sql.Time.class, java.sql.Timestamp.class}; 53 54 /** 55 * Returns an array of the supported Class types for this FieldHandlerFactory. The array may be 56 * empty, but must not be null. 57 * 58 * @return an array of supported Class types. 59 */ 60 public Class[] getSupportedTypes() { 61 return (Class[]) SUPPORTED_CLASSES.clone(); 62 } // -- getSupportedTypes 63 64 /** 65 * Returns true if the given Class type is supported by this FieldHandlerFactory. If the type is 66 * supported, a call to {@link #createFieldHandler} will return a valid FieldHandler. If the type 67 * is not supported, a call to createFieldHandler may return null or throw a MappingException. 68 * 69 * @param type the Class type to determine support for. 70 * 71 * @return true if the given Class type is supported. 72 */ 73 public boolean isSupportedType(final Class type) { 74 for (int i = 0; i < SUPPORTED_CLASSES.length; i++) { 75 if (SUPPORTED_CLASSES[i].isAssignableFrom(type)) { 76 return true; 77 } 78 } 79 return false; 80 } // -- isSupportedType 81 82 /** 83 * Creates a GeneralizedFieldHandler for the given class type. The method should return a new 84 * GeneralizedFieldHandler as an "underlying" FieldHandler will need to be set by the caller. 85 * 86 * @param type the Class type to create the FieldHandler for. 87 * @return a new FieldHandler 88 * @throws MappingException if a <code>valueOf</code> method cannot be found. 89 */ 90 public GeneralizedFieldHandler createFieldHandler(final Class type) throws MappingException { 91 if (type == null) { 92 return null; 93 } 94 if (java.sql.Time.class.isAssignableFrom(type)) { 95 return new SQLTimeFieldHandler(); 96 } 97 if (java.sql.Timestamp.class.isAssignableFrom(type)) { 98 return new ValueOfFieldHandler(type); 99 } 100 return null; 101 } // -- createFieldHandler 102 103 } // -- DefaultFieldHandlerFactory