org.priha
Class RepositoryManager

java.lang.Object
  extended by org.priha.RepositoryManager

public final class RepositoryManager
extends java.lang.Object

This is the main API for getting yourself a Repository object, and as such, probably the only class you will need outside the basic JCR classes (unless you want to develop a RepositoryProvider, but that's a whole another story).

The simplest way of getting yourself a Priha JCR Repository is to simply call RepositoryManager.getRepository, which will find your "priha.properties" file and return a ready-to-use repository. This default repository is a singleton.

Simple basic usage example which stores "some text" to the repository, and then retrieves and prints it:

     Repository rep = RepositoryManager.getRepository();
     Session session = rep.login();
     
     Node nd = session.getRootNode().addNode("myfirstnode");
     nd.addProperty("myfirstproperty", "some text");
     session.save();
     
     Property newp = (Property)session.getItem("/myfirstnode/myfirstproperty");
     System.out.println( newp.getString() );
  

The workspace you get with Repository.login() depends on the configuration. It is always the first workspace defined for the first provider that is on the "priha.providers" line.


Field Summary
static java.lang.String NS_PRIHA
          The Priha Namespace.
 
Method Summary
static RepositoryImpl getRepository()
          Returns a default repository object for no-pain setup.
static RepositoryImpl getRepository(java.util.Properties prefs)
          Returns a new repository object based on the Properties given.
static RepositoryImpl getRepository(java.lang.String propertyFilename)
          Returns a new repository object by locating the property file given.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NS_PRIHA

public static final java.lang.String NS_PRIHA
The Priha Namespace. Value is "http://www.priha.org/ns/1.0".

See Also:
Constant Field Values
Method Detail

getRepository

public static RepositoryImpl getRepository()
                                    throws ConfigurationException
Returns a default repository object for no-pain setup. The Repository object is shared among all requestors of the default repository.

This method will search for a "priha.properties" configuration file from your classpath (and /WEB-INF/) and will use that. Failing to find one, it will use the internal defaults (from the built-in priha_default.properties), which almost certainly is not something you want - unless you just want to test Priha.

Returns:
The default repository object.s
Throws:
ConfigurationException - If there is a problem with the discovered preferences.

getRepository

public static RepositoryImpl getRepository(java.util.Properties prefs)
                                    throws ConfigurationException
Returns a new repository object based on the Properties given. This method guarantees a new Repository object, so it's a good idea to cache whatever you get from here.

Note that if you do get two Repositories who share the same property file, you will almost certainly hit some nasty race conditions with the repository itself. So be very, very careful.

Parameters:
prefs - A Properties object containing preferences in Priha format.
Returns:
A new Repository.
Throws:
ConfigurationException - If the preferences were incorrect in some way.

getRepository

public static RepositoryImpl getRepository(java.lang.String propertyFilename)
                                    throws ConfigurationException
Returns a new repository object by locating the property file given. This method also guarantees a new Repository object.

This class is somewhat lenient in how it searches the property file. It first tries the name as-is, then it tries to locate the file from the classpath root, and then it tries to search your WEB-INF library.

Note that if you do get two Repositories who share the same property file, you will almost certainly hit some nasty race conditions with the repository itself. So be very, very careful.

Parameters:
propertyFilename - A name for the property file.
Returns:
A JCR Repository.
Throws:
ConfigurationException - If the repository cannot be configured or the property file cannot be located.