All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.bristleback.server.bristle.messages.PacketProcessingUtil Maven / Gradle / Ivy

// Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
// ---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
// This library is distributed in the hope that it will be useful,
// but without any warranty; without even the implied warranty of merchantability
// or fitness for a particular purpose.
// You should have received a copy of the GNU Lesser General Public License along
// with this program; if not, see .
// ---------------------------------------------------------------------------
package pl.bristleback.server.bristle.messages;

import org.apache.log4j.Logger;
import org.jwebsocket.api.WebSocketPacket;
import org.jwebsocket.config.JWebSocketCommonConstants;
import org.jwebsocket.config.JWebSocketConfig;
import org.jwebsocket.packetProcessors.CSVProcessor;
import org.jwebsocket.packetProcessors.JSONProcessor;
import org.jwebsocket.packetProcessors.XMLProcessor;
import org.jwebsocket.token.Token;

/**
 * Util for packet and token processing taken from original jwebsocket framework grouped in one class.
 * 

* Created on: 2010-09-24 22:40:39
* * @author Wojciech Niemiec */ public final class PacketProcessingUtil { private static Logger log = Logger.getLogger(PacketProcessingUtil.class.getName()); private PacketProcessingUtil() { throw new UnsupportedOperationException(); } public static Token processPacketToToken(WebSocketPacket packet, String protocol) { Token lToken = null; if (protocol.equals(JWebSocketCommonConstants.SUB_PROT_JSON)) { lToken = JSONProcessor.packetToToken(packet); } else if (protocol.equals(JWebSocketCommonConstants.SUB_PROT_CSV)) { lToken = CSVProcessor.packetToToken(packet); } else if (protocol.equals(JWebSocketCommonConstants.SUB_PROT_XML)) { lToken = XMLProcessor.packetToToken(packet); } return lToken; } public static WebSocketPacket processTokenToPacket(Token token, String protocol) { WebSocketPacket packet = null; if (protocol.equals(JWebSocketCommonConstants.SUB_PROT_JSON)) { packet = JSONProcessor.tokenToPacket(token); } else if (protocol.equals(JWebSocketCommonConstants.SUB_PROT_CSV)) { packet = CSVProcessor.tokenToPacket(token); } else if (protocol.equals(JWebSocketCommonConstants.SUB_PROT_XML)) { packet = XMLProcessor.tokenToPacket(token); } return packet; } /** * Process token to packet using protocol defined in jwebsocket configuration file. * * @param token token * @return packet representation of token */ public static WebSocketPacket processTokenToPacket(Token token) { return processTokenToPacket(token, JWebSocketConfig.getConfig().getProtocol()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy