use of com.zsmartsystems.zigbee.dao.ZigBeeNodeDao in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkStateSerializerImpl method deserialize.
/**
* Deserializes the network state.
*
* @param networkState the network state
*/
@Override
public void deserialize(final ZigBeeNetworkManager networkState) {
final File file = new File(networkId);
boolean networkStateExists = file.exists();
if (networkStateExists == false) {
return;
}
logger.info("Loading network state...");
try {
XStream stream = openStream();
BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
final List<Object> objects = (List<Object>) stream.fromXML(reader);
for (final Object object : objects) {
if (object instanceof ZigBeeNodeDao) {
ZigBeeNodeDao nodeDao = (ZigBeeNodeDao) object;
ZigBeeNode node = new ZigBeeNode(networkState, new IeeeAddress(nodeDao.getIeeeAddress()));
node.setDao(nodeDao);
networkState.addNode(node);
}
}
} catch (Exception e) {
e.printStackTrace();
}
logger.info("Loading network state complete.");
}
use of com.zsmartsystems.zigbee.dao.ZigBeeNodeDao in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNode method getDao.
/**
* Gets a {@link ZigBeeNodeDao} representing the node
*
* @return the {@link ZigBeeNodeDao}
*/
public ZigBeeNodeDao getDao() {
ZigBeeNodeDao dao = new ZigBeeNodeDao();
dao.setIeeeAddress(ieeeAddress.toString());
dao.setNetworkAddress(networkAddress);
dao.setNodeDescriptor(nodeDescriptor);
dao.setPowerDescriptor(powerDescriptor);
dao.setBindingTable(bindingTable);
List<ZigBeeEndpointDao> endpointDaoList = new ArrayList<ZigBeeEndpointDao>();
for (ZigBeeEndpoint endpoint : endpoints.values()) {
endpointDaoList.add(endpoint.getDao());
}
dao.setEndpoints(endpointDaoList);
return dao;
}
use of com.zsmartsystems.zigbee.dao.ZigBeeNodeDao in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkStateSerializerImpl method serialize.
/**
* Serializes the network state.
*
* @param networkState the network state
*/
@Override
public void serialize(final ZigBeeNetworkManager networkState) {
XStream stream = openStream();
final List<ZigBeeNodeDao> destinations = new ArrayList<ZigBeeNodeDao>();
for (ZigBeeNode node : networkState.getNodes()) {
ZigBeeNodeDao nodeDao = node.getDao();
destinations.add(nodeDao);
}
final File file = new File(networkId);
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
stream.marshal(destinations, new PrettyPrintWriter(writer));
writer.flush();
writer.close();
} catch (IOException e) {
logger.error("Error writing network state", e);
}
logger.info("ZigBee saving network state complete.");
}
Aggregations