private static Channel unpackChannel(ChannelRecord chanRec){ Channel chan = new Channel(chanRec.getChannelId(), chanRec.getName()); for(MotionPathRecord pathRec : chanRec.getMotionPaths()){ chan.addPath(unpackMotionPath(pathRec)); } if(chanRec.getStartTime() != null){ chan.setStartTime(chanRec.getStartTime()); } if(chanRec.getStopTime() != null){ chan.setStopTime(chanRec.getStopTime()); } return chan; }
private static ChannelRecord packChannel(Channel channel){ ChannelRecord chanRec = new ChannelRecord(); chanRec.setName(channel.getName()); chanRec.setChannelId(channel.getId()); chanRec.setStartTime(channel.getStartTime()); chanRec.setStopTime(channel.getStopTime()); Schema arraySchema = Schema.createArray(MotionPathRecord.SCHEMA$); List<MotionPath> pathList = channel.getMotionPaths(); GenericArray<MotionPathRecord> paths = new Array<MotionPathRecord>(pathList.size(), arraySchema); int i=0; for(MotionPath mp : pathList){ paths.add(packMotionPath(mp, i++)); } chanRec.setMotionPaths(paths); return chanRec; }
public static Channel readChannel(HierarchicalConfiguration config){ Integer id = XMLConfigUtils.getIntegerAttribute(config, CHANNEL_ID, null); if(id == null){ theLogger.log(Level.WARNING, "Unable to find " + CHANNEL_ID + " attribute for Channel, using -1."); id = -1; } String name = XMLConfigUtils.getStringAttribute(config, CHANNEL_NAME, null); Channel channel = new Channel(id, name); HierarchicalConfiguration pathsConfig = config.configurationAt(MOTION_PATHS); if(pathsConfig == null || pathsConfig.isEmpty()){ return channel; } List<MotionPath> paths = readMotionPaths(pathsConfig); channel.addPaths(paths); return channel; }
public static ConfigurationNode writeChannel(Channel channel){ if(channel == null){ return null; } ConfigurationNode node = XMLConfigUtils.node(CHANNEL); node.addAttribute(XMLConfigUtils.node(CHANNEL_ID, channel.getId())); String name = channel.getName(); if(name != null && !name.isEmpty()){ node.addAttribute(XMLConfigUtils.node(MOTION_PATH_NAME, name)); } node.addChild(writeMotionPaths(channel.getMotionPaths())); return node; }
/** * * @param xs * @param channel * @throws IOException */ public static void writeChannel(XmlSerializer xs, Channel channel) throws IOException{ xs.startTag(NAMESPACE, CHANNEL); xs.attribute(NAMESPACE, CHANNEL_ID, channel.getId().toString()); String name = channel.getName(); if(name != null && !name.isEmpty()){ xs.attribute(NAMESPACE, CHANNEL_NAME, name); } xs.startTag(NAMESPACE, MOTION_PATHS); for(MotionPath mp : channel.getMotionPaths()){ writeMotionPath(xs, mp); } xs.endTag(NAMESPACE, MOTION_PATHS); xs.endTag(NAMESPACE, CHANNEL); }