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 1999-2003 (C) Intalio, Inc. All Rights Reserved. 32 * 33 * $Id$ 34 */ 35 36 package org.exolab.castor.xml; 37 38 import org.exolab.castor.mapping.AbstractFieldHandler; 39 40 /** 41 * This FieldHandler is used in the generated descriptors. 42 * <p> 43 * A field handler knows how to perform various operations on the field that require access to the 44 * field value. 45 * </p> 46 * 47 * @author <a href="arkin@intalio.com">Assaf Arkin</a> 48 * @author <a href="kvisco@intalio.com">Keith Visco</a> 49 * @version $Revision$ $Date: 2006-04-14 04:14:43 -0600 (Fri, 14 Apr 2006) $ 50 * @see org.exolab.castor.mapping.FieldDescriptor 51 */ 52 public class XMLFieldHandler<T> extends AbstractFieldHandler<T> { 53 54 /** 55 * Creates a new default XMLFieldHandler instance. 56 */ 57 public XMLFieldHandler() { 58 super(); 59 } 60 61 /** 62 * Returns true if the given object is an XMLFieldHandler that is equivalent to this one. An 63 * equivalent XMLFieldHandler is an XMLFieldHandler that is an instances of the same class. This 64 * method can be overwritten to provide more advanced equivalence tests. 65 * 66 * @return true if the given object is an XMLFieldHandler that is equivalent to this one. 67 **/ 68 public boolean equals(Object obj) { 69 if (obj == null) { 70 return false; 71 } 72 if (!(obj instanceof XMLFieldHandler)) { 73 return false; 74 } 75 return getClass().isInstance(obj); 76 } 77 78 /** 79 * Returns the value of the field from the object. 80 * 81 * @param object The object 82 * @return The value of the field 83 * @throws IllegalStateException The Java object has changed and is no longer supported by this 84 * handler, or the handler is not compatiable with the Java object 85 */ 86 public T getValue(Object object) throws IllegalStateException { 87 // -- Do nothing, this method is overloaded by the 88 // -- source code generator 89 return null; 90 } 91 92 /** 93 * Creates a new instance of the object described by this field. 94 * 95 * @param parent The object for which the field is created 96 * @return A new instance of the field's value 97 * @throws IllegalStateException This field is a simple type and cannot be instantiated 98 */ 99 public T newInstance(Object parent) throws IllegalStateException { 100 // -- Do nothing, this method is overloaded by the 101 // -- source code generator 102 return null; 103 } 104 105 /** 106 * Creates a new instance of the object described by this field. 107 * 108 * @param parent The object for which the field is created 109 * @param args the set of constructor arguments 110 * @return A new instance of the field's value 111 * @throws IllegalStateException This field is a simple type and cannot be instantiated 112 */ 113 public Object newInstance(final Object parent, final Object[] args) throws IllegalStateException { 114 // -- backward compatability...ignore args 115 return newInstance(parent); 116 } 117 118 /** 119 * Sets the value of the field on the object. 120 * 121 * @param object The object. 122 * @param value The new value. 123 * @throws IllegalStateException The Java object has changed and is no longer supported by this 124 * handler, or the handler is not compatiable with the Java object. 125 * @throws IllegalArgumentException The value passed is not of a supported type. 126 */ 127 public void setValue(final Object object, final T value) 128 throws IllegalStateException, IllegalArgumentException { 129 // -- Do nothing, this method is overloaded by the 130 // -- source code generator 131 } 132 133 public void resetValue(final Object object) 134 throws IllegalStateException, IllegalArgumentException { 135 // -- Do nothing, this method is overloaded by the 136 // -- source code generator 137 } 138 }