@Override public void processAnnotationRemoved( ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState removed) { ElementHandle.Package pkg = metaModel.getHandle(); if (key.getElement().getPackage().equals(pkg.getPackage())) { servlets.remove(pkg); } }
@Override public void postProcessAnnotations(ApplicationMetaModel metaModel) { ElementHandle.Package pkg = metaModel.getHandle(); AnnotationState annotation = servlets.remove(pkg); if (annotation != null) { PackageElement pkgElt = metaModel.processingContext.get(pkg); String urlPattern = (String) annotation.get("value"); String simpleName = (String) annotation.get("name"); if (simpleName == null) { simpleName = metaModel.getBaseName() + "Servlet"; } Name clazz = pkg.getPackage().append(simpleName); Writer writer = null; try { JavaFileObject file = metaModel.processingContext.createSourceFile(clazz, pkgElt); writer = file.openWriter(); writer.append("package ").append(pkg.getPackage()).append(";\n"); writer.append("import javax.servlet.annotation.WebServlet;\n"); writer.append("import javax.servlet.annotation.WebInitParam;\n"); writer .append("@WebServlet(name=\"") .append(simpleName) .append("\",urlPatterns=\"") .append(urlPattern) .append("\")\n"); writer .append("public class ") .append(simpleName) .append(" extends juzu.bridge.servlet.JuzuServlet {\n"); writer.append("@Override\n"); writer.append( "protected String getApplicationName(javax.servlet.ServletConfig config) {\n"); writer.append("return \"").append(pkg.getPackage()).append("\";\n"); writer.append("}\n"); writer.append("}\n"); } catch (IOException e) { throw CANNOT_WRITE_SERVLET_CLASS.failure(e, pkgElt, pkg.getPackage()); } finally { Tools.safeClose(writer); } } }