Example usage for org.apache.commons.lang3 SerializationUtils clone

List of usage examples for org.apache.commons.lang3 SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SerializationUtils clone.

Prototype

public static <T extends Serializable> T clone(final T object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.apache.flink.api.java.record.ReduceWrappingFunctionTest.java

@SuppressWarnings("unchecked")
@Test/*from ww  w  .ja  v  a2 s. c  o  m*/
public void testWrappedReduceClass() {
    try {
        ReduceOperator reduceOp = ReduceOperator.builder(TestReduceFunction.class).build();

        UserCodeWrapper<GroupReduceFunction<Record, Record>> udf = reduceOp.getUserCodeWrapper();
        UserCodeWrapper<GroupReduceFunction<Record, Record>> copy = SerializationUtils.clone(udf);
        GroupReduceFunction<Record, Record> reducer = copy.getUserCodeObject();

        // prepare the reduce / combine tests
        final List<Record> target = new ArrayList<Record>();
        Collector<Record> collector = new Collector<Record>() {
            @Override
            public void collect(Record record) {
                target.add(record);
            }

            @Override
            public void close() {
            }
        };

        List<Record> source = new ArrayList<Record>();
        source.add(new Record(new IntValue(42), new LongValue(11)));
        source.add(new Record(new IntValue(13), new LongValue(17)));

        // test reduce
        reducer.reduce(source, collector);
        assertEquals(2, target.size());
        assertEquals(new IntValue(42), target.get(0).getField(0, IntValue.class));
        assertEquals(new LongValue(11), target.get(0).getField(1, LongValue.class));
        assertEquals(new IntValue(13), target.get(1).getField(0, IntValue.class));
        assertEquals(new LongValue(17), target.get(1).getField(1, LongValue.class));
        target.clear();

        // test combine
        ((GroupCombineFunction<Record, Record>) reducer).combine(source, collector);
        assertEquals(2, target.size());
        assertEquals(new IntValue(42), target.get(0).getField(0, IntValue.class));
        assertEquals(new LongValue(11), target.get(0).getField(1, LongValue.class));
        assertEquals(new IntValue(13), target.get(1).getField(0, IntValue.class));
        assertEquals(new LongValue(17), target.get(1).getField(1, LongValue.class));
        target.clear();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:org.apache.flink.runtime.jobgraph.JobTaskVertexTest.java

@Test
public void testOutputFormatVertex() {
    try {/*from  w  w  w .j av a 2s  . c om*/
        final TestingOutputFormat outputFormat = new TestingOutputFormat();
        final OutputFormatVertex of = new OutputFormatVertex("Name");
        new TaskConfig(of.getConfiguration())
                .setStubWrapper(new UserCodeObjectWrapper<OutputFormat<?>>(outputFormat));
        final ClassLoader cl = getClass().getClassLoader();

        try {
            of.initializeOnMaster(cl);
            fail("Did not throw expected exception.");
        } catch (TestException e) {
            // all good
        }

        OutputFormatVertex copy = SerializationUtils.clone(of);
        try {
            copy.initializeOnMaster(cl);
            fail("Did not throw expected exception.");
        } catch (TestException e) {
            // all good
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:org.apache.streams.rss.test.RssTypeConverterTest.java

@Test
public void testSerializability() {
    RssTypeConverter converter = new RssTypeConverter();
    RssTypeConverter clone = SerializationUtils.clone(converter);
}

From source file:org.apache.streams.tika.TestCategoryParser.java

@Test
public void testSerializability() {
    CategoryParser parser = new CategoryParser();
    CategoryParser clone = SerializationUtils.clone(parser);
}

From source file:org.apache.streams.tika.TestTikaProcessor.java

@Test
public void testSerializability() {
    TikaProcessor processor = new TikaProcessor();
    TikaProcessor clone = SerializationUtils.clone(processor);
}

From source file:org.apache.streams.urls.TestLinkUnwinderProcessor.java

@Ignore
@Test/* w  w w.  j  ava  2 s  .co m*/
public void testLinkResolverSerializability() {
    LinkResolver resolver = new LinkResolver("http://bit.ly/1cX5Rh4");
    LinkResolver clone = SerializationUtils.clone(resolver);
}

From source file:org.apache.streams.urls.TestLinkUnwinderProcessor.java

@Test
public void testLinkResolverProcessorSerializability() {
    LinkResolverProcessor processor = new LinkResolverProcessor();
    LinkResolverProcessor clone = SerializationUtils.clone(processor);
}

From source file:org.apache.syncope.client.console.pages.EditUserModalPage.java

public EditUserModalPage(final PageReference pageRef, final ModalWindow window, final UserTO userTO) {
    super(pageRef, window, userTO, Mode.ADMIN, true);

    this.initialUserTO = SerializationUtils.clone(userTO);

    form = setupEditPanel();//from w  w w.  j  a  va 2  s  .  c  o m

    // add resource assignment details in case of update
    if (userTO.getKey() != 0) {
        form.addOrReplace(new Label("pwdChangeInfo", new ResourceModel("pwdChangeInfo")));

        statusPanel = new StatusPanel("statuspanel", userTO, new ArrayList<StatusBean>(), getPageReference());
        statusPanel.setOutputMarkupId(true);
        MetaDataRoleAuthorizationStrategy.authorize(statusPanel, RENDER,
                xmlRolesReader.getEntitlement("Resources", "getConnectorObject"));
        form.addOrReplace(statusPanel);

        form.addOrReplace(new AccountInformationPanel("accountinformation", userTO));

        form.addOrReplace(new ResourcesPanel.Builder("resources").attributableTO(userTO)
                .statusPanel(statusPanel).build());

        form.addOrReplace(new MembershipsPanel("memberships", userTO, mode, statusPanel, getPageReference()));
    }
}

From source file:org.apache.syncope.client.console.pages.GroupModalPage.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public GroupModalPage(final PageReference pageRef, final ModalWindow window, final GroupTO groupTO,
        final Mode mode) {

    super();/*from  w  ww.  j  a  va  2  s.c o  m*/

    this.pageRef = pageRef;
    this.window = window;
    this.mode = mode;

    this.createFlag = groupTO.getKey() == 0;
    if (!createFlag) {
        originalGroupTO = SerializationUtils.clone(groupTO);
    }

    final Form<GroupTO> form = new Form<GroupTO>("groupForm");
    form.setMultiPart(true);

    add(new Label("displayName", groupTO.getKey() == 0 ? "" : groupTO.getDisplayName()));

    form.setModel(new CompoundPropertyModel<GroupTO>(groupTO));

    this.groupPanel = new GroupPanel.Builder("groupPanel").form(form).groupTO(groupTO).groupModalPageMode(mode)
            .pageRef(getPageReference()).build();
    form.add(groupPanel);

    final AjaxButton submit = new IndicatingAjaxButton(SUBMIT, new ResourceModel(SUBMIT)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            try {
                submitAction(target, form);

                if (pageRef.getPage() instanceof BasePage) {
                    ((BasePage) pageRef.getPage()).setModalResult(true);
                }

                closeAction(target, form);
            } catch (Exception e) {
                error(getString(Constants.ERROR) + ": " + e.getMessage());
                feedbackPanel.refresh(target);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            feedbackPanel.refresh(target);
        }
    };
    form.add(submit);
    form.setDefaultButton(submit);

    final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            closeAction(target, form);
        }
    };
    cancel.setDefaultFormProcessing(false);
    form.add(cancel);

    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE,
            xmlRolesReader.getEntitlement("Groups", createFlag ? "create" : "update"));

    add(form);
}

From source file:org.apache.syncope.client.console.pages.RoleModalPage.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public RoleModalPage(final PageReference pageRef, final ModalWindow window, final RoleTO roleTO,
        final Mode mode) {
    super();//w ww  . j  a va  2s .  c  o m

    this.pageRef = pageRef;
    this.window = window;
    this.mode = mode;

    this.createFlag = roleTO.getKey() == 0;
    if (!createFlag) {
        originalRoleTO = SerializationUtils.clone(roleTO);
    }

    final Form<RoleTO> form = new Form<RoleTO>("roleForm");
    form.setMultiPart(true);

    add(new Label("displayName", roleTO.getKey() == 0 ? "" : roleTO.getDisplayName()));

    form.setModel(new CompoundPropertyModel<RoleTO>(roleTO));

    this.rolePanel = new RolePanel.Builder("rolePanel").form(form).roleTO(roleTO).roleModalPageMode(mode)
            .pageRef(getPageReference()).build();
    form.add(rolePanel);

    final AjaxButton submit = new IndicatingAjaxButton(SUBMIT, new ResourceModel(SUBMIT)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            try {
                submitAction(target, form);

                if (pageRef.getPage() instanceof BasePage) {
                    ((BasePage) pageRef.getPage()).setModalResult(true);
                }

                closeAction(target, form);
            } catch (Exception e) {
                error(getString(Constants.ERROR) + ": " + e.getMessage());
                feedbackPanel.refresh(target);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            feedbackPanel.refresh(target);
        }
    };
    form.add(submit);
    form.setDefaultButton(submit);

    final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            closeAction(target, form);
        }
    };
    cancel.setDefaultFormProcessing(false);
    form.add(cancel);

    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE,
            xmlRolesReader.getEntitlement("Roles", createFlag ? "create" : "update"));

    add(form);
}