Example #1
0
  /**
   * @param resourceDescriptor see {@link AbstractResourceDescriptor}
   * @return see {@link WadlGenerator#createResponse()}
   */
  private org.exoplatform.services.rest.wadl.research.Resource processResource(
      AbstractResourceDescriptor resourceDescriptor) {
    org.exoplatform.services.rest.wadl.research.Resource wadlResource =
        wadlGenerator.createResource(resourceDescriptor);

    // Keeps common parameters for resource.
    Map<String, Param> wadlResourceParams = new HashMap<String, Param>();

    ResourceMethodMap<ResourceMethodDescriptor> resourceMethods =
        resourceDescriptor.getResourceMethods();
    for (List<ResourceMethodDescriptor> l : resourceMethods.values()) {
      for (ResourceMethodDescriptor rmd : l) {
        org.exoplatform.services.rest.wadl.research.Method wadlMethod =
            processMethod(rmd, wadlResourceParams);
        if (wadlMethod == null) continue;
        wadlResource.getMethodOrResource().add(wadlMethod);
      }
    }

    // Add parameters to a resource
    for (Param p : wadlResourceParams.values()) wadlResource.getParam().add(p);

    processSubResourceMethods(wadlResource, resourceDescriptor);

    processSubResourceLocators(wadlResource, resourceDescriptor);

    return wadlResource;
  }
Example #2
0
 /**
  * Process sub-resource locators.
  *
  * @param wadlResource see {@link org.exoplatform.services.rest.wadl.research.Resource}
  * @param resourceDescriptor see {@link AbstractResourceDescriptor}
  */
 private void processSubResourceLocators(
     org.exoplatform.services.rest.wadl.research.Resource wadlResource,
     AbstractResourceDescriptor resourceDescriptor) {
   for (SubResourceLocatorDescriptor srld : resourceDescriptor.getSubResourceLocators().values()) {
     // Specify SINGLETON life-cycle to avoid processing constructors and fields.
     // We are not interested about it since creation instance of resource is
     // responsibility of sub-resource locator.
     AbstractResourceDescriptor subResourceDescriptor =
         new AbstractResourceDescriptorImpl(
             srld.getMethod().getReturnType(), ComponentLifecycleScope.SINGLETON);
     org.exoplatform.services.rest.wadl.research.Resource wadlSubResource =
         processResource(subResourceDescriptor);
     wadlSubResource.setPath(srld.getPathValue().getPath());
     wadlResource.getMethodOrResource().add(wadlSubResource);
   }
 }
Example #3
0
  /**
   * Process sub-resource methods.
   *
   * @param wadlResource see {@link org.exoplatform.services.rest.wadl.research.Resource}
   * @param resourceDescriptor see {@link AbstractResourceDescriptor}
   */
  private void processSubResourceMethods(
      org.exoplatform.services.rest.wadl.research.Resource wadlResource,
      AbstractResourceDescriptor resourceDescriptor) {

    // Keeps common parameter for sub-resource.
    Map<String, Map<String, Param>> wadlCommonSubResourceParams =
        new HashMap<String, Map<String, Param>>();
    // Mapping resource path to resource.
    Map<String, org.exoplatform.services.rest.wadl.research.Resource> wadlSubResources =
        new HashMap<String, org.exoplatform.services.rest.wadl.research.Resource>();

    SubResourceMethodMap subresourceMethods = resourceDescriptor.getSubResourceMethods();
    for (ResourceMethodMap<SubResourceMethodDescriptor> rmm : subresourceMethods.values()) {
      for (List<SubResourceMethodDescriptor> l : rmm.values()) {
        for (SubResourceMethodDescriptor srmd : l) {
          String path = srmd.getPathValue().getPath();
          org.exoplatform.services.rest.wadl.research.Resource wadlSubResource =
              wadlSubResources.get(path);
          // There is no any resource for 'path' yet.
          if (wadlSubResource == null) {
            wadlSubResource = wadlGenerator.createResource(path);
            Map<String, Param> wadlResourceParams = new HashMap<String, Param>();
            org.exoplatform.services.rest.wadl.research.Method wadlMethod =
                processMethod(srmd, wadlResourceParams);
            if (wadlMethod == null) continue;
            wadlSubResource.getMethodOrResource().add(wadlMethod);
            // Remember sub-resource and parameters.
            wadlSubResources.put(path, wadlSubResource);
            wadlCommonSubResourceParams.put(path, wadlResourceParams);
          } else {
            // Get parameters for sub-resource that was created by one of previous
            // iteration.
            Map<String, Param> wadlResourceParams = wadlCommonSubResourceParams.get(path);
            // Add new method.
            org.exoplatform.services.rest.wadl.research.Method wadlMethod =
                processMethod(srmd, wadlResourceParams);
            if (wadlMethod == null) continue;
            wadlSubResource.getMethodOrResource().add(wadlMethod);
          }
        }
      }
    }
    // Add sub-resources to the root resource.
    for (Map.Entry<String, org.exoplatform.services.rest.wadl.research.Resource> entry :
        wadlSubResources.entrySet()) {
      String path = entry.getKey();
      org.exoplatform.services.rest.wadl.research.Resource wadlSubResource = entry.getValue();

      for (Param wadlSubParam : wadlCommonSubResourceParams.get(path).values())
        wadlSubResource.getParam().add(wadlSubParam);

      wadlResource.getMethodOrResource().add(wadlSubResource);
    }
  }