/** * @param monitor * @throws Exception */ private void addServletToGwtXml(IProgressMonitor monitor) throws Exception { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); File moduleFile = getModuleFile(); Document document = builder.parse(moduleFile); Node module = document.getDocumentElement(); Element newServlet = document.createElement("servlet"); newServlet.setAttribute("path", "/" + serviceUri); // $NON-NLS-2$ newServlet.setAttribute( "class", getPackageFragment().getElementName() + '.' + getTypeName() + "Impl"); // $NON-NLS-2$ module.appendChild(newServlet); Transformer writer = TransformerFactory.newInstance().newTransformer(); writer.transform(new DOMSource(document), new StreamResult(moduleFile)); } finally { monitor.done(); } }
// @Override public void createType(IProgressMonitor monitor) throws CoreException, InterruptedException { monitor = Util.getNonNullMonitor(monitor); isImplCreation = false; super.createType(monitor); isImplCreation = true; try { addServletToWebXml(new SubProgressMonitor(monitor, 1)); createRemoteServiceImpl(new SubProgressMonitor(monitor, 2)); addServletToGwtXml(new SubProgressMonitor(monitor, 3)); } catch (Exception e) { throw new CoreException(Util.errorStatus); } }
private void createRemoteServiceImpl(IProgressMonitor monitor) throws IOException, CoreException { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); IFile remoteServiceImpl = Util.getProject(projectText) .getFile( getPackageFragment() .getResource() .getProjectRelativePath() .append(getTypeName() + "Impl.java")); // modifiedResource = remoteServiceImpl; initTemplateVars(getTypeName(), "", getBasePackageFragment().getElementName()); Util.writeFile("/RemoteService.ServiceImpl.template", remoteServiceImpl, templateVars); } finally { monitor.done(); } }
// @SuppressWarnings("unchecked") private void addServletToWebXml(IProgressMonitor monitor) { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); WebapplicationFactory factory = WebapplicationFactory.eINSTANCE; Servlet servlet = factory.createServlet(); servlet.setServletName(getTypeName()); ServletType servletType = factory.createServletType(); servletType.setClassName( getPackageFragment().getElementName() + '.' + getTypeName() + "Impl"); servlet.setWebType(servletType); IVirtualComponent component = ComponentCore.createComponent(Util.getProject(projectText)); WebArtifactEdit artifactEdit = WebArtifactEdit.getWebArtifactEditForWrite(component); WebApp webApp = (WebApp) artifactEdit.getContentModelRoot(); webApp.getServlets().add(servlet); ServletMapping mapping = WebapplicationFactory.eINSTANCE.createServletMapping(); mapping.setServlet(servlet); mapping.setName(servlet.getServletName()); mapping.setUrlPattern("/" + serviceUri); webApp.getServletMappings().add(mapping); artifactEdit.saveIfNecessary(monitor); artifactEdit.dispose(); } finally { monitor.done(); } }