01: /*
02: Copyright (c) 2002,2003, Dennis M. Sosnoski.
03: All rights reserved.
04:
05: Redistribution and use in source and binary forms, with or without modification,
06: are permitted provided that the following conditions are met:
07:
08: * Redistributions of source code must retain the above copyright notice, this
09: 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: * Check if marshaller represents an extension mapping. This is used by the
54: * framework in generated code to verify compatibility of objects being
55: * marshalled using an abstract mapping.
56: *
57: * @param index abstract mapping index to be checked
58: * @return <code>true</code> if this mapping is an extension of the abstract
59: * mapping, <code>false</code> if not
60: */
61:
62: public boolean isExtension(int index);
63:
64: /**
65: * Marshal instance of handled class. This method call is responsible
66: * for all handling of the marshalling of an object to XML text. It is
67: * called at the point where the start tag for the associated element
68: * should be generated.
69: *
70: * @param obj object to be marshalled (may be <code>null</code> if property
71: * is not optional)
72: * @param ctx XML text output context
73: * @throws JiBXException on error in marshalling process
74: */
75:
76: public void marshal(Object obj, IMarshallingContext ctx)
77: throws JiBXException;
78: }
|