Ejemplo n.º 1
0
  /**
   * Create a file that contains the base class of all worker thread classes. This method will
   * trigger the class generation and add all required Java imports to the source file.
   *
   * @throws Exception Error during code generation
   */
  private void createBaseWorkerThreadFile() throws Exception {
    JSourceFile jsf =
        this.workspace
            .getJava()
            .getJSourceFile(this.threadWorkerPackageName, WORKER_THREAD_CLASS_NAME);

    // Add base worker thread class
    jsf.add(this.createBaseWorkerThreadClass());

    // Add required imports
    this.addRequiredImport(jsf, "org.atmosphere.websocket.WebSocket");
    this.addRequiredImport(
        jsf, this.serviceProviderPackageName + "." + this.serviceProviderClassName);
    this.addRequiredImport(jsf, this.packageName + "." + this.interfaceName);
  }
Ejemplo n.º 2
0
  /**
   * Private helper method to add required Java imports to the source file of a worker thread class.
   * The method will only import a class, if it does not reside in the same package as the worker
   * thread class. Furthermore, the method checks for duplicate imports automatically. It will only
   * import a class, if it is not present in the source file's imports already.
   *
   * <p>Multiple calls to this function with the same arguments will result in a single import
   * statement on source code write-out.
   *
   * @param requiredImport Name of required import
   */
  private void addRequiredImport(final JSourceFile sourceFile, final String requiredImport) {
    if (null != requiredImport) {
      // Extract package name from fully qualified class name
      String importPackageName = requiredImport.substring(0, requiredImport.lastIndexOf("."));

      // Do not import from same package!
      if (!this.threadWorkerPackageName.equals(importPackageName)) {
        // No duplicate imports!
        if (!sourceFile.containsImport(requiredImport)) {
          try {
            sourceFile.addImport(requiredImport);
          } catch (JDuplicateException e) {
            // Exception ignored intentionally
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * Create a file that contains a single worker thread class. All child worker classes are
   * generated on a per-operation basis for each and every RPC method defined in the WSDL document.
   *
   * <p>This method will trigger the class generation and add all required Java imports to the
   * source file.
   *
   * @param operation FOperation object from WSDL parser
   * @throws Exception Error during code generation
   */
  private void createWorkerThreadFile(final FOperation operation) throws Exception {
    String rpcMethodName = WorkerThreadGenerator.firstLetterCapital(operation.getOperationName());
    JSourceFile jsf =
        this.workspace
            .getJava()
            .getJSourceFile(this.threadWorkerPackageName, rpcMethodName + "Worker");

    // Add child worker thread class
    jsf.add(this.createWorkerThreadClass(operation));

    // Add required imports
    this.addRequiredImport(jsf, "org.slf4j.Logger");
    this.addRequiredImport(jsf, "org.slf4j.LoggerFactory");
    this.addRequiredImport(jsf, "org.atmosphere.websocket.WebSocket");

    this.addRequiredImport(
        jsf, this.serviceProviderPackageName + "." + this.serviceProviderClassName);
    this.addRequiredImport(jsf, this.packageName + "." + this.interfaceName);
    this.addRequiredImport(
        jsf, this.packageName + "." + JSONMarshallerGenerator.MARSHALLER_CLASS_NAME);

    // Import server only if required
    if (null != operation.getOutputMessage()) {
      this.addRequiredImport(jsf, this.packageName + "." + this.interfaceName);
    }

    // Operation has input message
    if (null != operation.getInputMessage()) {
      this.addRequiredImport(
          jsf, this.serviceProviderPackageName + "." + this.getInputMessageName(operation));
    }

    // Operation has output message
    if (null != operation.getOutputMessage()) {
      this.addRequiredImport(
          jsf, this.serviceProviderPackageName + "." + this.getOutputMessageName(operation));
    }
  }