Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ModeShape Distribution 3.0.0.Alpha6
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.modeshape.jcr.api
Class JndiRepositoryFactory

    java.lang.Object
      org.modeshape.jcr.api.JndiRepositoryFactory

All Implemented Interfaces:
  RepositoryFactory

    public class JndiRepositoryFactory

extends Object
implements RepositoryFactory

Service provider for the JCR2 `RepositoryFactory` interface. This class provides a single public method, `getRepository(Map)`, that enables finding a JCR repository that is registered in JNDI.

The canonical way to get a reference to this class is to use the `ServiceLoader`. For example, when the `Repository` instance is registered in JNDI, the following code will find it via the ServiceLoader:

     String jndiUrl = "jndi:jcr/local/myRepository";
     Map parameters = Collections.singletonMap(JndiRepositoryFactory.URL, configUrl);
     Repository repository;

     for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
         repository = factory.getRepository(parameters);
         if (repository != null) break;
     }

Or, if the ModeShape engine is registered in JNDI at "jcr/local", the same technique can be used with a slightly modified URL parameter:

     String jndiUrl = "jndi:jcr/local?repositoryName=myRepository"; // Different URL
     Map parameters = Collections.singletonMap(JndiRepositoryFactory.URL, configUrl);
     Repository repository;

     for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
         repository = factory.getRepository(parameters);
         if (repository != null) break;
     }

Alternatively, the repository name can be provided completely separately from the JNDI URL (again, if the ModeShape engine is registered in JNDI at "jcr/local"):

     String jndiUrl = "jndi:jcr/local";
     String repoName = "myRepository";

     Map<String, String> parameters = new HashMap<String, String>();
     parameters.put(org.modeshape.jcr.api.JndiRepositoryFactory.URL, jndiUrl);
     parameters.put(org.modeshape.jcr.api.JndiRepositoryFactory.REPOSITORY_NAME, repoName);

     Repository repository = null;
     for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
         repository = factory.getRepository(parameters);
         if (repository != null) break;
     }

See Also:
  `getRepository(Map)`, `RepositoryFactory.getRepository(Map)`

Field Summary
`static String` | `REPOSITORY_NAME` The name of the key for the ModeShape JCR repository name in the parameter map.
`static String` | `REPOSITORY_NAME_PARAM` The name of the URL parameter that specifies the repository name.
`static String` | `URL` The name of the key for the ModeShape JCR URL in the parameter map.

Constructor Summary
`JndiRepositoryFactory()`

Method Summary
`Repository` | `getRepository(Map parameters)`
`protected String` | `getRepositoryNameFrom(URL url, Map<String,Object> parameters)`
`Set<String>` | `getRepositoryNames(Map<String,Object> parameters)` Get the names of the available repositories given the supplied parameters (which must have a URL pointing to a `Repositories` object).
`protected URL` | `getUrlFrom(Map<String,Object> parameters)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### URL

    public static final String URL

  The name of the key for the ModeShape JCR URL in the parameter map.

  For example, define a URL that points to the configuration file for your repository:

       String jndiUrl = "jndi:jcr/local/myRepository";

       Map<String, String> parameters = new HashMap<String, String>();
       parameters.put(org.modeshape.jcr.api.JndiRepositoryFactory.URL, configUrl);

       Repository repository = null;
       for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
           repository = factory.getRepository(parameters);
           if (repository != null) break;
       }

  See Also:
    Constant Field Values

### REPOSITORY_NAME

    public static final String REPOSITORY_NAME

  The name of the key for the ModeShape JCR repository name in the parameter map. This can be used as with a `URL` that contains the JNDI name of a `Repositories` implementation.

  For example:

       String jndiUrl = "jndi:jcr/local";
       String repoName = "myRepository";

       Map<String, String> parameters = new HashMap<String, String>();
       parameters.put(org.modeshape.jcr.api.JndiRepositoryFactory.URL, jndiUrl);
       parameters.put(org.modeshape.jcr.api.JndiRepositoryFactory.REPOSITORY_NAME, repoName);

       Repository repository = null;
       for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
           repository = factory.getRepository(parameters);
           if (repository != null) break;
       }

  See Also:
    Constant Field Values

### REPOSITORY_NAME_PARAM

    public static final String REPOSITORY_NAME_PARAM

  The name of the URL parameter that specifies the repository name.

  See Also:
    Constant Field Values

Constructor Detail

### JndiRepositoryFactory

    public JndiRepositoryFactory()

Method Detail

### getRepository

    public Repository getRepository(Map parameters)
                             throws RepositoryException

  Specified by:
    `getRepository` in interface `RepositoryFactory`
  Throws:
    `RepositoryException`

### getUrlFrom

    protected URL getUrlFrom(Map<String,Object> parameters)

### getRepositoryNameFrom

    protected String getRepositoryNameFrom(URL url,
                                           Map<String,Object> parameters)

### getRepositoryNames

    public Set<String> getRepositoryNames(Map<String,Object> parameters)
                                   throws RepositoryException

  Get the names of the available repositories given the supplied parameters (which must have a URL pointing to a `Repositories` object).

  Parameters:
    `parameters` - map of string key/value pairs as repository arguments or `null` if none are provided and a client wishes to connect to a default repository.
  Returns:
    the immutable set of repository names provided by this server; may be empty if the implementation does not understand the passed `parameters`.
  Throws:
    `RepositoryException` - if if no suitable repository is found or another error occurs.
    `RepositoryException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ModeShape Distribution 3.0.0.Alpha6
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.