/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind;
import javax.xml.bind.Marshaller;
Optional interface that can be implemented by JAXB-bound objects
to handle cycles in the object graph.
As discussed in
the users' guide, normally a cycle in the object graph causes the marshaller to report an error,
and when an error is found, the JAXB RI recovers by cutting the cycle arbitrarily.
This is not always a desired behavior.
Implementing this interface allows user application to change this behavior.
Author: Kohsuke Kawaguchi Since: JAXB 2.1 EA2
/**
* Optional interface that can be implemented by JAXB-bound objects
* to handle cycles in the object graph.
*
* <p>
* As discussed in <a href="https://javaee.github.io/jaxb-v2/doc/user-guide/ch03.html#annotating-your-classes-mapping-cyclic-references-to-xml">
* the users' guide</a>, normally a cycle in the object graph causes the marshaller to report an error,
* and when an error is found, the JAXB RI recovers by cutting the cycle arbitrarily.
* This is not always a desired behavior.
*
* <p>
* Implementing this interface allows user application to change this behavior.
*
* @since JAXB 2.1 EA2
* @author Kohsuke Kawaguchi
*/
public interface CycleRecoverable {
Called when a cycle is detected by the JAXB RI marshaller
to nominate a new object to be marshalled instead.
Params: - context –
This object is provided by the JAXB RI to inform
the object about the marshalling process that's going on.
Returns: the object to be marshalled instead of this
object. Or return null to indicate that the JAXB RI should behave just like when your object does not implement CycleRecoverable
(IOW, cut the cycle arbitrarily and try to go on.)
/**
* Called when a cycle is detected by the JAXB RI marshaller
* to nominate a new object to be marshalled instead.
*
* @param context
* This object is provided by the JAXB RI to inform
* the object about the marshalling process that's going on.
*
*
* @return
* the object to be marshalled instead of {@code this} object.
* Or return null to indicate that the JAXB RI should behave
* just like when your object does not implement {@link CycleRecoverable}
* (IOW, cut the cycle arbitrarily and try to go on.)
*/
Object onCycleDetected(Context context);
This interface is implemented by the JAXB RI to provide
information about the on-going marshalling process.
We may add more methods in the future, so please do not
implement this interface in your application.
/**
* This interface is implemented by the JAXB RI to provide
* information about the on-going marshalling process.
*
* <p>
* We may add more methods in the future, so please do not
* implement this interface in your application.
*/
public interface Context {
Returns the marshaller object that's doing the marshalling.
Returns:
always non-null.
/**
* Returns the marshaller object that's doing the marshalling.
*
* @return
* always non-null.
*/
Marshaller getMarshaller();
}
}