001    /**
002     * Copyright (c) 2000-2010 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.jcr;
016    
017    import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
018    
019    import javax.jcr.RepositoryException;
020    import javax.jcr.Session;
021    
022    /**
023     * @author Michael Young
024     */
025    public class JCRFactoryUtil {
026    
027            public static JCRFactory getJCRFactory() {
028                    if (_jcrFactory == null) {
029                            _jcrFactory = (JCRFactory)PortalBeanLocatorUtil.locate(
030                                    _JCR_FACTORY);
031                    }
032    
033                    return _jcrFactory;
034            }
035    
036            public static Session createSession(String workspaceName)
037                    throws RepositoryException {
038    
039                    if (workspaceName == null) {
040                            workspaceName = JCRFactory.WORKSPACE_NAME;
041                    }
042    
043                    return getJCRFactory().createSession(workspaceName);
044            }
045    
046            public static Session createSession() throws RepositoryException {
047                    return createSession(null);
048            }
049    
050            public static void initialize() throws RepositoryException {
051                    getJCRFactory().initialize();
052            }
053    
054            public static void prepare() throws RepositoryException {
055                    getJCRFactory().prepare();
056            }
057    
058            public static void shutdown() {
059                    getJCRFactory().shutdown();
060            }
061    
062            private static final String _JCR_FACTORY = JCRFactory.class.getName();
063    
064            private static JCRFactory _jcrFactory;
065    
066    }