Java Code Examples for javax.xml.bind.Marshaller#Listener

The following examples show how to use javax.xml.bind.Marshaller#Listener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLSerializer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 2
Source File: XMLSerializer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 3
Source File: XMLSerializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 4
Source File: JsonProviderPrototypeServiceFactory.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: XmlTransformer.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
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 );
		}
	}
}
 
Example 6
Source File: ScreenshotFolderPersistence.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
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 );
			}
		}
	};
}
 
Example 7
Source File: XMLSerializer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 8
Source File: XMLSerializer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 9
Source File: XMLSerializer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 10
Source File: XMLSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 11
Source File: XMLSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 12
Source File: XMLSerializer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 13
Source File: XMLSerializer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 14
Source File: XMLSerializer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 15
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Specify the {@code Marshaller.Listener} to be registered with the JAXB {@code Marshaller}.
 */
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
	this.marshallerListener = marshallerListener;
}
 
Example 16
Source File: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Specify the {@code Marshaller.Listener} to be registered with the JAXB {@code Marshaller}.
 */
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
	this.marshallerListener = marshallerListener;
}
 
Example 17
Source File: AbstractJAXBProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
    this.marshallerListener = marshallerListener;
}
 
Example 18
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Specify the {@code Marshaller.Listener} to be registered with the JAXB {@code Marshaller}.
 */
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
	this.marshallerListener = marshallerListener;
}
 
Example 19
Source File: JAXBDataBinding.java    From cxf with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the Marshaller.Listener that will be registered on the Marshallers
 * @return
 */
public Marshaller.Listener getMarshallerListener() {
    return marshallerListener;
}
 
Example 20
Source File: JAXBDataBinding.java    From cxf with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the Marshaller.Listener that will be registered on the Marshallers
 * @param marshallerListener
 */
public void setMarshallerListener(Marshaller.Listener marshallerListener) {
    this.marshallerListener = marshallerListener;
}