public static ServerProtocol createServerProtocol(final String protocolName) { final Set<Class<? extends ServerProtocol>> classSet = getServerProtocolClasses(protocolName); if (classSet.isEmpty()) { throw new IllegalArgumentException("Unknkown Server Protocol: " + protocolName); } Class<? extends ServerProtocol> desiredClass = desiredServerProtocolClassMap.get(protocolName); if (desiredClass == null && classSet.size() > 1) { throw new IllegalStateException("Multiple implementations of Server Protocol " + protocolName + " were found and no preferred implementation has been specified"); } if (desiredClass != null && !classSet.contains(desiredClass)) { throw new IllegalStateException("Desired implementation of Server Protocol " + protocolName + " is set to " + desiredClass + ", but that Protocol is not registered as a Server Protocol"); } if (desiredClass == null) { desiredClass = classSet.iterator().next(); } try { return desiredClass.newInstance(); } catch (final Exception e) { throw new RuntimeException("Unable to instantiate class " + desiredClass.getName(), e); } }
public static ServerProtocol createServerProtocol(final String protocolName) { final Set<Class<? extends ServerProtocol>> classSet = getServerProtocolClasses(protocolName); if (classSet.isEmpty()) { throw new IllegalArgumentException("Unknkown Server Protocol: " + protocolName); } Class<? extends ServerProtocol> desiredClass = desiredServerProtocolClassMap.get(protocolName); if (desiredClass == null && classSet.size() > 1) { throw new IllegalStateException("Multiple implementations of Server Protocol " + protocolName + " were found and no preferred implementation has been specified"); } if (desiredClass != null && !classSet.contains(desiredClass)) { throw new IllegalStateException("Desired implementation of Server Protocol " + protocolName + " is set to " + desiredClass + ", but that Protocol is not registered as a Server Protocol"); } if (desiredClass == null) { desiredClass = classSet.iterator().next(); } try { return desiredClass.newInstance(); } catch (final Exception e) { throw new RuntimeException("Unable to instantiate class " + desiredClass.getName(), e); } }