Problem with custom node types
craigching Sep 8, 2010 2:34 PMHi!
First, I'm very new to JCR and ModeShape in particular, I've dabbled a bit in Jackrabbit, but I'd still consider myself pretty new to the subject.
I'm sure I'm missing something fundamental, but I just can't figure out what it is. I've got the following code working with Jackrabbit, but I want to use ModeShape (in particular the Infinispan connector). Here's my code:
public class JcrTest {
static public void main(String [] args) throws Exception {
Repository repo = null;
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("org.modeshape.jcr.URL", "file:cars-repository-config.xml?repositoryName=Cars");
for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
repo = factory.getRepository(parameters);
if (repo != null) {
break;
}
}
if (repo != null) {
Session session = repo.login();
String [] prefixes = session.getNamespacePrefixes();
for (String prefix : prefixes) {
System.out.println("Prefix: " + prefix);
}
Workspace ws = session.getWorkspace();
System.out.println("WS Name: " + ws.getName());
Node root = session.getRootNode();
Node type = root.addNode("Hybrid", "nt:unstructured");
for(int i=0;i<10;i++) {
Node car = type.addNode("car_" + i, "car:Car");
car.setProperty("car:maker", "Volkswagen");
car.setProperty("car:model", "Passat");
car.setProperty("car:year", "2010");
car.setProperty("car:msrp", "$32,000");
}
session.save();
}
}
and here is my repository configuration (basically a bastardization of the repository example):
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:mode="http://www.modeshape.org/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
<mode:sources jcr:primaryType="nt:unstructured">
<mode:source jcr:name="Cars" mode:classname="org.modeshape.graph.connector.inmemory.InMemoryRepositorySource" mode:retryLimit="3" mode:defaultWorkspaceName="cars-workspace" mode:updatesAllowed="true"/>
</mode:sources>
<mode:repositories>
<mode:repository jcr:name="Cars">
<!-- Specify the source that should be used for the repository -->
<mode:source>Cars</mode:source>
<!-- Define the options for the JCR repository, using camelcase version of JcrRepository.Option names -->
<mode:options jcr:primaryType="mode:options">
<jaasLoginConfigName jcr:primaryType="mode:option" mode:value="modeshape-jcr"/>
</mode:options>
<!-- Define any custom node types. Importing CND files via JcrConfiguration is equivalent to specifying here. -->
<jcr:nodeTypes mode:resource="file:cars.cnd" />
<!-- Define any namespaces for this repository, other than those already defined by JCR or ModeShape -->
<namespaces jcr:primaryType="mode:namespaces">
<car jcr:primaryType="mode:namespace" mode:uri="http://www.modeshape.org/examples/cars/1.0"/>
</namespaces>
</mode:repository>
</mode:repositories>
</configuration>