Example usage for com.liferay.portal.kernel.jndi JNDIUtil lookup

List of usage examples for com.liferay.portal.kernel.jndi JNDIUtil lookup

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.jndi JNDIUtil lookup.

Prototype

public static Object lookup(Context context, String location) throws NamingException 

Source Link

Usage

From source file:com.liferay.mail.util.MailSessionFactoryBean.java

License:Open Source License

@Override
protected Session createInstance() throws Exception {
    Properties properties = PropsUtil.getProperties(_propertyPrefix, true);

    String jndiName = properties.getProperty("jndi.name");

    if (Validator.isNotNull(jndiName)) {
        try {/*from   ww w.  java 2 s  .co m*/
            return (Session) JNDIUtil.lookup(new InitialContext(), jndiName);
        } catch (Exception e) {
            _log.error("Unable to lookup " + jndiName, e);
        }
    }

    Session session = Session.getInstance(properties);

    if (_log.isDebugEnabled()) {
        session.setDebug(true);

        SortedProperties sortedProperties = new SortedProperties(session.getProperties());

        _log.debug("Properties for prefix " + _propertyPrefix);

        sortedProperties.list(System.out);
    }

    return session;
}