JBoss Community Archive (Read Only)

JBoss Marshalling

Cloning API quick start

The base cloner API is quite simple. A cloner factory is acquired, a configuration is created, and the cloner is constructed from the factory and configuration. It can then be used to create object clones.

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.jboss.marshalling.cloner.ClonerConfiguration;
import org.jboss.marshalling.cloner.ObjectCloner;
import org.jboss.marshalling.cloner.ObjectClonerFactory;
import org.jboss.marshalling.cloner.ObjectCloners;

public final class CloningExample {

    public static void main(String[] args) {
        final ObjectClonerFactory clonerFactory = ObjectCloners.getSerializingObjectClonerFactory();
        final ClonerConfiguration configuration = new ClonerConfiguration();
        final ObjectCloner cloner = clonerFactory.createCloner(configuration);
        try {
            final List<String> clone = (List<String>) cloner.clone(Arrays.asList("One", "two", "three"));
            for (String s : clone) {
        } catch (IOException e) {
        } catch (ClassNotFoundException e) {

Note that IOException is among the possible exceptions thrown. This is because the cloner uses the same object construction logic that the marshalling layer uses.

There are a number of advanced features available to the user of the cloning API. See the section Cloning for more information.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 11:32:15 UTC, last content change 2011-08-02 00:08:25 UTC.