1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }