001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.spring.jndi;
016    
017    import com.liferay.portal.kernel.jndi.JNDIUtil;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.util.PropsKeys;
021    import com.liferay.portal.util.PropsUtil;
022    
023    import java.util.Properties;
024    
025    import javax.naming.Context;
026    import javax.naming.InitialContext;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class JndiObjectFactoryBean
032            extends org.springframework.jndi.JndiObjectFactoryBean {
033    
034            @Override
035            protected Object lookup() {
036                    try {
037                            Properties properties = PropsUtil.getProperties(
038                                    PropsKeys.JNDI_ENVIRONMENT, true);
039    
040                            Context context = new InitialContext(properties);
041    
042                            return JNDIUtil.lookup(context, getJndiName());
043                    }
044                    catch (Exception e) {
045                            _log.error("Unable to lookup " + getJndiName());
046    
047                            return null;
048                    }
049            }
050    
051            private static Log _log = LogFactoryUtil.getLog(
052                    JndiObjectFactoryBean.class);
053    
054    }