// @Override public IPackageFragmentRoot getPackageFragmentRoot() { IPackageFragmentRoot root = null; if (!projectText.equals("")) { // $NON-NLS-1$ try { IJavaProject project = JavaCore.create(Util.getProject(projectText)); IPath moduleXmlPath = new Path(moduleText); root = project.findPackageFragmentRoot( new Path("/").append(projectText).append(moduleXmlPath.segment(0))); // $NON-NLS-1$ } catch (JavaModelException e) { Activator.logException(e); } } return root; }
public IPackageFragment getBasePackageFragment() { IPackageFragment packageFragment = null; if (!projectText.equals("")) { // $NON-NLS-1$ try { IJavaProject project = JavaCore.create(Util.getProject(projectText)); IPath moduleXmlPath = new Path(moduleText); IPath packageFragmentPath = new Path("/") .append(projectText) .append(moduleXmlPath.removeLastSegments(1)); // $NON-NLS-1$ packageFragment = project.findPackageFragment(packageFragmentPath); } catch (JavaModelException e) { Activator.logException(e); } } return packageFragment; }
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(); } }
private File getModuleFile() throws CoreException { IResource resource = Util.getProject(projectText).findMember(moduleText); return resource.getLocation().toFile(); }