The Seam JCR Module aims to simplify the integration points between JCR implementations and CDI applications.
The Seam JCR module is compatible with JCR 2.0 implementations. It strictly compiles against JCR 2.0. However, test cases are executed against both ModeShape and JackRabbit to ensure compatibility.
If you are using Maven as your build tool, you can add the following single dependency to your pom.xml file to include Seam JCR:
<dependency>
<groupId>org.jboss.seam.jcr</groupId>
<artifactId>seam-jcr</artifactId>
<version>${seam.jcr.version}</version>
</dependency>
Substitute the expression ${seam.jcr.version} with the most recent or appropriate version of Seam JCR. Alternatively, you can create a Maven user-defined property to satisfy this substitution so you can centrally manage the version.
Alternatively, you can use the API at compile time and only include the implementation at runtime. This protects you from inadvertantly depending on an implementation class.
<dependency>
<groupId>org.jboss.seam.jcr</groupId>
<artifactId>seam-jcr-api</artifactId>
<version>${seam.jcr.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.seam.jcr</groupId>
<artifactId>seam-jcr-impl</artifactId>
<version>${seam.jcr.version}</version>
<scope>runtime</scope>
</dependency>
In addition to your Seam JCR dependencies, you must also declare a dependency on a JCR Implementation.
In order to activate ModeShape support within your application, you need to include ModeShape on your classpath. At a minimum, the following maven dependencies must be satisfied.
<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr</artifactId>
<version>${modeshape.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene.version}</version>
</dependency>
Substitute ${modeshape.version} for the ModeShape version you are running against. Currently, Seam JCR tests against 2.5.0.Final. In addition, Lucene is required to run ModeShape. Please consult the ModeShape getting stated guide for exact versions.
In order to use ModeShape's Repository and Session objects in your application, you must define an injection point using the JcrConfiguration annotation based on ModeShape's required configuration parameters. Please review the ModeShape getting started guide for further details.
@Inject @JcrConfiguration(name="org.modeshape.jcr.URL",value="file:path/to/modeshape.xml?repositoryName=MyRepo") Repository repository; @Inject @JcrConfiguration(name="org.modeshape.jcr.URL",value="file:path/to/modeshape.xml?repositoryName=MyRepo") Session session;
In order to activate JackRabbit support within your application, you need to include JackRabbit on your classpath. At a minimum, the following maven dependency must be satisfied.
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<version>${jackrabbit.version}</version>
</dependency>
Substitute ${jackrabbit.version} for the JackRabbit version you are running against. Currently, Seam JCR tests against 2.2.4. Please review JackRabbit documentation to determine any additional dependencies.
In order to use JackRabbit's Repository and Session objects in your application, you must define an injection point using the JcrConfiguration annotation based on JackRabbit's required configuration parameters.
@Inject @JcrConfiguration(name="org.apache.jackrabbit.repository.home",value="target") Repository repository; @Inject @JcrConfiguration(name="org.apache.jackrabbit.repository.home",value="target") Session session;
Seam JCR provides functionality to fire CDI Events based on events found in JCR. The rules of how events are fired are based around the underlying implementation.
To observe an event, use the @Observes and the additional qualifiers on seam-jcr-api module (Check package org.jboss.seam.jcr.annotations.events). If you need to watch any JCR event, then avoid using any Qualifier at all.
import javax.jcr.observation.Event; public void observeAdded(@Observes @NodeAdded Event evt) { // Called when a node is added } public void observeAll(@Observes javax.jcr.observation.Event evt) { // Called when any node event occurs }