br.mdarte.exemplo.academico.web.geral.manterCurso.AlterandoCursoSalvaCurso.java Source code

Java tutorial

Introduction

Here is the source code for br.mdarte.exemplo.academico.web.geral.manterCurso.AlterandoCursoSalvaCurso.java

Source

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by: bpm4struts2/actions/Action.java.vsl in andromda-bpm4struts-cartridge-coppetec.
//

package br.mdarte.exemplo.academico.web.geral.manterCurso;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.ServletActionContext;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Enumeration;
import java.io.PrintWriter;
import org.andromda.presentation.bpm4struts.ActionUtil;
import org.andromda.presentation.bpm4struts.Struts2ViewContainer;
import br.mdarte.exemplo.academico.util.Constantes;

import com.opensymphony.xwork2.ActionSupport;

import br.mdarte.exemplo.academico.web.geral.manterCurso.MantemCursoControleFactory;

public class AlterandoCursoSalvaCurso extends br.mdarte.exemplo.academico.accessControl.Login2 {

    private java.lang.String codigo;

    public java.lang.String getCodigo() {
        return codigo;
    }

    public void setCodigo(java.lang.String codigo) {
        this.codigo = codigo;
    }

    private java.lang.Long idCurso;

    public java.lang.Long getIdCurso() {
        return idCurso;
    }

    public void setIdCurso(Object idCurso) {
        if (idCurso == null)
            this.idCurso = null;
        else if (idCurso instanceof String[]) {
            String temp = ((String[]) idCurso)[0];
            if (temp.isEmpty())
                this.idCurso = null;
            else
                this.idCurso = java.lang.Long.valueOf(((String[]) idCurso)[0]);
        } else
            this.idCurso = (java.lang.Long) idCurso;
    }

    private java.lang.String nome;

    public java.lang.String getNome() {
        return nome;
    }

    public void setNome(java.lang.String nome) {
        this.nome = nome;
    }

    public void saveErrorMessage(String message) {
        org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) request
                .getSession().getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
        if (messages == null) {
            messages = new org.apache.struts.action.ActionMessages();
            request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
        }
        messages.add("org.andromda.bpm4struts.errormessages",
                new org.apache.struts.action.ActionMessage(message, null));
    }

    public void validate() {
        //Removendo mensagens antigas
        //request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY, new org.apache.struts.action.ActionMessages());

        //Validando campos

    }

    public String particularExecute() throws Exception {
        String casoDeUso = null;
        String urlCasoDeUso = null;
        String modulo = null;

        boolean adicionaBreadCrumb = true;
        casoDeUso = "MantemCursoUC";
        urlCasoDeUso = "/MantemCursoUC/AlterandoCursoSalvaCurso";

        modulo = "geral";
        Iterator breadCrumbIt = null;
        Boolean aplicacaoPermiteUsoBackBrowser = (Boolean) request.getSession().getServletContext()
                .getAttribute("aplicacaoPermiteUsoBackBrowser");

        if (!aplicacaoPermiteUsoBackBrowser ^ false) {
            if (getInvalidatePageControlCounter(request).get("MantemCursoUC.AlterandoCurso") != null
                    && request.getParameter("invalidatePageControlCounter") != null
                    && !(((Integer) getInvalidatePageControlCounter(request).get("MantemCursoUC.AlterandoCurso"))
                            .equals(Integer.valueOf(request.getParameter("invalidatePageControlCounter"))))) {
                javax.servlet.http.HttpSession session = request.getSession();
                org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) session
                        .getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
                if (messages == null) {
                    messages = new org.apache.struts.action.ActionMessages();
                    session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
                }
                messages.add("org.andromda.bpm4struts.errormessages",
                        new org.apache.struts.action.ActionMessage("pagina.expirou"));

                return "forwardAction";
            }
        }

        String forward = null;
        String redirect = "";
        forward = "detalha.curso";

        boolean copyParameters = true;

        if (request.getSession().getAttribute(Constantes.COPY_PARAMETERS) != null) {
            copyParameters = (Boolean) request.getSession().getAttribute(Constantes.COPY_PARAMETERS);
            request.getSession().removeAttribute(Constantes.COPY_PARAMETERS);
        }

        AlterandoCursoSalvaCursoFormImpl form = new AlterandoCursoSalvaCursoFormImpl();

        form.setCodigo(this.codigo);
        form.setIdCurso(this.idCurso);
        form.setNome(this.nome);

        final AlterandoCursoSalvaCursoFormImpl specificForm = (AlterandoCursoSalvaCursoFormImpl) form;

        if (getInvalidatePageControlCounter(request).get("MantemCursoUC.AlterandoCurso") == null)
            getInvalidatePageControlCounter(request).put("MantemCursoUC.AlterandoCurso", 0);
        getInvalidatePageControlCounter(request).put("MantemCursoUC.AlterandoCurso",
                ((Integer) getInvalidatePageControlCounter(request).get("MantemCursoUC.AlterandoCurso")).intValue()
                        + 1);

        request.getSession().setAttribute("form", form);

        try {

            forward = _salvandoCurso(form);

        } //fim try
        catch (java.lang.Exception exception) {
            Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request,
                    "MantemCursoUC.AlterandoCurso");

            if (formObj != null) {
                try {
                    formObj.getClass()
                            .getMethod("resetCheckBoxes",
                                    new Class[] { org.apache.struts.action.ActionMapping.class,
                                            javax.servlet.http.HttpServletRequest.class })
                            .invoke(formObj, new Object[] { null, null });
                } catch (Exception e2) {
                    // ignoring
                }

                final java.util.Map parameters = new java.util.HashMap();
                for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                    final String name = String.valueOf(names.nextElement());
                    parameters.put(name, request.getParameterValues(name));
                }
                try {
                    org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters);
                } catch (java.lang.Exception populateException) {
                    // ignore if we have an exception here (we just don't populate).
                }
            }
            throw exception;
        }

        if (request.getAttribute("$forwardKeyModule") != null
                && !request.getAttribute("$forwardKeyModule").equals("geral")) {
            java.util.Enumeration atributosName = request.getSession().getAttributeNames();
            java.util.Map atributos = new java.util.HashMap();

            while (atributosName.hasMoreElements()) {
                String atributo = (String) atributosName.nextElement();
                atributos.put(atributo, request.getSession().getAttribute(atributo));
            }

            org.andromda.presentation.bpm4struts.ShareSessionUtil.saveMapIntoContext(request, response, atributos,
                    ServletActionContext.getServletContext().getContext("/sistemaacademico"));
        }

        if (redirect != "") {//troca de modules - to be tested
            response.sendRedirect(redirect);
        }

        request.removeAttribute("$forwardKey");
        request.removeAttribute("$forwardKeyModule");

        return forward;
    }

    /**
     * 
     */
    private String _salvandoCurso(org.apache.struts.validator.ValidatorForm form) throws java.lang.Exception {
        String forward = null;
        String redirect = "";
        request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY,
                new org.apache.struts.action.ActionMessages());

        MantemCursoControleFactory.getMantemCursoControleInstance().salvaCurso(
                (AlterandoCursoSalvaCursoFormImpl) form, new Struts2ViewContainer(this, request, response));
        java.util.HashMap map = new java.util.HashMap();
        if (request.getSession().getAttribute(Constantes.MODO_OPERACAO) != null)
            map = (java.util.HashMap) request.getSession().getAttribute(Constantes.MODO_OPERACAO);
        map.remove("geral/DetalhaCursoUC/DetalhaCursoUC.action");
        request.getSession().setAttribute(Constantes.MODO_OPERACAO, map);

        if (request.getSession().getAttribute("tableNameList") != null) {
            java.util.Collection tableNameList = (java.util.Collection) request.getSession()
                    .getAttribute("tableNameList");

            for (java.util.Iterator it = tableNameList.iterator(); it.hasNext();) {
                String tableName = (String) it.next();
                request.getSession().removeAttribute(tableName);
            }

            request.getSession().removeAttribute("tableNameList");
        }

        if (request.getAttribute("$forwardKey") != null) {
            forward = (String) request.getAttribute("$forwardKey");
        } else {
            forward = "detalha.curso";
        }

        return forward;
    }

    private java.util.Map getInvalidatePageControlCounter(javax.servlet.http.HttpServletRequest request) {
        java.util.Map invalidatePageControlCounter = (java.util.Map) request.getSession()
                .getAttribute("invalidatePageControlCounter");

        if (invalidatePageControlCounter == null) {
            invalidatePageControlCounter = new java.util.HashMap();
            request.getSession().setAttribute("invalidatePageControlCounter", invalidatePageControlCounter);
        }

        return invalidatePageControlCounter;
    }

    public void loadUseCaseInfo() {
        __casoDeUso = "MantemCursoUC";
        __urlCasoDeUso = "/MantemCursoUC/AlterandoCursoSalvaCurso.action";
        __modulo = "geral";
        __contexto = "";
    }
}