java/SpringDemo1/SpringDemo1-war/src/java/cz/frantovo/springDemo1/web/SpringDemo1Bean.java
changeset 2 d549a4eb6aa9
parent 1 9a3fced9634d
child 5 7cf0cbef2936
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/SpringDemo1/SpringDemo1-war/src/java/cz/frantovo/springDemo1/web/SpringDemo1Bean.java	Wed Feb 10 21:05:17 2010 +0100
     1.3 @@ -0,0 +1,39 @@
     1.4 +package cz.frantovo.springDemo1.web;
     1.5 +
     1.6 +import cz.frantovo.springDemo1.KnihaDAORemote;
     1.7 +import cz.frantovo.springDemo1.dao.KnihaDAO;
     1.8 +import cz.frantovo.springDemo1.dto.Kniha;
     1.9 +import java.util.Collection;
    1.10 +import java.util.logging.Level;
    1.11 +import java.util.logging.Logger;
    1.12 +import javax.naming.Context;
    1.13 +import javax.naming.InitialContext;
    1.14 +import javax.naming.NamingException;
    1.15 +
    1.16 +/**
    1.17 + *
    1.18 + * @author fiki
    1.19 + */
    1.20 +public class SpringDemo1Bean {
    1.21 +
    1.22 +    private static final Logger log = Logger.getLogger(SpringDemo1Bean.class.getSimpleName());
    1.23 +    private KnihaDAORemote knihaDAO;
    1.24 +
    1.25 +    public Collection<Kniha> getKnihy() {
    1.26 +	return lookupCilDAO().getKnihy();
    1.27 +    }
    1.28 +
    1.29 +    private KnihaDAORemote lookupCilDAO() {
    1.30 +        if (knihaDAO == null) {
    1.31 +            try {
    1.32 +                Context c = new InitialContext();
    1.33 +                knihaDAO = (KnihaDAORemote) c.lookup("cz.frantovo.springDemo1.KnihaDAORemote");
    1.34 +            } catch (NamingException e) {
    1.35 +                log.log(Level.SEVERE, "Chyba při hledání CilDAO", e);
    1.36 +                throw new RuntimeException(e);
    1.37 +            }
    1.38 +        }
    1.39 +        return knihaDAO;
    1.40 +    }
    1.41 +
    1.42 +}