1 /* 2 Copyright (c) 2002,2003, Dennis M. Sosnoski. 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without modification, 6 are permitted provided that the following conditions are met: 7 8 * Redistributions of source code must retain the above copyright notice, this 9 list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright notice, 11 this list of conditions and the following disclaimer in the documentation 12 and/or other materials provided with the distribution. 13 * Neither the name of JiBX nor the names of its contributors may be used 14 to endorse or promote products derived from this software without specific 15 prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 package org.jibx.runtime; 30 31 /** 32 * Marshaller interface definition. This interface must be implemented 33 * by the handler for marshalling an object.<p> 34 * 35 * Instances of classes implementing this interface must be serially 36 * reusable, meaning they can store state information while in the process 37 * of marshalling an object but must reset all state when called to 38 * marshal another object after the first one is done (even if the first 39 * object throws an exception during marshalling). 40 * 41 * The JiBX framework will only create one instance of a marshaller class 42 * for each mapped class using that marshaller. Generally the marshaller 43 * instance will not be called recursively, but this may happen in cases where 44 * the binding definition includes recursive mappings and the marshaller 45 * uses other marshallers (as opposed to handling all children directly). 46 * 47 * @author Dennis M. Sosnoski 48 * @version 1.0 49 */ 50 51 public interface IMarshaller 52 { 53 /** 54 * Check if marshaller represents an extension mapping. This is used by the 55 * framework in generated code to verify compatibility of objects being 56 * marshalled using an abstract mapping. 57 * 58 * @param index abstract mapping index to be checked 59 * @return <code>true</code> if this mapping is an extension of the abstract 60 * mapping, <code>false</code> if not 61 */ 62 63 public boolean isExtension(int index); 64 65 /** 66 * Marshal instance of handled class. This method call is responsible 67 * for all handling of the marshalling of an object to XML text. It is 68 * called at the point where the start tag for the associated element 69 * should be generated. 70 * 71 * @param obj object to be marshalled (may be <code>null</code> if property 72 * is not optional) 73 * @param ctx XML text output context 74 * @throws JiBXException on error in marshalling process 75 */ 76 77 public void marshal(Object obj, IMarshallingContext ctx) 78 throws JiBXException; 79 } 80