public static SelectorThread create(URI u, Class<? extends Servlet> c,
Map<String, String> initParams) throws IOException {
if (u == null)
throw new IllegalArgumentException("The URI must not be null");
ServletAdapter adapter = new ServletAdapter();
if (initParams == null) {
adapter.addInitParameter(ClasspathResourceConfig.PROPERTY_CLASSPATH,
System.getProperty("java.class.path").replace(File.pathSeparatorChar, ';'));
} else {
for (Map.Entry<String, String> e : initParams.entrySet()) {
adapter.addInitParameter(e.getKey(), e.getValue());
}
}
adapter.setServletInstance(getInstance(c));
String path = u.getPath();
if (path == null)
throw new IllegalArgumentException("The URI path, of the URI " + u +
", must be non-null");
else if (path.length() == 0)
throw new IllegalArgumentException("The URI path, of the URI " + u +
", must be present");
else if (path.charAt(0) != '/')
throw new IllegalArgumentException("The URI path, of the URI " + u +
". must start with a '/'");
if (path.length() > 1) {
if (path.endsWith("/"))
path = path.substring(0, path.length() - 1);
adapter.setContextPath(path);
}
return GrizzlyServerFactory.create(u, adapter);
}