KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jcr > file > FileRepository


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jcr.file;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.jcr.base.BaseRepository;
34 import com.caucho.util.L10N;
35 import com.caucho.vfs.Path;
36
37 import javax.jcr.Credentials;
38 import javax.jcr.LoginException;
39 import javax.jcr.NoSuchWorkspaceException;
40 import javax.jcr.RepositoryException;
41 import javax.jcr.Session;
42
43 /**
44  * Represents a repository based on a filesystem.
45  *
46  * Configuration looks like:
47  *
48  * <pre>
49  * &lt;resource jndi-name="crm/wiki"
50  * type="com.caucho.cms.file.FileRepository">
51  * &lt;init>
52  * &lt;root>wiki-data&lt;/root>
53  * &lt;/init>
54  * &lt;/resource>
55  * </pre>
56  */

57 public class FileRepository extends BaseRepository {
58   private static final L10N L = new L10N(FileRepository.class);
59   
60   private Path _root;
61
62   /**
63    * Sets the file root.
64    */

65   public void setRoot(Path root)
66   {
67     _root = root.createRoot();
68   }
69
70   /**
71    * Returns the file root.
72    */

73   public Path getRoot()
74   {
75     return _root;
76   }
77
78   /**
79    * Initialize the FileRespository.
80    */

81   public void init()
82     throws ConfigException
83   {
84     if (_root == null)
85       throw new ConfigException(L.l("'root' property is required for FileRepository"));
86   }
87
88   /**
89    * Returns the value for Repository feature descriptor keys.
90    */

91   public String JavaDoc getDescriptor(String JavaDoc key)
92   {
93     if (REP_NAME_DESC.equals(key))
94       return "Resin File Repository";
95     else
96       return super.getDescriptor(key);
97   }
98
99   /**
100    * Opens a new session, specifying the security credentials
101    * and a workspace.
102    *
103    * @param credentials the security credentials
104    * @param workspaceName select an optional workspace
105    */

106   public Session login(Credentials credentials, String JavaDoc workspaceName)
107     throws LoginException,
108        NoSuchWorkspaceException,
109        RepositoryException
110   {
111     return new FileSession(this);
112   }
113 }
114
Popular Tags