All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.way.upload.Execute Maven / Gradle / Ivy

/*
 * Copyright 2013 Objectos, Fábrica de Software LTDA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package br.com.objectos.way.upload;

import java.io.File;

import com.google.sitebricks.headless.Reply;

/**
 * @author [email protected] (Marcio Endo)
 */
public abstract class Execute {

  final UploadCtx ctx;

  Execute(UploadCtx ctx) {
    this.ctx = ctx;
  }

  public abstract RedirectWith redirectWith(UploadRedirect redirect);

  public abstract Reply reply();

  public abstract Reply replyWith(UploadReplier replier);

  static  Execute execute(UploadCtx ctx, UploadSingleAction a, File file) {
    try {
      UploadedRequest request = ctx.getRequest();
      T pojo = a.execute(file, request);
      return new ExecuteValid(ctx, pojo);
    } catch (Exception e) {
      return new ExecuteInvalid(ctx, e);
    }
  }

  static  Execute executeAsync(UploadCtx ctx, UploadSingleAsync a, File file) {
    try {
      UploadedRequest request = ctx.getRequest();
      T pojo = a.execute(file, request);
      ctx.submitSingle(ctx, a, pojo, file);
      return new ExecuteValid(ctx, pojo);
    } catch (Exception e) {
      return new ExecuteInvalid(ctx, e);
    }
  }

  static  Execute execute(UploadCtx ctx, UploadUnzipAction a, UploadedZip file) {
    try {
      UploadedRequest request = ctx.getRequest();
      T pojo = a.execute(file, request);
      return new ExecuteValid(ctx, pojo);
    } catch (Exception e) {
      return new ExecuteInvalid(ctx, e);
    }
  }

  static  Execute executeAsync(UploadCtx ctx, UploadUnzipAsync a, UploadedZip file) {
    try {
      UploadedRequest request = ctx.getRequest();
      T pojo = a.execute(file, request);
      ctx.submitUnzip(ctx, a, pojo, file);
      return new ExecuteValid(ctx, pojo);
    } catch (Exception e) {
      return new ExecuteInvalid(ctx, e);
    }
  }

  T getPojo() {
    return null;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy