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.energy_home.jemma.javagal.layers.business.implementations.GatewayEventManager.java

/**
 * {@inheritDoc}/*from   w  w w  . j  a  v a2s .c o  m*/
 */
public void notifyZCLEvent(final ZCLMessage message) {
    executor.execute(new Runnable() {
        public void run() {
            for (GatewayDeviceEventEntry<?> gl : getGal().getListGatewayEventListener()) {
                if (gl.getGatewayEventListener() instanceof GatewayEventListenerExtended) {
                    ZCLMessage cmessage = null;
                    synchronized (message) {
                        cmessage = SerializationUtils.clone(message);
                    }
                    ((GatewayEventListenerExtended) gl.getGatewayEventListener()).notifyZCLCommand(cmessage);
                }
            }

        }
    });
}

From source file:org.energy_home.jemma.javagal.layers.business.implementations.GatewayEventManager.java

/**
 * {@inheritDoc}/*from  w w  w  . ja  va 2 s .co m*/
 */
public void notifyFrequencyAgility(final Status status) {
    executor.execute(new Runnable() {
        public void run() {
            LinkedList<GatewayDeviceEventEntry> copylist = null;
            for (GatewayDeviceEventEntry<?> gl : getGal().getListGatewayEventListener()) {
                if (gl.getGatewayEventListener() instanceof GatewayEventListenerExtended) {
                    Status cstatus = null;
                    synchronized (status) {
                        cstatus = SerializationUtils.clone(status);
                    }
                    ((GatewayEventListenerExtended) gl.getGatewayEventListener())
                            .FrequencyAgilityResponse(cstatus);
                }
            }

        }
    });

}

From source file:org.energy_home.jemma.javagal.layers.business.implementations.MessageManager.java

/**
 * Processes the APS indication message trying to dispatch it to the right
 * destination. The {@link GalController} maintains a collection of
 * registered callbacks' listeners. This method verifies if a match exists
 * on that collection for the callback's filter, i.e. looks if one or more
 * destination(s) for that APS message is present. If it exists, sends the
 * APS message to all found destinations.
 * //from   ww w  .j a  v a2s . c  o  m
 * @param message
 *            the indication APSMessageEvent to process.
 */
public void APSMessageIndication(final APSMessageEvent message) {
    executor.execute(new Runnable() {
        public void run() {
            LOG.debug("GAL -- Aps Message Indication in process...");

            for (CallbackEntry ce : getGal().getCallbacks()) {

                Callback callback = ce.getCallback();
                Filter filter = callback.getFilter();
                if (filter.getLevelSpecification().getLevel().get(0).equals(Level.APS_LEVEL)) {
                    if (filter.getMessageSpecification().size() > 0) {
                        boolean messageSpecificationFound = false;
                        for (MessageSpecification ms : filter.getMessageSpecification()) {

                            if (ms.getAPSClusterIdentifier() == null) {
                                messageSpecificationFound = true;
                                // If match we can stop the search loop.
                                break;

                            } else if (ms.getAPSClusterIdentifier() == message.getClusterID()) {
                                messageSpecificationFound = true;
                                // If match we can stop the search loop.
                                break;
                            }
                        }
                        if (!messageSpecificationFound) {
                            // If no Messaging Specification was found,
                            // then this callback doesn't match and we
                            // can jump to check the next one.
                            continue;
                        }
                    }

                    // Address Specification check. If there are at
                    // least one address specification in the filter,
                    // then we proceed to find a match, else if no
                    // address specification is present we assume that
                    // the check pass.
                    if (filter.getAddressSpecification().size() > 0) {
                        boolean addressingSpecificationFound = false;
                        for (AddressSpecification as : filter.getAddressSpecification()) {
                            // Source Address (Address Specification)
                            Address assa = as.getNWKSourceAddress();
                            int asnsa = 0xFFFF;
                            // If null, then we assume that all address
                            // match for this filter, and so we leave
                            // the initial value of 0xFFFF.
                            if (assa != null) {
                                asnsa = assa.getNetworkAddress();
                            }
                            short assep = -1;

                            if (as.getAPSSourceEndpoint() != null)
                                assep = as.getAPSSourceEndpoint();
                            // Pass if the callback has a broadcast
                            // Source Address
                            if (asnsa != 0xFFFF) {
                                // Source Address
                                long msam = message.getSourceAddressMode().longValue();
                                Address msa = message.getSourceAddress();
                                if (msam == 0x01) {
                                    // Network address, NO source end
                                    // point
                                    int msna0x01 = msa.getNetworkAddress();
                                    // Pass if the message has a
                                    // broadcast Source Address
                                    if (msna0x01 != 0xFFFF) {
                                        // Don't pass if they differs,
                                        // so we go ahead on the next
                                        // iteration in the for cycle
                                        if (asnsa != msna0x01) {
                                            continue;
                                        }
                                    }
                                } else if (msam == 0x02) {
                                    // Network address, AND source end
                                    // point present.
                                    int msna0x02 = msa.getNetworkAddress();
                                    short msep = message.getSourceEndpoint();
                                    // Pass if the message has a
                                    // broadcast Source Address.
                                    if (msna0x02 != 0xFFFF) {
                                        // Don't pass if they differs,
                                        // so we go ahead on the
                                        // next iteration in for cycle.
                                        if (asnsa != msna0x02) {
                                            // Don't pass if they
                                            // differs, so we go ahead
                                            // on the next iteration in
                                            // the for cycle.
                                            continue;
                                        } else if (msep != 0xFF) {
                                            if (msep != assep) {
                                                // Don't pass if they
                                                // differs, so we go
                                                // ahead on the next
                                                // iteration in the for
                                                // cycle.
                                                continue;
                                            }
                                        }
                                    }
                                } else if (msam == 0x03) {
                                    LOG.warn("AIA"); // FIXME is this
                                                     // something
                                                     // expected or not ?
                                                     // maybe a better
                                                     // log message would
                                                     // also help ...

                                    // ASK No ieee address defined in
                                    // the AddressSpecification
                                    // object. We do nothing since we
                                    // can't compare the values.
                                }
                            }

                            // If reached this point, then a matching
                            // Source Address is found for the current
                            // AddressSpecification. So we can proceed
                            // to check the Destination End Point.

                            // Destination End Point (Address
                            // Specification)
                            if (as.getAPSDestinationEndpoint() == null) {
                                addressingSpecificationFound = true;
                                break;
                            } else {
                                short asdep = as.getAPSDestinationEndpoint();
                                // Pass if the callback has a broadcast
                                // Destination End Point
                                if (asdep != 0xFF) {
                                    long dam = message.getDestinationAddressMode();
                                    // 0x00 and 0x01 Destination End
                                    // Point
                                    // not present
                                    if (dam > 0x01) {
                                        short mdep = message.getDestinationEndpoint();
                                        // Pass if the message has a
                                        // broadcast Destination End
                                        // Point
                                        if (mdep != 0xFF) {
                                            // Don't pass if they
                                            // differs,
                                            // so we go ahead on the
                                            // next
                                            // iteration in the for
                                            // cycle
                                            if ((asdep != mdep) && (mdep != ((byte) 0xFF))) {

                                                continue;
                                            }
                                        }
                                    }
                                }
                            }
                            // If reached this point, then a matching
                            // Destination End Point is also found for
                            // the current AddressSpecification. This
                            // means that a matching Addressing
                            // Specification is found. We can stop here
                            // the loop since one match it's enough.
                            addressingSpecificationFound = true;
                            break;
                        }

                        if (!addressingSpecificationFound) {
                            // If no Addressing Specification was found,
                            // then this callback doesn't match and we
                            // can jump to check the next one.
                            continue;
                        }
                    }

                    // If this point is reached, then a matching
                    // callback is found. Notify the message to its
                    // destination.

                    MessageListener napml = ce.getGenericDestination();
                    if (napml != null) {
                        APSMessageEvent cmessage = null;
                        synchronized (message) {
                            cmessage = SerializationUtils.clone(message);
                        }
                        LOG.debug("READY to CallBack NotifyApsMessage: {}",
                                ((cmessage.getDestinationAddress().getNetworkAddress() != null) ? String.format(
                                        "%04X", cmessage.getDestinationAddress().getNetworkAddress()) : ""));

                        napml.notifyAPSMessage(cmessage);
                    }
                    // Add it to the list of already notified
                    // destinations.

                }
            }

        }
    });
}

From source file:org.energy_home.jemma.javagal.layers.business.implementations.MessageManager.java

/**
 * Processes the InterPAN indication message trying to dispatch it to the
 * right destination. The {@link GalController} maintains a collection of
 * registered callbacks' listeners. This method verifies if a match exists
 * on that collection for the callback's filter, i.e. looks if one or more
 * destination(s) for that APS message is present. If it exists, sends the
 * APS message to all found destinations.
 * //  ww  w .j  ava  2s .  c  om
 * @param message
 *            the indication APSMessageEvent to process.
 */
public void InterPANMessageIndication(final InterPANMessageEvent message) {
    executor.execute(new Runnable() {
        public void run() {

            LOG.debug("Aps Message Indication in process...");

            for (CallbackEntry ce : getGal().getCallbacks()) {

                Callback callback = ce.getCallback();
                Filter filter = callback.getFilter();
                if (filter.getLevelSpecification().getLevel().get(0).equals(Level.INTRP_LEVEL)) {
                    if (filter.getMessageSpecification().size() > 0) {
                        boolean messageSpecificationFound = false;
                        for (MessageSpecification ms : filter.getMessageSpecification()) {

                            if (ms.getAPSClusterIdentifier() == null) {
                                messageSpecificationFound = true;
                                // If match we can stop the search loop.
                                break;

                            } else if (ms.getAPSClusterIdentifier() == message.getClusterID()) {
                                messageSpecificationFound = true;
                                // If match we can stop the search loop.
                                break;
                            }
                        }
                        if (!messageSpecificationFound) {
                            // If no Messaging Specification was found,
                            // then this callback doesn't match and we
                            // can jump to check the next one.
                            continue;
                        }
                    }

                    // Address Specification check. If there are at
                    // least one address specification in the filter,
                    // then we proceed to find a match, else if no
                    // address specification is present we assume that
                    // the check pass.
                    if (filter.getAddressSpecification().size() > 0) {
                        boolean addressingSpecificationFound = false;
                        for (AddressSpecification as : filter.getAddressSpecification()) {
                            // Source Address (Address Specification)
                            Address assa = as.getNWKSourceAddress();
                            int asnsa = 0xFFFF;
                            // If null, then we assume that all address
                            // match for this filter, and so we leave
                            // the initial value of 0xFFFF.
                            if (assa != null) {
                                asnsa = assa.getNetworkAddress();
                            }
                            short assep = -1;

                            if (as.getAPSSourceEndpoint() != null)
                                assep = as.getAPSSourceEndpoint();
                            // Pass if the callback has a broadcast
                            // Source Address
                            if (asnsa != 0xFFFF) {
                                // Source Address
                                long msam = message.getSrcAddressMode();
                                Address msa = message.getSrcAddress();
                                if (msam == 0x01) {
                                    // Network address, NO source end
                                    // point
                                    int msna0x01 = msa.getNetworkAddress();
                                    // Pass if the message has a
                                    // broadcast Source Address
                                    if (msna0x01 != 0xFFFF) {
                                        // Don't pass if they differs,
                                        // so we go ahead on the next
                                        // iteration in the for cycle
                                        if (asnsa != msna0x01) {
                                            continue;
                                        }
                                    }
                                } else if (msam == 0x02) {
                                    // Network address, AND source end
                                    // point present.
                                    int msna0x02 = msa.getNetworkAddress();
                                    // Pass if the message has a
                                    // broadcast Source Address.
                                    if (msna0x02 != 0xFFFF) {
                                        // Don't pass if they differs,
                                        // so we go ahead on the
                                        // next iteration in for cycle.
                                        if (asnsa != msna0x02) {
                                            // Don't pass if they
                                            // differs, so we go ahead
                                            // on the next iteration in
                                            // the for cycle.
                                            continue;
                                        }
                                    }
                                }
                            }
                        }

                        // If reached this point, then a matching
                        // Source Address is found for the current
                        // AddressSpecification. So we can proceed
                        // to check the Destination End Point.

                        // If reached this point, then a matching
                        // Destination End Point is also found for
                        // the current AddressSpecification. This
                        // means that a matching Addressing
                        // Specification is found. We can stop here
                        // the loop since one match it's enough.
                        addressingSpecificationFound = true;
                        break;
                    }

                }

                // If this point is reached, then a matching
                // callback is found. Notify the message to its
                // destination.

                MessageListener napml = ce.getGenericDestination();
                if (napml != null) {
                    InterPANMessageEvent cmessage = null;
                    synchronized (message) {
                        cmessage = SerializationUtils.clone(message);
                    }
                    napml.notifyInterPANMessage(cmessage);
                }
                // Add it to the list of already notified
                // destinations.

            }
        }

    });
}

From source file:org.faster.orm.service.hibernate.HibernateCountService.java

@SuppressWarnings("rawtypes")
private int doCount(DetachedCriteria criteria) {
    // ???/*  ww w. j a va2 s . c o m*/
    DetachedCriteria clone = SerializationUtils.clone(criteria);
    clone.setProjection(Projections.rowCount());
    Object value = null;
    try {
        value = fetchSingle(clone);
    } catch (Exception e) { // order????
        Field criteriaImplFiled; // ?order
        try {
            criteriaImplFiled = DetachedCriteria.class.getDeclaredField("impl");
            criteriaImplFiled.setAccessible(true);
            CriteriaImpl criteriaImpl = (CriteriaImpl) criteriaImplFiled.get(clone);

            Field orderField = CriteriaImpl.class.getDeclaredField("orderEntries");
            orderField.setAccessible(true);
            List<?> orderEntries = (List<?>) orderField.get(criteriaImpl); // ?order?

            orderField.set(criteriaImpl, new ArrayList(0)); // order?
            try {
                value = fetchSingle(clone);
            } finally {
                orderField.set(criteriaImpl, orderEntries); // ??order?
            }
        } catch (Exception ee) {
            throw new RuntimeException("Can't count " + persistClassName + "![" + criteria + "]", ee);
        }
    }

    return value == null ? 0 : getIntValue(value);
}

From source file:org.grouplens.grapht.reflect.internal.FieldInjectionPointTest.java

@Test
public void testSerialize() throws NoSuchFieldException, IOException, ClassNotFoundException {
    FieldInjectionPoint fip = new FieldInjectionPoint(getClass().getDeclaredField("foo"));
    FieldInjectionPoint fip2 = SerializationUtils.clone(fip);
    assertThat(fip2, equalTo(fip));//from  ww  w  .  java2  s .c om
    assertThat(fip2, not(sameInstance(fip)));
}

From source file:org.grouplens.grapht.reflect.QualifiersTest.java

@Test
public void testMatchAny() throws Exception {
    assertThat(Qualifiers.matchAny().matches(null), equalTo(true));
    assertThat(Qualifiers.matchAny().matches(makeQual()), equalTo(true));
    assertThat(Qualifiers.matchAny().matches(makeVQual("foo")), equalTo(true));
    assertThat(Qualifiers.matchAny().matches(makeDftQual()), equalTo(true));
    assertThat(Qualifiers.matchAny(), equalTo(Qualifiers.matchAny()));
    assertThat(SerializationUtils.clone(Qualifiers.matchAny()), equalTo(Qualifiers.matchAny()));
}

From source file:org.grouplens.grapht.reflect.QualifiersTest.java

@Test
public void testMatchNone() throws Exception {
    assertThat(Qualifiers.matchNone().matches(null), equalTo(true));
    assertThat(Qualifiers.matchNone().matches(makeQual()), equalTo(false));
    assertThat(Qualifiers.matchNone().matches(makeVQual("foo")), equalTo(false));
    assertThat(Qualifiers.matchNone().matches(makeDftQual()), equalTo(false));
    assertThat(Qualifiers.matchNone(), equalTo(Qualifiers.matchNone()));
    assertThat(Qualifiers.matchNone(), not(equalTo(Qualifiers.matchAny())));
    assertThat(SerializationUtils.clone(Qualifiers.matchNone()), equalTo(Qualifiers.matchNone()));
    assertThat(Qualifiers.matchNone().toString(), equalTo("-"));
}

From source file:org.grouplens.grapht.reflect.QualifiersTest.java

@Test
public void testMatchDefault() throws Exception {
    assertThat(Qualifiers.matchDefault().matches(null), equalTo(true));
    assertThat(Qualifiers.matchDefault().matches(makeQual()), equalTo(false));
    assertThat(Qualifiers.matchDefault().matches(makeVQual("foo")), equalTo(false));
    assertThat(Qualifiers.matchDefault().matches(makeDftQual()), equalTo(true));
    assertThat(Qualifiers.matchDefault(), equalTo(Qualifiers.matchDefault()));
    assertThat(Qualifiers.matchDefault(), not(equalTo(Qualifiers.matchAny())));
    assertThat(SerializationUtils.clone(Qualifiers.matchDefault()), equalTo(Qualifiers.matchDefault()));
}

From source file:org.grouplens.grapht.reflect.QualifiersTest.java

@Test
public void testMatchClass() throws Exception {
    assertThat(Qualifiers.match(Qual.class).matches(null), equalTo(false));
    assertThat(Qualifiers.match(Qual.class).matches(makeQual()), equalTo(true));
    assertThat(Qualifiers.match(Qual.class).matches(makeVQual("foo")), equalTo(false));
    assertThat(Qualifiers.match(VQual.class).matches(makeVQual("foo")), equalTo(true));
    assertThat(Qualifiers.match(Qual.class), equalTo(Qualifiers.match(Qual.class)));
    assertThat(Qualifiers.match(Qual.class), not(equalTo(Qualifiers.match(VQual.class))));
    assertThat(Qualifiers.match(Qual.class), not(equalTo(Qualifiers.matchAny())));
    assertThat(SerializationUtils.clone(Qualifiers.match(Qual.class)), equalTo(Qualifiers.match(Qual.class)));
    assertThat(SerializationUtils.clone(Qualifiers.match(VQual.class)), equalTo(Qualifiers.match(VQual.class)));
}