下面列出了javax.xml.bind.Marshaller#Listener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
/**
* Invoke the beforeMarshal api on the external listener (if it exists) and on the bean embedded
* beforeMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireBeforeMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasBeforeMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().beforeMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.beforeMarshal(currentTarget);
}
}
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
JsonProviderPrototypeServiceFactory(
Dictionary<String, ?> properties,
Optional<TypeConverter> typeConverter,
Optional<Marshaller.Listener> marshallerListener,
Optional<Unmarshaller.Listener> unmarshallerListener,
Optional<SchemaHandler> schemaHandler
) {
_properties = properties;
_typeConverter = typeConverter;
_marshallerListener = marshallerListener;
_unmarshallerListener = unmarshallerListener;
_schemaHandler = schemaHandler;
}
public void toXML( final Object obj, final OutputStream out, final Marshaller.Listener listener ) {
Marshaller marshaller = null;
try {
final JAXBContext jc = createJAXBContext( additionalClazzes );
marshaller = jc.createMarshaller();
marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
marshaller.setProperty( MarshallerProperties.NAMESPACE_PREFIX_MAPPER,
new MapNamespacePrefixMapper( NAMESPACE_MAPPINGS ) );
marshaller.setProperty( MarshallerProperties.INDENT_STRING, "\t" );
marshaller.setEventHandler( new DefaultValidationEventHandler() );
marshaller.setListener( listener );
final SessionLogDelegate sessionLog = new SessionLogDelegate( AbstractSessionLog.getLog() );
AbstractSessionLog.setLog( sessionLog );
if ( config.isOnlyFragment() ) {
log.info( "Create only fragment for '{}'.", obj );
marshaller.setProperty( Marshaller.JAXB_FRAGMENT, true );
}
if ( config.isLightweightXml() ) {
log.info( "Use lightweight XML for '{}'.", obj );
lightweightMarshallerSet.add( marshaller );
XmlUtil.addLightWeightAdapter( marshaller );
}
marshaller.marshal( obj, out );
if ( sessionLog.containsMessages() ) {
throw new RuntimeException( "Error persisting XML: " + sessionLog.getLog() );
}
} catch ( final JAXBException e ) {
throw new RuntimeException( e );
} finally {
if ( config.isLightweightXml() && marshaller != null ) {
lightweightMarshallerSet.remove( marshaller );
}
}
}
public Marshaller.Listener getMarshallListener() {
return new Marshaller.Listener() {
@Override
public void afterMarshal( final Object source ) {
if ( source instanceof Screenshot ) {
if ( !prepared ) {
prepare();
}
saveScreenshot( (Screenshot) source );
}
}
};
}
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
/**
* Invoke the beforeMarshal api on the external listener (if it exists) and on the bean embedded
* beforeMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireBeforeMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasBeforeMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().beforeMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.beforeMarshal(currentTarget);
}
}
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
/**
* Invoke the afterMarshal api on the external listener (if it exists) and on the bean embedded
* afterMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireAfterMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasAfterMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().afterMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener before bean embedded listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.afterMarshal(currentTarget);
}
}
/**
* Invoke the beforeMarshal api on the external listener (if it exists) and on the bean embedded
* beforeMarshal api(if it exists).
*
* This method is called only after the callee has determined that beanInfo.lookForLifecycleMethods == true.
*
* @param beanInfo
* @param currentTarget
*/
private void fireBeforeMarshalEvents(final JaxBeanInfo beanInfo, Object currentTarget) {
// first invoke bean embedded listener
if (beanInfo.hasBeforeMarshalMethod()) {
Method m = beanInfo.getLifecycleMethods().beforeMarshal;
fireMarshalEvent(currentTarget, m);
}
// then invoke external listener
Marshaller.Listener externalListener = marshaller.getListener();
if (externalListener != null) {
externalListener.beforeMarshal(currentTarget);
}
}
/**
* Specify the {@code Marshaller.Listener} to be registered with the JAXB {@code Marshaller}.
*/
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
this.marshallerListener = marshallerListener;
}
/**
* Specify the {@code Marshaller.Listener} to be registered with the JAXB {@code Marshaller}.
*/
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
this.marshallerListener = marshallerListener;
}
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
this.marshallerListener = marshallerListener;
}
/**
* Specify the {@code Marshaller.Listener} to be registered with the JAXB {@code Marshaller}.
*/
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
this.marshallerListener = marshallerListener;
}
/**
* Sets the Marshaller.Listener that will be registered on the Marshallers
* @param marshallerListener
*/
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
this.marshallerListener = marshallerListener;
}
/**
* Returns the Marshaller.Listener that will be registered on the Marshallers
* @return
*/
public Marshaller.Listener getMarshallerListener() {
return marshallerListener;
}