Package br.com.objectos.way.upload

Source Code of br.com.objectos.way.upload.Execute

/*
* 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 br.com.objectos.comuns.web.upload.UploadedForm;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
public abstract class Execute<T> {

  final UploadCtx ctx;

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

  public abstract RedirectWith<T> redirectWith(UploadRedirect<T> redirect);

  static <T> Execute<T> execute(UploadCtx ctx, UploadSingleAction<T> a, File file) {
    try {
      UploadedForm form = ctx.getForm();
      T pojo = a.execute(file, form);
      return new ExecuteValid<T>(ctx, pojo);
    } catch (Exception e) {
      return new ExecuteInvalid<T>(ctx, e);
    }
  }

  static <T> Execute<T> execute(UploadCtx ctx, UploadUnzipAction<T> a, UploadedZip file) {
    try {
      UploadedForm form = ctx.getForm();
      T pojo = a.execute(file, form);
      return new ExecuteValid<T>(ctx, pojo);
    } catch (Exception e) {
      return new ExecuteInvalid<T>(ctx, e);
    }
  }

  static <K, T> Execute<T> executeAsync(UploadCtx ctx, UploadUnzipAsync<T> a, UploadedZip file) {
    try {
      UploadedForm form = ctx.getForm();
      T pojo = a.execute(file, form);
      ctx.submitUnzip(ctx, a, pojo, file);
      return new ExecuteValid<T>(ctx, pojo);
    } catch (Exception e) {
      return new ExecuteInvalid<T>(ctx, e);
    }
  }

  T getPojo() {
    return null;
  }

}
TOP

Related Classes of br.com.objectos.way.upload.Execute

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.