123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package de.tudarmstadt.informatik.hostage.logging.formatter.protocol;
- /**
- * Protocol formatter. This class provides functionality to format the packet as
- * a human-readable string of a specific protocol. Custom formatters should
- * inherit from this class.
- *
- * @author Wulf Pfeiffer
- * @author Mihai Plasoianu
- */
- public class ProtocolFormatter {
- /**
- * Formats the content of packet. The packet content is represented as
- * string or hex, depending on the protocol.
- *
- * @param packet
- * Packet to format.
- * @return Formatted string.
- */
- public String format(String packet) {
- return packet;
- }
- /**
- * Loads a protocol formatter for a protocol. Load a class matching
- * {protocol} located in logging.formatter.protocol, default formatter
- * otherwise.
- *
- * @param protocolName
- * String representation of a protocol.
- * @return The protocol formatter.
- */
- public static ProtocolFormatter getFormatter(String protocolName) {
- String packageName = ProtocolFormatter.class.getPackage().getName();
- String className = String.format("%s.%s", packageName, protocolName);
- // TODO Auf Singletons umstellen und newInstance() sparen.
- try {
- return (ProtocolFormatter) Class.forName(className).newInstance();
- } catch (ReflectiveOperationException e) {
- return new ProtocolFormatter();
- }
- }
- }
|