List of usage examples for org.apache.commons.lang3 SerializationUtils clone
public static <T extends Serializable> T clone(final T object)
Deep clone an Object using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:org.dozer.functional_tests.MapperTest.java
@Test public void testDeepProperties() throws Exception { House src = testDataFactory.getHouse(); HomeDescription dest = mapper.map(src, HomeDescription.class); House src2 = mapper.map(dest, House.class); HomeDescription dest2 = mapper.map(src2, HomeDescription.class); long[] prim = { 1, 2, 3, 1, 2, 3 }; // cumulative relationship dest.setPrim(prim);/*from www .ja v a 2 s .co m*/ assertEquals(dest, dest2); // By reference src = testDataFactory.getHouse(); House houseClone = SerializationUtils.clone(src); dest = mapper.map(src, HomeDescription.class); mapper.map(dest, src); // cumulative relationship int[] prims = { 1, 2, 3, 1, 2, 3 }; houseClone.getOwner().setPrim(prims); // add two more rooms Room room1 = new Room(); room1.setName("Living"); Room room2 = new Room(); room2.setName("kitchen"); Van van = new Van(); van.setName("van2"); houseClone.getRooms().add(room1); houseClone.getRooms().add(room2); houseClone.getCustomSetGetMethod().add(van); assertEquals(houseClone, src); }
From source file:org.dozer.functional_tests.MapperTest.java
@Ignore("Failing after 4.3 release") @Test//from ww w. j a v a2 s .co m public void testMapByReference() throws Exception { // Map TestReferenceObject tro = newInstance(TestReferenceObject.class); TestReferenceFoo foo1 = newInstance(TestReferenceFoo.class); foo1.setA("a"); TestReferenceFoo foo = newInstance(TestReferenceFoo.class); foo.setA("a"); foo.setB(null); foo.setC("c"); List<TestReferenceFoo> list2 = newInstance(ArrayList.class); list2.add(foo); tro.setListA(list2); tro.setArrayToArrayCumulative(new Object[] { foo1 }); TestReferenceFoo foo2 = newInstance(TestReferenceFoo.class); foo2.setA("a"); foo2.setB(null); foo2.setC("c"); TestReferenceFoo foo3 = newInstance(TestReferenceFoo.class); foo3.setA("a"); foo3.setB(null); foo3.setC("c"); tro.setArrayToArrayNoncumulative(new Object[] { foo2 }); List<String> list3 = newInstance(ArrayList.class); list3.add("string1"); list3.add("string2"); tro.setListToArray(list3); int[] pa = { 1, 2, 3 }; tro.setPrimitiveArray(pa); Integer[] integerArray = { new Integer(1), new Integer(2) }; tro.setPrimitiveArrayWrapper(integerArray); Set<TestReferenceFoo> set = newInstance(HashSet.class); TestReferenceFoo foo4 = newInstance(TestReferenceFoo.class); foo4.setA("a"); set.add(foo4); tro.setSetToSet(set); Car car = new Car(); car.setName("myName"); tro.setCars(new Car[] { car }); Car car2 = new Car(); car2.setName("myName"); List<Car> vehicles = newInstance(ArrayList.class); vehicles.add(car2); tro.setVehicles(vehicles); TestReferenceObject toClone = SerializationUtils.clone(tro); TestReferencePrimeObject trop = mapper.map(tro, TestReferencePrimeObject.class); assertEquals("myName", (trop.getVans()[0]).getName()); assertEquals("myName", (trop.getMoreVans()[0]).getName()); TestReferenceFooPrime fooPrime = (TestReferenceFooPrime) trop.getListAPrime().get(0); fooPrime.setB("b"); TestReferenceFooPrime fooPrime2 = (TestReferenceFooPrime) trop.getArrayToArrayNoncumulative()[0]; fooPrime2.setB("b"); mapper.map(trop, tro); // make sure we update the array list and didnt lose the value 'c' - non-cumulative assertEquals("c", ((TestReferenceFoo) tro.getListA().get(0)).getC()); assertEquals("c", ((TestReferenceFoo) tro.getArrayToArrayNoncumulative()[0]).getC()); // cumulative toClone.setArrayToArrayCumulative(new Object[] { foo1, foo1 }); toClone.setCars(new Car[] { car, car }); Van van = new Van(); van.setName("myName"); toClone.getVehicles().add(van); // cumulative toClone.getListToArray().add("string1"); toClone.getListToArray().add("string2"); int[] paClone = { 1, 2, 3, 1, 2, 3 }; toClone.setPrimitiveArray(paClone); Integer[] integerArrayClone = { new Integer(1), new Integer(2), new Integer(1), new Integer(2) }; toClone.setPrimitiveArrayWrapper(integerArrayClone); assertEquals(toClone, tro); }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Allows the creation of an endpoint to which is associated a * {@code SimpleDescriptor}. The operation is synchronous and lasts for a * maximum timeout time./*from ww w.j a v a2 s . c om*/ * * @param timeout * the desired timeout. * @param desc * the {@code SimpleDescriptor}. * @return a short representing the endpoint. * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public short configureEndpoint(long timeout, SimpleDescriptor desc) throws IOException, Exception, GatewayException { if ((desc.getApplicationInputCluster().size() + desc.getApplicationOutputCluster().size()) > 30/* * 60 * Bytes */) { throw new Exception("Simple Descriptor Out Of Memory"); } else { short result = DataLayer.configureEndPointSync(timeout, desc); lastEndPoint = desc; return SerializationUtils.clone(result); } }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Retrieves the local services (the endpoints) on which the GAL is running * and listening//w ww . j a va 2s .c om * * @return the local services. * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public NodeServices getLocalServices() throws IOException, Exception, GatewayException { NodeServices result = DataLayer.getLocalServices(getPropertiesManager().getCommandTimeoutMS()); if (GalNode != null && GalNode.get_node().getAddress() != null) { result.setAddress(GalNode.get_node().getAddress()); synchronized (getNetworkcache()) { for (WrapperWSNNode o : getNetworkcache()) { if (o.get_node() != null && o.get_node().getAddress() != null && o.get_node().getAddress().getNetworkAddress() .equals(get_GalNode().get_node().getAddress().getNetworkAddress())) { o.set_nodeServices(result); result = o.get_nodeServices(); break; } } } } return SerializationUtils.clone(result); }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Returns the list of NodeServices of all nodes into the network * //from w w w. jav a 2 s . c o m * @return the list of NodeServices for every node. * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public NodeServicesList readServicesCache() throws IOException, Exception, GatewayException { NodeServicesList list = new NodeServicesList(); synchronized (getNetworkcache()) { for (WrapperWSNNode o : getNetworkcache()) { if (o.get_nodeServices() != null) list.getNodeServices().add(o.get_nodeServices()); } } return SerializationUtils.clone(list); }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Returns the list of active nodes and connected to the ZigBee network from * the cache of the GAL// w w w . ja v a2 s . c o m * * @return the list of active nodes connected. */ public WSNNodeList readNodeCache() { WSNNodeList _list = new WSNNodeList(); synchronized (getNetworkcache()) { for (WrapperWSNNode x : getNetworkcache()) { if (x.is_discoveryCompleted()) _list.getWSNNode().add(x.get_node()); } return SerializationUtils.clone(_list); } }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Returns the list of associated nodes in the network, and for each node * gives the short and the IEEE Address/* ww w . jav a2s.c om*/ * * @return the list of associated nodes in the network. */ public Aliases listAddress() { Aliases _list = new Aliases(); long counter = 0; synchronized (getNetworkcache()) { for (WrapperWSNNode x : getNetworkcache()) { if (x.is_discoveryCompleted()) { _list.getAlias().add(x.get_node().getAddress()); counter++; } } } _list.setNumberOfAlias(counter); return SerializationUtils.clone(_list); }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Returns the list of neighbor of the selected nodes of the network by the * address// w ww.ja v a 2 s . co m * * @param aoi * the address of interest * @return the list of neighbor of the nodes * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public LQIInformation getLQIInformation(Address aoi) throws IOException, Exception, GatewayException { LQIInformation _lqi = new LQIInformation(); WrapperWSNNode x = new WrapperWSNNode(this, String.format("%04X", aoi.getNetworkAddress())); WSNNode node = new WSNNode(); node.setAddress(aoi); x.set_node(node); x = getFromNetworkCache(x); if (x != null) { if (x.is_discoveryCompleted()) { LQINode _lqinode = new LQINode(); Mgmt_LQI_rsp _rsp = x.get_Mgmt_LQI_rsp(); _lqinode.setNodeAddress(x.get_node().getAddress().getIeeeAddress()); if (_rsp != null && _rsp.NeighborTableList != null) { for (NeighborTableLis_Record _n1 : _rsp.NeighborTableList) { Neighbor e = new Neighbor(); try { Integer _shortAddress = getShortAddress_FromIeeeAddress( BigInteger.valueOf(_n1._Extended_Address)); e.setShortAddress(_shortAddress); e.setDepth((short) _n1._Depth); e.setDeviceTypeRxOnWhenIdleRelationship(_n1._RxOnWhenIdle); e.setIeeeAddress(BigInteger.valueOf(_n1._Extended_Address)); e.setLQI((short) _n1._LQI); e.setExtendedPANId(BigInteger.valueOf(_n1._Extended_PAN_Id)); e.setPermitJoining((short) _n1._Permitting_Joining); _lqinode.getNeighborList().getNeighbor().add(e); } catch (Exception ex) { LOG.error(ex.getMessage()); } } } _lqi.getLQINode().add(_lqinode); } return SerializationUtils.clone(_lqi); } else throw new Exception("Address not found!"); }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Returns the list of neighbor of all nodes of the network * //from w w w . j a va 2 s . c om * @return the list of neighbor of all nodes * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public LQIInformation getAllLQIInformations() throws IOException, Exception, GatewayException { LQIInformation _lqi = new LQIInformation(); synchronized (getNetworkcache()) { for (WrapperWSNNode x : getNetworkcache()) { LOG.debug("Node: {} - DiscoveryCompleted: {}", x.get_node().getAddress().getNetworkAddress(), x.is_discoveryCompleted()); if (x.is_discoveryCompleted()) { LQINode _lqinode = new LQINode(); Mgmt_LQI_rsp _rsp = x.get_Mgmt_LQI_rsp(); if (x.get_node().getAddress().getIeeeAddress() != null) { _lqinode.setNodeAddress(x.get_node().getAddress().getIeeeAddress()); if (_rsp != null && _rsp.NeighborTableList != null) { NeighborList _list0 = new NeighborList(); for (NeighborTableLis_Record _n1 : _rsp.NeighborTableList) { try { Neighbor e = new Neighbor(); Integer _shortAddress = getShortAddress_FromIeeeAddress( BigInteger.valueOf(_n1._Extended_Address)); e.setShortAddress(_shortAddress); e.setDepth((short) _n1._Depth); e.setDeviceTypeRxOnWhenIdleRelationship( _n1._Device_Type_RxOnWhenIdle_Relationship); e.setIeeeAddress(BigInteger.valueOf(_n1._Extended_Address)); e.setExtendedPANId(BigInteger.valueOf(_n1._Extended_PAN_Id)); e.setPermitJoining((short) _n1._Permitting_Joining); e.setLQI((short) _n1._LQI); _list0.getNeighbor().add(e); } catch (Exception ex) { LOG.error(ex.getMessage()); } } _lqinode.setNeighborList(_list0); } _lqi.getLQINode().add(_lqinode); } } } } return SerializationUtils.clone(_lqi); }
From source file:org.energy_home.jemma.javagal.layers.business.GalController.java
/** * Retrieves the informations about the NodeDescriptor of a ZigBee node * /*w w w .ja va2 s.c o m*/ * @param timeout * the timeout * @param _requestIdentifier * the request identifier. * @param addrOfInterest * the address of interest. * @param Async * whether the operation will be synchronously or not. * @return the resulting {@code NodeDescriptor} * @throws IOException * if an Input Output error occurs. * @throws Exception * if a general error occurs. * @throws GatewayException * if a ZGD error occurs. */ public NodeDescriptor getNodeDescriptor(final long timeout, final int _requestIdentifier, final Address addrOfInterest, final boolean Async) throws IOException, Exception, GatewayException { if (addrOfInterest.getNetworkAddress() == null && addrOfInterest.getIeeeAddress() != null) addrOfInterest.setNetworkAddress(getShortAddress_FromIeeeAddress(addrOfInterest.getIeeeAddress())); if (addrOfInterest.getIeeeAddress() == null && addrOfInterest.getNetworkAddress() != null) addrOfInterest.setIeeeAddress(getIeeeAddress_FromShortAddress(addrOfInterest.getNetworkAddress())); if (Async) { executor.execute(new MyRunnable(this) { public void run() { NodeDescriptor nodeDescriptor = new NodeDescriptor(); if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { try { nodeDescriptor = DataLayer.getNodeDescriptorSync(timeout, addrOfInterest); WrapperWSNNode x = new WrapperWSNNode((GalController) this.getParameter(), String.format("%04X", addrOfInterest.getNetworkAddress())); WSNNode node = new WSNNode(); node.setAddress(addrOfInterest); x.set_node(node); x = getFromNetworkCache(x); if (x != null) x.setNodeDescriptor(nodeDescriptor); Status _s = new Status(); _s.setCode((short) GatewayConstants.SUCCESS); get_gatewayEventManager().notifyNodeDescriptor(_requestIdentifier, _s, nodeDescriptor); get_gatewayEventManager().notifyNodeDescriptorExtended(_requestIdentifier, _s, nodeDescriptor, addrOfInterest); } catch (IOException e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifyNodeDescriptor(_requestIdentifier, _s, nodeDescriptor); get_gatewayEventManager().notifyNodeDescriptorExtended(_requestIdentifier, _s, nodeDescriptor, addrOfInterest); } catch (GatewayException e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifyNodeDescriptor(_requestIdentifier, _s, nodeDescriptor); get_gatewayEventManager().notifyNodeDescriptorExtended(_requestIdentifier, _s, nodeDescriptor, addrOfInterest); } catch (Exception e) { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage(e.getMessage()); get_gatewayEventManager().notifyNodeDescriptor(_requestIdentifier, _s, nodeDescriptor); get_gatewayEventManager().notifyNodeDescriptorExtended(_requestIdentifier, _s, nodeDescriptor, addrOfInterest); } } else { Status _s = new Status(); _s.setCode((short) GatewayConstants.GENERAL_ERROR); _s.setMessage("Gal is not in running state!"); get_gatewayEventManager().notifyNodeDescriptor(_requestIdentifier, _s, nodeDescriptor); get_gatewayEventManager().notifyNodeDescriptorExtended(_requestIdentifier, _s, nodeDescriptor, addrOfInterest); } } }); return null; } else { if (getGatewayStatus() == GatewayStatus.GW_RUNNING) { NodeDescriptor nodeDescriptor = DataLayer.getNodeDescriptorSync(timeout, addrOfInterest); WrapperWSNNode x = new WrapperWSNNode(this, String.format("%04X", addrOfInterest.getNetworkAddress())); WSNNode node = new WSNNode(); node.setAddress(addrOfInterest); x.set_node(node); x = getFromNetworkCache(x); if (x != null) x.setNodeDescriptor(nodeDescriptor); return SerializationUtils.clone(nodeDescriptor); } else throw new GatewayException("Gal is not in running state!"); } }