1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.jcr;
16  
17  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
18  
19  import javax.jcr.RepositoryException;
20  import javax.jcr.Session;
21  
22  /**
23   * <a href="JCRFactoryUtil.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Michael Young
26   */
27  public class JCRFactoryUtil {
28  
29      public static JCRFactory getJCRFactory() {
30          if (_jcrFactory == null) {
31              _jcrFactory = (JCRFactory)PortalBeanLocatorUtil.locate(
32                  _JCR_FACTORY);
33          }
34  
35          return _jcrFactory;
36      }
37  
38      public static Session createSession(String workspaceName)
39          throws RepositoryException {
40  
41          if (workspaceName == null) {
42              workspaceName = JCRFactory.WORKSPACE_NAME;
43          }
44  
45          return getJCRFactory().createSession(workspaceName);
46      }
47  
48      public static Session createSession() throws RepositoryException {
49          return createSession(null);
50      }
51  
52      public static void initialize() throws RepositoryException {
53          getJCRFactory().initialize();
54      }
55  
56      public static void prepare() throws RepositoryException {
57          getJCRFactory().prepare();
58      }
59  
60      public static void shutdown() {
61          getJCRFactory().shutdown();
62      }
63  
64      private static final String _JCR_FACTORY = JCRFactory.class.getName();
65  
66      private static JCRFactory _jcrFactory;
67  
68  }