Example usage for javax.ejb CreateException CreateException

List of usage examples for javax.ejb CreateException CreateException

Introduction

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

Prototype

public CreateException(String message) 

Source Link

Document

Constructs a CreateException with the specified detail message.

Usage

From source file:com.interface21.ejb.support.AbstractEnterpriseBean.java

/**
 * Load a Spring BeanFactory namespace.//from   w w w  . j av  a  2s.c  o m
 * Subclasses must invoke this method. Package-visible as it
 * shouldn't be called directly by user-created subclasses.
 * @see com.interface21.ejb.support.AbstractStatelessSessionBean#ejbCreate()
 */
void loadBeanFactory() throws CreateException {
    if (this.beanFactoryLoader == null) {
        this.beanFactoryLoader = new XmlBeanFactoryLoader();
    }
    try {
        this.beanFactory = this.beanFactoryLoader.loadBeanFactory();
    } catch (BootstrapException ex) {
        throw new CreateException(ex.getMessage());
    }
}

From source file:de.juwimm.cms.safeguard.model.RealmSimplePwUserHbmDaoImpl.java

@Override
public RealmSimplePwUserHbm handleCreate(Element element, boolean newId) throws CreateException {
    RealmSimplePwUserHbm realm = new RealmSimplePwUserHbmImpl();
    if (newId) {//  w  w w. jav a 2 s. c o m
        try {
            Integer id = sequenceHbmDao.getNextSequenceNumber("realm_simple_pw_user.simple_pw_realm_user_id");
            realm.setSimplePwRealmUserId(id);
        } catch (Exception e) {
            log.error("Error creating primary key", e);
        }
    }
    try {
        String userName = XercesHelper.getNodeValue(element, "userName");
        String password = XercesHelper.getNodeValue(element, "password");
        realm.setUserName(userName);
        realm.setPassword(password);
    } catch (Exception e) {
        log.error("Error creating new RealmSimplePwBeanImpl: " + e.getMessage());
        throw new CreateException("Error creating new RealmSimplePwBeanImpl: " + e.getMessage());
    }
    return super.create(realm);
}

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

/**
 * PostGIS implementation of the /* w  ww . j a v a 2  s . c o m*/
 * {@link com.geodetix.geo.ejb.GeometryBean#ejbCreate(org.postgis.Geometry, java.lang.String)}
 * method.
 * 
 * @return the primary key of the persisted bean.
 * @param ejb the bean to persist.
 * @throws javax.ejb.CreateException launched if an EJB creation error is encountered.
 * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
 */
public java.lang.Integer create(com.geodetix.geo.ejb.GeometryBean ejb)
        throws javax.ejb.CreateException, javax.ejb.EJBException {

    PreparedStatement pstm = null;
    Connection con = null;

    try {
        con = this.dataSource.getConnection();

        pstm = con.prepareStatement(PostGisGeometryDAO.EJB_CREATE_STATEMENT);

        pstm.setInt(1, ejb.getId());
        pstm.setObject(2, new PGgeometry((Geometry) ejb.getGeometry()));
        pstm.setString(3, ejb.getDescription());

        if (pstm.executeUpdate() != 1) {
            throw new CreateException("Failed to add EJB to database");
        }

        return ejb.getId();

    } 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:es.caib.seycon.ng.servei.PuntEntradaServiceImpl.java

/**
 * @see es.caib.seycon.ng.servei.PuntEntradaService#create(es.caib.seycon.ng.comu.PuntEntrada)
 *///from   w ww. ja  v a  2 s . co m
protected es.caib.seycon.ng.comu.PuntEntrada handleCreate(es.caib.seycon.ng.comu.PuntEntrada puntEntrada)
        throws java.lang.Exception {
    //
    // VERIFICACIONS:
    //
    Long idPare = puntEntrada.getIdPare();

    // Verificamos que el padre sea de tipo men:
    if (puntEntrada.getIdPare() == null)
        throw new SeyconException(Messages.getString("PuntEntradaServiceImpl.ObtaintParentPointEntryError")); //$NON-NLS-1$

    PuntEntradaEntity pareE = getPuntEntradaEntityDao().findById(puntEntrada.getIdPare());

    if (pareE == null)
        throw new CreateException(Messages.getString("PuntEntradaServiceImpl.ParentMenuNotFounded")); //$NON-NLS-1$
    if (!"S".equals(pareE.getMenu())) { //$NON-NLS-1$
        throw new CreateException(Messages.getString("PuntEntradaServiceImpl.ParentNotAMenu")); //$NON-NLS-1$
    }
    // Verificamos autorizacin del padre
    PuntEntrada pare = getPuntEntradaEntityDao().toPuntEntrada(pareE);
    if (!canAdmin(pare)) {
        throw new SecurityException(
                Messages.getString("PuntEntradaServiceImpl.UnauthorizedtForAdminParentMenu")); //$NON-NLS-1$
    }

    // Si el nou node s de tipus men, verifiquem que tinga indicat el
    // tipus de menu
    // i esborrem les execucions (si existeixen)
    if ("S".equals(puntEntrada.getMenu())) { //$NON-NLS-1$
        if (puntEntrada.getTipusMenu() == null)
            throw new CreateException(Messages.getString("PuntEntradaServiceImpl.MenuTypeMessage")); //$NON-NLS-1$
        puntEntrada.setExecucions(new HashSet()); // esborrem execucions
                                                  // abans de crear entitat
    }

    // Validem el XML si no s buit
    if (puntEntrada.getXmlPUE() != null && !"".equals(puntEntrada.getXmlPUE())) { //$NON-NLS-1$
        String resValida = validaXMLPUE(puntEntrada);
        if (resValida != null && !"".equals(resValida.trim())) //$NON-NLS-1$
            throw new SeyconException(
                    String.format(Messages.getString("PuntEntradaServiceImpl.XMLValidationError"), //$NON-NLS-1$
                            puntEntrada.getNom(), resValida));
    }

    //
    // OBTENIM L'ENTITAT
    //
    PuntEntradaEntity entity = getPuntEntradaEntityDao().puntEntradaToEntity(puntEntrada);

    // CREEM L'ENTITAT (!!)
    getPuntEntradaEntityDao().create(entity);

    // Creem l'ARBRE del punt d'entrada
    int ordre = 0; //$NON-NLS-1$   //String ordre = "0";
    // Obtenim L'ORDRE DE L'ARBRE des dels fills del pare (estan ordenats
    // per ordre ascendent)
    List fills = (List) getArbrePuntEntradaEntityDao().findByPare(puntEntrada.getIdPare());
    if (fills != null) {// Ens quedem en el fill de major ordre
        if (fills.size() == 0) // Para nodes men sense fills
            ordre = 0; //$NON-NLS-1$   //ordre = "0";
        else { // Obtenim el seu fill "major"
            ArbrePuntEntradaEntity fill = (ArbrePuntEntradaEntity) fills.get(fills.size() - 1);
            int ordreFillMajor = fill.getOrdre(); //Integer.parseInt(fill.getOrdre());
            ordre = ordreFillMajor + 1; //$NON-NLS-1$   //"" + (ordreFillMajor + 1);
        }
    }
    ArbrePuntEntradaEntity arbre = getArbrePuntEntradaEntityDao().newArbrePuntEntradaEntity();
    arbre.setOrdre(ordre);
    arbre.setFill(entity);
    arbre.setPare(pareE);
    HashSet<ArbrePuntEntradaEntity> monArbre = new HashSet<ArbrePuntEntradaEntity>();
    monArbre.add(arbre);
    // Establim l'arbre
    entity.setArbrePuntEntradaSocFill(monArbre);

    // Creem les relacions del punt d'entrada
    // Arbre
    getArbrePuntEntradaEntityDao().create(arbre);

    // Creem les icones
    IconaEntity icona1 = null;
    if (puntEntrada.getImgIcona1() != null && puntEntrada.getImgIcona1().length != 0) {
        // Creem l'icona
        icona1 = createIcona(puntEntrada.getImgIcona1());
        entity.setIcona1(icona1.getId());
    }
    IconaEntity icona2 = null;
    if (puntEntrada.getImgIcona2() != null && puntEntrada.getImgIcona2().length != 0) {
        // S'ha actualitzat l'icona: creem una nova
        icona2 = createIcona(puntEntrada.getImgIcona2());
        entity.setIcona2(icona2.getId());
    }

    // Actualitzem l'entitat (amb les relacions)
    getPuntEntradaEntityDao().update(entity);

    // Afegim id del pare (per poder moure'l ara mateix)
    PuntEntrada res = getPuntEntradaEntityDao().toPuntEntrada(entity);
    res.setIdPare(idPare);

    // Assignem iconas (en el toVO encara no poden estar en la BD)
    if (icona1 != null) {
        res.setIdIcona1(icona1.getId());
        res.setImgIcona1(icona1.getIcona());
    }
    if (icona2 != null) {
        res.setIdIcona2(icona2.getId());
        res.setImgIcona2(icona2.getIcona());
    }

    // Posem la ruta que s'ha obtingut en el ZUL a partir del pare
    if (puntEntrada.getRutaArbre() != null)
        res.setRutaArbre(puntEntrada.getRutaArbre());

    auditarPuntEntrada("C", res.getNom() + Messages.getString("PuntEntradaServiceImpl.15") + pareE.getNom()); //$NON-NLS-1$ //$NON-NLS-2$

    return res;
}

From source file:com.duroty.application.mail.ejb.SendBean.java

/**
 * An ejbCreate method as required by the EJB specification.
 *
 * The container calls the instance?s <code>ejbCreate</code> method whose
 * signature matches the signature of the <code>create</code> method invoked
 * by the client. The input parameters sent from the client are passed to
 * the <code>ejbCreate</code> method. Each session bean class must have at
 * least one <code>ejbCreate</code> method. The number and signatures
 * of a session bean?s <code>create</code> methods are specific to each
 * session bean class.//from  ww w .j  av  a 2  s .c o  m
 *
 * @throws CreateException Thrown if method fails due to system-level error.
 *
 * @ejb.create-method
 * @ejb.permission
 *         role-name = "mail"
 *
 */
public void ejbCreate() throws CreateException {
    Map options = ApplicationConstants.options;

    try {
        ctx = new InitialContext();

        HashMap mail = (HashMap) ctx.lookup((String) options.get(Constants.MAIL_CONFIG));

        this.hibernateSessionFactory = (String) mail.get(Constants.HIBERNATE_SESSION_FACTORY);
        this.smtpSessionFactory = (String) mail.get(Constants.DUROTY_MAIL_FACTOTY);

        manager = new SendManager(mail);
    } catch (Exception e) {
        throw new CreateException(e.getMessage());
    }
}

From source file:de.juwimm.cms.remote.EditionServiceSpringImpl.java

private PersonHbm createPersonHbm(UnitHbm unit, Element ael, boolean useNewIds,
        Hashtable<Integer, Long> mappingPersons2, Hashtable<Integer, Long> mappingAddresses2,
        Hashtable<Integer, Long> mappingTalktime2) throws Exception {
    PersonHbm person = PersonHbm.Factory.newInstance();
    try {//from  w ww.j a  va 2 s . c  om
        person.setImageId(Integer.decode(ael.getAttribute("imageid")));
    } catch (Exception exe) {
    }
    try {
        person.setBirthDay(getNVal(ael, "birthDay"));
    } catch (Exception exe) {
    }
    try {
        person.setCountryJob(getNVal(ael, "countryJob"));
        person.setFirstname(getNVal(ael, "firstname"));
        person.setJob(getNVal(ael, "job"));
        person.setJobTitle(getNVal(ael, "jobTitle"));
        person.setLastname(getNVal(ael, "lastname"));
        person.setLinkMedicalAssociation(getNVal(ael, "linkMedicalAssociation"));
        person.setMedicalAssociation(getNVal(ael, "medicalAssociation"));
        person.setPosition(new Byte(getNVal(ael, "position")).byteValue());
        person.setSalutation(getNVal(ael, "salutation"));
        person.setSex(new Byte(getNVal(ael, "sex")).byteValue());
        person.setTitle(getNVal(ael, "title"));
        if (!useNewIds) {
            person.setPersonId(new Integer(ael.getAttribute("id")).longValue());
        }
        person.getUnits().add(unit);
        person = getPersonHbmDao().create(person);
    } catch (Exception exe) {
        log.warn("Error setting values: ", exe);
    }
    try {
        if (log.isDebugEnabled())
            log.debug("looking for addresses to import for person " + person.getPersonId()); //$NON-NLS-1$
        Iterator itAdr = XercesHelper.findNodes(ael, "./address"); //$NON-NLS-1$
        while (itAdr.hasNext()) {
            Element adrEl = (Element) itAdr.next();
            if (log.isDebugEnabled())
                log.debug("found address to import"); //$NON-NLS-1$
            AddressHbm local = createAddressHbm(adrEl, useNewIds, mappingAddresses);
            person.addAddress(local);
        }
    } catch (Exception exe) {
        log.warn("Error importing addresses: ", exe); //$NON-NLS-1$
        throw new CreateException(exe.getMessage());
    }
    try {
        if (log.isDebugEnabled())
            log.debug("looking for talktimes to import for person " + person.getPersonId()); //$NON-NLS-1$
        Iterator itTTimes = XercesHelper.findNodes(ael, "./talktime"); //$NON-NLS-1$
        while (itTTimes.hasNext()) {
            Element elm = (Element) itTTimes.next();
            if (log.isDebugEnabled())
                log.debug("found talktime to import"); //$NON-NLS-1$
            TalktimeHbm local = createTalktimeHbm(elm, useNewIds, mappingTalktime);
            person.addTalktime(local);
        }
    } catch (Exception exe) {
        log.warn("Error importing talktimes: ", exe); //$NON-NLS-1$
        throw new Exception(exe.getMessage());
    }
    return person;
}

From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java

private PersonHbm createPersonHbm(UnitHbm unit, Element ael, boolean useNewIds,
        Hashtable<Integer, Integer> picIds) throws Exception {
    PersonHbm person = new PersonHbmImpl();
    try {// w ww .j  a  va  2 s  . c o  m
        Integer imageId = Integer.parseInt(ael.getAttribute("imageid"));
        if (picIds != null) {
            Integer newPicId = picIds.get(imageId);
            person.setImageId(newPicId);
        } else {
            person.setImageId(imageId);
        }
    } catch (Exception exe) {
    }
    try {
        person.setBirthDay(getNVal(ael, "birthDay"));
    } catch (Exception exe) {
    }
    try {
        person.setCountryJob(getNVal(ael, "countryJob"));
        person.setFirstname(getNVal(ael, "firstname"));
        person.setJob(getNVal(ael, "job"));
        person.setJobTitle(getNVal(ael, "jobTitle"));
        person.setLastname(getNVal(ael, "lastname"));
        person.setLinkMedicalAssociation(getNVal(ael, "linkMedicalAssociation"));
        person.setMedicalAssociation(getNVal(ael, "medicalAssociation"));
        person.setPosition(new Byte(getNVal(ael, "position")).byteValue());
        person.setSalutation(getNVal(ael, "salutation"));
        person.setSex(new Byte(getNVal(ael, "sex")).byteValue());
        person.setTitle(getNVal(ael, "title"));
        person.getUnits().add(unit);
        person = getPersonHbmDao().create(person);
    } catch (Exception exe) {
        log.warn("Error setting values: ", exe);
    }
    try {
        if (log.isDebugEnabled())
            log.debug("looking for addresses to import for person " + person.getPersonId());
        Iterator itAdr = XercesHelper.findNodes(ael, "./address");
        while (itAdr.hasNext()) {
            Element adrEl = (Element) itAdr.next();
            if (log.isDebugEnabled())
                log.debug("found address to import");
            AddressHbm local = createAddressHbm(adrEl, useNewIds);
            person.addAddress(local);
        }
    } catch (Exception exe) {
        if (log.isWarnEnabled())
            log.warn("Error importing addresses: ", exe);
        throw new CreateException(exe.getMessage());
    }
    try {
        if (log.isDebugEnabled())
            log.debug("looking for talktimes to import for person " + person.getPersonId());
        Iterator itTTimes = XercesHelper.findNodes(ael, "./talktime");
        while (itTTimes.hasNext()) {
            Element elm = (Element) itTTimes.next();
            if (log.isDebugEnabled())
                log.debug("found talktime to import");
            TalktimeHbm local = createTalktimeHbm(elm, useNewIds);
            person.addTalktime(local);
        }
    } catch (Exception exe) {
        if (log.isWarnEnabled())
            log.warn("Error importing talktimes: ", exe);
        throw new Exception(exe.getMessage());
    }
    mappingPersons.put(Long.parseLong(ael.getAttribute("id")), person.getPersonId());
    return person;
}