Example usage for javax.ejb EJBException EJBException

List of usage examples for javax.ejb EJBException EJBException

Introduction

In this page you can find the example usage for javax.ejb EJBException EJBException.

Prototype

public EJBException(Exception ex) 

Source Link

Document

Constructs an EJBException that embeds the originally thrown exception.

Usage

From source file:com.geodetix.geo.dao.PostGisGeometryDAOImpl.java

/**
 * PostGIS implementation of the entity bean's lifecicle method 
 * <code>ejbRemove()</code>.
 * /*from  ww  w.j av  a  2s. co  m*/
 * 
 * @param pk primary key of the bean that must be removed .
 * @throws javax.ejb.RemoveException launched if an error during
 *   EJB remove operation is encountered.
 * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
 */
public void remove(java.lang.Integer pk) throws javax.ejb.RemoveException, javax.ejb.EJBException {

    PreparedStatement pstm = null;
    Connection con = null;

    try {

        con = this.dataSource.getConnection();

        pstm = con.prepareStatement(PostGisGeometryDAO.EJB_REMOVE_STATEMENT);

        pstm.setInt(1, pk.intValue());

        if (pstm.executeUpdate() != 1) {
            throw new EJBException("ejbRemove unable to remove EJB.");
        }
    } catch (SQLException se) {

        throw new EJBException(se);

    } finally {
        try {
            if (pstm != null) {
                pstm.close();
            }
        } catch (Exception e) {
        }

        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception e) {
        }
    }
}

From source file:com.stratelia.webactiv.newsEdito.servlets.NewsEditoRequestRouter.java

/**
 * This method has to be implemented by the component request rooter it has to compute a
 * destination page/* w w w  . java  2 s  . co m*/
 *
 *
 * @param function  The entering request function (ex : "Main.jsp")
 * @param newsEdito The component Session Controller, build and initialised.
 * @param request   The entering request. The request rooter need it to get parameters
 * @return The complete destination URL for a forward (ex : "/almanach/jsp/almanach.jsp?flag=user")
 */
@Override
public String getDestination(String function, NewsEditoSessionController newsEdito, HttpRequest request) {
    String destination = "";
    String rootDest = "/newsEdito/jsp/";
    SilverTrace.debug("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_ENTER",
            "function = " + function);

    if (function.startsWith("portlet")) {
        destination = rootDest + "portlet.jsp";
    } else if ((function.startsWith("Main")) || (function.startsWith("newsEdito"))) {
        // the flag is the best user's profile
        String flag = newsEdito.getUserRoleLevel();

        // initialisation de la variable indiquant que l'utilisateur est en mode
        // consultation
        newsEdito.setIsConsulting(true);
        destination = rootDest + "newsEdito.jsp?flag=" + flag;
    } else if (function.startsWith("manageNews")) {
        String flag = newsEdito.getUserRoleLevel();

        destination = rootDest + "manageNews.jsp?flag=" + flag;
    } else if (function.startsWith("manageArticles")) {

        String flag = newsEdito.getUserRoleLevel();
        // initialisation de la variable indiquant que l'utilisateur est en mode
        // manage
        newsEdito.setIsConsulting(false);
        destination = rootDest + "manageArticles.jsp?flag=" + flag;
    } else if (function.startsWith("publicationEdit")) {
        String flag = newsEdito.getUserRoleLevel();

        // initialisation de isConsulting inutile
        destination = rootDest + "publicationEdit.jsp?flag=" + flag;
    } else if (function.equals("UpdatePublication")) {
        String flag = newsEdito.getUserRoleLevel();

        try {
            // pour le formulaire XML
            setXMLForm(request, newsEdito, null);
        } catch (Exception e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_LIST_ERROR");
        }
        destination = rootDest + "publicationEdit.jsp?flag=" + flag;
    } else if (function.startsWith("publication")) {
        String flag = newsEdito.getUserRoleLevel();
        PublicationDetail pubDetail;

        try {
            // rcuprer l'id
            String pubId = request.getParameter("PublicationId");
            if (StringUtil.isDefined(pubId)) {
                pubDetail = newsEdito.getPublicationDetail(pubId);
            } else {
                pubDetail = newsEdito.getCompletePublication().getPublicationDetail();
            }
            // pour le formulaire XML
            putXMLDisplayerIntoRequest(pubDetail, newsEdito, request);
        } catch (Exception e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_LIST_ERROR");
        }

        destination = rootDest + "publication.jsp?flag=" + flag;
    } else if (function.startsWith("pdfCompile")) {
        String flag = newsEdito.getUserRoleLevel();

        // initialisation de isConsulting inutile
        destination = rootDest + "pdfCompile.jsp?flag=" + flag;
    } else if (function.startsWith("publishNews")) {
        String flag = newsEdito.getUserRoleLevel();

        // initialisation de isConsulting inutile
        destination = rootDest + "publishNews.jsp?flag=" + flag;
    } else if (function.equals("ListModels")) {
        try {
            List<PublicationTemplate> listModels = getPublicationTemplateManager().getPublicationTemplates();
            request.setAttribute("ListModels", listModels);
        } catch (PublicationTemplateException e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_LIST_ERROR");
        }
        destination = rootDest + "listModels.jsp";
    } else if (function.equals("SelectModel")) {
        try {
            String xmlFormName = request.getParameter("Name");
            setXMLForm(request, newsEdito, xmlFormName);

            // put current publication
            request.setAttribute("CurrentPublicationDetail",
                    newsEdito.getCompletePublication().getPublicationDetail());
        } catch (Exception e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_LIST_ERROR");
        }
        destination = rootDest + "model.jsp";
    } else if (function.equals("ReallyUpdatePublication")) {
        try {
            // mise  jour de l'entte de la publication
            List<FileItem> items = request.getFileItems();

            String name = FileUploadUtil.getParameter(items, "Name");
            String description = FileUploadUtil.getParameter(items, "Description");
            newsEdito.updatePublication(name, description);

            // mise  jour du formulaire
            updateXmlForm(items, newsEdito);
        } catch (Exception e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_LIST_ERROR");
        }
        destination = getDestination("publication", newsEdito, request);
    } else if (function.equals("UpdateXMLForm")) {
        try {
            List<FileItem> items = request.getFileItems();
            updateXmlForm(items, newsEdito);
        } catch (Exception e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_LIST_ERROR");
        }

        destination = getDestination("publication", newsEdito, request);

    } else if (function.startsWith("searchResult")) {
        String flag = newsEdito.getUserRoleLevel();
        String id = request.getParameter("Id");
        String type = request.getParameter("Type");
        if (type.equals("Publication")) {
            // newsEdito.initNavigationForPublication(id);
            destination = rootDest + "newsEdito.jsp?Action=SelectPublication&PublicationId=" + id + "&flag="
                    + flag;
        } else // if (type.equals("Node"))
        {
            try {
                newsEdito.initNavigationForNode(id);
            } catch (NewsEditoException e) {
                throw new EJBException(e);
            }
            if (newsEdito.getTitleId() != null) {
                destination = rootDest + "newsEdito.jsp?Action=SelectTitle&TitleId=" + id + "&flag=" + flag;
            } else {
                destination = rootDest + "newsEdito.jsp?Action=SelectArchive&ArchiveId=" + id + "&flag=" + flag;
            }
        }
    }
    // clipboard
    /*
     * ------ COMMENTED BY LBE, WAITING TO BE RESOLVED ------
     */
    else if (function.startsWith("multicopy")) {
        try {
            String Ids[] = request.getParameterValues("publicationIds");

            for (int i = 0; i < Ids.length; i++) {
                if (Ids[i] != null) {
                    CompletePublication pub = ((NewsEditoSessionController) newsEdito)
                            .getCompletePublication(Ids[i]);
                    PublicationSelection pubSelect = new PublicationSelection(pub);
                    newsEdito.addClipboardSelection((ClipboardSelection) pubSelect);
                }
            }
        } catch (Exception e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_COPY_ERROR");
        }

        destination = rootDest + URLManager.getURL(URLManager.CMP_CLIPBOARD)
                + "Idle.jsp?message=REFRESHCLIPBOARD";
        return destination;
    } else if (function.startsWith("paste")) {
        try {
            NewsEditoSessionController news = (NewsEditoSessionController) newsEdito;
            String titleId = news.getTitleId();
            Collection<ClipboardSelection> clipObjects = news.getClipboardSelectedObjects();
            Iterator<ClipboardSelection> clipObjectIterator = clipObjects.iterator();

            while (clipObjectIterator.hasNext()) {
                ClipboardSelection clipObject = clipObjectIterator.next();
                if (clipObject != null) {
                    if (clipObject.isDataFlavorSupported(PublicationSelection.CompletePublicationFlavor)) {
                        CompletePublication pub;

                        pub = (CompletePublication) clipObject
                                .getTransferData(PublicationSelection.CompletePublicationFlavor);
                        news.createPublication(pub.getPublicationDetail().getName(),
                                pub.getPublicationDetail().getDescription());
                    } else if (clipObject.isDataFlavorSupported(PublicationSelection.PublicationDetailFlavor)) {
                        PublicationDetail pub;

                        pub = (PublicationDetail) clipObject
                                .getTransferData(PublicationSelection.PublicationDetailFlavor);
                        news.createPublication(pub.getName(), pub.getDescription());
                    }
                }
            }
            news.setTitleId(titleId);
            news.clipboardPasteDone();
        } catch (Exception e) {
            SilverTrace.warn("NewsEdito", "NewsEditoRequestRooter.getDestination", "NewsEdito.EX_PAST_ERROR");
        }
        destination = URLManager.getURL(URLManager.CMP_CLIPBOARD) + "Idle.jsp";
        return rootDest + destination;
    }

    /*------ COMMENTED BY LBE, WAITING TO BE RESOLVED ------
     */
    else {
        destination = rootDest + function;
    }
    SilverTrace.info("newsEdito", "NewsEditoRequestRouter.getDestination()", "root.MSG_GEN_PARAM_VALUE",
            "destination = " + destination);

    return destination;
}

From source file:com.egt.ejb.toolkit.ToolKitSessionBean.java

@Override
public void generarMenu(ToolKitMessage message) {
    try {/* ww  w  . j  a va  2 s.  co m*/
        String procedimiento = OpcionMenuConstants.PROCESO_FUNCION_RECONSTRUIR_OPCION_MENU;
        int index = 0;
        int length = 0;
        length++;
        Object[] args = length == 0 ? null : new Object[length];
        args[index++] = message.getRastro();
        sqlAgent.executeProcedure(procedimiento, args);
        message.setGrabarRastroPendiente(false);
        TLC.getBitacora().info(Bundle.getString("generar.menu.ok"));
    } catch (SQLException ex) {
        throw new EJBException(ex);
    }
}

From source file:org.ejbca.core.ejb.services.ServiceSessionBean.java

@Override
public void cloneService(AuthenticationToken admin, String oldname, String newname)
        throws ServiceExistsException {
    if (log.isTraceEnabled()) {
        log.trace(">cloneService(name: " + oldname + ")");
    }/*from ww  w.  j  a v a  2  s  . c  o m*/
    ServiceConfiguration servicedata = null;
    ServiceData htp = serviceDataSession.findByName(oldname);
    if (htp == null) {
        String msg = "Error cloning service: No such service found.";
        log.error(msg);
        throw new EJBException(msg);
    }
    try {
        servicedata = (ServiceConfiguration) htp.getServiceConfiguration().clone();
        if (isAuthorizedToEditService(admin)) {
            addServiceInternal(admin, findFreeServiceId(), newname, servicedata);
            final String msg = intres.getLocalizedMessage("services.servicecloned", newname, oldname);
            final Map<String, Object> details = new LinkedHashMap<String, Object>();
            details.put("msg", msg);
            auditSession.log(EjbcaEventTypes.SERVICE_ADD, EventStatus.SUCCESS, EjbcaModuleTypes.SERVICE,
                    EjbcaServiceTypes.EJBCA, admin.toString(), null, null, null, details);
        } else {
            final String msg = intres.getLocalizedMessage("services.notauthorizedtoedit", oldname);
            log.info(msg);
        }
    } catch (CloneNotSupportedException e) {
        log.error("Error cloning service: ", e);
        throw new EJBException(e);
    }
    log.trace("<cloneService()");
}

From source file:com.geodetix.geo.dao.PostGisGeometryDAOImpl.java

/**
 * PostGIS implementation of the //ww w  .  jav  a 2  s.c om
 * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)}
 * method creating a NON-OpenGis compliant table in the PostGIS database.
 * The table will contain the geometry EJBs.
 */
public void makeDbTable() {

    PreparedStatement pstm = null;
    Connection con = null;

    try {

        con = this.dataSource.getConnection();

        System.out.println("Creating non-OpenGIG Bean table... ");

        pstm = con.prepareStatement(PostGisGeometryDAO.HOME_CREATE_NON_OPENGIS_TABLE_STATEMENT);
        pstm.execute();

        System.out.println("...done!");

    } catch (SQLException e) {
        throw new EJBException(e);

    } finally {

        try {
            if (pstm != null) {
                pstm.close();
            }
        } catch (Exception e) {
        }

        try {
            if (con != null) {
                con.close();
            }

        } catch (Exception e) {
        }
    }
}

From source file:edu.harvard.iq.dvn.core.study.StudyServiceBean.java

public Study getStudyByHarvestInfo(VDC dataverse, String harvestIdentifier) {
    String queryStr = "SELECT s FROM Study s WHERE s.owner.id = '" + dataverse.getId()
            + "' and s.harvestIdentifier = '" + harvestIdentifier + "'";
    Query query = em.createQuery(queryStr);
    List resultList = query.getResultList();
    Study study = null;//w  w  w  .  java2 s  . c  o m
    if (resultList.size() > 1) {
        throw new EJBException("More than one study found with owner_id= " + dataverse.getId()
                + " and harvestIdentifier= " + harvestIdentifier);
    }
    if (resultList.size() == 1) {
        study = (Study) resultList.get(0);
    }
    return study;

}

From source file:com.geodetix.geo.dao.PostGisGeometryDAOImpl.java

/**
 * PostGIS implementation of the /*w  ww  .java 2 s  .c  o  m*/
 * {@link com.geodetix.geo.interfaces.GeometryLocalHome#makeDbTable(java.lang.String, int, int)}
 * method creating an OpenGIS compliant table in the PostGIS database.
 * The table will contain the geometry EJBs.
 *
 * @param gemetryType the string that rapresent a valid PostGIS 
 * geometry type (i.e.: POINT, LINESTRING, POLYGON etc.).
 * @param srid the SRID of the geometry.
 * @param geometryDimension the dimension of the geometry.
 */
public void makeDbTable(String gemetryType, int srid, int geometryDimension) {

    PreparedStatement pstm = null;
    Connection con = null;

    try {

        con = this.dataSource.getConnection();

        System.out.println("Creating OpenGIS Bean table...");

        pstm = con.prepareStatement(PostGisGeometryDAO.HOME_CREATE_OPENGIS_TABLE_STATEMENT);
        pstm.execute();

        pstm = con.prepareStatement(PostGisGeometryDAO.ADD_OPEN_GIS_GEOMETRY_COLUMN_STATEMENT);
        pstm.setInt(1, srid);
        pstm.setString(2, gemetryType);
        pstm.setInt(3, geometryDimension);

        pstm.execute();

        System.out.println("...done!");

    } catch (SQLException e) {
        throw new EJBException(e);

    } finally {

        try {
            if (pstm != null) {
                pstm.close();
            }
        } catch (Exception e) {
        }

        try {
            if (con != null) {
                con.close();
            }

        } catch (Exception e) {
        }
    }
}

From source file:com.egt.ejb.toolkit.ToolKitSessionBean.java

@Override
public void generarBundles() {
    Utils.traceContext();//from  ww  w.j  a v a2s .  c om
    try {
        String root = ToolKitUtils.getWorkspaceDir();
        String filedir = ToolKitUtils.mkLibSrcDir(root, EA.getLowerCaseCode() + "-lib-base", "bundles");
        String filename;
        String query;
        ToolKitUtils utils = this.getToolKitUtils();
        VelocityContext context = new VelocityContext();
        context.put("utils", utils);
        //
        query = VelocityEngineer.write(context, "sdk-query-generar-funciones-p4.vm").toString();
        List<Funcion> funcionesP4 = funcionFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH);
        context.put("funciones", funcionesP4);
        filename = filedir + "BundleFunciones.properties";
        write(context, "sdk-plantilla-bundle-funciones-properties.vm", filename);
        //
        List<SystemRoutine> procedimientos = systemRoutineFacade.findAll();
        context.put("procedimientos", procedimientos);
        filename = filedir + "BundleProcedimientos.properties";
        write(context, "sdk-plantilla-bundle-procedimientos-properties.vm", filename);
        //
        query = VelocityEngineer.write(context, "sdk-query-generar-bundle-paginas-properties.vm").toString();
        List<Pagina> paginas = paginaFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH);
        context.put("paginas", paginas);
        filename = filedir + "BundlePaginas.properties";
        write(context, "sdk-plantilla-bundle-paginas-properties.vm", filename);
        //
        query = VelocityEngineer.write(context, "sdk-query-generar-roles.vm").toString();
        List<Rol> roles = rolFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH);
        context.put("roles", roles);
        query = VelocityEngineer.write(context, "sdk-query-generar-funciones.vm").toString();
        List<Funcion> funciones = funcionFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH);
        context.put("funciones", funciones);
        List<Aplicacion> aplicaciones = getAplicaciones("sdk-query-generar-aplicaciones-3.vm");
        context.put("aplicaciones", aplicaciones);
        context.put(EA.class.getSimpleName(), EA.class);
        filedir = ToolKitUtils.mkLibDir(root, EA.getLowerCaseCode(), "src-conf");
        filename = filedir + "application.xml";
        write(context, "sdk-plantilla-application-xml.vm", filename);
        filename = filedir + "sun-application.xml";
        write(context, "sdk-plantilla-sun-application-xml.vm", filename);
        //
        TLC.getBitacora().info(Bundle.getString("generar.bundles.ok"));
    } catch (Exception ex) {
        //          TLC.getBitacora().fatal(ex);
        throw ex instanceof EJBException ? (EJBException) ex : new EJBException(ex);
    }
}

From source file:com.geodetix.geo.dao.PostGisGeometryDAOImpl.java

/**
 * PostGIS implementation of the //from  ww  w  . ja  va  2  s.c  om
 * {@link com.geodetix.geo.interfaces.GeometryLocalHome#dropDbTable()}
 * method removing the table related to the EJBs.
 */
public void dropDbTable() {

    PreparedStatement pstm = null;
    Connection con = null;

    try {

        con = this.dataSource.getConnection();

        System.out.println("Dropping Bean Table... ");

        pstm = con.prepareStatement(PostGisGeometryDAO.DROP_TABLE_STATEMENT);
        pstm.execute();

        System.out.println("...done!");

    } catch (SQLException e) {

        throw new EJBException(e);

    } finally {

        try {
            if (pstm != null) {
                pstm.close();
            }
        } catch (Exception e) {
        }

        try {
            if (con != null) {
                con.close();
            }

        } catch (Exception e) {
        }
    }
}

From source file:com.egt.ejb.toolkit.ToolKitSessionBean.java

@Override
public void generarEntityConstants() {
    try {//  ww w.  j  a  v a  2s .c o  m
        VelocityContext context = new VelocityContext();
        String query = VelocityEngineer.write(context, "sdk-query-generar-entity-constants.vm").toString();
        List<Dominio> dominios = dominioFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH);
        generarEntityConstants(dominios);
        TLC.getBitacora().info(Bundle.getString("generar.constants.ok"), dominios.size());
    } catch (Exception ex) {
        //          TLC.getBitacora().fatal(ex);
        throw ex instanceof EJBException ? (EJBException) ex : new EJBException(ex);
    }
}