コード例 #1
0
 @Override
 protected void createDeploymentFiles(IProject project, final IProgressMonitor monitor) {
   final IVirtualComponent component = ComponentCore.createComponent(project);
   final IModelProvider provider = ModelProviderManager.getModelProvider(project);
   provider.modify(
       new Runnable() {
         public void run() {
           IVirtualReference[] componentReferences =
               J2EEProjectUtilities.getJ2EEModuleReferences(component);
           if (componentReferences != null && componentReferences.length > 0) {
             final IDataModel dataModel =
                 DataModelFactory.createDataModel(
                     new AddComponentToEnterpriseApplicationDataModelProvider());
             dataModel.setProperty(
                 ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, component);
             Map<IVirtualComponent, String> uriMap = new HashMap<IVirtualComponent, String>();
             for (int i = 0; i < componentReferences.length; i++) {
               IVirtualComponent referencedComponent =
                   componentReferences[i].getReferencedComponent();
               if (componentReferences[i].getRuntimePath().toString().equals("/")) { // $NON-NLS-1$
                 uriMap.put(referencedComponent, componentReferences[i].getArchiveName());
               } else {
                 uriMap.put(
                     referencedComponent,
                     componentReferences[i]
                         .getRuntimePath()
                         .append((new Path(componentReferences[i].getArchiveName())).lastSegment())
                         .toString());
               }
             }
             dataModel.setProperty(
                 ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_TO_URI_MAP,
                 uriMap);
             try {
               dataModel.getDefaultOperation().execute(monitor, null);
             } catch (ExecutionException e) {
               JEEPlugin.logError(e);
             }
           }
         }
       },
       IModelProvider.FORCESAVE);
 }
 /**
  * Creates the JAX-RS Application as a servlet-mapping in the web.xml (which could be created if
  * necessary)
  *
  * @param monitor the progress monitor
  */
 private void createWebXmlApplication(final IProgressMonitor monitor) {
   if (getJavaProject() != null) {
     final IProject project = getJavaProject().getProject();
     final IModelProvider provider = ModelProviderManager.getModelProvider(project);
     provider.modify(
         new Runnable() {
           @Override
           public void run() {
             Object object = provider.getModelObject();
             if (object instanceof WebApp) {
               final WebApp webApp = (WebApp) object;
               final ServletMapping servletMapping = WebFactory.eINSTANCE.createServletMapping();
               servletMapping.setServletName(JaxrsClassnames.APPLICATION);
               final UrlPatternType urlPattern = JavaeeFactory.eINSTANCE.createUrlPatternType();
               urlPattern.setValue(getApplicationPath());
               servletMapping.getUrlPatterns().add(urlPattern);
               webApp.getServletMappings().add(servletMapping);
               webApp.getServletMappings();
             }
           }
         },
         IModelProvider.FORCESAVE);
   }
 }
コード例 #3
0
  public void run() {
    final WebApp webApp = (WebApp) ModelProviderManager.getModelProvider(project).getModelObject();

    WebXmlUtilsForJavaEE.addServletMapping(webApp, servletName, servletClass, urlPatternString);
  }