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

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

Introduction

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

Prototype

public static Object clone(Serializable 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:com.gemstone.gemfire.security.GemFireSecurityExceptionTest.java

@Test
public void serializesWithNonSerializableNamingException() throws Exception {
    GemFireSecurityException instance = new GemFireSecurityException(this.message,
            this.nonSerializableNamingException);

    GemFireSecurityException cloned = (GemFireSecurityException) SerializationUtils.clone(instance);

    assertThat(cloned).hasMessage(this.message).hasCause(this.nonSerializableNamingException);
    NamingException cause = (NamingException) cloned.getCause();
    assertThat(cause).hasMessage(this.causeMessage);
    assertThat(cause.getResolvedObj()).isNull();
}

From source file:io.cloudslang.lang.runtime.steps.ParallelLoopExecutionData.java

public void addBranches(
        @Param(ScoreLangConstants.PARALLEL_LOOP_STATEMENT_KEY) LoopStatement parallelLoopStatement,
        @Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv,
        @Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices,
        @Param(ScoreLangConstants.NODE_NAME_KEY) String nodeName,

        //CHECKSTYLE:OFF: checkstyle:parametername
        @Param(ExecutionParametersConsts.RUNNING_EXECUTION_PLAN_ID) Long RUNNING_EXECUTION_PLAN_ID,
        //CHECKSTYLE:ON

        @Param(ScoreLangConstants.NEXT_STEP_ID_KEY) Long nextStepId,
        @Param(ScoreLangConstants.BRANCH_BEGIN_STEP_ID_KEY) Long branchBeginStep,
        @Param(ScoreLangConstants.REF_ID) String refId) {

    try {// w  w w.j a va  2s.  c  om
        Context flowContext = runEnv.getStack().popContext();

        List<Value> splitData = parallelLoopBinding.bindParallelLoopList(parallelLoopStatement, flowContext,
                runEnv.getSystemProperties(), nodeName);

        fireEvent(executionRuntimeServices, ScoreLangConstants.EVENT_SPLIT_BRANCHES,
                "parallel loop expression bound", runEnv.getExecutionPath().getCurrentPath(),
                LanguageEventData.StepType.STEP, nodeName, flowContext.getImmutableViewOfVariables(),
                Pair.of(LanguageEventData.BOUND_PARALLEL_LOOP_EXPRESSION, (Serializable) splitData));

        runEnv.putNextStepPosition(nextStepId);
        runEnv.getExecutionPath().down();

        for (Value splitItem : splitData) {
            Context branchContext = (Context) SerializationUtils.clone(flowContext);

            // first fire event
            fireEvent(executionRuntimeServices, ScoreLangConstants.EVENT_BRANCH_START,
                    "parallel loop branch created", runEnv.getExecutionPath().getCurrentPath(),
                    LanguageEventData.StepType.STEP, nodeName, branchContext.getImmutableViewOfVariables(),
                    Pair.of(ScoreLangConstants.REF_ID, refId),
                    Pair.of(RuntimeConstants.SPLIT_ITEM_KEY, splitItem));
            // take path down one level
            runEnv.getExecutionPath().down();

            RunEnvironment branchRuntimeEnvironment = (RunEnvironment) SerializationUtils.clone(runEnv);
            branchRuntimeEnvironment.resetStacks();

            if (parallelLoopStatement instanceof ListLoopStatement) {
                branchContext.putVariable(((ListLoopStatement) parallelLoopStatement).getVarName(), splitItem);
            } else if (parallelLoopStatement instanceof MapLoopStatement) {
                branchContext.putVariable(((MapLoopStatement) parallelLoopStatement).getKeyName(),
                        (Value) ((ImmutablePair) splitItem.get()).getLeft());
                branchContext.putVariable(((MapLoopStatement) parallelLoopStatement).getValueName(),
                        (Value) ((ImmutablePair) splitItem.get()).getRight());
            }
            updateCallArgumentsAndPushContextToStack(branchRuntimeEnvironment, branchContext,
                    new HashMap<String, Value>());

            createBranch(branchRuntimeEnvironment, executionRuntimeServices, refId, branchBeginStep);

            // take path up level
            runEnv.getExecutionPath().up();

            // forward for next branch
            runEnv.getExecutionPath().forward();
        }

        updateCallArgumentsAndPushContextToStack(runEnv, flowContext, new HashMap<String, Value>());
    } catch (RuntimeException e) {
        logger.error("There was an error running the add branches execution step of: \'" + nodeName
                + "\'. Error is: " + e.getMessage());
        throw new RuntimeException("Error running: " + nodeName + ": " + e.getMessage(), e);
    }

}

From source file:com.gemstone.gemfire.security.NotAuthorizedExceptionTest.java

@Test
public void serializesWithThrowable() throws Exception {
    Throwable cause = new Exception(this.causeMessage);
    NotAuthorizedException instance = new NotAuthorizedException(this.message, cause);

    NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);

    assertThat(cloned).hasMessage(this.message);
    assertThat(cloned).hasCause(cause);/*  w w  w .jav  a 2s . c o  m*/
}

From source file:com.autentia.tnt.businessobject.Tag.java

public void initChanges() {
    if (this.getContactTags() != null) {
        for (Contact contact : this.getContactTags()) {
            contact.getId();//from  w  ww .j a  va  2  s  .com
            contact.getName();
            //                for (ContactChange change: contact.getHistory()) {
            //                    change.getId();
            //                    change.getField();
            //                }
        }
    }
    this.changes = (Tag) SerializationUtils.clone(this);
}

From source file:com.hp.mqm.atrf.octane.services.OctaneQueryBuilder.java

public OctaneQueryBuilder clone() {
    OctaneQueryBuilder qb = (OctaneQueryBuilder) SerializationUtils.clone(this);
    return qb;
}

From source file:com.gemstone.gemfire.security.NotAuthorizedExceptionTest.java

@Test
public void serializesWithNonSerializablePrincipal() throws Exception {
    NotAuthorizedException instance = new NotAuthorizedException(this.message, this.nonSerializablePrincipal);
    assertThat(instance.getPrincipal()).isNotNull();

    NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);

    assertThat(cloned).hasMessage(this.message);
    assertThat(cloned.getPrincipal()).isNull();
}

From source file:com.gemstone.gemfire.security.GemFireSecurityExceptionTest.java

@Test
public void serializesWithSerializableNamingException() throws Exception {
    GemFireSecurityException instance = new GemFireSecurityException(this.message,
            this.serializableNamingException);

    GemFireSecurityException cloned = (GemFireSecurityException) SerializationUtils.clone(instance);

    assertThat(cloned).hasMessage(this.message).hasCause(this.serializableNamingException);
    NamingException cause = (NamingException) cloned.getCause();
    assertThat(cause).hasMessage(this.causeMessage);
    assertThat(cause.getResolvedObj()).isNotNull().isEqualTo(this.serializableResolvedObj);
}

From source file:hudson.plugins.timestamper.TimestampNoteTest.java

private TimestampNote serialize(TimestampNote note) {
    return (TimestampNote) SerializationUtils.clone(note);
}

From source file:com.hp.mqm.atrf.alm.services.AlmQueryBuilder.java

public AlmQueryBuilder clone() {
    AlmQueryBuilder qb = (AlmQueryBuilder) SerializationUtils.clone(this);
    return qb;
}

From source file:com.gemstone.gemfire.security.NotAuthorizedExceptionTest.java

@Test
public void serializesWithSerializablePrincipal() throws Exception {
    NotAuthorizedException instance = new NotAuthorizedException(this.message, this.serializablePrincipal);

    NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);

    assertThat(cloned).hasMessage(this.message);
    assertThat(cloned.getPrincipal()).isNotNull().isEqualTo(this.serializablePrincipal);
}