001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }