DNA SVN: r976 - trunk/docs/examples/gettingstarted/sequencers/src/main/resources.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-04 17:46:34 -0400 (Thu, 04 Jun 2009)
New Revision: 976
Removed:
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitConfig.xml
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/log4j.properties
Log:
DNA-405 Removed all remaining traces of Jackrabbit from the sequencer example.
Deleted: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitConfig.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitConfig.xml 2009-06-04 21:42:27 UTC (rev 975)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitConfig.xml 2009-06-04 21:46:34 UTC (rev 976)
@@ -1,115 +0,0 @@
-<?xml version="1.0"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN"
- "http://jackrabbit.apache.org/dtd/repository-1.2.dtd">
-<!-- Example Repository Configuration File -->
-<Repository>
- <!--
- virtual file system where the repository stores global state
- (e.g. registered namespaces, custom node types, etc.)
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/repository"/>
- </FileSystem>
-
- <!--
- security configuration
- -->
- <Security appName="Jackrabbit">
- <!--
- access manager:
- class: FQN of class implementing the AccessManager interface
- -->
- <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager">
- <!-- <param name="config" value="${rep.home}/access.xml"/> -->
- </AccessManager>
-
- <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
- <!-- anonymous user name ('anonymous' is the default value) -->
- <param name="anonymousId" value="anonymous"/>
- <!--
- default user name to be used instead of the anonymous user
- when no login credentials are provided (unset by default)
- -->
- <!-- <param name="defaultUserId" value="superuser"/> -->
- </LoginModule>
- </Security>
-
- <!--
- location of workspaces root directory and name of default workspace
- -->
- <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
- <!--
- workspace configuration template:
- used to create the initial workspace if there's no workspace yet
- -->
- <Workspace name="Jackrabbit Core">
- <!--
- virtual file system of the workspace:
- class: FQN of class implementing the FileSystem interface
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${wsp.home}"/>
- </FileSystem>
- <!--
- persistence manager of the workspace:
- class: FQN of class implementing the PersistenceManager interface
- -->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager">
- <param name="persistent" value="false"/>
- </PersistenceManager>
- <!--
- Search index and the file system it uses.
- class: FQN of class implementing the QueryHandler interface
- -->
- <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${wsp.home}/index"/>
- </SearchIndex>
- </Workspace>
-
- <!--
- Configures the versioning
- -->
- <Versioning rootPath="${rep.home}/version">
- <!--
- Configures the filesystem to use for versioning for the respective
- persistence manager
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/version" />
- </FileSystem>
-
- <!--
- Configures the persistence manager to be used for persisting version state.
- Please note that the current versioning implementation is based on
- a 'normal' persistence manager, but this could change in future
- implementations.
- -->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager">
- <param name="persistent" value="false"/>
- </PersistenceManager>
- </Versioning>
-
- <!--
- Search index for content that is shared repository wide
- (/jcr:system tree, contains mainly versions)
- -->
- <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${rep.home}/repository/index"/>
- </SearchIndex>
-</Repository>
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/log4j.properties
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/log4j.properties 2009-06-04 21:42:27 UTC (rev 975)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/log4j.properties 2009-06-04 21:46:34 UTC (rev 976)
@@ -10,7 +10,3 @@
# Set up the default logging to be INFO level, then override specific units
log4j.logger.org.jboss.dna=INFO
-# Jackrabbit logging
-log4j.logger.org.apache.jackrabbit=WARN, stdout
-log4j.logger.org.apache.derby=INFO, stdout
-
16 years, 6 months
DNA SVN: r975 - in trunk: dna-repository/src/main/java/org/jboss/dna/repository/sequencer and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-04 17:42:27 -0400 (Thu, 04 Jun 2009)
New Revision: 975
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueComparators.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
Log:
DNA-389 More minor corrections in how property types are determined for different values (including values that are instances of non-canonical classes, such as Integer). Discovered DNA-443, so adding temporary ignore to the sequencing test of Java source code.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java 2009-06-04 19:29:32 UTC (rev 974)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java 2009-06-04 21:42:27 UTC (rev 975)
@@ -26,10 +26,13 @@
import java.math.BigDecimal;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
@@ -42,20 +45,45 @@
@Immutable
public enum PropertyType {
- STRING("String", ValueComparators.STRING_COMPARATOR, String.class),
- BINARY("Binary", ValueComparators.BINARY_COMPARATOR, Binary.class),
- LONG("Long", ValueComparators.LONG_COMPARATOR, Long.class),
- DOUBLE("Double", ValueComparators.DOUBLE_COMPARATOR, Double.class),
- DECIMAL("Decimal", ValueComparators.DECIMAL_COMPARATOR, BigDecimal.class),
- DATE("Date", ValueComparators.DATE_TIME_COMPARATOR, DateTime.class),
- BOOLEAN("Boolean", ValueComparators.BOOLEAN_COMPARATOR, Boolean.class),
- NAME("Name", ValueComparators.NAME_COMPARATOR, Name.class),
- PATH("Path", ValueComparators.PATH_COMPARATOR, Path.class),
- UUID("UUID", ValueComparators.UUID_COMPARATOR, UUID.class),
- REFERENCE("Reference", ValueComparators.REFERENCE_COMPARATOR, Reference.class),
- URI("URI", ValueComparators.URI_COMPARATOR, URI.class),
- OBJECT("Object", ValueComparators.OBJECT_COMPARATOR, Object.class);
+ STRING("String", ValueComparators.STRING_COMPARATOR, new ObjectCanonicalizer(), String.class),
+ BINARY("Binary", ValueComparators.BINARY_COMPARATOR, new ObjectCanonicalizer(), Binary.class),
+ LONG("Long", ValueComparators.LONG_COMPARATOR, new LongCanonicalizer(), Long.class, Integer.class, Short.class),
+ DOUBLE("Double", ValueComparators.DOUBLE_COMPARATOR, new DoubleCanonicalizer(), Double.class, Float.class),
+ DECIMAL("Decimal", ValueComparators.DECIMAL_COMPARATOR, new ObjectCanonicalizer(), BigDecimal.class),
+ DATE("Date", ValueComparators.DATE_TIME_COMPARATOR, new ObjectCanonicalizer(), DateTime.class),
+ BOOLEAN("Boolean", ValueComparators.BOOLEAN_COMPARATOR, new ObjectCanonicalizer(), Boolean.class),
+ NAME("Name", ValueComparators.NAME_COMPARATOR, new ObjectCanonicalizer(), Name.class),
+ PATH("Path", ValueComparators.PATH_COMPARATOR, new ObjectCanonicalizer(), Path.class),
+ UUID("UUID", ValueComparators.UUID_COMPARATOR, new ObjectCanonicalizer(), UUID.class),
+ REFERENCE("Reference", ValueComparators.REFERENCE_COMPARATOR, new ObjectCanonicalizer(), Reference.class),
+ URI("URI", ValueComparators.URI_COMPARATOR, new ObjectCanonicalizer(), URI.class),
+ OBJECT("Object", ValueComparators.OBJECT_COMPARATOR, new ObjectCanonicalizer(), Object.class);
+ private static interface Canonicalizer {
+ Object canonicalizeValue( Object value );
+ }
+
+ protected final static class ObjectCanonicalizer implements Canonicalizer {
+ public Object canonicalizeValue( Object value ) {
+ return value;
+ }
+ }
+
+ protected final static class LongCanonicalizer implements Canonicalizer {
+ public Object canonicalizeValue( Object value ) {
+ if (value instanceof Integer) return new Long((Integer)value);
+ if (value instanceof Short) return new Long((Short)value);
+ return value;
+ }
+ }
+
+ protected final static class DoubleCanonicalizer implements Canonicalizer {
+ public Object canonicalizeValue( Object value ) {
+ if (value instanceof Float) return new Double((Float)value);
+ return value;
+ }
+ }
+
private static final List<PropertyType> ALL_PROPERTY_TYPES;
static {
List<PropertyType> types = new ArrayList<PropertyType>();
@@ -67,14 +95,24 @@
private final String name;
private final Comparator<?> comparator;
+ private final Canonicalizer canonicalizer;
private final Class<?> valueClass;
+ private final Set<Class<?>> castableValueClasses;
private PropertyType( String name,
Comparator<?> comparator,
- Class<?> valueClass ) {
+ Canonicalizer canonicalizer,
+ Class<?> valueClass,
+ Class<?>... castableClasses ) {
this.name = name;
this.comparator = comparator;
+ this.canonicalizer = canonicalizer;
this.valueClass = valueClass;
+ if (castableClasses != null && castableClasses.length != 0) {
+ castableValueClasses = Collections.unmodifiableSet(new HashSet<Class<?>>(Arrays.asList(castableClasses)));
+ } else {
+ castableValueClasses = Collections.emptySet();
+ }
}
public Class<?> getValueClass() {
@@ -89,21 +127,39 @@
return this.comparator;
}
- public boolean isTypeFor( Object value ) {
- return this.valueClass.isInstance(value);
+ /**
+ * Obtain a value of this type in its canonical form. Some property types allow values to be instances of the canonical class
+ * or an alternative class. This method ensures that the value is always an instance of the canonical class.
+ * <p>
+ * Note that this method does <i>not</i> cast from one property type to another.
+ * </p>
+ *
+ * @param value the property value
+ * @return the value in canonical form
+ */
+ public Object getCanonicalValue( Object value ) {
+ return this.canonicalizer.canonicalizeValue(value);
}
- public boolean isTypeForEach( Iterable<?> values ) {
+ public final boolean isTypeFor( Object value ) {
+ if (this.valueClass.isInstance(value)) return true;
+ for (Class<?> valueClass : castableValueClasses) {
+ if (valueClass.isInstance(value)) return true;
+ }
+ return false;
+ }
+
+ public final boolean isTypeForEach( Iterable<?> values ) {
for (Object value : values) {
- if (!this.valueClass.isInstance(value)) return false;
+ if (!isTypeFor(value)) return false;
}
return true;
}
- public boolean isTypeForEach( Iterator<?> values ) {
+ public final boolean isTypeForEach( Iterator<?> values ) {
while (values.hasNext()) {
Object value = values.next();
- if (!this.valueClass.isInstance(value)) return false;
+ if (!isTypeFor(value)) return false;
}
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueComparators.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueComparators.java 2009-06-04 19:29:32 UTC (rev 974)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueComparators.java 2009-06-04 21:42:27 UTC (rev 975)
@@ -308,6 +308,11 @@
if (o2 == null) return 1;
PropertyType type1 = PropertyType.discoverType(o1);
PropertyType type2 = PropertyType.discoverType(o2);
+
+ // Canonicalize the values ...
+ o1 = type1.getCanonicalValue(o1);
+ o2 = type2.getCanonicalValue(o2);
+
if (type1 != PropertyType.OBJECT && type2 != PropertyType.OBJECT) {
if (type1 == type2) return ((Comparator<Object>)type1.getComparator()).compare(o1, o2);
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java 2009-06-04 19:29:32 UTC (rev 974)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java 2009-06-04 21:42:27 UTC (rev 975)
@@ -178,13 +178,18 @@
SequencerContext context ) {
PathFactory pathFactory = context.getExecutionContext().getValueFactories().getPathFactory();
+ if (targetPath.isRoot()) return;
Path workingPath = pathFactory.createRootPath();
Path.Segment[] segments = targetPath.getSegmentsArray();
- for (int i = 0; i < segments.length; i++) {
- workingPath = pathFactory.create(workingPath, segments[i]);
-
- context.graph().createIfMissing(workingPath);
+ int i = 0;
+ if (segments.length > 1) {
+ for (int max = segments.length - 1; i < max; i++) {
+ workingPath = pathFactory.create(workingPath, segments[i]);
+ context.graph().createIfMissing(workingPath);
+ }
}
+ workingPath = pathFactory.create(workingPath, segments[i]);
+ context.graph().create(workingPath);
}
/**
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-04 19:29:32 UTC (rev 974)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-04 21:42:27 UTC (rev 975)
@@ -103,9 +103,9 @@
config.sequencer("Java Sequencer")
.usingClass("org.jboss.dna.sequencer.java.JavaMetadataSequencer")
.loadedFromClasspath()
- .setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
- .sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
- .andOutputtingTo("/mp3s/$1");
+ .setDescription("Sequences Java files to extract the AST structure of the Java source code")
+ .sequencingFrom("//(*.java[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/java/$1");
// Now start the client and tell it which repository and workspace to use ...
SequencingClient client = new SequencingClient(config, repositoryId, workspaceName);
Modified: trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-06-04 19:29:32 UTC (rev 974)
+++ trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-06-04 21:42:27 UTC (rev 975)
@@ -26,6 +26,7 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -91,9 +92,9 @@
// Set up the Java source file sequencer ...
config.sequencer("Java Sequencer")
.usingClass(JavaMetadataSequencer.class)
- .setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
- .sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
- .andOutputtingTo("/mp3s/$1");
+ .setDescription("Sequences Java files to extract the AST structure of the Java source code")
+ .sequencingFrom("//(*.java[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/java/$1");
// Now start the client and tell it which repository and workspace to use ...
client = new SequencingClient(config, repositoryId, workspaceName);
@@ -125,69 +126,64 @@
client.startRepository();
client.uploadFile();
- // Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
- // and to then shut down the DNA services (which will block until all sequencing has been completed) ...
- Thread.sleep(4000);
+ waitUntilSequencedNodesIs(1);
- assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
-
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
client.search();
}
- @Ignore
@Test
public void shouldUploadAndSequenceJpegFile() throws Exception {
client.setUserInterface(new MockUserInterface(this.jpegImageUrl, "/a/b/caution.jpeg", 1));
client.startRepository();
client.uploadFile();
- // Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
- // and to then shut down the DNA services (which will block until all sequencing has been completed) ...
- Thread.sleep(1000);
+ waitUntilSequencedNodesIs(1);
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
client.search();
-
- assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
}
- @Ignore
@Test
- public void shouldUploadAndNotSequencePictFile() throws Exception {
- client.setUserInterface(new MockUserInterface(this.pictImageUrl, "/a/b/caution.pict", 0));
+ public void shouldUploadAndSequenceMp3File() throws Exception {
+ client.setUserInterface(new MockUserInterface(this.mp3Url, "/a/b/test.mp3", 1));
client.startRepository();
client.uploadFile();
- // Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
- // and to then shut down the DNA services (which will block until all sequencing has been completed) ...
- Thread.sleep(1000);
+ waitUntilSequencedNodesIs(1);
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
client.search();
-
- assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(0l));
}
@Ignore
@Test
- public void shouldUploadAndSequenceMp3File() throws Exception {
- client.setUserInterface(new MockUserInterface(this.mp3Url, "/a/b/test.mp3", 1));
+ public void shouldUploadAndSequenceJavaSourceFile() throws Exception {
+ client.setUserInterface(new MockUserInterface(this.javaSourceUrl, "/a/b/MySource.java", 1));
client.startRepository();
client.uploadFile();
- // Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
- // and to then shut down the DNA services (which will block until all sequencing has been completed) ...
- Thread.sleep(1000);
+ waitUntilSequencedNodesIs(1);
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
client.search();
+ }
- assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
+ protected void waitUntilSequencedNodesIs( int totalNumberOfNodesSequenced ) throws InterruptedException {
+ // check 50 times, waiting 0.1 seconds between (for a total of 5 seconds max) ...
+ long numFound = 0;
+ for (int i = 0; i != 50; i++) {
+ numFound = client.getStatistics().getNumberOfNodesSequenced();
+ if (numFound >= totalNumberOfNodesSequenced) {
+ return;
+ }
+ Thread.sleep(100);
+ }
+ fail("Expected to find " + totalNumberOfNodesSequenced + " nodes sequenced, but found " + numFound);
}
@Test
@@ -203,21 +199,4 @@
}
}
- @Ignore
- @Test
- public void shouldUploadAndSequenceJavaSourceFile() throws Exception {
- client.setUserInterface(new MockUserInterface(this.javaSourceUrl, "/a/b/MySource.java", 1));
- client.startRepository();
- client.uploadFile();
-
- // Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
- // and to then shut down the DNA services (which will block until all sequencing has been completed) ...
- Thread.sleep(1000);
-
- // The sequencers should have run, so perform the search.
- // The mock user interface checks the results.
- client.search();
- assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1L));
- }
-
}
16 years, 6 months
DNA SVN: r974 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-04 15:29:32 -0400 (Thu, 04 Jun 2009)
New Revision: 974
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
Log:
DNA-442 Small change to allow node types to be registered in any order (within the batch)
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-04 19:16:36 UTC (rev 973)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-04 19:29:32 UTC (rev 974)
@@ -1177,8 +1177,6 @@
* <ol>
* <li>Residual child node definitions cannot be mandatory</li>
* <li>If the child node is auto-created, it must specify a default primary type name</li>
- * <li>All required primary types must already be fully registered with the type manager or must have been defined earlier in
- * the batch. <i>This requirement may be relaxed in a future version of DNA.</i></li>
* <li>If the child node overrides an existing child node definition from a supertype, the new definition must be mandatory if
* the old definition was mandatory</li>
* <li>The child node cannot override an existing child node definition from a supertype if the ancestor definition is
@@ -1268,8 +1266,6 @@
* <ol>
* <li>Residual child node definitions cannot be mandatory</li>
* <li>If the child node is auto-created, it must specify a default primary type name</li>
- * <li>All required primary types must already be fully registered with the type manager or must have been defined earlier in
- * the batch. <i>This requirement may be relaxed in a future version of DNA.</i></li>
* <li>If the child node overrides an existing child node definition from a supertype, the new definition must be mandatory if
* the old definition was mandatory</li>
* <li>The child node cannot override an existing child node definition from a supertype if the ancestor definition is
@@ -1346,8 +1342,6 @@
* <ol>
* <li>Residual child node definitions cannot be mandatory</li>
* <li>If the child node is auto-created, it must specify a default primary type name</li>
- * <li>All required primary types must already be fully registered with the type manager or must have been defined earlier in
- * the batch. <i>This requirement may be relaxed in a future version of DNA.</i></li>
* <li>If the child node overrides an existing child node definition from a supertype, the new definition must be mandatory if
* the old definition was mandatory</li>
* <li>The child node cannot override an existing child node definition from a supertype if the ancestor definition is
@@ -1774,8 +1768,6 @@
* <ol>
* <li>Residual child node definitions cannot be mandatory</li>
* <li>If the child node is auto-created, it must specify a default primary type name</li>
- * <li>All required primary types must already be fully registered with the type manager or must have been defined earlier in
- * the batch. This requirement may be relaxed in a future version of DNA.</li>
* <li>If the child node overrides an existing child node definition from a supertype, the new definition must be mandatory if
* the old definition was mandatory</li>
* <li>The child node cannot override an existing child node definition from a supertype if the ancestor definition is
16 years, 6 months
DNA SVN: r973 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-04 15:16:36 -0400 (Thu, 04 Jun 2009)
New Revision: 973
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
Log:
DNA-442 Small change to allow node types to be registered in any order (within the batch)
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-04 18:13:03 UTC (rev 972)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-04 19:16:36 UTC (rev 973)
@@ -1413,10 +1413,21 @@
List<JcrNodeDefinition> nodeDefs = new ArrayList<JcrNodeDefinition>(
nodeType.getDeclaredChildNodeDefinitions().length);
+ for (JcrNodeDefinition nodeDef : nodeType.getDeclaredChildNodeDefinitions()) {
+ nodeDefs.add(nodeDef.with(this.context).with(this));
+ }
+ // Create a new node type that also has the correct property and child node definitions associated
+ JcrNodeType newNodeType = new JcrNodeType(this.context, this, nodeType.getInternalName(), supertypes,
+ nodeType.getInternalPrimaryItemName(), nodeDefs, propertyDefs,
+ nodeType.isMixin(), nodeType.hasOrderableChildNodes());
+ typesPendingRegistration.add(newNodeType);
+ }
+
+ // Make sure the nodes have primary types that are either already registered, or pending registration ...
+ for (JcrNodeType nodeType : typesPendingRegistration) {
for (JcrNodeDefinition nodeDef : nodeType.getDeclaredChildNodeDefinitions()) {
JcrNodeType[] requiredPrimaryTypes = new JcrNodeType[nodeDef.requiredPrimaryTypeNames().length];
-
int i = 0;
for (Name primaryTypeName : nodeDef.requiredPrimaryTypeNames()) {
requiredPrimaryTypes[i] = findTypeInMapOrList(primaryTypeName, typesPendingRegistration);
@@ -1427,15 +1438,7 @@
}
i++;
}
-
- nodeDefs.add(nodeDef.with(this.context).with(this));
}
-
- // Create a new node type that also has the correct property and child node definitions associated
- JcrNodeType newNodeType = new JcrNodeType(this.context, this, nodeType.getInternalName(), supertypes,
- nodeType.getInternalPrimaryItemName(), nodeDefs, propertyDefs,
- nodeType.isMixin(), nodeType.hasOrderableChildNodes());
- typesPendingRegistration.add(newNodeType);
}
// Graph.Batch batch = graph.batch();
16 years, 6 months
DNA SVN: r972 - in trunk/extensions/dna-connector-svn/src: main/resources/org/jboss/dna/connector/svn and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-04 14:13:03 -0400 (Thu, 04 Jun 2009)
New Revision: 972
Added:
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.properties
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18nTest.java
Removed:
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java
Log:
Many errors in the SVN connector tests, and the I18n files are all messed up.
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2009-06-04 16:32:16 UTC (rev 971)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2009-06-04 18:13:03 UTC (rev 972)
@@ -35,11 +35,8 @@
public static I18n connectorName;
public static I18n nodeDoesNotExist;
public static I18n nodeIsActuallyUnknow;
- public static I18n nodeTypeIsNotSupported;
public static I18n propertyIsRequired;
public static I18n errorSerializingCachePolicyInSource;
- public static I18n objectFoundInJndiWasNotCache;
- public static I18n objectFoundInJndiWasNotCacheFactory;
public static I18n locationInRequestMustHavePath;
public static I18n sourceIsReadOnly;
public static I18n sourceDoesNotSupportCreatingWorkspaces;
@@ -49,7 +46,6 @@
public static I18n pathForPredefinedWorkspaceDoesNotExist;
public static I18n pathForPredefinedWorkspaceIsNotDirectory;
public static I18n pathForPredefinedWorkspaceCannotBeRead;
- public static I18n worspaceDoesNotExist;
public static I18n workspaceDoesNotExist;
public static I18n pathForDefaultWorkspaceDoesNotExist;
public static I18n pathForDefaultWorkspaceIsNotDirectory;
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-06-04 16:32:16 UTC (rev 971)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-06-04 18:13:03 UTC (rev 972)
@@ -403,7 +403,7 @@
}
if (!found) {
request.setError(new InvalidWorkspaceException(
- SVNRepositoryConnectorI18n.worspaceDoesNotExist.text(workspaceName)));
+ SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(workspaceName)));
return;
}
}
@@ -800,7 +800,7 @@
* @param message - comment for the creation.
* @throws SVNException - if during the creation, there is an error.
*/
- @SuppressWarnings("unused")
+ @SuppressWarnings( "unused" )
private void mkdir( SVNRepository repos,
String root,
String childName,
@@ -825,7 +825,7 @@
* @param message
* @throws SVNException
*/
- @SuppressWarnings("unused")
+ @SuppressWarnings( "unused" )
private void newFile( String path,
String file,
byte[] content,
@@ -954,7 +954,7 @@
}
- @SuppressWarnings("unused")
+ @SuppressWarnings( "unused" )
private byte[] getContent( Object[] objs ) {
byte[] content = null;
for (Object object : objs) {
@@ -966,7 +966,7 @@
return content;
}
- @SuppressWarnings("unused")
+ @SuppressWarnings( "unused" )
private Object[] values( Collection<Property> childNodeProperties ) {
Set<Object> result = new HashSet<Object>();
for (Property property : childNodeProperties) {
@@ -984,10 +984,10 @@
throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
}
// TODO
-// if (!segment.getName().getNamespaceUri().equals(defaultNamespaceUri)) {
-// I18n msg = SVNRepositoryConnectorI18n.onlyTheDefaultNamespaceIsAllowed;
-// throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
-// }
+ // if (!segment.getName().getNamespaceUri().equals(defaultNamespaceUri)) {
+ // I18n msg = SVNRepositoryConnectorI18n.onlyTheDefaultNamespaceIsAllowed;
+ // throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+ // }
}
}
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java 2009-06-04 16:32:16 UTC (rev 971)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java 2009-06-04 18:13:03 UTC (rev 972)
@@ -16,9 +16,7 @@
import org.tmatesoft.svn.core.wc.SVNWCUtil;
/**
- *
* @author Serge Pagop
- *
*/
public class SVNRepositoryUtil {
@@ -73,7 +71,6 @@
return kind;
}
-
/**
* Create a {@link SVNRepository} from a http protocol.
*
@@ -84,8 +81,7 @@
*/
public static SVNRepository createRepository( String url,
String username,
- String password
- ) {
+ String password ) {
// for DAV (over http and https)
DAVRepositoryFactory.setup();
// For File
@@ -196,7 +192,6 @@
return false;
}
-
public static boolean exists( SVNRepository repository,
String path ) {
try {
Deleted: trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties 2009-06-04 16:32:16 UTC (rev 971)
+++ trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties 2009-06-04 18:13:03 UTC (rev 972)
@@ -1,53 +0,0 @@
-#
-# JBoss DNA (http://www.jboss.org/dna)
-# See the COPYRIGHT.txt file distributed with this work for information
-# regarding copyright ownership. Some portions may be licensed
-# to Red Hat, Inc. under one or more contributor license agreements.
-# See the AUTHORS.txt file in the distribution for a full listing of
-# individual contributors.
-#
-# JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
-# is licensed to you under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# JBoss DNA is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this software; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-#
-
-connectorName = SVN Connector
-workspaceDoesNotExist = The workspace "{0}" does not exist
-nodeDoesNotExist = This node kind is missing at {0}
-locationInRequestMustHavePath = {0} requires a path in the request\: {1}
-nodeIsActuallyUnknow = This node kind is actually unknown {0}
-propertyIsRequired = The {0} property is required but has no value
-errorSerializingCachePolicyInSource = Error serializing a {0} instance owned by the {1} SVNRepositorySource
-objectFoundInJndiWasNotSVNRepository = Object in JNDI at {0} found by SVNRepositorySource {1} was expected to be a typ of org.tmatesoft.svn.core.io.SVNRepository but instead was {2}
-objectFoundInJndiWasNotSVNRepositoryFactory =Object in JNDI at {0} found by SVNRepositorySource {1} was expected to be a typ of org.tmatesoft.svn.core.io.SVNRepositoryFactory but instead was {2}
-sourceIsReadOnly = {0} is a read-only source; no updates are allowed
-sourceDoesNotSupportCreatingWorkspaces = {0} is a source that does not allow creating workspaces
-sourceDoesNotSupportCloningWorkspaces = {0} is a source that does not allow cloning workspaces
-sourceDoesNotSupportDeletingWorkspaces = {0} is a source that does not allow deleting workspaces
-connectingFailureOrUserAuthenticationProblem=failure occured while connecting to the repository {0} or the user's authentication failed
-workspaceDoesNotExist = The workspace "{0}" does not exist
-pathForDefaultWorkspaceDoesNotExist = The path "{0}" for the default workspace for the file system source "{1}" does not represent an existing directory
-pathForDefaultWorkspaceIsNotDirectory = The path "{0}" for the default workspace for the file system source "{1}" is actually a path to an existing file
-pathForDefaultWorkspaceCannotBeRead = The path "{0}" for the default workspace for the file system source "{1}" cannot be read
-pathForPredefinedWorkspaceDoesNotExist = The path "{0}" for the predefined workspace for the file system source "{1}" does not represent an existing directory
-pathForPredefinedWorkspaceIsNotDirectory = The path "{0}" for the predefined workspace for the file system source "{1}" is actually a path to an existing file
-pathForPredefinedWorkspaceCannotBeRead = The path "{0}" for the predefined workspace for the file system source "{1}" cannot be read
-sameNameSiblingsAreNotAllowed = {0} does not allow same name siblings on nodes: {1}
-onlyTheDefaultNamespaceIsAllowed = {0} requires node names use the default namespace: {1}
-unableToCreateWorkspaces ={0} does not allow creating new workspaces (request was to create "{1}")
-locationInRequestMustHavePath = {0} requires a path in the request: {1}
-sameNameSiblingsAreNotAllowed = {0} does not allow same name siblings on nodes: {1}
-onlyTheDefaultNamespaceIsAllowed = {0} requires node names use the default namespace: {1}
-sourceIsReadOnly = {0} is a read-only source; no updates are allowed
-unableToCreateWorkspaces = {0} does not allow creating new workspaces (request was to create "{1}")
\ No newline at end of file
Copied: trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.properties (from rev 971, trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties)
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.properties (rev 0)
+++ trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.properties 2009-06-04 18:13:03 UTC (rev 972)
@@ -0,0 +1,45 @@
+#
+# JBoss DNA (http://www.jboss.org/dna)
+# See the COPYRIGHT.txt file distributed with this work for information
+# regarding copyright ownership. Some portions may be licensed
+# to Red Hat, Inc. under one or more contributor license agreements.
+# See the AUTHORS.txt file in the distribution for a full listing of
+# individual contributors.
+#
+# JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+# is licensed to you under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# JBoss DNA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+#
+
+connectorName = SVN Connector
+nodeDoesNotExist = This node kind is missing at {0}
+nodeIsActuallyUnknow = This node kind is actually unknown {0}
+propertyIsRequired = The {0} property is required but has no value
+errorSerializingCachePolicyInSource = Error serializing a {0} instance owned by the {1} SVNRepositorySource
+sourceIsReadOnly = {0} is a read-only source; no updates are allowed
+sourceDoesNotSupportCreatingWorkspaces = {0} is a source that does not allow creating workspaces
+sourceDoesNotSupportCloningWorkspaces = {0} is a source that does not allow cloning workspaces
+sourceDoesNotSupportDeletingWorkspaces = {0} is a source that does not allow deleting workspaces
+connectingFailureOrUserAuthenticationProblem=failure occured while connecting to the repository {0} or the user's authentication failed
+workspaceDoesNotExist = The workspace "{0}" does not exist
+pathForDefaultWorkspaceDoesNotExist = The path "{0}" for the default workspace for the file system source "{1}" does not represent an existing directory
+pathForDefaultWorkspaceIsNotDirectory = The path "{0}" for the default workspace for the file system source "{1}" is actually a path to an existing file
+pathForDefaultWorkspaceCannotBeRead = The path "{0}" for the default workspace for the file system source "{1}" cannot be read
+pathForPredefinedWorkspaceDoesNotExist = The path "{0}" for the predefined workspace for the file system source "{1}" does not represent an existing directory
+pathForPredefinedWorkspaceIsNotDirectory = The path "{0}" for the predefined workspace for the file system source "{1}" is actually a path to an existing file
+pathForPredefinedWorkspaceCannotBeRead = The path "{0}" for the predefined workspace for the file system source "{1}" cannot be read
+sameNameSiblingsAreNotAllowed = {0} does not allow same name siblings on nodes: {1}
+onlyTheDefaultNamespaceIsAllowed = {0} requires node names use the default namespace: {1}
+locationInRequestMustHavePath = {0} requires a path in the request: {1}
+unableToCreateWorkspaces = {0} does not allow creating new workspaces (request was to create "{1}")
\ No newline at end of file
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-06-04 16:32:16 UTC (rev 971)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-06-04 18:13:03 UTC (rev 972)
@@ -127,7 +127,7 @@
}
public static String createURL( String src,
- String dst ) throws IOException {
+ String dst ) throws IOException, SVNException {
// First we need to find the absolute path. Note that Maven always runs the tests from the project's directory,
// so use new File to create an instance at the current location ...
File mySrc = new File(src);
@@ -138,8 +138,16 @@
FileUtil.copy(mySrc, myDst);
// Now set the two path roots
- String url = myDst.getCanonicalFile().toURI().toURL().toString();
- return url.replaceFirst("file:/", "file://localhost/");
+ String url = myDst.getCanonicalFile().toURI().toURL().toExternalForm();
+
+ url = url.replaceFirst("file:/", "file://localhost/");
+
+ // Have to decode the URL ...
+ SVNURL encodedUrl = SVNURL.parseURIEncoded(url);
+ url = encodedUrl.toDecodedString();
+
+ if (!url.endsWith("/")) url = url + "/";
+ return url;
}
@SuppressWarnings( "unchecked" )
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java 2009-06-04 16:32:16 UTC (rev 971)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java 2009-06-04 18:13:03 UTC (rev 972)
@@ -12,8 +12,8 @@
public class SVNRepositoryConnectorCreateWorspaceTest extends WorkspaceConnectorTest {
-
private String repositoryRootURL;
+
/**
* {@inheritDoc}
*
@@ -22,7 +22,7 @@
@Override
protected RepositorySource setUpSource() throws Exception {
repositoryRootURL = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
- String[] predefinedWorkspaceNames = new String[]{repositoryRootURL + "trunk", repositoryRootURL + "tags"};
+ String[] predefinedWorkspaceNames = new String[] {repositoryRootURL + "trunk", repositoryRootURL + "tags"};
SVNRepositorySource source = new SVNRepositorySource();
source.setName("Test Repository");
source.setUsername("sp");
@@ -31,10 +31,10 @@
source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
source.setCreatingWorkspacesAllowed(true);
-
+
return source;
}
-
+
/**
* {@inheritDoc}
*
@@ -62,9 +62,9 @@
*/
@Override
protected String[] generateValidNamesForNewWorkspaces() {
- return new String[] { repositoryRootURL + "branches"};
+ return new String[] {repositoryRootURL + "branches"};
}
-
+
@Test
public void shouldReturnListOfWorkspacesMatchingRepositoryURLs() throws Exception {
// The the actual names of the workspaces ...
@@ -73,7 +73,7 @@
Workspace workspace = graph.useWorkspace(workspaceName);
workspaceNames.add(workspace.getName());
}
-
+
assertThat(workspaceNames.remove(repositoryRootURL + "trunk"), is(true));
assertThat(workspaceNames.remove(repositoryRootURL + "tags"), is(true));
assertThat(workspaceNames.isEmpty(), is(true));
Added: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18nTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18nTest.java (rev 0)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18nTest.java 2009-06-04 18:13:03 UTC (rev 972)
@@ -0,0 +1,35 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ */
+public class SVNRepositoryConnectorI18nTest extends AbstractI18nTest {
+
+ public SVNRepositoryConnectorI18nTest() {
+ super(SVNRepositoryConnectorI18n.class);
+ }
+}
Property changes on: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18nTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
16 years, 6 months
DNA SVN: r971 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph/connector/federation and 14 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-04 12:32:16 -0400 (Thu, 04 Jun 2009)
New Revision: 971
Added:
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/sequencing.cnd
Removed:
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphBatchDestination.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ProjectionPathRuleTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryWorkspaceTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
trunk/docs/examples/gettingstarted/sequencers/pom.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/UserInterface.java
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/MockUserInterface.java
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
Log:
DNA-389 Further changes to make the JcrConfiguration and JcrEngine easier to use while also correcting a few problems. Additional changes to the sequencing example toward getting it working again.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -2676,8 +2676,9 @@
protected Batch submit( Location parent,
String workspaceName,
Name childName,
- Collection<Property> properties ) {
- requestQueue.createNode(parent, workspaceName, childName, properties.iterator());
+ Collection<Property> properties,
+ NodeConflictBehavior behavior ) {
+ requestQueue.createNode(parent, workspaceName, childName, properties.iterator(), behavior);
return Batch.this;
}
@@ -2751,157 +2752,6 @@
}
/**
- * Begin the request to create a node located at the supplied path if there is no such node already.
- * <p>
- * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
- * called.
- * </p>
- *
- * @param atPath the path to the node that is to be created.
- * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
- * node where the node is to be created
- */
- public Create<Batch> createIfMissing( String atPath ) {
- return createIfMissing(createPath(atPath));
- }
-
- /**
- * Begin the request to create a node located at the supplied path if there is no such node already.
- * <p>
- * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
- * called.
- * </p>
- *
- * @param atPath the path to the node that is to be created.
- * @param property a property for the new node
- * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
- * node where the node is to be created
- */
- public Create<Batch> createIfMissing( String atPath,
- Property property ) {
- return createIfMissing(createPath(atPath)).with(property);
- }
-
- /**
- * Begin the request to create a node located at the supplied path if there is no such node already.
- * <p>
- * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
- * called.
- * </p>
- *
- * @param atPath the path to the node that is to be created.
- * @param firstProperty a property for the new node
- * @param additionalProperties additional properties for the new node
- * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
- * node where the node is to be created
- */
- public Create<Batch> createIfMissing( String atPath,
- Property firstProperty,
- Property... additionalProperties ) {
- return createIfMissing(createPath(atPath)).with(firstProperty, additionalProperties);
- }
-
- /**
- * Begin the request to create a node located at the supplied path if there is no such node already.
- * <p>
- * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
- * called.
- * </p>
- *
- * @param at the path to the node that is to be created.
- * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
- * node where the node is to be created
- */
- public final Create<Batch> createIfMissing( Path at ) {
- assertNotExecuted();
- CheckArg.isNotNull(at, "at");
- Path parent = at.getParent();
- Name name = at.getLastSegment().getName();
- return createIfMissing(Location.create(parent), name);
- }
-
- protected final CreateAction<Batch> createIfMissing( Location parent,
- Name child ) {
- return new CreateAction<Batch>(this, parent, getCurrentWorkspaceName(), child) {
- @Override
- protected Batch submit( Location parent,
- String workspaceName,
- Name childName,
- Collection<Property> properties ) {
- requestQueue.createNode(parent, workspaceName, childName, properties.iterator(), NodeConflictBehavior.UPDATE);
- return Batch.this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.Graph.Executable#execute()
- */
- public Results execute() {
- and();
- return Batch.this.execute();
- }
- };
- }
-
- /**
- * Begin the request to create a node located at the supplied path.
- * <p>
- * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
- * called.
- * </p>
- *
- * @param at the path to the node that is to be created.
- * @param properties the iterator over the properties for the new node
- * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
- * node where the node is to be created
- */
- public Create<Batch> createIfMissing( Path at,
- Iterable<Property> properties ) {
- Create<Batch> action = createIfMissing(at);
- for (Property property : properties) {
- action.and(property);
- }
- return action;
- }
-
- /**
- * Begin the request to create a node located at the supplied path if there is no such node already.
- * <p>
- * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
- * called.
- * </p>
- *
- * @param at the path to the node that is to be created.
- * @param property a property for the new node
- * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
- * node where the node is to be created
- */
- public Create<Batch> createIfMissing( Path at,
- Property property ) {
- return createIfMissing(at).with(property);
- }
-
- /**
- * Begin the request to create a node located at the supplied path if there is no such node already.
- * <p>
- * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
- * called.
- * </p>
- *
- * @param at the path to the node that is to be created.
- * @param firstProperty a property for the new node
- * @param additionalProperties additional properties for the new node
- * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
- * node where the node is to be created
- */
- public Create<Batch> createIfMissing( Path at,
- Property firstProperty,
- Property... additionalProperties ) {
- return createIfMissing(at).with(firstProperty, additionalProperties);
- }
-
- /**
* Begin the request to create a node under the existing parent node at the supplied location. This request is submitted
* to the repository after the returned components are completed.
*
@@ -3913,9 +3763,9 @@
}
/**
- * A component that defines the location before which a node should be copied or moved. This is similar to an
- * {@link Into}, but it allows for placing a node at a particular location within the new destination, rather than
- * always placing the moved or copied node as the last child of the new parent.
+ * A component that defines the location before which a node should be copied or moved. This is similar to an {@link Into},
+ * but it allows for placing a node at a particular location within the new destination, rather than always placing the moved
+ * or copied node as the last child of the new parent.
*
* @param <Next> The interface that is to be returned when this request is completed
* @author Randall Hauch
@@ -3989,7 +3839,7 @@
* @return the interface for additional requests or actions
*/
Next before( Property firstParentIdProperty,
- Property... additionalParentIdProperties );
+ Property... additionalParentIdProperties );
}
/**
@@ -4154,6 +4004,38 @@
*/
public interface Create<Next> extends Conjunction<Next>, Executable<Node> {
/**
+ * Create the node only if there is no existing node with the same {@link Path.Segment#getName() name} (ignoring
+ * {@link Path.Segment#getIndex() same-name-sibling indexes}).
+ *
+ * @return this interface for continued specification of the request
+ */
+ Create<Next> ifAbsent();
+
+ /**
+ * Create the node if it does not exist, or update any existing node that has the same {@link Path.Segment#getName() name}
+ * (ignoring {@link Path.Segment#getIndex() same-name-sibling indexes}).
+ *
+ * @return this interface for continued specification of the request
+ */
+ Create<Next> orUpdate();
+
+ /**
+ * Create the node if it does not exist, or replace any existing node that has the same {@link Path.Segment#getName()
+ * name} (ignoring {@link Path.Segment#getIndex() same-name-sibling indexes}).
+ *
+ * @return this interface for continued specification of the request
+ */
+ Create<Next> orReplace();
+
+ /**
+ * Create the node if it does not exist by appending or adjusting the {@link Path.Segment#getIndex() same-name-sibling
+ * index}). This is the default behavior.
+ *
+ * @return this interface for continued specification of the request
+ */
+ Create<Next> byAppending();
+
+ /**
* Specify the UUID that should the new node should have. This is an alias for {@link #and(UUID)}.
*
* @param uuid the UUID
@@ -5822,8 +5704,8 @@
* @return this object, for method chaining
*/
protected T submit( Locations from,
- Location into,
- Name newName ) {
+ Location into,
+ Name newName ) {
return submit(from, into, null, newName);
}
@@ -5851,7 +5733,7 @@
public T into( String into ) {
return submit(from, Location.create(createPath(into)), newName);
}
-
+
public T before( Location before ) {
return submit(from, null, before, newName);
}
@@ -5865,7 +5747,7 @@
}
public T before( Property firstIdProperty,
- Property... additionalIdProperties ) {
+ Property... additionalIdProperties ) {
return submit(from, null, Location.create(firstIdProperty, additionalIdProperties), newName);
}
@@ -5875,7 +5757,7 @@
public T before( String before ) {
return submit(from, null, Location.create(createPath(before)), newName);
- }
+ }
}
@NotThreadSafe
@@ -5993,6 +5875,7 @@
private final Name childName;
private final Map<Name, Property> properties = new HashMap<Name, Property>();
private boolean submitted = false;
+ private NodeConflictBehavior conflictBehavior = NodeConflictBehavior.APPEND;
/*package*/CreateAction( T afterConjunction,
Location parent,
@@ -6004,6 +5887,46 @@
this.childName = childName;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Graph.Create#ifAbsent()
+ */
+ public Create<T> ifAbsent() {
+ conflictBehavior = NodeConflictBehavior.DO_NOT_REPLACE;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Graph.Create#orReplace()
+ */
+ public Create<T> orReplace() {
+ conflictBehavior = NodeConflictBehavior.REPLACE;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Graph.Create#orUpdate()
+ */
+ public Create<T> orUpdate() {
+ conflictBehavior = NodeConflictBehavior.UPDATE;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Graph.Create#byAppending()
+ */
+ public Create<T> byAppending() {
+ conflictBehavior = NodeConflictBehavior.APPEND;
+ return this;
+ }
+
public Create<T> and( UUID uuid ) {
PropertyFactory factory = getContext().getPropertyFactory();
properties.put(DnaLexicon.UUID, factory.create(DnaLexicon.UUID, uuid));
@@ -6078,12 +6001,13 @@
protected abstract T submit( Location parent,
String workspaceName,
Name childName,
- Collection<Property> properties );
+ Collection<Property> properties,
+ NodeConflictBehavior conflictBehavior );
@Override
public T and() {
if (!submitted) {
- submit(parent, workspaceName, childName, this.properties.values());
+ submit(parent, workspaceName, childName, this.properties.values(), this.conflictBehavior);
submitted = true;
}
return super.and();
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -575,8 +575,8 @@
public PathRule( Path repositoryPath,
Path sourcePath,
Path... exceptions ) {
- assert sourcePath != null;
- assert repositoryPath != null;
+ CheckArg.isNotNull(sourcePath, "sourcePath");
+ CheckArg.isNotNull(repositoryPath, "repositoryPath");
this.sourcePath = sourcePath;
this.repositoryPath = repositoryPath;
if (exceptions == null || exceptions.length == 0) {
@@ -589,15 +589,21 @@
this.exceptions = Collections.unmodifiableList(exceptionList);
}
this.hc = HashCode.compute(sourcePath, repositoryPath, exceptions);
- assert exceptionPathsAreRelative();
+ if (this.exceptions != null) {
+ for (Path path : this.exceptions) {
+ if (path.isAbsolute()) {
+ throw new IllegalArgumentException(GraphI18n.pathIsNotRelative.text(path));
+ }
+ }
+ }
this.topLevelRepositoryPaths = Collections.singletonList(getPathInRepository());
}
public PathRule( Path repositoryPath,
Path sourcePath,
List<Path> exceptions ) {
- assert sourcePath != null;
- assert repositoryPath != null;
+ CheckArg.isNotNull(sourcePath, "sourcePath");
+ CheckArg.isNotNull(repositoryPath, "repositoryPath");
this.sourcePath = sourcePath;
this.repositoryPath = repositoryPath;
if (exceptions == null || exceptions.isEmpty()) {
@@ -606,17 +612,14 @@
this.exceptions = Collections.unmodifiableList(new ArrayList<Path>(exceptions));
}
this.hc = HashCode.compute(sourcePath, repositoryPath, exceptions);
- assert exceptionPathsAreRelative();
- this.topLevelRepositoryPaths = Collections.singletonList(getPathInRepository());
- }
-
- private boolean exceptionPathsAreRelative() {
if (this.exceptions != null) {
for (Path path : this.exceptions) {
- if (path.isAbsolute()) return false;
+ if (path.isAbsolute()) {
+ throw new IllegalArgumentException(GraphI18n.pathIsNotRelative.text(path));
+ }
}
}
- return true;
+ this.topLevelRepositoryPaths = Collections.singletonList(getPathInRepository());
}
/**
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphBatchDestination.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphBatchDestination.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphBatchDestination.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -27,7 +27,9 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.NodeConflictBehavior;
import org.jboss.dna.graph.Graph.Batch;
+import org.jboss.dna.graph.Graph.Create;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Property;
@@ -92,11 +94,31 @@
public void create( Path path,
List<Property> properties ) {
assert properties != null;
+ Create<Batch> create = null;
if (properties.isEmpty()) {
- batch.create(path).and();
+ create = batch.create(path);
} else {
- batch.create(path, properties).and();
+ create = batch.create(path, properties);
}
+ assert create != null;
+ NodeConflictBehavior behavior = createBehaviorFor(path);
+ if (behavior != null) {
+ switch (behavior) {
+ case APPEND:
+ create.byAppending();
+ break;
+ case REPLACE:
+ create.orReplace();
+ break;
+ case UPDATE:
+ create.byAppending();
+ break;
+ case DO_NOT_REPLACE:
+ create.byAppending();
+ break;
+ }
+ }
+ create.and();
}
/**
@@ -108,22 +130,43 @@
public void create( Path path,
Property firstProperty,
Property... additionalProperties ) {
+ Create<Batch> create = null;
if (firstProperty == null) {
- batch.create(path).and();
+ create = batch.create(path);
} else {
- batch.create(path, firstProperty, additionalProperties).and();
+ create = batch.create(path, firstProperty, additionalProperties);
}
+ assert create != null;
+ NodeConflictBehavior behavior = createBehaviorFor(path);
+ if (behavior != null) {
+ switch (behavior) {
+ case APPEND:
+ create.byAppending();
+ break;
+ case REPLACE:
+ create.orReplace();
+ break;
+ case UPDATE:
+ create.byAppending();
+ break;
+ case DO_NOT_REPLACE:
+ create.byAppending();
+ break;
+ }
+ }
+ create.and();
}
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.graph.io.Destination#setProperties(org.jboss.dna.graph.property.Path, org.jboss.dna.graph.property.Property[])
+ *
+ * @see org.jboss.dna.graph.io.Destination#setProperties(org.jboss.dna.graph.property.Path,
+ * org.jboss.dna.graph.property.Property[])
*/
- public void setProperties( Path path,
+ public void setProperties( Path path,
Property... properties ) {
if (properties == null) return;
-
+
batch.set(properties).on(path);
}
@@ -135,6 +178,16 @@
public void submit() {
// Execute only if we're not ignoring submits ...
if (!this.ignoreSubmit && !batch.hasExecuted()) batch.execute();
+ }
+ /**
+ * Override this method in a subclass to control the {@link NodeConflictBehavior} that should be used when creating the node
+ * at the supplied path. By default, this method returns null.
+ *
+ * @param path the path of the new node
+ * @return the conflict behavior, or null if {@link NodeConflictBehavior#UPDATE} should be used
+ */
+ protected NodeConflictBehavior createBehaviorFor( Path path ) {
+ return null;
}
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ProjectionPathRuleTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ProjectionPathRuleTest.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ProjectionPathRuleTest.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -80,19 +80,19 @@
assertThat(rule.getExceptionsToRule(), hasItems(validExceptions));
}
- @Test( expected = AssertionError.class )
+ @Test( expected = IllegalArgumentException.class )
public void shouldFailToCreateInstanceWithNullRepositoryPathAndValidSourcePathAndNoExceptions() {
repositoryPath = null;
new Projection.PathRule(repositoryPath, sourcePath);
}
- @Test( expected = AssertionError.class )
+ @Test( expected = IllegalArgumentException.class )
public void shouldFailToCreateInstanceWithValidRepositoryPathAndNullSourcePathAndNoExceptions() {
sourcePath = null;
new Projection.PathRule(repositoryPath, sourcePath);
}
- @Test( expected = AssertionError.class )
+ @Test( expected = IllegalArgumentException.class )
public void shouldFailToCreateInstanceWithValidRepositoryPathAndValidSourcePathAndAbsoluteExceptions() {
Path relativePath = validExceptions[0];
Path absolutePath = pathFactory.create("/j/k/l/m");
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryWorkspaceTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryWorkspaceTest.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryWorkspaceTest.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -30,7 +30,6 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;
-import static org.mockito.Mockito.mock;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@@ -101,17 +100,6 @@
assertThat(workspace.getRoot().getProperties().size(), is(0));
}
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNodeToBeRemovedUsingNullEnvironment() {
- InMemoryNode node = mock(InMemoryNode.class);
- workspace.removeNode(null, node);
- }
-
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNullNodeToBeRemoved() {
- workspace.removeNode(context, null);
- }
-
@Test
public void shouldCreateNodesByPath() {
Name name_a = nameFactory.create("a");
@@ -274,7 +262,7 @@
Name propName = nameFactory.create("prop");
node_b.setProperty(propertyFactory.create(propName, "node_b"));
node_b2.setProperty(propertyFactory.create(propName, "node_b2"));
-
+
assertThat(workspace.getNodesByUuid().size(), is(7));
assertThat(workspace.getNode(pathFactory.create("/")), is(sameInstance(workspace.getRoot())));
assertThat(workspace.getNode(pathFactory.create("/a")), is(sameInstance(node_a)));
@@ -296,8 +284,10 @@
assertThat(workspace.getNode(pathFactory.create("/d/b[2]")), is(sameInstance(node_b2)));
assertThat(workspace.getNode(pathFactory.create("/d/b[1]")), is(sameInstance(node_b)));
assertThat(workspace.getNode(pathFactory.create("/d/b[1]/c")), is(sameInstance(node_c)));
- assertThat(workspace.getNode(pathFactory.create("/d/b[1]")).getProperty(propName).getFirstValue().toString(), is("node_b"));
- assertThat(workspace.getNode(pathFactory.create("/d/b[2]")).getProperty(propName).getFirstValue().toString(), is("node_b2"));
+ assertThat(workspace.getNode(pathFactory.create("/d/b[1]")).getProperty(propName).getFirstValue().toString(),
+ is("node_b"));
+ assertThat(workspace.getNode(pathFactory.create("/d/b[2]")).getProperty(propName).getFirstValue().toString(),
+ is("node_b2"));
// Move after the last node
workspace.moveNode(context, node_b, null, workspace, root, null);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -604,7 +604,7 @@
Path nodeTypesPath = subpath(DnaLexicon.NODE_TYPES);
createIfMissing(DnaLexicon.NODE_TYPES).and();
- // Now set up the destination ...
+ // Now set up the destination, but make it so that ...
Destination destination = new GraphBatchDestination(batch, true); // will NOT be executed
// And create the importer that will load the CND content into the repository ...
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -144,12 +144,7 @@
// Register all the the node types ...
Node nodeTypesNode = subgraph.getNode(DnaLexicon.NODE_TYPES);
if (nodeTypesNode != null) {
- try {
- repository.getRepositoryTypeManager().registerNodeTypes(subgraph, nodeTypesNode.getLocation());
- } catch (RepositoryException e) {
- // Error registering the node types ...
- getProblems().addError(e, JcrI18n.errorRegisteringNodeTypes, repositoryName);
- }
+ repository.getRepositoryTypeManager().registerNodeTypes(subgraph, nodeTypesNode.getLocation());// throws exception
}
return repository;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -60,7 +60,6 @@
public static I18n unableToRemapUriNotRegisteredInNamespaceRegistry;
public static I18n unableToRemapUriUsingPrefixUsedInNamespaceRegistry;
- public static I18n errorRegisteringNodeTypes;
public static I18n errorWhileInitializingTheNamespaceRegistry;
public static I18n invalidRelativePath;
public static I18n invalidPathParameter;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -218,6 +218,10 @@
return graph.batch();
}
+ String sourceName() {
+ return this.repository.getRepositorySourceName();
+ }
+
/**
* {@inheritDoc}
*
@@ -329,9 +333,10 @@
this.checkPermission(executionContext.getValueFactories().getPathFactory().create(path), actions);
}
-
- public void checkPermission( Path path, String actions) {
-
+
+ public void checkPermission( Path path,
+ String actions ) {
+
CheckArg.isNotNull(path, "path");
CheckArg.isNotEmpty(actions, "actions");
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -204,6 +204,10 @@
return workspaceName;
}
+ String sourceName() {
+ return session.sourceName();
+ }
+
ExecutionContext context() {
return context;
}
@@ -2085,7 +2089,8 @@
throw new ItemNotFoundException(JcrI18n.itemNotFoundWithUuid.text(uuid, workspaceName, e.getLocalizedMessage()));
} catch (RepositorySourceException e) {
throw new RepositoryException(
- JcrI18n.errorWhileFindingNodeWithUuid.text(uuid, workspaceName, e.getLocalizedMessage()));
+ JcrI18n.errorWhileFindingNodeWithUuid.text(uuid, workspaceName, e.getLocalizedMessage()),
+ e);
}
}
@@ -2234,7 +2239,7 @@
}
if (definition == null) {
String msg = JcrI18n.nodeDefinitionCouldNotBeDeterminedForNode.text(path, workspaceName);
- throw new RepositorySourceException(msg);
+ throw new RepositorySourceException(sourceName(), msg);
}
}
@@ -2248,7 +2253,7 @@
if (primaryType == null) {
Path path = location.getPath();
String msg = JcrI18n.missingNodeTypeForExistingNode.text(primaryTypeName.getString(namespaces), path, workspaceName);
- throw new RepositorySourceException(msg);
+ throw new RepositorySourceException(sourceName(), msg);
}
if (primaryType.isNodeType(JcrMixLexicon.REFERENCEABLE)) referenceable = true;
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-06-04 16:32:16 UTC (rev 971)
@@ -50,7 +50,6 @@
unableToRemapUriNotRegisteredInNamespaceRegistry = Unable to remap the namespace "{1}" to prefix "{0}" because the URI is not already registered in the workspace's namespace registry
unableToRemapUriUsingPrefixUsedInNamespaceRegistry = Unable to remap the namespace "{1}" to prefix "{0}" because the prefix is already used as the prefix for the namespace "{2}" in the workspace's namespace registry
-errorRegisteringNodeTypes = Error while registering the node types for repository "{0}"
errorWhileInitializingTheNamespaceRegistry = Error while initializing the namespace registry for workspace "{0}"
invalidRelativePath = "{0}" is not a valid relative path
invalidPathParameter = The "{1}" parameter value "{0}" was not a valid path
@@ -123,4 +122,4 @@
allNodeTypeTemplatesMustComeFromSameSession=All node type templates must be created from the same javax.jcr.Session
nodeNotReferenceable=Only referenceable nodes may be the value of reference properties
-noPendingChangesAllowed=This operation cannot be performed when the session has pending changes
\ No newline at end of file
+noPendingChangesAllowed=This operation cannot be performed when the session has pending changes
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -976,11 +976,11 @@
protected Graph.Create<Graph.Batch> createIfMissing( Name child,
String... segments ) {
Path nodePath = context.getValueFactories().getPathFactory().create(path, child);
- Graph.Create<Graph.Batch> result = batch.createIfMissing(nodePath);
+ Graph.Create<Graph.Batch> result = batch.create(nodePath).orUpdate();
for (String name : segments) {
result.and();
nodePath = context.getValueFactories().getPathFactory().create(nodePath, name);
- result = batch.createIfMissing(nodePath);
+ result = batch.create(nodePath).orUpdate();
}
return result;
}
@@ -994,7 +994,7 @@
*/
protected Graph.Create<Graph.Batch> createIfMissing( Name segment ) {
Path nodePath = context.getValueFactories().getPathFactory().create(path, segment);
- Graph.Create<Graph.Batch> result = batch.createIfMissing(nodePath);
+ Graph.Create<Graph.Batch> result = batch.create(nodePath).orUpdate();
return result;
}
@@ -1013,7 +1013,7 @@
for (Name name : segments) {
if (result != null) result.and();
nodePath = context.getValueFactories().getPathFactory().create(nodePath, name);
- result = batch.createIfMissing(nodePath);
+ result = batch.create(nodePath).orUpdate();
}
return result;
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -31,9 +31,11 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.collection.Problem;
import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.JcrLexicon;
@@ -240,6 +242,16 @@
* @see #shutdown()
*/
public void start() {
+ if (getProblems().hasErrors()) {
+ // First log the messages ...
+ Logger log = Logger.getLogger(getClass());
+ log.error(RepositoryI18n.errorsPreventStarting);
+ for (Problem problem : getProblems()) {
+ log.error(problem.getMessage(), problem.getParameters());
+ }
+ // Then throw an exception ...
+ throw new IllegalStateException(RepositoryI18n.errorsPreventStarting.text());
+ }
repositoryService.getAdministrator().start();
sequencingService.getAdministrator().start();
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -124,6 +124,7 @@
// Engine
public static I18n engineIsNotRunning;
+ public static I18n errorsPreventStarting;
static {
try {
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/StreamSequencerAdapter.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -34,6 +34,7 @@
import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.graph.Node;
import org.jboss.dna.graph.observe.NetChangeObserver.NetChange;
+import org.jboss.dna.graph.property.Binary;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.Property;
@@ -90,18 +91,21 @@
// Get the property that contains the data, given by 'propertyName' ...
Property sequencedProperty = input.getProperty(sequencedPropertyName);
- if (sequencedProperty == null) {
+ if (sequencedProperty == null || sequencedProperty.isEmpty()) {
String msg = RepositoryI18n.unableToFindPropertyForSequencing.text(sequencedPropertyName, input.getLocation());
throw new SequencerException(msg);
}
// Get the binary property with the image content, and build the image metadata from the image ...
- SequencerOutputMap output = new SequencerOutputMap(context.getExecutionContext().getValueFactories());
+ ValueFactories factories = context.getExecutionContext().getValueFactories();
+ SequencerOutputMap output = new SequencerOutputMap(factories);
InputStream stream = null;
Throwable firstError = null;
+ Binary binary = factories.getBinaryFactory().create(sequencedProperty.getFirstValue());
+ binary.acquire();
try {
// Parallel the JCR lemma for converting objects into streams
- stream = new ByteArrayInputStream(sequencedProperty.toString().getBytes());
+ stream = binary.getStream();
StreamSequencerContext StreamSequencerContext = createStreamSequencerContext(input,
sequencedProperty,
context,
@@ -111,20 +115,24 @@
// Record the error ...
firstError = t;
} finally {
- if (stream != null) {
- // Always close the stream, recording the error if we've not yet seen an error
- try {
- stream.close();
- } catch (Throwable t) {
- if (firstError == null) firstError = t;
- } finally {
- stream = null;
+ try {
+ if (stream != null) {
+ // Always close the stream, recording the error if we've not yet seen an error
+ try {
+ stream.close();
+ } catch (Throwable t) {
+ if (firstError == null) firstError = t;
+ } finally {
+ stream = null;
+ }
}
+ if (firstError != null) {
+ // Wrap and throw the first error that we saw ...
+ throw new SequencerException(firstError);
+ }
+ } finally {
+ binary.release();
}
- if (firstError != null) {
- // Wrap and throw the first error that we saw ...
- throw new SequencerException(firstError);
- }
}
// Find each output node and save the image metadata there ...
Modified: trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
===================================================================
--- trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2009-06-04 16:32:16 UTC (rev 971)
@@ -102,3 +102,4 @@
errorStartingRepositoryService = Error while starting repository service
engineIsNotRunning = The engine is not running; make sure it was started.
+errorsPreventStarting = The engine has errors and cannot be started
\ No newline at end of file
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -138,7 +138,7 @@
assertThat(file.exists(), is(true));
assertThat(file.canRead(), is(true));
assertThat(file.isFile(), is(true));
- URL fileUrl = file.toURL();
+ URL fileUrl = file.toURI().toURL();
assertThat(fileUrl, is(notNullValue()));
configuration.loadFrom(fileUrl);
@@ -177,7 +177,7 @@
public void shouldLoadConfigurationEvenAfterAlreadyHavingLoadedConfiguration() throws Exception {
configuration.loadFrom("src/test/resources/config/configRepository.xml");
configuration.loadFrom(new File("src/test/resources/config/configRepository.xml"));
- configuration.loadFrom(new File("src/test/resources/config/configRepository.xml").toURL());
+ configuration.loadFrom(new File("src/test/resources/config/configRepository.xml").toURI().toURL());
assertThat(configuration.getProblems().isEmpty(), is(true));
}
Modified: trunk/docs/examples/gettingstarted/sequencers/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/pom.xml 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/docs/examples/gettingstarted/sequencers/pom.xml 2009-06-04 16:32:16 UTC (rev 971)
@@ -63,27 +63,17 @@
<artifactId>jcr</artifactId>
</dependency>
<!--
- Test cases use JUnit
- -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <!--
JAAS implementation (and dependencies)
-->
<dependency>
<groupId>org.jboss.security</groupId>
<artifactId>jboss-idtrust</artifactId>
<version>2.0.2.CR1</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.security</groupId>
<artifactId>jboss-security-spi-bare</artifactId>
<version>2.0.2.SP6</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.security</groupId>
@@ -99,6 +89,13 @@
<artifactId>serializer</artifactId>
</exclusion>
</exclusions>
+ </dependency>
+ <!--
+ Test cases use JUnit
+ -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -198,4 +198,8 @@
sb.append("\n");
return sb.toString();
}
+
+ public void displayError( Exception e ) {
+ System.err.println(e.getMessage());
+ }
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -47,9 +47,6 @@
import org.jboss.dna.jcr.JcrRepository;
import org.jboss.dna.repository.sequencer.SequencingService;
import org.jboss.dna.repository.util.SessionFactory;
-import org.jboss.dna.sequencer.image.ImageMetadataSequencer;
-import org.jboss.dna.sequencer.java.JavaMetadataSequencer;
-import org.jboss.dna.sequencer.mp3.Mp3MetadataSequencer;
import org.jboss.security.config.IDTrustConfiguration;
/**
@@ -72,7 +69,9 @@
throw new IllegalStateException(ex);
}
- // Configure the DNA JCR engine ...
+ // Configure the DNA JCR engine. This could be done by loading a configuration from a file, or by
+ // using a (local or remote) configuration repository, or by setting up the configuration programmatically.
+ // This example uses the programmatic approach...
String repositoryId = "content";
String workspaceName = "default";
JcrConfiguration config = new JcrConfiguration();
@@ -83,9 +82,7 @@
.setProperty("defaultWorkspaceName", workspaceName);
// Set up the JCR repository to use the source ...
config.repository(repositoryId)
- .addNodeTypes(ImageMetadataSequencer.class.getResource("org/jboss/dna/sequencer/image/images.cnd"))
- .addNodeTypes(Mp3MetadataSequencer.class.getResource("org/jboss/dna/sequencer/mp3/mp3.cnd"))
- .addNodeTypes(JavaMetadataSequencer.class.getResource("org/jboss/dna/sequencer/java/javaSource.cnd"))
+ .addNodeTypes("sequencing.cnd")
.setSource("store")
.setOption(JcrRepository.Option.JAAS_LOGIN_CONFIG_NAME, "dna-jcr");
// Set up the image sequencer ...
@@ -97,13 +94,15 @@
.andOutputtingTo("/images/$1");
// Set up the MP3 sequencer ...
config.sequencer("MP3 Sequencer")
- .usingClass(Mp3MetadataSequencer.class)
+ .usingClass("org.jboss.dna.sequencer.mp3.Mp3MetadataSequencer")
+ .loadedFromClasspath()
.setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
.sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
.andOutputtingTo("/mp3s/$1");
// Set up the Java source file sequencer ...
config.sequencer("Java Sequencer")
- .usingClass(JavaMetadataSequencer.class)
+ .usingClass("org.jboss.dna.sequencer.java.JavaMetadataSequencer")
+ .loadedFromClasspath()
.setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
.sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
.andOutputtingTo("/mp3s/$1");
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/UserInterface.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/UserInterface.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/UserInterface.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -37,4 +37,6 @@
public String getRepositoryPath( String defaultPath ) throws IllegalArgumentException, IOException;
public void displaySearchResults( List<ContentInfo> contentInfo ) throws IOException;
+
+ public void displayError( Exception e );
}
Deleted: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd 2009-06-04 16:32:16 UTC (rev 971)
@@ -1,264 +0,0 @@
-<jcr='http://www.jcp.org/jcr/1.0'>
-<nt='http://www.jcp.org/jcr/nt/1.0'>
-<mix='http://www.jcp.org/jcr/mix/1.0'>
-<image='http://jboss.org/dna/images/1.0'>
-<mp3='http://jboss.org/dna/mp3/1.0'>
-<java='http://www.jboss.org/dna/java/1.0'>
-
-// ----------------------------------------------------------
-// JCR Pre-defined Mixin Types that are not loaded by default
-// ----------------------------------------------------------
-
-[mix:mimeTyped] mixin
- - jcr:mimeType (string)
- - jcr:encoding (string)
-
-
-// -------------------
-// DNA Image Sequencer
-// -------------------
-
-/**
- * Node type that defines the metadata for an image
- */
-[image:metadata] > nt:unstructured, mix:mimeTyped
- - image:formatName (string) mandatory
- < 'JPEG', 'GIF', 'PNG', 'BMP', 'PCX', 'IFF', 'RAS', 'PBM', 'PGM', 'PPM', 'PSD'
- - image:width (long)
- - image:height (long)
- - image:bitsPerPixel (long)
- - image:progressive (boolean)
- - image:numberOfImages (long)
- - image:physicalWidthDpi (long)
- - image:physicalHeightDpi (long)
- - image:physicalWidthInches (long)
- - image:physicalHeightInches (long)
-
-// -------------------
-// DNA MP3 Sequencer
-// -------------------
-
-/**
- * Node type that defines the metadata for an MP3 audio file
- */
-[mp3:metadata] > nt:unstructured, mix:mimeTyped
- - mp3:title (string)
- - mp3:author (string)
- - mp3:album (string)
- - mp3:year (long)
- - mp3:comment (string)
-
-// -------------------
-// DNA Java Sequencer
-// -------------------
-
-/**
- * Node types that define metadata for a Java source file
- */
-/**
- * Element-value
- */
-[java:elementValue] > nt:unstructured
- + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
-
-/**
- * Modifiers
- */
-[java:modifierDeclaration] > nt:unstructured
- - java:modifierName (string) mandatory
-
-/**
- * Expression element-value type
- */
-[java:conditionalExpression] > nt:unstructured
- - java:expression (string)
-
-/**
- * Array initializer element-value type
- */
-[java:elementValueArrayInitializer] > nt:unstructured
- + java:elementValue (java:elementValue) = java:elementValue multiple
-
-/**
- * Identifier
- */
-[java:identifier] > nt:unstructured
- - java:identifierName (String) mandatory
- + java:value (java:elementValue) = java:elementValue mandatory
-
-/**
- * Element-value pair
- */
-[java:elementValuePair] > nt:unstructured
- + java:identifier (java:identifier) mandatory
-
-/**
- * Annotation type
- */
-[java:annotationDeclaration] > nt:unstructured
- + java:annotationType (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
-
-/**
- * Normal annotation e.g. @Entity(name="Customer")
- */
-[java:normalAnnotation] > nt:unstructured
- - java:normalAnnotationName (string) mandatory
- + java:elementValuePair (java:elementValuePair)
-
-/**
- * Marker annotation e.g. @GET
- */
-[java:markerAnnotation] > nt:unstructured
- - java:markerAnnotationName (string) mandatory
-
-/**
- * Single element annotation e.g. @Path("/book")
- */
-[java:singleElementAnnotation] > nt:unstructured
- - java:singleElementAnnotationNam
- + java:value (java:elementValue) = java:elementValue mandatory
-
-/**
- * Formal parameter
- */
-[java:formalParameter] > nt:unstructured
- + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType)
-
-/**
- * Primitive type:
- * - Integral type ('byte', 'short', 'int', 'long', 'char')
- * - Floating point type ('float', 'double')
- * - Boolean type ('boolean')
- * - No return type ('void')
- */
-[java:primitiveType] > nt:unstructured
- - java:primitiveTypeDescription (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:primitiveTypeName (string) mandatory
- + java:primitiveVariable (java:variable) = java:variable
-
- [java:variable] > nt:unstructured
- - java:variableName (string) mandatory
-
-/**
- * java:arrayType
- */
-[java:arrayType] > nt:unstructured
- - java:arrayTypeDescription (string)
- + java:arrayTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:arrayTypeName (string) mandatory
- + java:arrayTypeVariable (java:variable) = java:variable
-
-[java:simpleType] > nt:unstructured
- - java:simpleTypeDescription (string)
- + java:simpleTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:simpleTypeName (string) mandatory
- + java:simpleTypeVariable (java:variable) = java:variable
-
-[java:qualifiedType] > nt:unstructured
- - java:qualifiedTypeDescription (string)
- + java:qualifiedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:qualifiedTypeName (string) mandatory
- + java:qualifiedTypeVariable (java:variable) = java:variable
-
-[java:wildcardType] > nt:unstructured
- - java:wildcardTypeDescription (string)
- + java:wildcardTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:wildcardTypeName (string) mandatory
- + java:wildcardTypeVariable (java:variable) = java:variable
-
-[java:parameterizedType] > nt:unstructured
- - java:parameterizedTypeDescription (string)
- + java:parameterizedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:parameterizedTypeName (string) mandatory
- + java:parameterizedTypeVariable (java:variable) = java:variable
-
-/**
- * Field type
- */
-[java:fieldType] > nt:unstructured
- + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory multiple
-
- /**
- * Method declaration
- */
-[java:methodDeclaration] > nt:unstructured
- - java:methodDescription (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- + java:resultType (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory
- - java:methodName (string) mandatory
- + java:parameter (java:formalParameter) multiple
-
-/**
- * Constructor declarations
- */
-[java:constructorDeclaration] > nt:unstructured
- - java:constructorDescription (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:constructorName (string) mandatory
- + java:parameter (java:formalParameter)
-
-
-/**
- * Package declarations
- */
-[java:packageDeclaration] > nt:unstructured
- + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
- - java:packageKeyword (string)
- < 'package'
- - java:packageName (string) mandatory
-
-/**
- * Import declarations
- */
-[java:singleTypeImportDeclaration] > nt:unstructured
- - java:singleTypeImportkeyword (string) mandatory
- < 'import'
- - java:singleImportName (string) mandatory
-
-[java:typeImportOnDemandDeclaration] > nt:unstructured
- - java:onDemandImportKeyword (string) mandatory
- < 'import'
- - java:onDemandImportName (string) mandatory
-
- [java:importDeclaration] > nt:unstructured
- + java:singleImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
- + java:importOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
-
-
-/**
- * Class declaration
- *
- * The body of class declares members (fields and methods and nested classes and interfaces),
- * instance and static initializers, and constructors
- */
-[java:normalClassDeclaration] > nt:unstructured
- - java:description (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:normalClassName (string) mandatory
- + java:field (java:fieldType) = java:fieldType multiple
- + java:method (java:methodDeclaration) = java:methodDeclaration multiple
- + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
-
-[java:enumDeclaration] > nt:unstructured // TODO
-
-[java:classDeclaration] > nt:unstructured
- + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
- + java:enum (java:enumDeclaration) = java:enumDeclaration
-
-/**
- * Interface declaration
- *
- * The body of class declares members (fields and methods and nested classes and interfaces),
- * instance and static initializers, and constructors
- */
-[java:interfaceDeclaration] > nt:unstructured
-
-
-/**
- * Compilation unit
- */
-[java:compilationUnit] > nt:unstructured
- + java:package (java:packageDeclaration) = java:packageDeclaration
- + java:import (java:importDeclaration) = java:importDeclaration
- + java:unitType (java:classDeclaration, java:interfaceDeclaration)
Copied: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/sequencing.cnd (from rev 970, trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd)
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/sequencing.cnd (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/sequencing.cnd 2009-06-04 16:32:16 UTC (rev 971)
@@ -0,0 +1,266 @@
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+<image='http://jboss.org/dna/images/1.0'>
+<mp3='http://jboss.org/dna/mp3/1.0'>
+<java='http://www.jboss.org/dna/java/1.0'>
+
+// ----------------------------------------------------------
+// JCR Pre-defined Mixin Types that are not loaded by default
+// ----------------------------------------------------------
+
+[mix:mimeTyped] mixin
+ - jcr:mimeType (string)
+ - jcr:encoding (string)
+
+
+// -------------------
+// DNA Image Sequencer
+// -------------------
+
+/**
+ * Node type that defines the metadata for an image
+ */
+[image:metadata] > nt:unstructured, mix:mimeTyped
+ - image:formatName (string) mandatory
+ < 'JPEG', 'GIF', 'PNG', 'BMP', 'PCX', 'IFF', 'RAS', 'PBM', 'PGM', 'PPM', 'PSD'
+ - image:width (long)
+ - image:height (long)
+ - image:bitsPerPixel (long)
+ - image:progressive (boolean)
+ - image:numberOfImages (long)
+ - image:physicalWidthDpi (long)
+ - image:physicalHeightDpi (long)
+ - image:physicalWidthInches (long)
+ - image:physicalHeightInches (long)
+
+// -------------------
+// DNA MP3 Sequencer
+// -------------------
+
+/**
+ * Node type that defines the metadata for an MP3 audio file
+ */
+[mp3:metadata] > nt:unstructured, mix:mimeTyped
+ - mp3:title (string)
+ - mp3:author (string)
+ - mp3:album (string)
+ - mp3:year (long)
+ - mp3:comment (string)
+
+// -------------------
+// DNA Java Sequencer
+// -------------------
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+/**
+ * Element-value
+ */
+[java:elementValue] > nt:unstructured
+ + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
+
+/**
+ * Modifiers
+ */
+[java:modifierDeclaration] > nt:unstructured
+ - java:modifierName (string) mandatory
+
+/**
+ * Expression element-value type
+ */
+[java:conditionalExpression] > nt:unstructured
+ - java:expression (string)
+
+/**
+ * Array initializer element-value type
+ */
+[java:elementValueArrayInitializer] > nt:unstructured
+ + java:elementValue (java:elementValue) = java:elementValue multiple
+
+/**
+ * Identifier
+ */
+[java:identifier] > nt:unstructured
+ - java:identifierName (String) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Element-value pair
+ */
+[java:elementValuePair] > nt:unstructured
+ + java:identifier (java:identifier) mandatory
+
+/**
+ * Annotation type
+ */
+[java:annotationDeclaration] > nt:unstructured
+ + java:annotationType (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
+
+/**
+ * Normal annotation e.g. @Entity(name="Customer")
+ */
+[java:normalAnnotation] > nt:unstructured
+ - java:normalAnnotationName (string) mandatory
+ + java:elementValuePair (java:elementValuePair)
+
+/**
+ * Marker annotation e.g. @GET
+ */
+[java:markerAnnotation] > nt:unstructured
+ - java:markerAnnotationName (string) mandatory
+
+/**
+ * Single element annotation e.g. @Path("/book")
+ */
+[java:singleElementAnnotation] > nt:unstructured
+ - java:singleElementAnnotationName (string) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Formal parameter
+ */
+[java:formalParameter] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType)
+
+/**
+ * Primitive type:
+ * - Integral type ('byte', 'short', 'int', 'long', 'char')
+ * - Floating point type ('float', 'double')
+ * - Boolean type ('boolean')
+ * - No return type ('void')
+ */
+[java:primitiveType] > nt:unstructured
+ - java:primitiveTypeDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:primitiveTypeName (string) mandatory
+ + java:primitiveVariable (java:variable) = java:variable
+
+ [java:variable] > nt:unstructured
+ - java:variableName (string) mandatory
+
+/**
+ * java:arrayType
+ */
+[java:arrayType] > nt:unstructured
+ - java:arrayTypeDescription (string)
+ + java:arrayTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:arrayTypeName (string) mandatory
+ + java:arrayTypeVariable (java:variable) = java:variable
+
+[java:simpleType] > nt:unstructured
+ - java:simpleTypeDescription (string)
+ + java:simpleTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:simpleTypeName (string) mandatory
+ + java:simpleTypeVariable (java:variable) = java:variable
+
+[java:qualifiedType] > nt:unstructured
+ - java:qualifiedTypeDescription (string)
+ + java:qualifiedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:qualifiedTypeName (string) mandatory
+ + java:qualifiedTypeVariable (java:variable) = java:variable
+
+[java:wildcardType] > nt:unstructured
+ - java:wildcardTypeDescription (string)
+ + java:wildcardTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:wildcardTypeName (string) mandatory
+ + java:wildcardTypeVariable (java:variable) = java:variable
+
+[java:parameterizedType] > nt:unstructured
+ - java:parameterizedTypeDescription (string)
+ + java:parameterizedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:parameterizedTypeName (string) mandatory
+ + java:parameterizedTypeVariable (java:variable) = java:variable
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:methodDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ + java:resultType (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory
+ - java:methodName (string) mandatory
+ + java:parameter (java:formalParameter) multiple
+
+/**
+ * Constructor declarations
+ */
+[java:constructorDeclaration] > nt:unstructured
+ - java:constructorDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:constructorName (string) mandatory
+ + java:parameter (java:formalParameter)
+
+
+/**
+ * Package declarations
+ */
+[java:packageDeclaration] > nt:unstructured
+ + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
+ - java:packageKeyword (string)
+ < 'package'
+ - java:packageName (string) mandatory
+
+/**
+ * Import declarations
+ */
+[java:singleTypeImportDeclaration] > nt:unstructured
+ - java:singleTypeImportkeyword (string) mandatory
+ < 'import'
+ - java:singleImportName (string) mandatory
+
+[java:typeImportOnDemandDeclaration] > nt:unstructured
+ - java:onDemandImportKeyword (string) mandatory
+ < 'import'
+ - java:onDemandImportName (string) mandatory
+
+ [java:importDeclaration] > nt:unstructured
+ + java:singleImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
+ + java:importOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
+
+
+/**
+ * Class declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:normalClassDeclaration] > nt:unstructured
+ - java:description (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:normalClassName (string) mandatory
+ + java:field (java:fieldType) = java:fieldType multiple
+ + java:method (java:methodDeclaration) = java:methodDeclaration multiple
+ + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
+
+[java:enumDeclaration] > nt:unstructured // TODO
+
+[java:classDeclaration] > nt:unstructured
+ + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
+ + java:enum (java:enumDeclaration) = java:enumDeclaration
+
+/**
+ * Interface declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:interfaceDeclaration] > nt:unstructured
+
+
+/**
+ * Compilation unit
+ */
+[java:compilationUnit] > nt:unstructured
+ + java:package (java:packageDeclaration) = java:packageDeclaration
+ + java:import (java:importDeclaration) = java:importDeclaration
+ + java:unitType (java:classDeclaration, java:interfaceDeclaration)
+
\ No newline at end of file
Modified: trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/MockUserInterface.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/MockUserInterface.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/MockUserInterface.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -27,8 +27,6 @@
import static org.junit.Assert.assertThat;
import java.net.URL;
import java.util.List;
-import org.jboss.example.dna.sequencer.ContentInfo;
-import org.jboss.example.dna.sequencer.UserInterface;
/**
* @author Randall Hauch
@@ -72,4 +70,13 @@
return this.repositoryPath != null ? this.repositoryPath : defaultPath;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.example.dna.sequencer.UserInterface#displayError(java.lang.Exception)
+ */
+ public void displayError( Exception e ) {
+ // Do nothing
+ }
+
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -34,7 +34,6 @@
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.jcr.JcrConfiguration;
import org.jboss.dna.jcr.JcrRepository;
-import org.jboss.dna.sequencer.image.ImageMetadataSequencer;
import org.jboss.dna.sequencer.java.JavaMetadataSequencer;
import org.jboss.dna.sequencer.mp3.Mp3MetadataSequencer;
import org.junit.After;
@@ -73,10 +72,7 @@
.setProperty("defaultWorkspaceName", workspaceName);
// Set up the JCR repository to use the source ...
config.repository(repositoryId)
- .addNodeTypes(ImageMetadataSequencer.class.getClassLoader().getResource("org/jboss/dna/sequencer/image/images.cnd"))
- .addNodeTypes(Mp3MetadataSequencer.class.getClassLoader().getResource("org/jboss/dna/sequencer/mp3/mp3.cnd"))
- .addNodeTypes(JavaMetadataSequencer.class.getClassLoader()
- .getResource("org/jboss/dna/sequencer/java/javaSource.cnd"))
+ .addNodeTypes(getClass().getClassLoader().getResource("sequencing.cnd"))
.setSource("store")
.setOption(JcrRepository.Option.JAAS_LOGIN_CONFIG_NAME, "dna-jcr");
// Set up the image sequencer ...
@@ -123,7 +119,6 @@
}
- @Ignore
@Test
public void shouldUploadAndSequencePngFile() throws Exception {
client.setUserInterface(new MockUserInterface(this.pngImageUrl, "/a/b/caution.png", 1));
@@ -132,13 +127,13 @@
// Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
// and to then shut down the DNA services (which will block until all sequencing has been completed) ...
- Thread.sleep(1000);
+ Thread.sleep(4000);
+ assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
+
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
client.search();
-
- assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
}
@Ignore
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-06-03 20:26:37 UTC (rev 970)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-06-04 16:32:16 UTC (rev 971)
@@ -45,7 +45,7 @@
*/
public class SVNConnectorTestUtil {
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public static void main( String[] args ) throws Exception {
try {
System.out.println("My repos. ......");
@@ -53,53 +53,47 @@
String username = "sp";
String password = "";
System.out.println(svnUrl);
- SVNRepository trunkWorkspace = createRepository(svnUrl +"/trunk", username, password);
+ SVNRepository trunkWorkspace = createRepository(svnUrl + "/trunk", username, password);
System.out.println("Repository location: " + trunkWorkspace.getLocation().toString());
System.out.println("Repository Root: " + trunkWorkspace.getRepositoryRoot(true));
System.out.println("Repository UUID: " + trunkWorkspace.getRepositoryUUID(true));
/**
- * Returns the repository location to which this object is set.
- * It may be the location that was used to create this object
- * (see {@link SVNRepositoryFactory#create(SVNURL)}), or the recent
- * one the object was set to.
+ * Returns the repository location to which this object is set. It may be the location that was used to create this
+ * object (see {@link SVNRepositoryFactory#create(SVNURL)}), or the recent one the object was set to.
*/
System.out.println("location: " + trunkWorkspace.getLocation().getPath());
System.out.println("decoded location: " + trunkWorkspace.getLocation().toDecodedString());
System.out.println("last seg: " + getRepositoryWorspaceName(trunkWorkspace));
-
- final Collection<SVNDirEntry> dirEntries = trunkWorkspace.getDir("",
- -1,
- null,
- (Collection<SVNDirEntry>)null);
+
+ final Collection<SVNDirEntry> dirEntries = trunkWorkspace.getDir("", -1, null, (Collection<SVNDirEntry>)null);
for (SVNDirEntry dirEntry : dirEntries) {
- System.out.println("name: " + dirEntry.getName());
+ System.out.println("name: " + dirEntry.getName());
}
-
-////
-// SVNNodeKind nodeKind = trunkWorkspace.checkPath( "/" , -1 );
-// if ( nodeKind == SVNNodeKind.NONE ) {
-// System.err.println( "There is no entry in the workspace "+ trunkWorkspace );
-// System.exit( 1 );
-// } else if ( nodeKind == SVNNodeKind.FILE ) {
-// System.err.println( "The entry at '" + trunkWorkspace + "' is a file while a directory was expected." );
-// System.exit( 1 );
-// } else {
-// listEntries(trunkWorkspace, "/root");
-//// long latestRevision = trunkWorkspace.getLatestRevision( );
-//// System.out.println( "workspace latest revision: " + latestRevision );
-//
-////// SVNNodeKind kind = trunkWorkspace.checkPath("/", -1);
-//// if(kind == SVNNodeKind.NONE) {
-//// System.out.println("none");
-//// } else if(kind == SVNNodeKind.UNKNOWN) {
-//// System.out.println("unknown");
-//// } else if(kind == SVNNodeKind.FILE) {
-//// System.out.println("file");
-//// } else if(kind == SVNNodeKind.DIR) {
-// System.out.println("dir");
-//// listEntries(trunkWorkspace,"root");
-// }
+ // //
+ // SVNNodeKind nodeKind = trunkWorkspace.checkPath( "/" , -1 );
+ // if ( nodeKind == SVNNodeKind.NONE ) {
+ // System.err.println( "There is no entry in the workspace "+ trunkWorkspace );
+ // System.exit( 1 );
+ // } else if ( nodeKind == SVNNodeKind.FILE ) {
+ // System.err.println( "The entry at '" + trunkWorkspace + "' is a file while a directory was expected." );
+ // System.exit( 1 );
+ // } else {
+ // listEntries(trunkWorkspace, "/root");
+ // // long latestRevision = trunkWorkspace.getLatestRevision( );
+ // // System.out.println( "workspace latest revision: " + latestRevision );
+ //
+ // //// SVNNodeKind kind = trunkWorkspace.checkPath("/", -1);
+ // // if(kind == SVNNodeKind.NONE) {
+ // // System.out.println("none");
+ // // } else if(kind == SVNNodeKind.UNKNOWN) {
+ // // System.out.println("unknown");
+ // // } else if(kind == SVNNodeKind.FILE) {
+ // // System.out.println("file");
+ // // } else if(kind == SVNNodeKind.DIR) {
+ // System.out.println("dir");
+ // // listEntries(trunkWorkspace,"root");
+ // }
} catch (SVNException e) {
e.printStackTrace();
@@ -144,26 +138,26 @@
FileUtil.copy(mySrc, myDst);
// Now set the two path roots
- String url = myDst.getCanonicalFile().toURL().toString();
+ String url = myDst.getCanonicalFile().toURI().toURL().toString();
return url.replaceFirst("file:/", "file://localhost/");
}
-
- @SuppressWarnings("unchecked")
- public static void listEntries( SVNRepository workspace, String path ) throws SVNException {
- Collection<SVNDirEntry> entries = workspace.getDir( path, -1 , null , (Collection) null );
- Iterator<SVNDirEntry> iterator = entries.iterator( );
- while ( iterator.hasNext( ) ) {
- SVNDirEntry entry = iterator.next( );
- System.out.println( "/" + (path.equals( "" ) ? "" : path + "/" ) + entry.getName( ) +
- " ( author: '" + entry.getAuthor( ) + "'; revision: " + entry.getRevision( ) +
- "; date: " + entry.getDate( ) + ")" );
- if ( entry.getKind() == SVNNodeKind.DIR ) {
- listEntries( workspace, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) );
+
+ @SuppressWarnings( "unchecked" )
+ public static void listEntries( SVNRepository workspace,
+ String path ) throws SVNException {
+ Collection<SVNDirEntry> entries = workspace.getDir(path, -1, null, (Collection)null);
+ Iterator<SVNDirEntry> iterator = entries.iterator();
+ while (iterator.hasNext()) {
+ SVNDirEntry entry = iterator.next();
+ System.out.println("/" + (path.equals("") ? "" : path + "/") + entry.getName() + " ( author: '" + entry.getAuthor()
+ + "'; revision: " + entry.getRevision() + "; date: " + entry.getDate() + ")");
+ if (entry.getKind() == SVNNodeKind.DIR) {
+ listEntries(workspace, (path.equals("")) ? entry.getName() : path + "/" + entry.getName());
}
}
}
- public static String getRepositoryWorspaceName(SVNRepository repository) {
+ public static String getRepositoryWorspaceName( SVNRepository repository ) {
String[] segments = repository.getLocation().getPath().split("/");
return segments[segments.length - 1];
}
16 years, 6 months
DNA SVN: r970 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-03 16:26:37 -0400 (Wed, 03 Jun 2009)
New Revision: 970
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
Log:
DNA-389 Corrected the JcrEngine's code that obtained a too-shallow subgraph of the configuration repository, so that it obtains a sufficiently deep subgraph.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-03 20:10:19 UTC (rev 969)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-03 20:26:37 UTC (rev 970)
@@ -103,7 +103,7 @@
Path repositoriesPath = pathFactory.create(configuration.getPath(), DnaLexicon.REPOSITORIES);
Path repositoryPath = pathFactory.create(repositoriesPath, repositoryName);
Graph configuration = getConfigurationGraph();
- Subgraph subgraph = configuration.getSubgraphOfDepth(3).at(repositoryPath);
+ Subgraph subgraph = configuration.getSubgraphOfDepth(6).at(repositoryPath);
// Read the options ...
Node optionsNode = subgraph.getNode(DnaLexicon.OPTIONS);
16 years, 6 months
DNA SVN: r969 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph and 19 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-03 16:10:19 -0400 (Wed, 03 Jun 2009)
New Revision: 969
Added:
trunk/dna-jcr/src/test/resources/config/
trunk/dna-jcr/src/test/resources/config/configRepository.xml
trunk/dna-repository/src/test/resources/config/
trunk/dna-repository/src/test/resources/config/configRepository.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/jaas.conf.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/roles.properties
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/users.properties
Removed:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java
Modified:
trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaLexicon.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
trunk/docs/examples/gettingstarted/sequencers/pom.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheRequestProcessor.java
trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd
Log:
DNA-389 Change Getting Started examples to use the DnaConfiguration and JcrConfiguration components
Simplified and improved the DnaConfiguration and JcrConfiguration classes, and added to JcrConfiguration the ability to define the repositories separately from the repository sources and to define on these repositories the JCR options, namespaces, and node types in the configuration (including via the configuration API). All the existing uses of the configuration classes were changed to use the new/modified methods.
Modified: trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java
===================================================================
--- trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -222,7 +222,7 @@
String prefix = namespace.getFirstChildWithType(CndLexer.PREFIX).getChild(0).getText();
String uri = namespace.getFirstChildWithType(CndLexer.URI).getChild(0).getText();
// Register the namespace ...
- context.namespaces().register(removeQuotes(prefix), removeQuotes(uri));
+ context.register(removeQuotes(prefix), removeQuotes(uri));
}
}
@@ -346,6 +346,7 @@
*/
protected final class ImportContext {
private final ExecutionContext context;
+ private final ExecutionContext originalContext;
private final Problems problems;
private final String resourceName;
@@ -354,6 +355,7 @@
String resourceName ) {
// Create a context that has a local namespace registry
NamespaceRegistry localNamespaces = new LocalNamespaceRegistry(context.getNamespaceRegistry());
+ this.originalContext = context;
this.context = context.with(localNamespaces);
this.problems = problems;
this.resourceName = resourceName;
@@ -363,8 +365,17 @@
return this.context;
}
- protected NamespaceRegistry namespaces() {
- return this.context.getNamespaceRegistry();
+ protected void register( String prefix,
+ String uri ) {
+ // Register it in the local registry with the supplied prefix ...
+ context.getNamespaceRegistry().register(prefix, uri);
+
+ // See if it is already registered in the original context ...
+ NamespaceRegistry registry = originalContext.getNamespaceRegistry();
+ if (!registry.isRegisteredNamespaceUri(uri)) {
+ // It is not, so register it ...
+ registry.register(prefix, uri);
+ }
}
protected NameFactory nameFactory() {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -109,6 +109,7 @@
* @param context the context in which all executions should be performed
* @return the new graph
* @throws IllegalArgumentException if the source or context parameters are null
+ * @throws RepositorySourceException if a source with the supplied name does not exist
*/
public static Graph create( String sourceName,
RepositoryConnectionFactory connectionFactory,
@@ -1311,6 +1312,15 @@
return nextGraph;
}
+ public Conjunction<Graph> to( Object[] values ) {
+ for (int i = 0, len = values.length; i != len; ++i) {
+ values[i] = convertReferenceValue(values[i]);
+ }
+ Property property = getContext().getPropertyFactory().create(propertyName, values);
+ requests.setProperty(location, getCurrentWorkspaceName(), property);
+ return nextGraph;
+ }
+
public Conjunction<Graph> to( Iterable<?> values ) {
List<Object> valueList = new LinkedList<Object>();
for (Object value : values) {
@@ -1468,6 +1478,13 @@
return set(getContext().getPropertyFactory().create(propertyName, firstValue, otherValues));
}
+ public On<Conjunction<Graph>> to( Object[] values ) {
+ for (int i = 0, len = values.length; i != len; ++i) {
+ values[i] = convertReferenceValue(values[i]);
+ }
+ return set(getContext().getPropertyFactory().create(propertyName, values));
+ }
+
public On<Conjunction<Graph>> to( Iterable<?> values ) {
List<Object> valueList = new LinkedList<Object>();
for (Object value : values) {
@@ -2734,6 +2751,157 @@
}
/**
+ * Begin the request to create a node located at the supplied path if there is no such node already.
+ * <p>
+ * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
+ * called.
+ * </p>
+ *
+ * @param atPath the path to the node that is to be created.
+ * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
+ * node where the node is to be created
+ */
+ public Create<Batch> createIfMissing( String atPath ) {
+ return createIfMissing(createPath(atPath));
+ }
+
+ /**
+ * Begin the request to create a node located at the supplied path if there is no such node already.
+ * <p>
+ * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
+ * called.
+ * </p>
+ *
+ * @param atPath the path to the node that is to be created.
+ * @param property a property for the new node
+ * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
+ * node where the node is to be created
+ */
+ public Create<Batch> createIfMissing( String atPath,
+ Property property ) {
+ return createIfMissing(createPath(atPath)).with(property);
+ }
+
+ /**
+ * Begin the request to create a node located at the supplied path if there is no such node already.
+ * <p>
+ * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
+ * called.
+ * </p>
+ *
+ * @param atPath the path to the node that is to be created.
+ * @param firstProperty a property for the new node
+ * @param additionalProperties additional properties for the new node
+ * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
+ * node where the node is to be created
+ */
+ public Create<Batch> createIfMissing( String atPath,
+ Property firstProperty,
+ Property... additionalProperties ) {
+ return createIfMissing(createPath(atPath)).with(firstProperty, additionalProperties);
+ }
+
+ /**
+ * Begin the request to create a node located at the supplied path if there is no such node already.
+ * <p>
+ * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
+ * called.
+ * </p>
+ *
+ * @param at the path to the node that is to be created.
+ * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
+ * node where the node is to be created
+ */
+ public final Create<Batch> createIfMissing( Path at ) {
+ assertNotExecuted();
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
+ return createIfMissing(Location.create(parent), name);
+ }
+
+ protected final CreateAction<Batch> createIfMissing( Location parent,
+ Name child ) {
+ return new CreateAction<Batch>(this, parent, getCurrentWorkspaceName(), child) {
+ @Override
+ protected Batch submit( Location parent,
+ String workspaceName,
+ Name childName,
+ Collection<Property> properties ) {
+ requestQueue.createNode(parent, workspaceName, childName, properties.iterator(), NodeConflictBehavior.UPDATE);
+ return Batch.this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Graph.Executable#execute()
+ */
+ public Results execute() {
+ and();
+ return Batch.this.execute();
+ }
+ };
+ }
+
+ /**
+ * Begin the request to create a node located at the supplied path.
+ * <p>
+ * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
+ * called.
+ * </p>
+ *
+ * @param at the path to the node that is to be created.
+ * @param properties the iterator over the properties for the new node
+ * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
+ * node where the node is to be created
+ */
+ public Create<Batch> createIfMissing( Path at,
+ Iterable<Property> properties ) {
+ Create<Batch> action = createIfMissing(at);
+ for (Property property : properties) {
+ action.and(property);
+ }
+ return action;
+ }
+
+ /**
+ * Begin the request to create a node located at the supplied path if there is no such node already.
+ * <p>
+ * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
+ * called.
+ * </p>
+ *
+ * @param at the path to the node that is to be created.
+ * @param property a property for the new node
+ * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
+ * node where the node is to be created
+ */
+ public Create<Batch> createIfMissing( Path at,
+ Property property ) {
+ return createIfMissing(at).with(property);
+ }
+
+ /**
+ * Begin the request to create a node located at the supplied path if there is no such node already.
+ * <p>
+ * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is
+ * called.
+ * </p>
+ *
+ * @param at the path to the node that is to be created.
+ * @param firstProperty a property for the new node
+ * @param additionalProperties additional properties for the new node
+ * @return the object that can be used to specify addition properties for the new node to be copied or the location of the
+ * node where the node is to be created
+ */
+ public Create<Batch> createIfMissing( Path at,
+ Property firstProperty,
+ Property... additionalProperties ) {
+ return createIfMissing(at).with(firstProperty, additionalProperties);
+ }
+
+ /**
* Begin the request to create a node under the existing parent node at the supplied location. This request is submitted
* to the repository after the returned components are completed.
*
@@ -2930,6 +3098,15 @@
return nextRequests;
}
+ public BatchConjunction to( Object[] values ) {
+ for (int i = 0; i != values.length; ++i) {
+ values[i] = convertReferenceValue(values[i]);
+ }
+ Property property = getContext().getPropertyFactory().create(propertyName, values);
+ requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
+ return nextRequests;
+ }
+
public BatchConjunction to( Iterable<?> values ) {
List<Object> valueList = new LinkedList<Object>();
for (Object value : values) {
@@ -3089,6 +3266,13 @@
return set(getContext().getPropertyFactory().create(propertyName, values));
}
+ public On<BatchConjunction> to( Object[] values ) {
+ for (int i = 0, len = values.length; i != len; ++i) {
+ values[i] = convertReferenceValue(values[i]);
+ }
+ return set(getContext().getPropertyFactory().create(propertyName, values));
+ }
+
public On<BatchConjunction> to( Iterable<?> values ) {
List<Object> valueList = new LinkedList<Object>();
for (Object value : values) {
@@ -4779,6 +4963,18 @@
Next to( Object value );
/**
+ * Set the property values to the given object. Each of the supplied <code>values</code> should be a valid property value,
+ * or a {@link Node} (or {@link Location}) if the property value is to be a reference to that node (or location). Note
+ * that it is an error if the Node (or Location) does not have a {@link Location#getUuid() UUID}.
+ *
+ * @param values the property values
+ * @return the interface for additional requests or actions
+ * @throws IllegalArgumentException if the any of the values is a Node or Location that has no {@link Location#getUuid()
+ * UUID}
+ */
+ Next to( Object[] values );
+
+ /**
* Set the property value to the given objects. Each of the supplied values should be a valid property value, or a
* {@link Node} (or {@link Location}) if the property value is to be a reference to that node (or location). Note that it
* is an error if the Node (or Location) does not have a {@link Location#getUuid() UUID}.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -467,6 +467,7 @@
// Record this operation as a pending change ...
pendingRequest = new NodeChange(on, workspaceName);
for (Property property : properties) {
+ if (property == null) continue;
pendingRequest.pendingProperties.put(property.getName(), property);
}
return this;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -6,8 +6,8 @@
* See the AUTHORS.txt file in the distribution for a full listing of
* individual contributors.
*
- * Unless otherwise indicated, all code in JBoss DNA is licensed
- * to you under the terms of the GNU Lesser General Public License as
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
@@ -27,496 +27,589 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.cnd.CndImporter;
+import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.Node;
+import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.io.Destination;
import org.jboss.dna.graph.io.GraphBatchDestination;
-import org.jboss.dna.graph.mimetype.MimeTypeDetector;
+import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.sequencer.StreamSequencer;
-import org.jboss.dna.repository.Configurator;
+import org.jboss.dna.graph.property.PathNotFoundException;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.NamespaceRegistry.Namespace;
+import org.jboss.dna.jcr.JcrRepository.Option;
import org.jboss.dna.repository.DnaConfiguration;
import org.jboss.dna.repository.DnaConfigurationException;
-import org.jboss.dna.repository.Configurator.And;
-import org.jboss.dna.repository.Configurator.ChooseClass;
-import org.jboss.dna.repository.Configurator.ConfigSourceDetails;
-import org.jboss.dna.repository.Configurator.MimeTypeDetectorDetails;
-import org.jboss.dna.repository.Configurator.RepositorySourceDetails;
-import org.jboss.dna.repository.Configurator.SequencerDetails;
-import org.jboss.dna.repository.Configurator.SetName;
+import org.xml.sax.SAXException;
/**
* A configuration builder for a {@link JcrEngine}. This class is an internal domain-specific language (DSL), and is designed to
* be used in a traditional way or in a method-chained manner:
*
* <pre>
- * configuration.addRepository("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description");
- * configuration.addMimeTypeDetector("detector").usingClass(ExtensionBasedMimeTypeDetector.class).describedAs("default detector");
- * configuration.addSequencer("MicrosoftDocs")
- * .usingClass("org.jboss.dna.sequencer.msoffice.MSOfficeMetadataSequencer")
- * .loadedFromClasspath()
- * .named("Microsoft Document sequencer")
- * .describedAs("Our primary sequencer for all .doc files")
+ * configuration.repositorySource("Source1").setClass(InMemoryRepositorySource.class).setDescription("description");
+ * configuration.mimeTypeDetector("detector").setClass(ExtensionBasedMimeTypeDetector.class).setDescription("default detector");
+ * configuration.sequencer("MicrosoftDocs")
+ * .setClass("org.jboss.dna.sequencer.msoffice.MSOfficeMetadataSequencer")
+ * .setDescription("Our primary sequencer for all .doc files")
* .sequencingFrom("/public//(*.(doc|xml|ppt)[*]/jcr:content[@jcr:data]")
* .andOutputtingTo("/documents/$1");
+ * configuration.repository("MyRepository").setSource("Source1");
* configuration.save();
* </pre>
*/
-public class JcrConfiguration
- implements Configurator.Initializer<JcrConfiguration>, Configurator.SequencerConfigurator<JcrConfiguration>,
- Configurator.RepositorySourceConfigurator<JcrConfiguration>, Configurator.MimeDetectorConfigurator<JcrConfiguration>,
- Configurator.Builder<JcrEngine> {
+@NotThreadSafe
+public class JcrConfiguration extends DnaConfiguration {
- private final JcrConfiguration.Builder<JcrConfiguration> builder;
+ /**
+ * Interface used to define a JCR Repository that's accessible from the JcrEngine.
+ *
+ * @param <ReturnType>
+ */
+ public interface RepositoryDefinition<ReturnType> extends Returnable<ReturnType>, Removable<ReturnType> {
+ /**
+ * Specify the name of the repository source that is to be used by this JCR repository.
+ *
+ * @param sourceName the name of the repository source that should be exposed by this JCR repository
+ * @return the interface used to set the value for the property; never null
+ * @throws IllegalArgumentException if the source name parameter is null
+ */
+ RepositoryDefinition<ReturnType> setSource( String sourceName );
+
+ /**
+ * Get the name of the repository source that is to be used by this JCR repository.
+ *
+ * @return the source name, or null if it has not yet been set
+ */
+ String getSource();
+
+ /**
+ * Specify the repository option that is to be set.
+ *
+ * @param option the option to be set
+ * @param value the new value for the option
+ * @return the interface used to set the value for the property; never null
+ * @throws IllegalArgumentException if either parameter is null
+ */
+ RepositoryDefinition<ReturnType> setOption( JcrRepository.Option option,
+ String value );
+
+ /**
+ * Get the value for the repository option.
+ *
+ * @param option the option
+ * @return the current option value, which may be null if the option has not been set (and its default would be used)
+ * @throws IllegalArgumentException if the option parameter is null
+ */
+ String getOption( JcrRepository.Option option );
+
+ /**
+ * Specify that the CND in the supplied string should be loaded into the repository.
+ *
+ * @param cndContents the string containing the compact node definitions
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the string is null or empty
+ * @throws DnaConfigurationException if there is an error reading the CND contents
+ */
+ RepositoryDefinition<ReturnType> addNodeTypes( String cndContents );
+
+ /**
+ * Specify that the CND file is to be loaded into the repository.
+ *
+ * @param cndFile the CND file
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the file is null
+ * @throws DnaConfigurationException if there is an error reading the file
+ */
+ RepositoryDefinition<ReturnType> addNodeTypes( File cndFile );
+
+ /**
+ * Specify that the CND file is to be loaded into the repository.
+ *
+ * @param urlOfCndFile the URL of the CND file
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the URL is null
+ * @throws DnaConfigurationException if there is an error reading the content at the URL
+ */
+ RepositoryDefinition<ReturnType> addNodeTypes( URL urlOfCndFile );
+
+ /**
+ * Specify that the CND file is to be loaded into the repository.
+ *
+ * @param cndContent the stream containing the CND content
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the URL is null
+ * @throws DnaConfigurationException if there is an error reading the stream at the URL
+ */
+ RepositoryDefinition<ReturnType> addNodeTypes( InputStream cndContent );
+
+ /**
+ * Specify the namespace binding that should be made available in this repository.
+ *
+ * @param prefix the namespace prefix; may not be null or empty, and must be a valid prefix
+ * @param uri the uri for the namespace; may not be null or empty
+ * @return the interface used to set the value for the property; never null
+ */
+ RepositoryDefinition<ReturnType> registerNamespace( String prefix,
+ String uri );
+ }
+
+ private final Map<String, RepositoryDefinition<? extends JcrConfiguration>> repositoryDefinitions = new HashMap<String, RepositoryDefinition<? extends JcrConfiguration>>();
+
/**
- * Create a new configuration for DNA.
+ * Create a new configuration, using a default-constructed {@link ExecutionContext}.
*/
public JcrConfiguration() {
- this(new ExecutionContext());
+ super();
}
/**
- * Specify a new {@link ExecutionContext} that should be used for this DNA instance.
+ * Create a new configuration using the supplied {@link ExecutionContext}.
*
- * @param context the new context, or null if a default-constructed execution context should be used
- * @throws IllegalArgumentException if the supplied context reference is null
+ * @param context the execution context
+ * @throws IllegalArgumentException if the path is null or empty
*/
public JcrConfiguration( ExecutionContext context ) {
- this.builder = new JcrConfiguration.Builder<JcrConfiguration>(context, this);
+ super(context);
}
/**
- * Get the execution context used by this configurator.
+ * {@inheritDoc}
*
- * @return the execution context; never null
+ * @throws IOException
+ * @throws SAXException
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.lang.String)
*/
- public final ExecutionContext getExecutionContext() {
- return builder.getExecutionContext();
+ @Override
+ public JcrConfiguration loadFrom( String pathToFile ) throws IOException, SAXException {
+ super.loadFrom(pathToFile);
+ return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationSource()
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.lang.String, java.lang.String)
*/
- public ChooseClass<RepositorySource, ConfigSourceDetails<JcrConfiguration>> withConfigurationSource() {
- return builder.withConfigurationSource();
+ @Override
+ public JcrConfiguration loadFrom( String pathToConfigurationFile,
+ String path ) throws IOException, SAXException {
+ super.loadFrom(pathToConfigurationFile, path);
+ return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String)
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.io.File)
*/
- public ChooseClass<StreamSequencer, SequencerDetails<JcrConfiguration>> addSequencer( String id ) {
- CheckArg.isNotEmpty(id, "id");
- return builder.addSequencer(id);
+ @Override
+ public JcrConfiguration loadFrom( File configurationFile ) throws IOException, SAXException {
+ super.loadFrom(configurationFile);
+ return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(java.lang.String)
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.io.File, java.lang.String)
*/
- public ChooseClass<RepositorySource, RepositorySourceDetails<JcrConfiguration>> addSource( String id ) {
- CheckArg.isNotEmpty(id, "id");
- return builder.addSource(id);
+ @Override
+ public JcrConfiguration loadFrom( File configurationFile,
+ String path ) throws IOException, SAXException {
+ super.loadFrom(configurationFile, path);
+ return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(org.jboss.dna.graph.connector.RepositorySource)
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.net.URL)
*/
- public JcrConfiguration addSource( RepositorySource source ) {
- CheckArg.isNotNull(source, "source");
- CheckArg.isNotEmpty(source.getName(), "source.getName()");
- return builder.addSource(source);
+ @Override
+ public JcrConfiguration loadFrom( URL urlToConfigurationFile ) throws IOException, SAXException {
+ super.loadFrom(urlToConfigurationFile);
+ return this;
}
/**
- * Add a JCR repository to this configuration.
+ * {@inheritDoc}
*
- * @param id the identifier for this repository; may not be null or empty
- * @return the interface used to configure the repository
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.net.URL, java.lang.String)
*/
- public SourceSetter<JcrRepositoryDetails<JcrConfiguration>> addRepository( final String id ) {
- CheckArg.isNotEmpty(id, "id");
- final JcrConfiguration.Builder<JcrConfiguration> builder = this.builder;
- return new SourceSetter<JcrRepositoryDetails<JcrConfiguration>>() {
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrConfiguration.SourceSetter#usingSource(java.lang.String)
- */
- public JcrRepositoryDetails<JcrConfiguration> usingSource( String sourceId ) {
- return builder.addRepository(id, sourceId);
- }
- };
+ @Override
+ public JcrConfiguration loadFrom( URL urlToConfigurationFile,
+ String path ) throws IOException, SAXException {
+ super.loadFrom(urlToConfigurationFile, path);
+ return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.MimeDetectorConfigurator#addMimeTypeDetector(java.lang.String)
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.io.InputStream)
*/
- public ChooseClass<MimeTypeDetector, MimeTypeDetectorDetails<JcrConfiguration>> addMimeTypeDetector( String id ) {
- CheckArg.isNotEmpty(id, "id");
- return builder.addMimeTypeDetector(id);
+ @Override
+ public JcrConfiguration loadFrom( InputStream configurationFileInputStream ) throws IOException, SAXException {
+ super.loadFrom(configurationFileInputStream);
+ return this;
}
/**
- * Save any changes that have been made so far to the configuration. This method does nothing if no changes have been made.
+ * {@inheritDoc}
*
- * @return this configuration object for method chaining purposes; never null
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(java.io.InputStream, java.lang.String)
*/
- public JcrConfiguration save() {
- return builder.save();
+ @Override
+ public JcrConfiguration loadFrom( InputStream configurationFileInputStream,
+ String path ) throws IOException, SAXException {
+ super.loadFrom(configurationFileInputStream, path);
+ return this;
}
- protected Graph graph() {
- return builder.getGraph();
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource)
+ */
+ @Override
+ public JcrConfiguration loadFrom( RepositorySource source ) {
+ super.loadFrom(source);
+ return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.Builder#build()
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource, java.lang.String)
*/
- public JcrEngine build() throws DnaConfigurationException {
- save();
- return new JcrEngine(builder.buildDnaEngine());
+ @Override
+ public JcrConfiguration loadFrom( RepositorySource source,
+ String workspaceName ) {
+ super.loadFrom(source, workspaceName);
+ return this;
}
/**
- * The interface used to set the RepositorySource that should be used.
+ * {@inheritDoc}
*
- * @param <ReturnType> the interface returned from these methods
+ * @see org.jboss.dna.repository.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource, java.lang.String,
+ * java.lang.String)
*/
- public interface SourceSetter<ReturnType> {
- /**
- * Set the repository source that should be used.
- *
- * @param sourceId that identifier of the repository source
- * @return the next component to continue configuration; never null
- */
- ReturnType usingSource( String sourceId );
+ @Override
+ public JcrConfiguration loadFrom( RepositorySource source,
+ String workspaceName,
+ String pathInWorkspace ) {
+ super.loadFrom(source, workspaceName, pathInWorkspace);
+ return this;
}
- public interface JcrRepositoryDetails<ReturnType>
- extends SetOptions<JcrRepositoryDetails<ReturnType>>, SetNamespace<JcrRepositoryDetails<ReturnType>>,
- SetName<JcrRepositoryDetails<ReturnType>>,
- /* SetDescription<JcrRepositoryDetails<ReturnType>>, */
- And<ReturnType> {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration#and()
+ */
+ @Override
+ public JcrConfiguration and() {
+ return this;
+ }
- /**
- * Specify that the CND in the supplied string should be loaded into the repository.
- *
- * @param cndContents the string containing the compact node definitions
- * @return this object for chained method invocation
- * @throws IllegalArgumentException if the string is null or empty
- * @throws DnaConfigurationException if there is an error reading the CND contents
- */
- JcrRepositoryDetails<ReturnType> withNodeTypes( String cndContents );
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration#withClassLoaderFactory(org.jboss.dna.common.component.ClassLoaderFactory)
+ */
+ @Override
+ public JcrConfiguration withClassLoaderFactory( ClassLoaderFactory classLoaderFactory ) {
+ super.withClassLoaderFactory(classLoaderFactory);
+ return this;
+ }
- /**
- * Specify that the CND file is to be loaded into the repository.
- *
- * @param cndFile the CND file
- * @return this object for chained method invocation
- * @throws IllegalArgumentException if the file is null
- * @throws DnaConfigurationException if there is an error reading the file
- */
- JcrRepositoryDetails<ReturnType> withNodeTypes( File cndFile );
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration#mimeTypeDetector(java.lang.String)
+ */
+ @Override
+ public MimeTypeDetectorDefinition<JcrConfiguration> mimeTypeDetector( String name ) {
+ return mimeTypeDetectorDefinition(this, name);
+ }
- /**
- * Specify that the CND file is to be loaded into the repository.
- *
- * @param urlOfCndFile the URL of the CND file
- * @return this object for chained method invocation
- * @throws IllegalArgumentException if the URL is null
- * @throws DnaConfigurationException if there is an error reading the content at the URL
- */
- JcrRepositoryDetails<ReturnType> withNodeTypes( URL urlOfCndFile );
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration#repositorySource(java.lang.String)
+ */
+ @Override
+ public RepositorySourceDefinition<JcrConfiguration> repositorySource( String name ) {
+ return repositorySourceDefinition(this, name);
+ }
- /**
- * Specify that the CND file is to be loaded into the repository.
- *
- * @param cndContent the stream containing the CND content
- * @return this object for chained method invocation
- * @throws IllegalArgumentException if the URL is null
- * @throws DnaConfigurationException if there is an error reading the stream at the URL
- */
- JcrRepositoryDetails<ReturnType> withNodeTypes( InputStream cndContent );
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration#sequencer(java.lang.String)
+ */
+ @Override
+ public SequencerDefinition<JcrConfiguration> sequencer( String name ) {
+ return sequencerDefinition(this, name);
+ }
+ /**
+ * Obtain or create a definition for the {@link javax.jcr.Repository JCR Repository} with the supplied name or identifier. A
+ * new definition will be created if there currently is no sequencer defined with the supplied name.
+ *
+ * @param name the name or identifier of the sequencer
+ * @return the details of the sequencer definition; never null
+ */
+ public RepositoryDefinition<JcrConfiguration> repository( String name ) {
+ return repositoryDefinition(this, name);
}
/**
- * Interface for configuring the {@link JcrRepository.Option JCR repository options} for a {@link JcrRepository JCR
- * repository}.
+ * Get the list of sequencer definitions.
*
- * @param <ReturnType> the interface returned after the option has been set.
+ * @return the unmodifiable set of definitions; never null but possibly empty if there are no definitions
*/
- public interface SetOptions<ReturnType> {
- /**
- * Specify the repository option that is to be set. The value may be set using the interface returned by this method.
- *
- * @param option the option to be set
- * @return the interface used to set the value for the property; never null
- */
- OptionSetter<ReturnType> with( JcrRepository.Option option );
+ public Set<RepositoryDefinition<JcrConfiguration>> repositories() {
+ // Get the children under the 'dna:mimeTypeDetectors' node ...
+ Set<String> names = getNamesOfComponentsUnder(DnaLexicon.REPOSITORIES);
+ names.addAll(this.repositoryDefinitions.keySet());
+ Set<RepositoryDefinition<JcrConfiguration>> results = new HashSet<RepositoryDefinition<JcrConfiguration>>();
+ for (String name : names) {
+ results.add(repository(name));
+ }
+ return Collections.unmodifiableSet(results);
}
/**
- * The interface used to set the value for a {@link JcrRepository.Option JCR repository option}.
+ * {@inheritDoc}
*
- * @param <ReturnType> the interface returned from these methods
- * @see JcrConfiguration.SetOptions#with(org.jboss.dna.jcr.JcrRepository.Option)
+ * @see org.jboss.dna.repository.DnaConfiguration#save()
*/
- public interface OptionSetter<ReturnType> {
- /**
- * Set the property value to an integer.
- *
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setTo( String value );
+ @Override
+ public JcrConfiguration save() {
+ super.save();
+ this.repositoryDefinitions.clear();
+ return this;
}
/**
- * Interface for setting a namespace for a {@link JcrRepository JCR repository}.
+ * {@inheritDoc}
*
- * @param <ReturnType> the interface returned after the option has been set.
+ * @see org.jboss.dna.repository.DnaConfiguration#build()
*/
- public interface SetNamespace<ReturnType> {
- /**
- * Specify the repository option that is to be set. The value may be set using the interface returned by this method.
- *
- * @param uri the uri for the namespace
- * @return the interface used to set the value for the property; never null
- */
- NamespaceSetter<ReturnType> withNamespace( String uri );
+ @Override
+ public JcrEngine build() {
+ save();
+ return new JcrEngine(getExecutionContext(), getConfigurationDefinition());
}
/**
- * The interface used to set the prefix for a namespace.
+ * Utility method to construct a definition object for the repository with the supplied name and return type.
*
- * @param <ReturnType> the interface returned from these methods
- * @see JcrConfiguration.SetNamespace#withNamespace(String)
+ * @param <ReturnType> the type of the return object
+ * @param returnObject the return object
+ * @param name the name of the repository
+ * @return the definition for the repository
*/
- public interface NamespaceSetter<ReturnType> {
- /**
- * Set the prefix for the namespace
- *
- * @param prefix the prefix for the namespace
- * @return the next component to continue configuration; never null
- */
- ReturnType usingPrefix( String prefix );
+ @SuppressWarnings( "unchecked" )
+ protected <ReturnType extends JcrConfiguration> RepositoryDefinition<ReturnType> repositoryDefinition( ReturnType returnObject,
+ String name ) {
+ RepositoryDefinition<ReturnType> definition = (RepositoryDefinition<ReturnType>)repositoryDefinitions.get(name);
+ if (definition == null) {
+ definition = new RepositoryBuilder<ReturnType>(returnObject, changes(), path(), DnaLexicon.REPOSITORIES, name(name));
+ repositoryDefinitions.put(name, definition);
+ }
+ return definition;
}
- public static class Builder<ReturnType> extends DnaConfiguration.Builder<ReturnType> {
+ protected class RepositoryBuilder<ReturnType> extends GraphReturnable<ReturnType, RepositoryDefinition<ReturnType>>
+ implements RepositoryDefinition<ReturnType> {
+ private final EnumMap<JcrRepository.Option, String> optionValues = new EnumMap<Option, String>(Option.class);
- private Path repositoriesPath;
+ protected RepositoryBuilder( ReturnType returnObject,
+ Graph.Batch batch,
+ Path path,
+ Name... names ) {
+ super(returnObject, batch, path, names);
+ // Load the current options ...
+ try {
+ Path optionsPath = context.getValueFactories().getPathFactory().create(path, DnaLexicon.OPTIONS);
+ Subgraph options = batch.getGraph().getSubgraphOfDepth(2).at(optionsPath);
+ for (Location optionChild : options.getRoot().getChildren()) {
+ Node option = options.getNode(optionChild);
+ Property property = option.getProperty(DnaLexicon.VALUE);
+ if (property != null && property.isEmpty()) {
+ try {
+ Option key = Option.findOption(optionChild.getPath()
+ .getLastSegment()
+ .getString(context.getNamespaceRegistry()));
+ String value = context.getValueFactories().getStringFactory().create(property.getFirstValue());
+ optionValues.put(key, value);
+ } catch (IllegalArgumentException e) {
+ // the key is not valid, so skip it ...
+ }
+ }
+ }
+ } catch (PathNotFoundException e) {
+ // No current options
+ }
+ }
- /**
- * Specify a new {@link ExecutionContext} that should be used for this DNA instance.
- *
- * @param context the new context, or null if a default-constructed execution context should be used
- * @param builder the builder object returned from all the methods
- * @throws IllegalArgumentException if the supplied context reference is null
- */
- public Builder( ExecutionContext context,
- ReturnType builder ) {
- super(context, builder);
+ @Override
+ protected RepositoryDefinition<ReturnType> thisType() {
+ return this;
}
- protected Graph getGraph() {
- return graph();
+ public RepositoryDefinition<ReturnType> setSource( String sourceName ) {
+ setProperty(DnaLexicon.SOURCE_NAME, sourceName);
+ return this;
}
- protected Path repositoriesPath() {
- // Make sure the "dna:repositories" node is there
- if (repositoriesPath == null) {
- Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.REPOSITORIES);
- Node node = graph().createIfMissing(path).andReturn();
- this.repositoriesPath = node.getLocation().getPath();
+ public String getSource() {
+ Property property = getProperty(DnaLexicon.SOURCE_NAME);
+ if (property != null && !property.isEmpty()) {
+ return context.getValueFactories().getStringFactory().create(property.getFirstValue());
}
- return this.repositoriesPath;
+ return null;
}
- public JcrRepositoryDetails<ReturnType> addRepository( String id,
- String sourceId ) {
- CheckArg.isNotEmpty(id, "id");
- // Now create the "dna:repositories/id" node ...
- Path path = createOrReplaceNode(repositoriesPath(), id);
- configuration().set(DnaLexicon.SOURCE_NAME).to(sourceId).on(path);
- return new JcrGraphRepositoryDetails<ReturnType>(path, builder);
+ public RepositoryDefinition<ReturnType> setOption( JcrRepository.Option option,
+ String value ) {
+ CheckArg.isNotNull(option, "option");
+ CheckArg.isNotNull(value, "value");
+ createIfMissing(DnaLexicon.OPTIONS, option.name()).with(DnaLexicon.VALUE, value.trim()).and();
+ optionValues.put(option, value);
+ return this;
}
- public class JcrGraphRepositoryDetails<RT> implements JcrRepositoryDetails<RT> {
- private final Path path;
- private final RT returnObject;
+ public String getOption( Option option ) {
+ CheckArg.isNotNull(option, "option");
+ return optionValues.get(option);
+ }
- protected JcrGraphRepositoryDetails( Path path,
- RT returnObject ) {
- this.path = path;
- this.returnObject = returnObject;
- }
+ public RepositoryDefinition<ReturnType> registerNamespace( String prefix,
+ String uri ) {
+ CheckArg.isNotEmpty(prefix, "prefix");
+ CheckArg.isNotEmpty(uri, "uri");
+ prefix = prefix.trim();
+ uri = uri.trim();
+ createIfMissing(DnaLexicon.NAMESPACES, prefix).with(DnaLexicon.URI, uri).and();
+ return this;
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetName#named(java.lang.String)
- */
- @SuppressWarnings( "synthetic-access" )
- public JcrRepositoryDetails<RT> named( String name ) {
- configuration().set(DnaLexicon.READABLE_NAME).to(name).on(name);
- return this;
- }
+ public RepositoryDefinition<ReturnType> addNodeTypes( String cndContents ) {
+ CheckArg.isNotEmpty(cndContents, "cndContents");
+ CndImporter importer = createCndImporter();
+ try {
+ Set<Namespace> namespacesBefore = batch.getGraph().getContext().getNamespaceRegistry().getNamespaces();
+ importer.importFrom(cndContents, getProblems(), "stream");
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrConfiguration.SetNamespace#withNamespace(java.lang.String)
- */
- @SuppressWarnings( "synthetic-access" )
- public NamespaceSetter<JcrRepositoryDetails<RT>> withNamespace( final String uri ) {
- final Path namespacesPath = createOrReplaceNode(path, DnaLexicon.NAMESPACES);
- final JcrRepositoryDetails<RT> details = this;
- return new NamespaceSetter<JcrRepositoryDetails<RT>>() {
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrConfiguration.NamespaceSetter#usingPrefix(java.lang.String)
- */
- public JcrRepositoryDetails<RT> usingPrefix( String prefix ) {
- Path nsPath = createOrReplaceNode(namespacesPath, prefix);
- configuration().set(DnaLexicon.URI).to(uri).on(nsPath);
- return details;
- }
- };
+ // Record any new namespaces added by this import ...
+ registerNewNamespaces(namespacesBefore);
+ } catch (IOException e) {
+ throw new DnaConfigurationException(e);
}
+ return this;
+ }
- @SuppressWarnings( "synthetic-access" )
- public OptionSetter<JcrRepositoryDetails<RT>> with( final JcrRepository.Option option ) {
- final Path optionsPath = createOrReplaceNode(path, DnaLexicon.OPTIONS);
- final JcrRepositoryDetails<RT> details = this;
- return new OptionSetter<JcrRepositoryDetails<RT>>() {
- public JcrRepositoryDetails<RT> setTo( String value ) {
- Path optionPath = createOrReplaceNode(optionsPath, option.name());
- configuration().set(DnaLexicon.VALUE).to(value).on(optionPath);
- return details;
- }
- };
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.lang.String)
- */
- public JcrRepositoryDetails<RT> withNodeTypes( String content ) {
- CheckArg.isNotEmpty(content, "content");
+ public RepositoryDefinition<ReturnType> addNodeTypes( File file ) {
+ CheckArg.isNotNull(file, "file");
+ if (file.exists() && file.canRead()) {
CndImporter importer = createCndImporter();
try {
- importer.importFrom(content, getProblems(), "stream");
- } catch (IOException e) {
- throw new DnaConfigurationException(e);
- }
- return this;
- }
+ Set<Namespace> namespacesBefore = batch.getGraph().getContext().getNamespaceRegistry().getNamespaces();
+ importer.importFrom(file, getProblems());
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.net.URL)
- */
- public JcrRepositoryDetails<RT> withNodeTypes( URL url ) {
- CheckArg.isNotNull(url, "url");
- // Obtain the stream ...
- InputStream stream = null;
- boolean foundError = false;
- try {
- stream = url.openStream();
- CndImporter importer = createCndImporter();
- importer.importFrom(stream, getProblems(), url.toString());
+ // Record any new namespaces added by this import ...
+ registerNewNamespaces(namespacesBefore);
} catch (IOException e) {
- foundError = true;
throw new DnaConfigurationException(e);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- if (!foundError) {
- throw new DnaConfigurationException(e);
- }
- }
- }
}
return this;
}
+ throw new DnaConfigurationException(JcrI18n.fileDoesNotExist.text(file.getPath()));
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.io.File)
- */
- public JcrRepositoryDetails<RT> withNodeTypes( File file ) {
- CheckArg.isNotNull(file, "file");
- if (file.exists() && file.canRead()) {
- CndImporter importer = createCndImporter();
+ public RepositoryDefinition<ReturnType> addNodeTypes( URL url ) {
+ CheckArg.isNotNull(url, "url");
+ // Obtain the stream ...
+ InputStream stream = null;
+ boolean foundError = false;
+ try {
+ Set<Namespace> namespacesBefore = batch.getGraph().getContext().getNamespaceRegistry().getNamespaces();
+ stream = url.openStream();
+ CndImporter importer = createCndImporter();
+ importer.importFrom(stream, getProblems(), url.toString());
+
+ // Record any new namespaces added by this import ...
+ registerNewNamespaces(namespacesBefore);
+ } catch (IOException e) {
+ foundError = true;
+ throw new DnaConfigurationException(e);
+ } finally {
+ if (stream != null) {
try {
- importer.importFrom(file, getProblems());
+ stream.close();
} catch (IOException e) {
- throw new DnaConfigurationException(e);
+ if (!foundError) {
+ throw new DnaConfigurationException(e);
+ }
}
- return this;
}
- throw new DnaConfigurationException(JcrI18n.fileDoesNotExist.text(file.getPath()));
}
+ return this;
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.io.InputStream)
- */
- public JcrRepositoryDetails<RT> withNodeTypes( InputStream stream ) {
- CndImporter importer = createCndImporter();
- try {
- importer.importFrom(stream, getProblems(), "stream");
- } catch (IOException e) {
- throw new DnaConfigurationException(e);
- }
- return this;
+ public RepositoryDefinition<ReturnType> addNodeTypes( InputStream cndContent ) {
+ CndImporter importer = createCndImporter();
+ try {
+ Set<Namespace> namespacesBefore = batch.getGraph().getContext().getNamespaceRegistry().getNamespaces();
+ importer.importFrom(cndContent, getProblems(), "stream");
+
+ // Record any new namespaces added by this import ...
+ registerNewNamespaces(namespacesBefore);
+ } catch (IOException e) {
+ throw new DnaConfigurationException(e);
}
+ return this;
+ }
- @SuppressWarnings( "synthetic-access" )
- protected CndImporter createCndImporter() {
- // The node types will be loaded into 'dna:repositories/{repositoryName}/dna:nodeTypes/' ...
- Path nodeTypesPath = createOrReplaceNode(path, DnaLexicon.NODE_TYPES);
+ protected void registerNewNamespaces( Set<Namespace> namespacesBefore ) {
+ Set<Namespace> namespacesAfter = batch.getGraph().getContext().getNamespaceRegistry().getNamespaces();
+ Set<Namespace> newNamespaces = new HashSet<Namespace>(namespacesAfter);
+ newNamespaces.removeAll(namespacesBefore);
+ for (Namespace namespace : newNamespaces) {
+ registerNamespace(namespace.getPrefix(), namespace.getNamespaceUri());
+ }
+ }
- // Now set up the destination ...
- Destination destination = new GraphBatchDestination(graph().batch()); // will be executed
+ protected CndImporter createCndImporter() {
+ // The node types will be loaded into 'dna:repositories/{repositoryName}/dna:nodeTypes/' ...
+ Path nodeTypesPath = subpath(DnaLexicon.NODE_TYPES);
+ createIfMissing(DnaLexicon.NODE_TYPES).and();
- // And create the importer that will load the CND content into the repository ...
- return new CndImporter(destination, nodeTypesPath);
- }
+ // Now set up the destination ...
+ Destination destination = new GraphBatchDestination(batch, true); // will NOT be executed
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.And#and()
- */
- public RT and() {
- return returnObject;
- }
+ // And create the importer that will load the CND content into the repository ...
+ return new CndImporter(destination, nodeTypesPath);
}
+ }
- }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -23,17 +23,12 @@
*/
package org.jboss.dna.jcr;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
-import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -42,100 +37,43 @@
import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.PathNotFoundException;
import org.jboss.dna.graph.property.Property;
import org.jboss.dna.graph.property.basic.GraphNamespaceRegistry;
import org.jboss.dna.jcr.JcrRepository.Option;
+import org.jboss.dna.repository.DnaConfiguration;
import org.jboss.dna.repository.DnaEngine;
-import org.jboss.dna.repository.RepositoryLibrary;
-import org.jboss.dna.repository.RepositoryService;
-import org.jboss.dna.repository.sequencer.SequencingService;
/**
* The basic component that encapsulates the JBoss DNA services, including the {@link Repository} instances.
*/
-public class JcrEngine {
+public class JcrEngine extends DnaEngine {
- private final DnaEngine dnaEngine;
private final Map<String, JcrRepository> repositories;
private final Lock repositoriesLock;
- JcrEngine( DnaEngine dnaEngine ) {
- this.dnaEngine = dnaEngine;
+ JcrEngine( ExecutionContext context,
+ DnaConfiguration.ConfigurationDefinition configuration ) {
+ super(context, configuration);
this.repositories = new HashMap<String, JcrRepository>();
this.repositoriesLock = new ReentrantLock();
}
/**
- * Get the problems that were encountered when setting up this engine from the configuration.
- *
- * @return the problems, which may be empty but will never be null
- */
- public Problems getProblems() {
- return dnaEngine.getProblems();
- }
-
- /**
- * Get the execution context for this engine. This context can be used to create additional (perhaps narrowed) contexts.
- *
- * @return the engine's execution context; never null
- */
- public final ExecutionContext getExecutionContext() {
- return dnaEngine.getExecutionContext();
- }
-
- /**
- * Get the RepositorySource with the supplied name.
- *
- * @param repositoryName the name of the repository (or repository source)
- * @return the named repository source, or null if there is no such repository
- */
- protected final RepositorySource getRepositorySource( String repositoryName ) {
- return dnaEngine.getRepositorySource(repositoryName);
- }
-
- protected final RepositoryConnectionFactory getRepositoryConnectionFactory() {
- return dnaEngine.getRepositoryConnectionFactory();
- }
-
- protected final RepositoryService getRepositoryService() {
- return dnaEngine.getRepositoryService();
- }
-
- protected final SequencingService getSequencingService() {
- return dnaEngine.getSequencingService();
- }
-
- /**
- * Returns a list of the names of all available JCR repositories.
- * <p>
- * In a {@code JcrEngine}, the available repositories are {@link RepositoryLibrary#getSourceNames() all repositories} except
- * for the {@link RepositoryService#getConfigurationSourceName() the configuration repository}.
- * </p>
- *
- * @return a list of all repository names.
- */
- public final Collection<String> getJcrRepositoryNames() {
- List<String> jcrRepositories = new ArrayList<String>();
- jcrRepositories.addAll(getRepositoryService().getRepositoryLibrary().getSourceNames());
-
- jcrRepositories.remove(getRepositoryService().getConfigurationSourceName());
-
- return jcrRepositories;
- }
-
- /**
* Get the {@link Repository} implementation for the named repository.
*
* @param repositoryName the name of the repository, which corresponds to the name of a configured {@link RepositorySource}
* @return the named repository instance
* @throws IllegalArgumentException if the repository name is null, blank or invalid
* @throws RepositoryException if there is no repository with the specified name
+ * @throws IllegalStateException if this engine was not {@link #start() started}
*/
public final JcrRepository getRepository( String repositoryName ) throws RepositoryException {
CheckArg.isNotEmpty(repositoryName, "repositoryName");
+ checkRunning();
try {
repositoriesLock.lock();
JcrRepository repository = repositories.get(repositoryName);
@@ -155,17 +93,16 @@
}
}
- protected JcrRepository doCreateJcrRepository( String repositoryName ) {
+ protected JcrRepository doCreateJcrRepository( String repositoryName ) throws RepositoryException, PathNotFoundException {
RepositoryConnectionFactory connectionFactory = getRepositoryConnectionFactory();
Map<String, String> descriptors = null;
Map<Option, String> options = new HashMap<Option, String>();
// Read the subgraph that represents the repository ...
PathFactory pathFactory = getExecutionContext().getValueFactories().getPathFactory();
- Path repositoriesPath = pathFactory.create(DnaLexicon.REPOSITORIES);
+ Path repositoriesPath = pathFactory.create(configuration.getPath(), DnaLexicon.REPOSITORIES);
Path repositoryPath = pathFactory.create(repositoriesPath, repositoryName);
- String configurationName = dnaEngine.getRepositoryService().getConfigurationSourceName();
- Graph configuration = Graph.create(connectionFactory.createConnection(configurationName), getExecutionContext());
+ Graph configuration = getConfigurationGraph();
Subgraph subgraph = configuration.getSubgraphOfDepth(3).at(repositoryPath);
// Read the options ...
@@ -191,8 +128,18 @@
context = context.with(registry);
}
+ // Get the name of the source ...
+ Property property = subgraph.getRoot().getProperty(DnaLexicon.SOURCE_NAME);
+ if (property == null || property.isEmpty()) {
+ String readableName = readable(DnaLexicon.SOURCE_NAME);
+ String readablePath = readable(subgraph.getLocation());
+ String msg = JcrI18n.propertyNotFoundOnNode.text(readableName, readablePath, configuration.getCurrentWorkspaceName());
+ throw new RepositoryException(msg);
+ }
+ String sourceName = context.getValueFactories().getStringFactory().create(property.getFirstValue());
+
// Create the repository ...
- JcrRepository repository = new JcrRepository(context, connectionFactory, repositoryName, descriptors, options);
+ JcrRepository repository = new JcrRepository(context, connectionFactory, sourceName, descriptors, options);
// Register all the the node types ...
Node nodeTypesNode = subgraph.getNode(DnaLexicon.NODE_TYPES);
@@ -208,44 +155,15 @@
return repository;
}
- /*
- * Lifecycle methods
- */
-
- /**
- * Start this engine to make it available for use.
- *
- * @throws IllegalStateException if this method is called when already shut down.
- * @see #shutdown()
- */
- public void start() {
- dnaEngine.start();
+ protected final String readable( Name name ) {
+ return name.getString(context.getNamespaceRegistry());
}
- /**
- * Shutdown this engine to close all connections, terminate any ongoing background operations (such as sequencing), and
- * reclaim any resources that were acquired by this engine. This method may be called multiple times, but only the first time
- * has an effect.
- *
- * @see #start()
- */
- public void shutdown() {
- dnaEngine.shutdown();
+ protected final String readable( Path path ) {
+ return path.getString(context.getNamespaceRegistry());
}
- /**
- * Blocks until the shutdown has completed, or the timeout occurs, or the current thread is interrupted, whichever happens
- * first.
- *
- * @param timeout the maximum time to wait for each component in this engine
- * @param unit the time unit of the timeout argument
- * @return <tt>true</tt> if this service complete shut down and <tt>false</tt> if the timeout elapsed before it was shut down
- * completely
- * @throws InterruptedException if interrupted while waiting
- */
- public boolean awaitTermination( long timeout,
- TimeUnit unit ) throws InterruptedException {
- return dnaEngine.awaitTermination(timeout, unit);
+ protected final String readable( Location location ) {
+ return location.getString(context.getNamespaceRegistry());
}
-
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -104,18 +104,21 @@
*/
public static Option findOption( String option ) {
if (option == null) return null;
- Option result = Option.valueOf(option);
- if (result != null) return result;
- // Try an uppercased version ...
- result = Option.valueOf(option.toUpperCase());
- if (result != null) return result;
- // Try a camel-case version ...
- String underscored = Inflector.getInstance().underscore(option, '_');
- if (underscored != null) {
- result = Option.valueOf(underscored);
+ try {
+ return Option.valueOf(option);
+ } catch (IllegalArgumentException e) {
+ // Try an uppercased version ...
+ try {
+ return Option.valueOf(option.toUpperCase());
+ } catch (IllegalArgumentException e2) {
+ // Try a camel-case version ...
+ String underscored = Inflector.getInstance().underscore(option, '_');
+ if (underscored == null) {
+ throw e2;
+ }
+ return Option.valueOf(underscored.toUpperCase());
+ }
}
-
- return result;
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -413,29 +413,31 @@
}
if (checkMultiValuedDefinitions) {
- // Look for a multi-value property definition on the primary type that matches by name and type ...
- for (JcrPropertyDefinition definition : primaryType.allMultiValuePropertyDefinitions(propertyName)) {
- matchedOnName = true;
- // See if the definition allows the value ...
- if (skipProtected && definition.isProtected()) return null;
- if (setToEmpty) {
- if (!definition.isMandatory()) return definition;
- // Otherwise this definition doesn't work, so continue with the next ...
- continue;
- }
- assert value != null;
- // We can use the definition if it matches the type and satisfies the constraints ...
- int type = definition.getRequiredType();
- if ((type == PropertyType.UNDEFINED || type == value.getType()) && definition.satisfiesConstraints(value)) return definition;
- }
- if (value != null) {
+ if (primaryType != null) {
+ // Look for a multi-value property definition on the primary type that matches by name and type ...
for (JcrPropertyDefinition definition : primaryType.allMultiValuePropertyDefinitions(propertyName)) {
matchedOnName = true;
// See if the definition allows the value ...
if (skipProtected && definition.isProtected()) return null;
- assert definition.getRequiredType() != PropertyType.UNDEFINED;
- if (definition.canCastToTypeAndSatisfyConstraints(value)) return definition;
+ if (setToEmpty) {
+ if (!definition.isMandatory()) return definition;
+ // Otherwise this definition doesn't work, so continue with the next ...
+ continue;
+ }
+ assert value != null;
+ // We can use the definition if it matches the type and satisfies the constraints ...
+ int type = definition.getRequiredType();
+ if ((type == PropertyType.UNDEFINED || type == value.getType()) && definition.satisfiesConstraints(value)) return definition;
}
+ if (value != null) {
+ for (JcrPropertyDefinition definition : primaryType.allMultiValuePropertyDefinitions(propertyName)) {
+ matchedOnName = true;
+ // See if the definition allows the value ...
+ if (skipProtected && definition.isProtected()) return null;
+ assert definition.getRequiredType() != PropertyType.UNDEFINED;
+ if (definition.canCastToTypeAndSatisfyConstraints(value)) return definition;
+ }
+ }
}
if (matchedOnName) return null;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -576,16 +576,16 @@
}
/**
- * The JCR specification assumes that reading a node into the session does not imply reading the
- * relationship between the node and its children into the session. As a performance optimization,
- * DNA eagerly loads the list of child names and UUIDs (but not the child nodes themselves). This creates
- * an issue when direct writes are performed through the workspace. The act of modifying a node is assumed
- * to imply loading its children, but we must load the node in order to modify it.
+ * The JCR specification assumes that reading a node into the session does not imply reading the relationship between the node
+ * and its children into the session. As a performance optimization, DNA eagerly loads the list of child names and UUIDs (but
+ * not the child nodes themselves). This creates an issue when direct writes are performed through the workspace. The act of
+ * modifying a node is assumed to imply loading its children, but we must load the node in order to modify it.
* <p>
- * This method provides a way to signal that a child should be added to one parent and, optionally, removed
- * from another. The cache of loaded nodes and the cache of changed nodes are modified accordingly, but no
- * additional graph requests are batched.
+ * This method provides a way to signal that a child should be added to one parent and, optionally, removed from another. The
+ * cache of loaded nodes and the cache of changed nodes are modified accordingly, but no additional graph requests are
+ * batched.
* </p>
+ *
* @param newParentUuid the UUID of the node to which the child is to be moved; may not be null
* @param oldParentUuid the UUID of the parent node from which the child was moved; may not be null
* @param child the UUID of the child node that was moved or copied; may not be null
@@ -593,13 +593,13 @@
* @throws RepositoryException if an error occurs
*/
public void compensateForWorkspaceChildChange( UUID newParentUuid,
- UUID oldParentUuid,
- UUID child,
- Name childName ) throws RepositoryException {
+ UUID oldParentUuid,
+ UUID child,
+ Name childName ) throws RepositoryException {
assert newParentUuid != null;
assert child != null;
assert childName != null;
-
+
ChangedNodeInfo changedNode = this.changedNodes.get(newParentUuid);
if (changedNode != null) {
// This adds the child to the changed node, but doesn't generate a corresponding pending request
@@ -1343,12 +1343,13 @@
}
}
- public void orderChildBefore(Path.Segment childToBeMoved, Path.Segment before) throws RepositoryException {
+ public void orderChildBefore( Path.Segment childToBeMoved,
+ Path.Segment before ) {
PathFactory pathFactory = SessionCache.this.pathFactory;
Path thisPath = this.currentLocation.getPath();
UUID fromUuid = this.node.getChildren().getChild(childToBeMoved).getUuid();
Location fromLocation = Location.create(pathFactory.create(thisPath, childToBeMoved), fromUuid);
-
+
Children children = this.node.getChildren();
ChildNode nodeToBeMoved = children.getChild(childToBeMoved);
this.node.removeChild(nodeToBeMoved.getUuid(), pathFactory);
@@ -1358,17 +1359,16 @@
// Moving the node into its parent will remove it from its current spot in the child list and re-add it to the end
operations.move(fromLocation).into(this.currentLocation);
- }
- else {
+ } else {
Path beforePath = pathFactory.create(thisPath, before);
UUID beforeUuid = this.node.getChildren().getChild(before).getUuid();
Location beforeLocation = Location.create(beforePath, beforeUuid);
-
+
this.node.addChild(nodeToBeMoved.getName(), before, nodeToBeMoved.getUuid(), pathFactory);
operations.move(fromLocation).before(beforeLocation);
}
}
-
+
/**
* Move the child specified by the supplied UUID to be a child of this node, appending the child to the end of the current
* list of children. This method automatically disconnects the node from its current parent.
@@ -1407,8 +1407,8 @@
if (!definition.getId().equals(node.getDefinitionId())) {
// The node definition changed, so try to set the property ...
try {
- JcrValue value = new JcrValue(factories(), SessionCache.this, PropertyType.STRING,
- definition.getId().getString());
+ JcrValue value = new JcrValue(factories(), SessionCache.this, PropertyType.STRING, definition.getId()
+ .getString());
setProperty(DnaIntLexicon.NODE_DEFINITON, value);
} catch (ConstraintViolationException e) {
// We can't set this property on the node (according to the node definition).
@@ -1641,7 +1641,10 @@
// ---------------------------------------
// Now record the changes to the store ...
// ---------------------------------------
- Graph.Create<Graph.Batch> create = operations.createUnder(currentLocation).nodeNamed(name).with(desiredUuid).with(primaryTypeProp);
+ Graph.Create<Graph.Batch> create = operations.createUnder(currentLocation)
+ .nodeNamed(name)
+ .with(desiredUuid)
+ .with(primaryTypeProp);
if (nodeDefnDefn != null) {
create = create.with(nodeDefinitionProp);
}
@@ -2396,8 +2399,8 @@
DnaIntLexicon.MULTI_VALUED_PROPERTIES,
values,
false);
- Property dnaProp = propertyFactory.create(DnaIntLexicon.MULTI_VALUED_PROPERTIES,
- newSingleMultiPropertyNames.iterator().next());
+ Property dnaProp = propertyFactory.create(DnaIntLexicon.MULTI_VALUED_PROPERTIES, newSingleMultiPropertyNames.iterator()
+ .next());
PropertyId propId = new PropertyId(uuid, dnaProp.getName());
JcrPropertyDefinition defn = (JcrPropertyDefinition)propertyDefinition;
return new PropertyInfo(propId, defn.getId(), PropertyType.STRING, dnaProp, defn.isMultiple(), true, false);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -181,8 +181,8 @@
}
/**
+ * {@inheritDoc}
*
- * {@inheritDoc}
* @return {@code false} always as this object represents unmodified nodes only
* @see org.jboss.dna.jcr.cache.NodeInfo#isNew()
*/
@@ -191,8 +191,8 @@
}
/**
+ * {@inheritDoc}
*
- * {@inheritDoc}
* @return {@code false} always as this object represents unmodified nodes only
* @see org.jboss.dna.jcr.cache.NodeInfo#isModified()
*/
@@ -200,7 +200,8 @@
return false;
}
+ @Override
public String toString() {
- return this.uuid + " (" + primaryTypeName + ") {" + properties + "}";
+ return this.uuid + " (" + primaryTypeName + ") {" + properties + "}";
}
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -32,7 +32,6 @@
import javax.jcr.Item;
import javax.jcr.ItemNotFoundException;
import javax.jcr.ItemVisitor;
-import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -59,28 +59,20 @@
super(env);
// Create the in-memory (DNA) repository
- JcrEngine engine = new JcrConfiguration().withConfigurationSource()
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("configuration repository")
- .usingWorkspace("configuration workspace")
- .with("name")
- .setTo("configuration repository")
- .with("defaultWorkspaceName")
- .setTo("configuration workspace")
- .and()
- .addSource("Store")
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("JCR Repository persistent store")
- .and()
- .addRepository(REPOSITORY_SOURCE_NAME)
- .usingSource("Store")
- .withNodeTypes(getClass().getClassLoader().getResource("tck_test_types.cnd"))
- .with(Option.PROJECT_NODE_TYPES)
- .setTo(Boolean.FALSE.toString())
- .and()
- .build();
+ JcrConfiguration configuration = new JcrConfiguration();
+ // Define the single in-memory repository source ...
+ configuration.repositorySource("Store")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .setDescription("JCR Repository persistent store");
+ // Define the JCR repository for the source ...
+ configuration.repository(REPOSITORY_SOURCE_NAME)
+ .setSource("Store")
+ .setOption(Option.PROJECT_NODE_TYPES, "false")
+ .addNodeTypes(getClass().getClassLoader().getResource("tck_test_types.cnd"));
+ // Save and build the engine ...
+ configuration.save();
+ JcrEngine engine = configuration.build();
engine.start();
// Print all of the problems from the engine configuration ...
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -24,43 +24,71 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
import static org.jboss.dna.graph.IsNodeWithChildren.hasChild;
+import static org.jboss.dna.graph.IsNodeWithChildren.hasChildren;
import static org.jboss.dna.graph.IsNodeWithProperty.hasProperty;
import static org.junit.Assert.assertThat;
+import java.io.File;
+import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.nodetype.NodeTypeManager;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.cache.ImmutableCachePolicy;
-import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.jcr.JcrRepository.Option;
import org.jboss.dna.repository.DnaConfiguration;
-import org.jboss.dna.repository.DnaEngine;
-import org.jboss.dna.repository.RepositoryLibrary;
+import org.jboss.dna.repository.DnaLexicon;
+import org.jboss.dna.repository.DnaConfiguration.ConfigurationDefinition;
+import org.jboss.security.config.IDTrustConfiguration;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class JcrConfigurationTest {
- private ExecutionContext context;
private JcrConfiguration configuration;
+ private JcrEngine engine;
@Before
public void beforeEach() {
- context = new ExecutionContext();
configuration = new JcrConfiguration();
}
+ @After
+ public void afterEach() throws Exception {
+ if (engine != null) {
+ try {
+ engine.shutdown();
+ engine.awaitTermination(3, TimeUnit.SECONDS);
+ } finally {
+ engine = null;
+ }
+ }
+ }
+
+ protected ExecutionContext context() {
+ return configuration.getConfigurationDefinition().getContext();
+ }
+
+ protected Path path( String path ) {
+ return context().getValueFactories().getPathFactory().create(path);
+ }
+
protected Path.Segment segment( String segment ) {
- return context.getValueFactories().getPathFactory().createSegment(segment);
+ return context().getValueFactories().getPathFactory().createSegment(segment);
}
@Test
@@ -70,72 +98,73 @@
@Test
public void shouldAllowCreatingWithSpecifiedExecutionContext() {
- configuration = new JcrConfiguration(context);
+ ExecutionContext newContext = new ExecutionContext();
+ configuration = new JcrConfiguration(newContext);
+ assertThat(configuration.getConfigurationDefinition().getContext(), is(sameInstance(newContext)));
}
@Test
public void shouldHaveDefaultConfigurationSourceIfNotSpecified() {
- assertThat(configuration.graph(), is(notNullValue()));
+ assertThat(configuration.getConfigurationDefinition(), is(notNullValue()));
}
@Test
public void shouldAllowAddingRepositorySourceInstance() {
UUID rootUuid = UUID.randomUUID();
CachePolicy cachePolicy = new ImmutableCachePolicy(100);
- InMemoryRepositorySource newSource = new InMemoryRepositorySource();
- newSource.setName("name");
- newSource.setDefaultCachePolicy(cachePolicy);
- newSource.setDefaultWorkspaceName("default workspace name");
- newSource.setRetryLimit(100);
- newSource.setRootNodeUuid(rootUuid);
// Update the configuration and save it ...
- configuration.addSource(newSource).save();
+ configuration.repositorySource("name")
+ .usingClass(InMemoryRepositorySource.class)
+ .setRetryLimit(100)
+ .setProperty("defaultCachePolicy", cachePolicy)
+ .setProperty("defaultWorkspaceName", "default workspace name")
+ .setProperty("rootNodeUuid", rootUuid)
+ .and()
+ .save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/name"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/name"), hasProperty(DnaLexicon.READABLE_NAME, "name"));
assertThat(subgraph.getNode("/dna:sources/name"), hasProperty(DnaLexicon.RETRY_LIMIT, 100));
- assertThat(subgraph.getNode("/dna:sources/name"), hasProperty(DnaLexicon.DEFAULT_CACHE_POLICY, cachePolicy));
+ assertThat(subgraph.getNode("/dna:sources/name"), hasProperty("defaultCachePolicy", cachePolicy));
assertThat(subgraph.getNode("/dna:sources/name"), hasProperty("defaultWorkspaceName", "default workspace name"));
assertThat(subgraph.getNode("/dna:sources/name"), hasProperty("rootNodeUuid", rootUuid));
}
@Test
public void shouldAllowSettingUpConfigurationRepositoryWithDifferentConfigurationSourceName() throws Exception {
- JcrEngine engine = configuration.withConfigurationSource()
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("config")
- .with("retryLimit")
- .setTo(5)
- .and()
- .addSource("Source2")
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("description")
- .and()
- .addRepository("JCR Repository")
- .usingSource("Source2")
- .with(Option.JAAS_LOGIN_CONFIG_NAME)
- .setTo("test")
- .and()
- .build();
+ configuration.repositorySource("Source2")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .setDescription("description")
+ .and()
+ .repository("JCR Repository")
+ .setSource("Source2")
+ .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test")
+ .and()
+ .save();
+
+ // Start the engine ...
+ engine = configuration.build();
engine.start();
// Get a graph to the configuration source ...
- RepositorySource configReposSource = engine.getRepositoryService().getRepositoryLibrary().getSource("config");
+ RepositorySource configReposSource = engine.getRepositoryService()
+ .getRepositoryLibrary()
+ .getSource(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
assertThat(configReposSource, is(notNullValue()));
assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
- assertThat(configReposSource.getName(), is("config"));
+ assertThat(configReposSource.getName(), is(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME));
InMemoryRepositorySource configSource = (InMemoryRepositorySource)configReposSource;
- assertThat(configSource.getDefaultWorkspaceName(), is(""));
- Graph graph = Graph.create("config", engine.getRepositoryService().getRepositoryLibrary(), context);
+ assertThat(configSource.getDefaultWorkspaceName(), is(JcrConfiguration.DEFAULT_WORKSPACE_NAME));
+ Graph graph = engine.getGraph(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
assertThat(graph, is(notNullValue()));
assertThat(graph.getNodeAt("/"), is(notNullValue()));
+ assertThat(graph.getNodeAt("/dna:sources"), is(notNullValue()));
+ assertThat(graph.getNodeAt("/dna:sources/Source2"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
+ assertThat(graph.getNodeAt("/dna:repositories/JCR Repository"), hasProperty(DnaLexicon.SOURCE_NAME, "Source2"));
// Get the repository ...
JcrRepository repository = engine.getRepository("JCR Repository");
@@ -144,40 +173,41 @@
@Test
public void shouldAllowSettingUpConfigurationRepositoryWithDifferentWorkspaceName() throws Exception {
- JcrEngine engine = configuration.withConfigurationSource()
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("Configuration Repository")
- .usingWorkspace("workspaceXYZ")
- .with("name")
- .setTo("config2")
- .with("defaultWorkspaceName")
- .setTo("workspaceXYZ")
- .with("retryLimit")
- .setTo(5)
- .and()
- .addSource("Source2")
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("description")
- .and()
- .addRepository("JCR Repository")
- .usingSource("Source2")
- .with(Option.JAAS_LOGIN_CONFIG_NAME)
- .setTo("test")
- .and()
- .build();
+ InMemoryRepositorySource configSource = new InMemoryRepositorySource();
+ configSource.setName("config2");
+ configSource.setRetryLimit(5);
+ configuration.loadFrom(configSource, "workspaceXYZ");
+ configuration.repositorySource("Source2")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .setDescription("description")
+ .and()
+ .repository("JCR Repository")
+ .setSource("Source2")
+ .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test");
+ configuration.save();
+ // Save the configuration and start the engine ...
+ engine = configuration.build();
engine.start();
+
+ ConfigurationDefinition configDefn = configuration.getConfigurationDefinition();
+ assertThat(configDefn.getWorkspace(), is("workspaceXYZ"));
+ assertThat(configDefn.getPath(), is(path("/")));
+
// Get a graph to the configuration source ...
RepositorySource configReposSource = engine.getRepositoryService().getRepositoryLibrary().getSource("config2");
assertThat(configReposSource, is(notNullValue()));
assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
assertThat(configReposSource.getName(), is("config2"));
- InMemoryRepositorySource configSource = (InMemoryRepositorySource)configReposSource;
- assertThat(configSource.getDefaultWorkspaceName(), is("workspaceXYZ"));
- Graph graph = Graph.create("config2", engine.getRepositoryService().getRepositoryLibrary(), context);
+ InMemoryRepositorySource configSource2 = (InMemoryRepositorySource)configReposSource;
+ assertThat(configSource2.getDefaultWorkspaceName(), is("")); // didn't change this
+
+ Graph graph = engine.getGraph("config2");
assertThat(graph, is(notNullValue()));
assertThat(graph.getNodeAt("/"), is(notNullValue()));
+ assertThat(graph.getNodeAt("/dna:sources"), is(notNullValue()));
+ assertThat(graph.getNodeAt("/dna:sources/Source2"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
+ assertThat(graph.getNodeAt("/dna:repositories/JCR Repository"), hasProperty(DnaLexicon.SOURCE_NAME, "Source2"));
// Get the repository ...
JcrRepository repository = engine.getRepository("JCR Repository");
@@ -185,221 +215,192 @@
}
@Test
- public void shouldAllowAddingRepositorySourceByClassNameAndSettingProperties() {
- // Update the configuration and save it ...
- configuration.addSource("Source1")
+ public void shouldAllowSpecifyingOptions() throws Exception {
+ configuration.repositorySource("Source2")
.usingClass(InMemoryRepositorySource.class.getName())
.loadedFromClasspath()
- .describedAs("description")
- .with("retryLimit")
- .setTo(5)
+ .setDescription("description")
.and()
- .save();
+ .repository("JCR Repository")
+ .setSource("Source2")
+ .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test");
+ engine = configuration.build();
+ engine.start();
+
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ Graph config = engine.getGraph(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
+ Subgraph subgraph = config.getSubgraphOfDepth(6).at("/");
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
+ assertThat(subgraph.getNode("/dna:sources/Source2"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Source2"), hasProperty(DnaLexicon.CLASSNAME,
InMemoryRepositorySource.class.getName()));
- }
+ assertThat(subgraph.getNode("/dna:repositories"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository"), hasProperty(DnaLexicon.SOURCE_NAME, "Source2"));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository/dna:options"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository/dna:options/JAAS_LOGIN_CONFIG_NAME"),
+ hasProperty(DnaLexicon.VALUE, "test"));
- @Test
- public void shouldAllowAddingRepositorySourceByClassNameAndClasspathAndSettingProperties() {
- // Update the configuration and save it ...
- configuration.addSource("Source1")
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFrom("cp1", "cp2")
- .describedAs("description")
- .with("retryLimit")
- .setTo(5)
- .and()
- .save();
+ JcrRepository repository = engine.getRepository("JCR Repository");
- // Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
- assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSPATH, "cp1", "cp2"));
+ Map<Option, String> options = new HashMap<Option, String>();
+ options.put(Option.JAAS_LOGIN_CONFIG_NAME, "test");
+ options.put(Option.PROJECT_NODE_TYPES, "false");
+ assertThat(repository.getOptions(), is(options));
}
@Test
- public void shouldAllowAddingRepositorySourceByClassReferenceAndSettingProperties() {
- // Update the configuration and save it ...
- configuration.addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("description")
- .with("retryLimit")
- .setTo(5)
- .and()
- .save();
+ public void shouldLoadConfigurationFromFilePath() throws Exception {
+ File file = new File("src/test/resources/config/configRepository.xml");
+ assertThat(file.exists(), is(true));
+ assertThat(file.canRead(), is(true));
+ assertThat(file.isFile(), is(true));
- // Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
- assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
- }
+ configuration.loadFrom("src/test/resources/config/configRepository.xml");
- @Test
- public void shouldAllowOverwritingRepositorySourceByRepositoryName() {
- // Update the configuration and save it ...
- configuration.addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("description")
- .with("retryLimit")
- .setTo(3)
- .and()
- .addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("new description")
- .with("retryLimit")
- .setTo(6)
- .and()
- .save();
+ assertThat(configuration.getProblems().isEmpty(), is(true));
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(6).at("/");
+
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources").getChildren(), hasChild(segment("Source1")));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 6));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "new description"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
- }
+ assertThat(subgraph.getNode("/dna:sources/Cars"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Cars"), hasProperty(DnaLexicon.RETRY_LIMIT, "3"));
+ assertThat(subgraph.getNode("/dna:sources/Cars"), hasProperty(DnaLexicon.CLASSNAME,
+ InMemoryRepositorySource.class.getName()));
+ assertThat(subgraph.getNode("/dna:sources/Aircraft"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Aircraft"), hasProperty("defaultWorkspaceName", "default"));
+ assertThat(subgraph.getNode("/dna:sources/Aircraft"), hasProperty(DnaLexicon.CLASSNAME,
+ InMemoryRepositorySource.class.getName()));
+ assertThat(subgraph.getNode("/dna:sources/Cache"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Cache"), hasProperty(DnaLexicon.CLASSNAME,
+ InMemoryRepositorySource.class.getName()));
- @Test
- public void shouldAllowAddingMimeTypeDetector() {
- // Update the configuration and save it ...
- configuration.addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("description")
- .and()
- .addMimeTypeDetector("detector")
- .usingClass(ExtensionBasedMimeTypeDetector.class)
- .describedAs("default detector")
- .and()
- .save();
-
- // Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
- assertThat(subgraph.getNode("/dna:sources").getChildren(), hasChild(segment("Source1")));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors").getChildren(), hasChild(segment("detector")));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.READABLE_NAME, "detector"));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.DESCRIPTION, "default detector"));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"),
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors").getChildren(), hasChild(segment("Detector")));
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors/Detector"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors/Detector"),
+ hasProperty(DnaLexicon.DESCRIPTION, "Standard extension-based MIME type detector"));
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors/Detector"),
hasProperty(DnaLexicon.CLASSNAME, ExtensionBasedMimeTypeDetector.class.getName()));
- }
- @Test
- public void shouldAllowConfigurationInMultipleSteps() {
- configuration.addSource("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description");
- configuration.addMimeTypeDetector("detector")
- .usingClass(ExtensionBasedMimeTypeDetector.class)
- .describedAs("default detector");
- configuration.save();
+ assertThat(subgraph.getNode("/dna:repositories").getChildren(), hasChild(segment("Car Repository")));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository"), hasProperty(DnaLexicon.SOURCE_NAME, "Cars"));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository").getChildren(), hasChild(segment("dna:options")));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:options"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:options").getChildren(),
+ hasChild(segment("jaasLoginConfigName")));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:options/jaasLoginConfigName"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:options/jaasLoginConfigName"),
+ hasProperty(DnaLexicon.VALUE, "dna-jcr"));
- // Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
- assertThat(subgraph.getNode("/dna:sources").getChildren(), hasChild(segment("Source1")));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors").getChildren(), hasChild(segment("detector")));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.READABLE_NAME, "detector"));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.DESCRIPTION, "default detector"));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"),
- hasProperty(DnaLexicon.CLASSNAME, ExtensionBasedMimeTypeDetector.class.getName()));
+ // Initialize IDTrust and a policy file (which defines the "dna-jcr" login config name)
+ String configFile = "security/jaas.conf.xml";
+ IDTrustConfiguration idtrustConfig = new IDTrustConfiguration();
+ try {
+ idtrustConfig.config(configFile);
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
+
+ // Create and start the engine ...
+ engine = configuration.build();
+ engine.start();
+ Repository repository = engine.getRepository("Car Repository");
+ assertThat(repository, is(notNullValue()));
+
+ // Create a session, authenticating using one of the usernames defined by our JAAS policy file(s) ...
+ Session session = null;
+ try {
+ session = repository.login(new SimpleCredentials("superuser", "superuser".toCharArray()));
+ } finally {
+ if (session != null) session.logout();
+ }
}
@Test
- public void shouldAllowSpecifyingOptions() throws Exception {
- // Update the configuration and save it ...
+ public void shouldAddNodeTypesAndNamespaces() throws Exception {
+ File file = new File("src/test/resources/config/configRepository.xml");
+ assertThat(file.exists(), is(true));
+ assertThat(file.canRead(), is(true));
+ assertThat(file.isFile(), is(true));
- JcrEngine engine = configuration.withConfigurationSource()
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("configuration")
- .with("retryLimit")
- .setTo(5)
- .and()
- .addSource("Source2")
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("description")
- .and()
- .addRepository("JCR Repository")
- .usingSource("Source2")
- .with(Option.JAAS_LOGIN_CONFIG_NAME)
- .setTo("test")
- .and()
- .build();
- engine.start();
+ configuration.loadFrom("src/test/resources/config/configRepository.xml");
+ // Verify that the configration was loaded correctly ...
+ assertThat(configuration.repository("Car Repository").getSource(), is("Cars"));
+ // Load the node types from the CND file, and save the configuration ...
+ URL nodeTypesUrl = getClass().getClassLoader().getResource("tck_test_types.cnd");
+ configuration.repository("Car Repository").addNodeTypes(nodeTypesUrl);
+ configuration.save();
+
+ // Verify there were no problems loading the CND file ...
+ assertThat(configuration.getProblems().isEmpty(), is(true));
+ assertThat(configuration.getConfigurationDefinition()
+ .getContext()
+ .getNamespaceRegistry()
+ .isRegisteredNamespaceUri("http://www.jboss.org/dna/test/1.0"), is(true));
+
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(6).at("/");
- assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source2"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source2"), hasProperty(DnaLexicon.READABLE_NAME, "Source2"));
- assertThat(subgraph.getNode("/dna:sources/Source2"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
- assertThat(subgraph.getNode("/dna:repositories"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:repositories/JCR Repository"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:repositories/JCR Repository"), hasProperty(DnaLexicon.SOURCE_NAME, "Source2"));
- assertThat(subgraph.getNode("/dna:repositories/JCR Repository/dna:options"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:repositories/JCR Repository/dna:options/JAAS_LOGIN_CONFIG_NAME"),
- hasProperty(DnaLexicon.VALUE, "test"));
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(6).at("/");
- JcrRepository repository = engine.getRepository("JCR Repository");
+ assertThat(subgraph.getNode("/dna:repositories").getChildren(), hasChild(segment("Car Repository")));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository"), hasProperty(DnaLexicon.SOURCE_NAME, "Cars"));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository").getChildren(), hasChild(segment("dna:options")));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:nodeTypes"), is(notNullValue()));
+ // for (Location child : subgraph.getNode("/dna:repositories/Car Repository/dna:nodeTypes").getChildren()) {
+ // System.out.println(child.getPath().getLastSegment().getString(context().getNamespaceRegistry()));
+ // }
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:nodeTypes").getChildren(),
+ hasChildren(segment("dnatest:noSameNameSibs"),
+ segment("dnatest:referenceableUnstructured"),
+ segment("dnatest:nodeWithMandatoryProperty"),
+ segment("dnatest:nodeWithMandatoryChild"),
+ segment("dnatest:unorderableUnstructured")));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:namespaces"), is(notNullValue()));
- Map<Option, String> options = new HashMap<Option, String>();
- options.put(Option.JAAS_LOGIN_CONFIG_NAME, "test");
- options.put(Option.PROJECT_NODE_TYPES, "false");
- assertThat(repository.getOptions(), is(options));
- }
+ // Check that the namespace in the CND file was persisted correctly ...
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:namespaces").getChildren(),
+ hasChild(segment("dnatest")));
+ assertThat(subgraph.getNode("/dna:repositories/Car Repository/dna:namespaces/dnatest"),
+ hasProperty(DnaLexicon.NAMESPACE_URI, "http://www.jboss.org/dna/test/1.0"));
- @Test
- public void shouldAllowCreatingWithConfigRepository() throws InterruptedException {
- DnaEngine engine = new DnaConfiguration().withConfigurationSource()
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("config repo")
- .and()
- .build();
+ // Initialize IDTrust and a policy file (which defines the "dna-jcr" login config name)
+ String configFile = "security/jaas.conf.xml";
+ IDTrustConfiguration idtrustConfig = new IDTrustConfiguration();
+ try {
+ idtrustConfig.config(configFile);
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
- assertThat(engine.getRepositorySource("config repo"), is(notNullValue()));
- assertThat(engine.getRepositorySource("config repo"), is(instanceOf(InMemoryRepositorySource.class)));
+ // Create and start the engine ...
+ engine = configuration.build();
+ engine.start();
+ Repository repository = engine.getRepository("Car Repository");
+ assertThat(repository, is(notNullValue()));
- RepositoryLibrary library = engine.getRepositoryService().getRepositoryLibrary();
- assertThat(library.getConnectionPool("config repo").getInUseCount(), is(0));
+ // Create a session, authenticating using one of the usernames defined by our JAAS policy file(s) ...
+ Session session = null;
+ try {
+ session = repository.login(new SimpleCredentials("superuser", "superuser".toCharArray()));
- RepositoryConnection connection = library.getConnectionPool("config repo").getConnection();
- assertThat(connection.ping(500, TimeUnit.MILLISECONDS), is(true));
- connection.close();
+ // Check that the namespace showed up ...
+ assertThat(session.getNamespacePrefix("http://www.jboss.org/dna/test/1.0"), is("dnatest"));
+ // Check that some of the node types showed up ...
+ NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
+ assertThat(ntm.getNodeType("dnatest:noSameNameSibs"), is(notNullValue())); // throws exception
+ assertThat(ntm.getNodeType("dnatest:referenceableUnstructured"), is(notNullValue())); // throws exception
+ assertThat(ntm.getNodeType("dnatest:nodeWithMandatoryProperty"), is(notNullValue())); // throws exception
+ assertThat(ntm.getNodeType("dnatest:nodeWithMandatoryChild"), is(notNullValue())); // throws exception
+ assertThat(ntm.getNodeType("dnatest:unorderableUnstructured"), is(notNullValue())); // throws exception
+ } finally {
+ if (session != null) session.logout();
+ }
}
}
Added: trunk/dna-jcr/src/test/resources/config/configRepository.xml
===================================================================
--- trunk/dna-jcr/src/test/resources/config/configRepository.xml (rev 0)
+++ trunk/dna-jcr/src/test/resources/config/configRepository.xml 2009-06-03 20:10:19 UTC (rev 969)
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss DNA (http://www.jboss.org/dna)
+ ~
+ ~ See the COPYRIGHT.txt file distributed with this work for information
+ ~ regarding copyright ownership. Some portions may be licensed
+ ~ to Red Hat, Inc. under one or more contributor license agreements.
+ ~ See the AUTHORS.txt file in the distribution for a full listing of
+ ~ individual contributors.
+ ~
+ ~ JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ ~ is licensed to you under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ JBoss DNA is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<configuration xmlns:dna="http://www.jboss.org/dna/1.0"
+ xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+ <!-- Define the sources from which content is made available. -->
+ <dna:sources jcr:primaryType="nt:unstructured">
+ <dna:source jcr:name="Cars" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" dna:retryLimit="3" defaultWorkspaceName="default"/>
+ <dna:source jcr:name="Aircraft" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource">
+ <defaultWorkspaceName>default</defaultWorkspaceName>
+ </dna:source>
+ <dna:source jcr:name="Cache" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource">
+ <defaultWorkspaceName>default</defaultWorkspaceName>
+ </dna:source>
+ </dna:sources>
+ <!-- Define the sequencers. This is an optional section. -->
+ <dna:sequencers>
+ <!--dna:sequencer jcr:name="Image Sequencer" dna:classname="org.jboss.dna.sequencer.image.ImageMetadataSequencer">
+ <dna:description>Image metadata sequencer</dna:description>
+ <dna:pathExpression>/foo/source => /foo/target</dna:pathExpression>
+ <dna:pathExpression>/bar/source => /bar/target</dna:pathExpression>
+ </dna:sequencer-->
+ </dna:sequencers>
+ <!-- Define the mime type detectors. This is an optional section. -->
+ <dna:mimeTypeDetectors>
+ <dna:mimeTypeDetector jcr:name="Detector">
+ <dna:description>Standard extension-based MIME type detector</dna:description>
+ <!--
+ Specify the implementation class (required), as a child element or attribute on parent element.
+ -->
+ <dna:classname>org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector</dna:classname>
+ <!--
+ Specify the classpath (optional) as an ordered list of 'names', where each name is significant to
+ the classpath factory. For example, a name could be an OSGI identifier or a Maven coordinate,
+ depending upon the classpath factory being used. If there is only one 'name' in the classpath,
+ it may be specified as an attribute on the 'mimeTypeDetector' element. If there is more than one
+ 'name', then they must be specified as child 'classpath' elements. Blank or empty values are ignored.
+ -->
+ <dna:classpath></dna:classpath>
+ <dna:classpath></dna:classpath>
+ </dna:mimeTypeDetector>
+ </dna:mimeTypeDetectors>
+ <!-- JCR Repositories. This is required, with a separate repository for each JCR repository instance. -->
+ <dna:repositories>
+ <dna:repository jcr:name="Car Repository" dna:sourceName="Cars">
+ <dna:options>
+ <dna:option jcr:name="projectNodeTypes" dna:value="true"/>
+ <dna:option jcr:name="jaasLoginConfigName" dna:value="dna-jcr"/>
+ </dna:options>
+ </dna:repository>
+ </dna:repositories>
+</configuration>
\ No newline at end of file
Property changes on: trunk/dna-jcr/src/test/resources/config/configRepository.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -1,1279 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.repository;
-
-import java.util.ArrayList;
-import java.util.List;
-import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.collection.Problems;
-import org.jboss.dna.common.collection.SimpleProblems;
-import org.jboss.dna.common.component.ClassLoaderFactory;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.text.Inflector;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.Reflection;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.Graph;
-import org.jboss.dna.graph.connector.RepositorySource;
-import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
-import org.jboss.dna.graph.mimetype.MimeTypeDetector;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.PathExpression;
-import org.jboss.dna.graph.property.PathFactory;
-import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.RootPath;
-import org.jboss.dna.graph.sequencer.StreamSequencer;
-import org.jboss.dna.repository.sequencer.Sequencer;
-
-/**
- * @param <BuilderType>
- */
-public abstract class Configurator<BuilderType> {
-
- /**
- * Interface used to configure a sequencer.
- *
- * @param <ReturnType> the type of interface to return after the sequencer's configuration is completed
- */
- public interface SequencerConfigurator<ReturnType> {
-
- /**
- * Add a new {@link StreamSequencer sequencer} to this configuration. The new sequencer will have the supplied name, and
- * if the name of an existing sequencer is used, this will replace the existing sequencer configuration.
- *
- * @param id the identifier of the new sequencer
- * @return the interface for choosing the class, which returns the interface used to configure the sequencer; never null
- * @throws IllegalArgumentException if the sequencer name is null, empty, or otherwise invalid
- */
- public ChooseClass<StreamSequencer, SequencerDetails<ReturnType>> addSequencer( String id );
-
- /**
- * Get the details for the sequencer with the supplied identifier.
- *
- * @param id the identifier of the sequencer that is to be added
- * @return the details for the repository source, or null if there is no such source in this configuration
- */
- public SequencerDetails<ReturnType> sequencer( String id );
- }
-
- /**
- * Interface used to initialize the configurator to use a specific repository containing configuration information.
- *
- * @param <ReturnType> the configurator type returned after the configuration repository is defined
- */
- public interface Initializer<ReturnType> {
- /**
- * Specify that this configuration should use a particular {@link RepositorySource} for its configuration repository. By
- * default each configuration uses an internal transient repository for its configuration, but using this method will make
- * the configuration use a different repository (that is perhaps shared with other processes).
- *
- * @return the interface for choosing the class, which returns the interface used to configure the source that will be
- * used for the configuration repository; never null
- */
- public ChooseClass<RepositorySource, ConfigSourceDetails<ReturnType>> withConfigurationSource();
-
- /**
- * Get the details for the configuration repository source.
- *
- * @return the details for the configuration's repository source; never null
- */
- public ConfigSourceDetails<ReturnType> configurationSource();
- }
-
- /**
- * Interface used to configure a repository source.
- *
- * @param <ReturnType> the type of interface to return after the repository source's configuration is completed
- */
- public interface RepositorySourceConfigurator<ReturnType> {
- /**
- * Add a new {@link RepositorySource repository} for this configuration. The new repository will have the supplied name,
- * and if the name of an existing repository is used, this will replace the existing repository configuration.
- *
- * @param id the id of the new repository that is to be added
- * @return the interface for choosing the class, which returns the interface used to configure the repository source;
- * never null
- * @throws IllegalArgumentException if the repository name is null, empty, or otherwise invalid
- * @see #addSource(RepositorySource)
- */
- public ChooseClass<RepositorySource, RepositorySourceDetails<ReturnType>> addSource( final String id );
-
- /**
- * Add a new {@link RepositorySource repository} for this configuration. The new repository will have the supplied name,
- * and if the name of an existing repository is used, this will replace the existing repository configuration.
- *
- * @param source the {@link RepositorySource} instance that should be used
- * @return this configuration object, for method-chaining purposes
- * @throws IllegalArgumentException if the repository source reference is null
- * @see #addSource(String)
- */
- public ReturnType addSource( RepositorySource source );
-
- /**
- * Get the details for the repository source with the supplied identifier.
- *
- * @param id the identifier of the repository that is to be added
- * @return the details for the repository source, or null if there is no such source in this configuration
- */
- public RepositorySourceDetails<ReturnType> source( String id );
- }
-
- /**
- * Interface used to configure a MIME type detector.
- *
- * @param <ReturnType> the type of interface to return after the detector's configuration is completed
- */
- public interface MimeDetectorConfigurator<ReturnType> {
- /**
- * Add a new {@link MimeTypeDetector MIME type detector} to this configuration. The new detector will have the supplied
- * name, and if the name of an existing detector is used, this will replace the existing detector configuration.
- *
- * @param id the id of the new detector
- * @return the interface for choosing the class, which returns the interface used to configure the detector; never null
- * @throws IllegalArgumentException if the detector name is null, empty, or otherwise invalid
- */
- public ChooseClass<MimeTypeDetector, MimeTypeDetectorDetails<ReturnType>> addMimeTypeDetector( final String id );
-
- /**
- * Get the details for the MIME type detector with the supplied identifier.
- *
- * @param id the identifier of the MIME type detector that is to be added
- * @return the details for the MIME type detector, or null if there is no such detector in this configuration
- */
- public MimeTypeDetectorDetails<ReturnType> mimeTypeDetector( String id );
- }
-
- /**
- * Interface used to build the configured component.
- *
- * @param <ReturnType> the type of component that this configuration builds
- */
- public interface Builder<ReturnType> {
- /**
- * Complete this configuration and create the corresponding engine.
- *
- * @return the new engine configured by this instance
- * @throws DnaConfigurationException if the engine cannot be created from this configuration.
- */
- public ReturnType build() throws DnaConfigurationException;
- }
-
- /**
- * Interface used to configure a {@link RepositorySource repository}.
- *
- * @param <ReturnType>
- */
- public interface RepositorySourceDetails<ReturnType>
- extends SetName<RepositorySourceDetails<ReturnType>>, SetDescription<RepositorySourceDetails<ReturnType>>,
- SetProperties<RepositorySourceDetails<ReturnType>>, And<ReturnType> {
- }
-
- /**
- * Interface used to define the configuration repository.
- *
- * @param <ReturnType>
- */
- public interface ConfigSourceDetails<ReturnType>
- extends SetDescription<ConfigSourceDetails<ReturnType>>, SetProperties<ConfigSourceDetails<ReturnType>>, And<ReturnType> {
- /**
- * Specify the path under which the configuration content is to be found. This path is assumed to be "/" by default.
- *
- * @param path the path to the configuration content in the configuration source; may not be null
- * @return this instance for method chaining purposes; never null
- */
- public ConfigSourceDetails<ReturnType> under( String path );
-
- /**
- * Specify the path under which the configuration content is to be found. This path is assumed to be "/" by default.
- *
- * @param workspace the name of the workspace with the configuration content in the configuration source; may not be null
- * @return this instance for method chaining purposes; never null
- */
- public ConfigSourceDetails<ReturnType> usingWorkspace( String workspace );
- }
-
- /**
- * Interface used to configure a {@link Sequencer sequencer}.
- *
- * @param <ReturnType>
- */
- public interface SequencerDetails<ReturnType>
- extends SetName<SequencerDetails<ReturnType>>, SetDescription<SequencerDetails<ReturnType>>, And<ReturnType> {
-
- /**
- * Specify the input {@link PathExpression path expression} represented as a string, which determines when this sequencer
- * will be executed.
- *
- * @param inputPathExpression the path expression for nodes that, when they change, will be passed as an input to the
- * sequencer
- * @return the interface used to specify the output path expression; never null
- */
- PathExpressionOutput<ReturnType> sequencingFrom( String inputPathExpression );
-
- /**
- * Specify the input {@link PathExpression path expression}, which determines when this sequencer will be executed.
- *
- * @param inputPathExpression the path expression for nodes that, when they change, will be passed as an input to the
- * sequencer
- * @return the interface used to continue specifying the configuration of the sequencer
- */
- SequencerDetails<ReturnType> sequencingFrom( PathExpression inputPathExpression );
- }
-
- /**
- * Interface used to specify the output path expression for a
- * {@link Configurator.SequencerDetails#sequencingFrom(PathExpression) sequencer configuration}.
- *
- * @param <ReturnType>
- */
- public interface PathExpressionOutput<ReturnType> {
- /**
- * Specify the output {@link PathExpression path expression}, which determines where this sequencer's output will be
- * placed.
- *
- * @param outputExpression the path expression for the location(s) where output generated by the sequencer is to be placed
- * @return the interface used to continue specifying the configuration of the sequencer
- */
- SequencerDetails<ReturnType> andOutputtingTo( String outputExpression );
- }
-
- /**
- * Interface used to configure a {@link MimeTypeDetector MIME type detector}.
- *
- * @param <ReturnType>
- */
- public interface MimeTypeDetectorDetails<ReturnType>
- extends SetName<MimeTypeDetectorDetails<ReturnType>>, SetDescription<MimeTypeDetectorDetails<ReturnType>>,
- SetProperties<MimeTypeDetectorDetails<ReturnType>>, And<ReturnType> {
- }
-
- /**
- * Interface for configuring the JavaBean-style properties of an object.
- *
- * @param <ReturnType> the interface returned after the property has been set.
- * @author Randall Hauch
- */
- public interface SetProperties<ReturnType> {
- /**
- * Set the property value to an integer.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- int value );
-
- /**
- * Set the property value to a long number.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- long value );
-
- /**
- * Set the property value to a short.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- short value );
-
- /**
- * Set the property value to a boolean.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- boolean value );
-
- /**
- * Set the property value to a float.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- float value );
-
- /**
- * Set the property value to a double.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- double value );
-
- /**
- * Set the property value to a string.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- String value );
-
- /**
- * Set the property value to an object.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- Object value );
- }
-
- /**
- * The interface used to configure the class used for a component.
- *
- * @param <ComponentClassType> the class or interface that the component is to implement
- * @param <ReturnType> the interface returned from these methods
- */
- public interface ChooseClass<ComponentClassType, ReturnType> {
-
- /**
- * Specify the name of the class that should be instantiated for the instance. The classpath information will need to be
- * defined using the returned interface.
- *
- * @param classname the name of the class that should be instantiated
- * @return the interface used to define the classpath information; never null
- * @throws IllegalArgumentException if the class name is null, empty, blank, or not a valid class name
- */
- LoadedFrom<ReturnType> usingClass( String classname );
-
- /**
- * Specify the class that should be instantiated for the instance. Because the class is already available to this class
- * loader, there is no need to specify the classloader information.
- *
- * @param clazz the class that should be instantiated
- * @return the next component to continue configuration; never null
- * @throws DnaConfigurationException if the class could not be accessed and instantiated (if needed)
- * @throws IllegalArgumentException if the class reference is null
- */
- ReturnType usingClass( Class<? extends ComponentClassType> clazz );
- }
-
- /**
- * The interface used to set a description on a component.
- *
- * @param <ReturnType> the interface returned from these methods
- */
- public interface SetDescription<ReturnType> {
- /**
- * Specify the description of this component.
- *
- * @param description the description; may be null or empty
- * @return the next component to continue configuration; never null
- */
- ReturnType describedAs( String description );
- }
-
- /**
- * The interface used to set a human readable name on a component.
- *
- * @param <ReturnType> the interface returned from these methods
- */
- public interface SetName<ReturnType> {
- /**
- * Specify the human-readable name for this component.
- *
- * @param name the name; may be null or empty
- * @return the next component to continue configuration; never null
- */
- ReturnType named( String name );
- }
-
- /**
- * Interface for specifying from where the component's class is to be loaded.
- *
- * @param <ReturnType> the interface returned from these methods
- */
- public interface LoadedFrom<ReturnType> {
- /**
- * Specify the names of the classloaders that form the classpath for the component, from which the component's class (and
- * its dependencies) can be loaded. The names correspond to the names supplied to the
- * {@link ExecutionContext#getClassLoader(String...)} methods.
- *
- * @param classPathNames the names for the classloaders, as passed to the {@link ClassLoaderFactory} implementation (e.g.,
- * the {@link ExecutionContext}).
- * @return the next component to continue configuration; never null
- * @see #loadedFromClasspath()
- * @see ExecutionContext#getClassLoader(String...)
- */
- ReturnType loadedFrom( String... classPathNames );
-
- /**
- * Specify that the component (and its dependencies) will be found on the current (or
- * {@link Thread#getContextClassLoader() current context}) classloader.
- *
- * @return the next component to continue configuration; never null
- * @see #loadedFrom(String...)
- * @see ExecutionContext#getClassLoader(String...)
- */
- ReturnType loadedFromClasspath();
- }
-
- /**
- * Continue with another aspect of configuration.
- *
- * @param <ReturnType>
- */
- public interface And<ReturnType> {
-
- /**
- * Return a reference to the next configuration interface for additional operations.
- *
- * @return a reference to the next configuration interface
- */
- ReturnType and();
- }
-
- protected final BuilderType builder;
- protected final ExecutionContext context;
- protected ConfigurationRepository configurationSource;
- private Graph graph;
- private Graph.Batch batch;
- private final Problems problems;
-
- /**
- * Specify a new {@link ExecutionContext} that should be used for this DNA instance.
- *
- * @param context the new context, or null if a default-constructed execution context should be used
- * @param builder the builder
- * @throws IllegalArgumentException if the supplied context reference is null
- */
- protected Configurator( ExecutionContext context,
- BuilderType builder ) {
- CheckArg.isNotNull(context, "context");
- CheckArg.isNotNull(builder, "builder");
- this.context = context;
- this.builder = builder;
- this.problems = new SimpleProblems();
-
- // Set up the default configuration repository ...
- this.configurationSource = createDefaultConfigurationSource();
- }
-
- /**
- * @return problems
- */
- public Problems getProblems() {
- return problems;
- }
-
- /**
- * Method that is used to set up the default configuration repository source. By default, this method sets up the
- * {@link InMemoryRepositorySource} loaded from the classpath.
- *
- * @return the default repository source
- */
- protected ConfigurationRepository createDefaultConfigurationSource() {
- InMemoryRepositorySource defaultSource = new InMemoryRepositorySource();
- defaultSource.setName("Configuration");
- ConfigurationRepository result = new ConfigurationRepository(defaultSource, "Configuration Repository", null, null);
- return result;
- }
-
- /**
- * Get the execution context used by this configurator.
- *
- * @return the execution context; never null
- */
- public final ExecutionContext getExecutionContext() {
- return this.context;
- }
-
- protected final PathFactory pathFactory() {
- return getExecutionContext().getValueFactories().getPathFactory();
- }
-
- /**
- * Get the graph containing the configuration information.
- *
- * @return the configuration repository graph; never null
- * @see #graph()
- */
- protected final Graph graph() {
- if (this.graph == null) {
- this.graph = Graph.create(configurationSource.getRepositorySource(), context);
- }
- return this.graph;
- }
-
- /**
- * Get the graph batch that can be used to change the configuration, where the changes are enqueued until {@link #save()
- * saved}.
- *
- * @return the latest batch for changes to the configuration repository; never null
- * @see #graph()
- */
- protected final Graph.Batch configuration() {
- if (this.batch == null) {
- this.batch = graph().batch();
- }
- return this.batch;
- }
-
- /**
- * Save any changes that have been made so far to the configuration. This method does nothing if no changes have been made.
- *
- * @return this configuration object for method chaining purposes; never null
- */
- public BuilderType save() {
- if (this.batch != null) {
- this.batch.execute();
- this.batch = this.graph.batch();
- }
- return this.builder;
- }
-
- protected abstract Name nameFor( String name );
-
- protected Path createOrReplaceNode( Path parentPath,
- String id,
- Name propertyName,
- Object value ) {
- Path path = pathFactory().create(parentPath, id);
- configuration().create(path).with(propertyName, value).and();
- return path;
-
- }
-
- protected Path createOrReplaceNode( Path parentPath,
- Name id,
- Name propertyName,
- Object value ) {
- Path path = pathFactory().create(parentPath, id);
- configuration().create(path).with(propertyName, value).and();
- return path;
- }
-
- protected Path createOrReplaceNode( Path parentPath,
- String id ) {
- Path path = pathFactory().create(parentPath, id);
- configuration().create(path).and();
- return path;
-
- }
-
- protected Path createOrReplaceNode( Path parentPath,
- Name id ) {
- Path path = pathFactory().create(parentPath, id);
- configuration().create(path).and();
- return path;
- }
-
- protected void recordBeanPropertiesInGraph( Path path,
- Object javaBean ) {
- Reflection reflector = new Reflection(javaBean.getClass());
- for (String propertyName : reflector.findGetterPropertyNames()) {
- Object value;
- try {
- value = reflector.invokeGetterMethodOnTarget(propertyName, javaBean);
- if (value == null) continue;
- propertyName = Inflector.getInstance().lowerCamelCase(propertyName);
- configuration().set(nameFor(propertyName)).to(value).on(path);
- } catch (ValueFormatException err) {
- throw err;
- } catch (Throwable err) {
- // Unable to call getter and set property
- }
- }
- }
-
- protected class ConfigurationRepositoryClassChooser<ReturnType>
- implements ChooseClass<RepositorySource, ConfigSourceDetails<ReturnType>> {
-
- private final ReturnType returnObject;
-
- protected ConfigurationRepositoryClassChooser( ReturnType returnObject ) {
- assert returnObject != null;
- this.returnObject = returnObject;
- }
-
- public LoadedFrom<ConfigSourceDetails<ReturnType>> usingClass( final String className ) {
- return new LoadedFrom<ConfigSourceDetails<ReturnType>>() {
- @SuppressWarnings( "unchecked" )
- public ConfigSourceDetails loadedFrom( String... classpath ) {
- ClassLoader classLoader = getExecutionContext().getClassLoader(classpath);
- Class<? extends RepositorySource> clazz = null;
- try {
- clazz = (Class<? extends RepositorySource>)classLoader.loadClass(className);
- } catch (ClassNotFoundException err) {
- throw new DnaConfigurationException(RepositoryI18n.unableToLoadClassUsingClasspath.text(className,
- classpath));
- }
- return usingClass(clazz);
- }
-
- @SuppressWarnings( "unchecked" )
- public ConfigSourceDetails loadedFromClasspath() {
- Class<? extends RepositorySource> clazz = null;
- try {
- clazz = (Class<? extends RepositorySource>)Class.forName(className);
- } catch (ClassNotFoundException err) {
- throw new DnaConfigurationException(RepositoryI18n.unableToLoadClass.text(className));
- }
- return usingClass(clazz);
- }
- };
- }
-
- public ConfigSourceDetails<ReturnType> usingClass( Class<? extends RepositorySource> repositorySource ) {
- try {
- Configurator.this.configurationSource = new ConfigurationRepository(repositorySource.newInstance());
- } catch (InstantiationException err) {
- I18n msg = RepositoryI18n.errorCreatingInstanceOfClass;
- throw new DnaConfigurationException(msg.text(repositorySource.getName(), err.getLocalizedMessage()), err);
- } catch (IllegalAccessException err) {
- I18n msg = RepositoryI18n.errorCreatingInstanceOfClass;
- throw new DnaConfigurationException(msg.text(repositorySource.getName(), err.getLocalizedMessage()), err);
- }
- return new ConfigurationSourceDetails<ReturnType>(returnObject);
- }
- }
-
- protected class ConfigurationSourceDetails<ReturnType> implements ConfigSourceDetails<ReturnType> {
- private final ReturnType returnObject;
-
- protected ConfigurationSourceDetails( ReturnType returnObject ) {
- assert returnObject != null;
- this.returnObject = returnObject;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
- */
- public ConfigSourceDetails<ReturnType> describedAs( String description ) {
- Configurator.this.configurationSource = Configurator.this.configurationSource.withDescription(description);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, boolean)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
- boolean value ) {
- return setProperty(propertyName, (Object)value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, int)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
- int value ) {
- return setProperty(propertyName, (Object)value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, short)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
- short value ) {
- return setProperty(propertyName, (Object)value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, long)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
- long value ) {
- return setProperty(propertyName, (Object)value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, float)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
- float value ) {
- return setProperty(propertyName, (Object)value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, double)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
- double value ) {
- return setProperty(propertyName, (Object)value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.String)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
- String value ) {
- return setProperty(propertyName, (Object)value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.Object)
- */
- public ConfigSourceDetails<ReturnType> setProperty( String beanPropertyName,
- Object value ) {
- // Set the JavaBean-style property on the RepositorySource instance ...
- Object javaBean = Configurator.this.configurationSource.getRepositorySource();
- Reflection reflection = new Reflection(javaBean.getClass());
- try {
- reflection.invokeSetterMethodOnTarget(beanPropertyName, javaBean, value);
- } catch (Throwable err) {
- I18n msg = RepositoryI18n.errorSettingJavaBeanPropertyOnInstanceOfClass;
- throw new DnaConfigurationException(msg.text(beanPropertyName, javaBean.getClass(), err.getMessage()), err);
- }
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.ConfigSourceDetails#usingWorkspace(java.lang.String)
- */
- public ConfigSourceDetails<ReturnType> usingWorkspace( String workspace ) {
- Configurator.this.configurationSource = Configurator.this.configurationSource.withWorkspace(workspace);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.ConfigSourceDetails#under(java.lang.String)
- */
- public ConfigSourceDetails<ReturnType> under( String path ) {
- CheckArg.isNotNull(path, "path");
- Path newPath = getExecutionContext().getValueFactories().getPathFactory().create(path);
- Configurator.this.configurationSource = Configurator.this.configurationSource.with(newPath);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.And#and()
- */
- public ReturnType and() {
- return returnObject;
- }
- }
-
- /**
- * Reusable implementation of {@link Configurator.ChooseClass} that can be used to obtain the name of a class and how its
- * class loader is defined.
- *
- * @param <ComponentClass> the type of the component that is being chosen
- * @param <ReturnType> the interface that should be returned when the class name and classpath have been chosen.
- */
- protected class ClassChooser<ComponentClass, ReturnType> implements Configurator.ChooseClass<ComponentClass, ReturnType> {
- protected final Path pathOfComponentNode;
- protected final ReturnType returnObject;
-
- public ClassChooser( Path pathOfComponentNode,
- ReturnType returnObject ) {
- assert pathOfComponentNode != null;
- assert returnObject != null;
- this.pathOfComponentNode = pathOfComponentNode;
- this.returnObject = returnObject;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Configurator.ChooseClass#usingClass(java.lang.String)
- */
- public Configurator.LoadedFrom<ReturnType> usingClass( final String classname ) {
- CheckArg.isNotEmpty(classname, "classname");
- configuration().set(DnaLexicon.CLASSNAME).to(classname).on(pathOfComponentNode);
- return new Configurator.LoadedFrom<ReturnType>() {
- public ReturnType loadedFromClasspath() {
- return returnObject;
- }
-
- public ReturnType loadedFrom( String... classpath ) {
- CheckArg.isNotEmpty(classpath, "classpath");
- if (classpath.length == 1 && classpath[0] != null) {
- configuration().set(DnaLexicon.CLASSPATH).to(classpath[0]).on(pathOfComponentNode);
- } else {
- Object[] remaining = new String[classpath.length - 1];
- System.arraycopy(classpath, 1, remaining, 0, remaining.length);
- configuration().set(DnaLexicon.CLASSPATH).to(classpath[0], remaining).on(pathOfComponentNode);
- }
- return returnObject;
- }
- };
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Configurator.ChooseClass#usingClass(java.lang.Class)
- */
- public ReturnType usingClass( Class<? extends ComponentClass> clazz ) {
- CheckArg.isNotNull(clazz, "clazz");
- return usingClass(clazz.getName()).loadedFromClasspath();
- }
- }
-
- protected <ReturnType> GraphRepositorySourceDetails<ReturnType> createRepositoryDetails( Path path,
- ReturnType returnObject ) {
- return new GraphRepositorySourceDetails<ReturnType>(path, returnObject);
- }
-
- protected class GraphRepositorySourceDetails<ReturnType> implements RepositorySourceDetails<ReturnType> {
- private final Path path;
- private final ReturnType returnObject;
-
- protected GraphRepositorySourceDetails( Path path,
- ReturnType returnObject ) {
- assert path != null;
- assert returnObject != null;
- this.path = path;
- this.returnObject = returnObject;
- }
-
- public Path path() {
- return this.path;
- }
-
- /**
- * Get the name used for this source.
- *
- * @return the source's node name
- */
- public Name name() {
- return path().getLastSegment().getName();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetName#named(java.lang.String)
- */
- public RepositorySourceDetails<ReturnType> named( String name ) {
- configuration().set(DnaLexicon.READABLE_NAME).to(name).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
- */
- public RepositorySourceDetails<ReturnType> describedAs( String description ) {
- configuration().set(DnaLexicon.DESCRIPTION).to(description).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, boolean)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- boolean value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, int)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- int value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, short)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- short value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, long)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- long value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, float)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- float value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, double)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- double value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.String)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- String value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.Object)
- */
- public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
- Object value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.And#and()
- */
- public ReturnType and() {
- return returnObject;
- }
- }
-
- protected class GraphSequencerDetails<ReturnType> implements SequencerDetails<ReturnType> {
- private final Path path;
- private final List<String> compiledExpressions = new ArrayList<String>();
- private final ReturnType returnObject;
-
- protected GraphSequencerDetails( Path path,
- ReturnType returnObject ) {
- assert path != null;
- assert returnObject != null;
- this.path = path;
- this.returnObject = returnObject;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SequencerDetails#sequencingFrom(java.lang.String)
- */
- public PathExpressionOutput<ReturnType> sequencingFrom( final String from ) {
- CheckArg.isNotEmpty(from, "from");
- return new PathExpressionOutput<ReturnType>() {
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.PathExpressionOutput#andOutputtingTo(java.lang.String)
- */
- public SequencerDetails<ReturnType> andOutputtingTo( String into ) {
- CheckArg.isNotEmpty(into, "into");
- return sequencingFrom(PathExpression.compile(from + " => " + into));
- }
- };
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetName#named(java.lang.String)
- */
- public SequencerDetails<ReturnType> named( String name ) {
- configuration().set(DnaLexicon.READABLE_NAME).to(name).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SequencerDetails#sequencingFrom(org.jboss.dna.graph.property.PathExpression)
- */
- public SequencerDetails<ReturnType> sequencingFrom( PathExpression expression ) {
- CheckArg.isNotNull(expression, "expression");
- String compiledExpression = expression.getExpression();
- if (!compiledExpressions.contains(compiledExpression)) compiledExpressions.add(compiledExpression);
- configuration().set(DnaLexicon.PATH_EXPRESSIONS).on(path).to(compiledExpressions);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
- */
- public SequencerDetails<ReturnType> describedAs( String description ) {
- configuration().set(DnaLexicon.DESCRIPTION).to(description).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.And#and()
- */
- public ReturnType and() {
- return returnObject;
- }
- }
-
- protected class GraphMimeTypeDetectorDetails<ReturnType> implements MimeTypeDetectorDetails<ReturnType> {
- private final Path path;
- private final ReturnType returnObject;
-
- protected GraphMimeTypeDetectorDetails( Path path,
- ReturnType returnObject ) {
- assert path != null;
- assert returnObject != null;
- this.path = path;
- this.returnObject = returnObject;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetName#named(java.lang.String)
- */
- public MimeTypeDetectorDetails<ReturnType> named( String name ) {
- configuration().set(DnaLexicon.READABLE_NAME).to(name).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, boolean)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- boolean value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, int)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- int value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, short)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- short value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, long)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- long value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, float)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- float value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, double)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- double value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.String)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- String value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.Object)
- */
- public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
- Object value ) {
- configuration().set(nameFor(propertyName)).to(value).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
- */
- public MimeTypeDetectorDetails<ReturnType> describedAs( String description ) {
- configuration().set(DnaLexicon.DESCRIPTION).to(description).on(path);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.And#and()
- */
- public ReturnType and() {
- return returnObject;
- }
- }
-
- @Immutable
- public static class ConfigurationRepository {
- private final RepositorySource source;
- private final String description;
- private final Path path;
- private final String workspace;
-
- protected ConfigurationRepository( RepositorySource source ) {
- this(source, null, null, null);
- }
-
- protected ConfigurationRepository( RepositorySource source,
- String description,
- Path path,
- String workspace ) {
- this.source = source;
- this.description = description != null ? description : "";
- this.path = path != null ? path : RootPath.INSTANCE;
- this.workspace = workspace != null ? workspace : "";
- }
-
- /**
- * @return source
- */
- public RepositorySource getRepositorySource() {
- return source;
- }
-
- /**
- * @return description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * @return path
- */
- public Path getPath() {
- return path;
- }
-
- /**
- * @return workspace
- */
- public String getWorkspace() {
- return workspace;
- }
-
- public ConfigurationRepository withDescription( String description ) {
- return new ConfigurationRepository(source, description, path, workspace);
- }
-
- public ConfigurationRepository with( Path path ) {
- return new ConfigurationRepository(source, description, path, workspace);
- }
-
- public ConfigurationRepository withWorkspace( String workspace ) {
- return new ConfigurationRepository(source, description, path, workspace);
- }
- }
-}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -6,8 +6,8 @@
* See the AUTHORS.txt file in the distribution for a full listing of
* individual contributors.
*
- * Unless otherwise indicated, all code in JBoss DNA is licensed
- * to you under the terms of the GNU Lesser General Public License as
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
@@ -23,285 +23,1365 @@
*/
package org.jboss.dna.repository;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.collection.SimpleProblems;
+import org.jboss.dna.common.component.ClassLoaderFactory;
+import org.jboss.dna.common.component.StandardClassLoaderFactory;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.Node;
+import org.jboss.dna.graph.Workspace;
import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.mimetype.MimeTypeDetector;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.PathExpression;
+import org.jboss.dna.graph.property.PathNotFoundException;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.basic.RootPath;
+import org.jboss.dna.graph.request.InvalidWorkspaceException;
import org.jboss.dna.graph.sequencer.StreamSequencer;
-import org.jboss.dna.repository.Configurator.ChooseClass;
-import org.jboss.dna.repository.Configurator.ConfigSourceDetails;
-import org.jboss.dna.repository.Configurator.ConfigurationRepository;
-import org.jboss.dna.repository.Configurator.MimeTypeDetectorDetails;
-import org.jboss.dna.repository.Configurator.RepositorySourceDetails;
-import org.jboss.dna.repository.Configurator.SequencerDetails;
+import org.xml.sax.SAXException;
/**
+ * A configuration builder for a {@link DnaEngine}. This class is an internal domain-specific language (DSL), and is designed to
+ * be used in a traditional way or in a method-chained manner:
*
+ * <pre>
+ * configuration.repositorySource("Source1").setClass(InMemoryRepositorySource.class).setDescription("description");
+ * configuration.mimeTypeDetector("detector").setClass(ExtensionBasedMimeTypeDetector.class).setDescription("default detector");
+ * configuration.sequencer("MicrosoftDocs")
+ * .setClass("org.jboss.dna.sequencer.msoffice.MSOfficeMetadataSequencer")
+ * .setDescription("Our primary sequencer for all .doc files")
+ * .sequencingFrom("/public//(*.(doc|xml|ppt)[*]/jcr:content[@jcr:data]")
+ * .andOutputtingTo("/documents/$1");
+ * configuration.save();
+ * </pre>
*/
-public class DnaConfiguration
- implements Configurator.Initializer<DnaConfiguration>, Configurator.SequencerConfigurator<DnaConfiguration>,
- Configurator.RepositorySourceConfigurator<DnaConfiguration>, Configurator.MimeDetectorConfigurator<DnaConfiguration>,
- Configurator.Builder<DnaEngine> {
+@NotThreadSafe
+public class DnaConfiguration {
- protected static final Map<String, Name> NAMES_TO_MAP;
- static {
- Map<String, Name> names = new HashMap<String, Name>();
- names.put(DnaLexicon.READABLE_NAME.getLocalName(), DnaLexicon.READABLE_NAME);
- names.put(DnaLexicon.DESCRIPTION.getLocalName(), DnaLexicon.DESCRIPTION);
- names.put(DnaLexicon.DEFAULT_CACHE_POLICY.getLocalName(), DnaLexicon.DEFAULT_CACHE_POLICY);
- names.put(DnaLexicon.RETRY_LIMIT.getLocalName(), DnaLexicon.RETRY_LIMIT);
- names.put(DnaLexicon.PATH_EXPRESSIONS.getLocalName(), DnaLexicon.PATH_EXPRESSIONS);
- names.put(DnaLexicon.CLASSNAME.getLocalName(), DnaLexicon.CLASSNAME);
- names.put(DnaLexicon.CLASSPATH.getLocalName(), DnaLexicon.CLASSPATH);
- NAMES_TO_MAP = Collections.unmodifiableMap(names);
- }
+ public static final String DEFAULT_WORKSPACE_NAME = "";
+ public static final String DEFAULT_PATH = "/";
+ public static final String DEFAULT_CONFIGURATION_SOURCE_NAME = "DNA Configuration Repository";
- private final Builder<DnaConfiguration> builder;
+ private final ExecutionContext context;
+ private final Problems problems = new SimpleProblems();
+ private ConfigurationDefinition configurationContent;
+ private Graph.Batch changes;
+ private final Map<String, SequencerDefinition<? extends DnaConfiguration>> sequencerDefinitions = new HashMap<String, SequencerDefinition<? extends DnaConfiguration>>();
+ private final Map<String, RepositorySourceDefinition<? extends DnaConfiguration>> repositorySourceDefinitions = new HashMap<String, RepositorySourceDefinition<? extends DnaConfiguration>>();
+ private final Map<String, MimeTypeDetectorDefinition<? extends DnaConfiguration>> mimeTypeDetectorDefinitions = new HashMap<String, MimeTypeDetectorDefinition<? extends DnaConfiguration>>();
+
/**
- * Create a new configuration for DNA.
+ * Create a new configuration, using a default-constructed {@link ExecutionContext}.
*/
public DnaConfiguration() {
this(new ExecutionContext());
}
/**
- * Specify a new {@link ExecutionContext} that should be used for this DNA instance.
+ * Create a new configuration using the supplied {@link ExecutionContext}.
*
- * @param context the new context, or null if a default-constructed execution context should be used
- * @throws IllegalArgumentException if the supplied context reference is null
+ * @param context the execution context
+ * @throws IllegalArgumentException if the path is null or empty
*/
public DnaConfiguration( ExecutionContext context ) {
- this.builder = new Builder<DnaConfiguration>(context, this);
+ CheckArg.isNotNull(context, "context");
+ this.context = context;
+
+ // Create the in-memory repository source in which the content will be stored ...
+ InMemoryRepositorySource source = new InMemoryRepositorySource();
+ source.setName(DEFAULT_CONFIGURATION_SOURCE_NAME);
+ source.setDefaultWorkspaceName(DEFAULT_WORKSPACE_NAME);
+
+ // The file was imported successfully, so now create the content information ...
+ configurationContent = new ConfigurationDefinition(source, null, null, context, null);
}
/**
- * Get the execution context used by this configurator.
+ * Load the configuration from a file at the given path.
*
- * @return the execution context; never null
+ * @param pathToConfigurationFile the path the file containing the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied location
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the path is null or empty
*/
- public final ExecutionContext getExecutionContext() {
- return builder.getExecutionContext();
+ public DnaConfiguration loadFrom( String pathToConfigurationFile ) throws IOException, SAXException {
+ CheckArg.isNotEmpty(pathToConfigurationFile, "pathToConfigurationFile");
+ return loadFrom(pathToConfigurationFile, DEFAULT_PATH);
}
/**
- * {@inheritDoc}
+ * Load the configuration from a file at the given path.
*
- * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationSource()
+ * @param pathToConfigurationFile the path the file containing the configuration information
+ * @param path path within the content to the parent containing the configuration information, or null if the
+ * {@link #DEFAULT_PATH default path} should be used
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied location
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the path is null or empty
*/
- public ChooseClass<RepositorySource, ConfigSourceDetails<DnaConfiguration>> withConfigurationSource() {
- return builder.withConfigurationSource();
+ public DnaConfiguration loadFrom( String pathToConfigurationFile,
+ String path ) throws IOException, SAXException {
+ CheckArg.isNotEmpty(pathToConfigurationFile, "pathToConfigurationFile");
+ return loadFrom(new File(pathToConfigurationFile), path);
}
/**
- * {@inheritDoc}
+ * Load the configuration from a file.
*
- * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(java.lang.String)
+ * @param configurationFile the file containing the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the supplied file
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the file reference is null
*/
- public ChooseClass<RepositorySource, RepositorySourceDetails<DnaConfiguration>> addSource( String id ) {
- return builder.addSource(id);
+ public DnaConfiguration loadFrom( File configurationFile ) throws IOException, SAXException {
+ CheckArg.isNotNull(configurationFile, "configurationFile");
+ return loadFrom(configurationFile, DEFAULT_PATH);
}
/**
- * {@inheritDoc}
+ * Load the configuration from a file.
*
- * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(org.jboss.dna.graph.connector.RepositorySource)
+ * @param configurationFile the file containing the configuration information
+ * @param path path within the content to the parent containing the configuration information, or null if the
+ * {@link #DEFAULT_PATH default path} should be used
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the supplied file
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the file reference is null
*/
- public DnaConfiguration addSource( RepositorySource source ) {
- return builder.addSource(source);
+ public DnaConfiguration loadFrom( File configurationFile,
+ String path ) throws IOException, SAXException {
+ CheckArg.isNotNull(configurationFile, "configurationFile");
+ InputStream stream = new FileInputStream(configurationFile);
+ try {
+ return loadFrom(stream, path);
+ } finally {
+ stream.close();
+ }
}
/**
- * {@inheritDoc}
+ * Load the configuration from a file at the supplied URL.
*
- * @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String)
+ * @param urlToConfigurationFile the URL of the file containing the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied URL
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the URL is null
*/
- public ChooseClass<StreamSequencer, SequencerDetails<DnaConfiguration>> addSequencer( String id ) {
- return builder.addSequencer(id);
+ public DnaConfiguration loadFrom( URL urlToConfigurationFile ) throws IOException, SAXException {
+ CheckArg.isNotNull(urlToConfigurationFile, "urlToConfigurationFile");
+ return loadFrom(urlToConfigurationFile, DEFAULT_PATH);
}
/**
- * {@inheritDoc}
+ * Load the configuration from a file at the supplied URL.
*
- * @see org.jboss.dna.repository.Configurator.MimeDetectorConfigurator#addMimeTypeDetector(java.lang.String)
+ * @param urlToConfigurationFile the URL of the file containing the configuration information
+ * @param path path within the content to the parent containing the configuration information, or null if the
+ * {@link #DEFAULT_PATH default path} should be used
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied URL
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the URL is null
*/
- public ChooseClass<MimeTypeDetector, MimeTypeDetectorDetails<DnaConfiguration>> addMimeTypeDetector( String id ) {
- return builder.addMimeTypeDetector(id);
+ public DnaConfiguration loadFrom( URL urlToConfigurationFile,
+ String path ) throws IOException, SAXException {
+ CheckArg.isNotNull(urlToConfigurationFile, "urlToConfigurationFile");
+ InputStream stream = urlToConfigurationFile.openStream();
+ try {
+ return loadFrom(stream, path);
+ } finally {
+ stream.close();
+ }
}
/**
- * Save any changes that have been made so far to the configuration. This method does nothing if no changes have been made.
+ * Load the configuration from a file at the supplied URL.
*
- * @return this configuration object for method chaining purposes; never null
+ * @param configurationFileInputStream the stream with the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied URL
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the stream is null
*/
+ public DnaConfiguration loadFrom( InputStream configurationFileInputStream ) throws IOException, SAXException {
+ CheckArg.isNotNull(configurationFileInputStream, "configurationFileInputStream");
+ return loadFrom(configurationFileInputStream, DEFAULT_PATH);
+ }
+
+ /**
+ * Load the configuration from a file at the supplied URL.
+ *
+ * @param configurationFileInputStream the stream with the configuration information
+ * @param path path within the content to the parent containing the configuration information, or null if the
+ * {@link #DEFAULT_PATH default path} should be used
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied URL
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the stream is null
+ */
+ public DnaConfiguration loadFrom( InputStream configurationFileInputStream,
+ String path ) throws IOException, SAXException {
+ CheckArg.isNotNull(configurationFileInputStream, "configurationFileInputStream");
+
+ // Create the in-memory repository source in which the content will be stored ...
+ InMemoryRepositorySource source = new InMemoryRepositorySource();
+ source.setName(DEFAULT_CONFIGURATION_SOURCE_NAME);
+ source.setDefaultWorkspaceName(DEFAULT_WORKSPACE_NAME);
+
+ // Import the information into the source ...
+ Path pathToParent = path(path != null ? path : DEFAULT_PATH);
+ Graph graph = Graph.create(source, context);
+ graph.importXmlFrom(configurationFileInputStream).skippingRootElement(true).into(pathToParent);
+
+ // The file was imported successfully, so now create the content information ...
+ configurationContent = new ConfigurationDefinition(source, null, pathToParent, context, null);
+ return this;
+ }
+
+ /**
+ * Load the configuration from the repository content using the supplied repository source. This method assumes that the
+ * supplied source has already been configured and is ready to {@link RepositorySource#getConnection() create connections}.
+ * Also, the default workspace of the source will be used, and the configuration content may be found directly under the root
+ * node.
+ *
+ * @param source the source that defines the repository with the configuration content
+ * @return this configuration object, for convenience and method chaining
+ * @throws IllegalArgumentException if the source is null
+ */
+ public DnaConfiguration loadFrom( RepositorySource source ) {
+ return loadFrom(source, null, null);
+ }
+
+ /**
+ * Load the configuration from the repository content using the workspace in the supplied repository source. This method
+ * assumes that the supplied source has already been configured and is ready to {@link RepositorySource#getConnection() create
+ * connections}. Also, the configuration content may be found directly under the root node.
+ *
+ * @param source the source that defines the repository with the configuration content
+ * @param workspaceName the name of the workspace with the configuration content, or null if the source's default workspace
+ * should be used
+ * @return this configuration object, for convenience and method chaining
+ * @throws IllegalArgumentException if the source is null
+ */
+ public DnaConfiguration loadFrom( RepositorySource source,
+ String workspaceName ) {
+ CheckArg.isNotNull(source, "source");
+ return loadFrom(source, workspaceName, null);
+ }
+
+ /**
+ * Load the configuration from the repository content at the supplied path in the workspace in the supplied repository source.
+ * This method assumes that the supplied source has already been configured and is ready to
+ * {@link RepositorySource#getConnection() create connections}.
+ *
+ * @param source the source that defines the repository with the configuration content
+ * @param workspaceName the name of the workspace with the configuration content, or null if the source's default workspace
+ * should be used
+ * @param pathInWorkspace the path to the parent node under which the configuration content may be found, or null if the
+ * content may be found under the root node
+ * @return this configuration object, for convenience and method chaining
+ * @throws IllegalArgumentException if the source is null
+ */
+ public DnaConfiguration loadFrom( RepositorySource source,
+ String workspaceName,
+ String pathInWorkspace ) {
+ CheckArg.isNotNull(source, "source");
+
+ // Verify connectivity ...
+ Graph graph = Graph.create(source, context);
+ if (workspaceName != null) {
+ Workspace workspace = null;
+ try {
+ workspace = graph.useWorkspace(workspaceName); // should throw exception if not connectable
+ } catch (InvalidWorkspaceException e) {
+ // Try creating the workspace ...
+ workspace = graph.createWorkspace().named(workspaceName);
+ }
+ assert workspace.getRoot() != null;
+ }
+
+ // Verify the path ...
+ Path path = pathInWorkspace != null ? path(pathInWorkspace) : path(DEFAULT_PATH);
+ Node parent = graph.getNodeAt(path);
+ assert parent != null;
+
+ // Now create the content information ...
+ configurationContent = new ConfigurationDefinition(source, workspaceName, path, context, null);
+ return this;
+ }
+
+ /**
+ * Get the immutable representation of the information defining where the configuration content can be found.
+ *
+ * @return the configuration definition
+ */
+ public ConfigurationDefinition getConfigurationDefinition() {
+ return configurationContent;
+ }
+
+ protected ExecutionContext getExecutionContext() {
+ return configurationContent.getContext();
+ }
+
+ protected Path path() {
+ return configurationContent.getPath();
+ }
+
+ protected Path path( String path ) {
+ return context.getValueFactories().getPathFactory().create(path);
+ }
+
+ protected Name name( String name ) {
+ return context.getValueFactories().getNameFactory().create(name);
+ }
+
+ /**
+ * Get the problems (if any) that are associated with this configuration.
+ *
+ * @return the problems
+ */
+ public Problems getProblems() {
+ return problems;
+ }
+
+ protected Graph.Batch changes() {
+ if (changes == null) {
+ ConfigurationDefinition content = getConfigurationDefinition();
+ Graph graph = Graph.create(content.getRepositorySource(), content.getContext());
+ if (content.getWorkspace() != null) {
+ graph.useWorkspace(content.getWorkspace());
+ }
+ changes = graph.batch();
+ }
+ return changes;
+ }
+
+ /**
+ * Determine if there are any unsaved changes to this configuration that must be {@link #save() saved} before they take
+ * effect.
+ *
+ * @return true if a {@link #save()} is required, or false no changes have been made to the configuration since the last
+ * {@link #save()}
+ */
+ public boolean hasChanges() {
+ Graph.Batch changes = this.changes;
+ return changes != null && changes.isExecuteRequired();
+ }
+
+ /**
+ * Persist any unsaved changes that have been made to this configuration. This method has no effect if there are currently
+ * {@link #hasChanges() no unsaved changes}.
+ *
+ * @return this configuration, for method chaining purposes
+ */
public DnaConfiguration save() {
- return builder.save();
+ Graph.Batch changes = this.changes;
+ if (changes != null && changes.isExecuteRequired()) {
+ changes.execute();
+ }
+ sequencerDefinitions.clear();
+ mimeTypeDetectorDefinitions.clear();
+ repositorySourceDefinitions.clear();
+ return this;
}
/**
- * {@inheritDoc}
+ * Specify the {@link ClassLoaderFactory} that should be used to load the classes for the various components. Most of the
+ * definitions can specify the {@link LoadedFrom#loadedFrom(String...) classpath} that should be used, and that classpath is
+ * passed to the supplied ClassLoaderFactory instance to obtain a {@link ClassLoader} for the class.
+ * <p>
+ * If not called, this configuration will use the class loader that loaded this configuration's class.
+ * </p>
*
- * @see org.jboss.dna.repository.Configurator.Builder#build()
+ * @param classLoaderFactory the class loader factory implementation, or null if the classes should be loaded using the class
+ * loader of this object
+ * @return this configuration, for method chaining purposes
*/
- public DnaEngine build() throws DnaConfigurationException {
+ public DnaConfiguration withClassLoaderFactory( ClassLoaderFactory classLoaderFactory ) {
+ this.configurationContent = this.configurationContent.with(classLoaderFactory);
+ return this;
+ }
+
+ protected Set<String> getNamesOfComponentsUnder( Name parentName ) {
+ Set<String> names = new HashSet<String>();
+ try {
+ ConfigurationDefinition content = this.getConfigurationDefinition();
+ Path path = context.getValueFactories().getPathFactory().create(content.getPath(), parentName);
+ for (Location child : content.graph().getChildren().of(path)) {
+ names.add(child.getPath().getLastSegment().getString(context.getNamespaceRegistry()));
+ }
+ } catch (PathNotFoundException e) {
+ // Nothing has been saved yet ...
+ }
+ return names;
+ }
+
+ /**
+ * Get the list of MIME type detector definitions.
+ *
+ * @return the unmodifiable set of definitions; never null but possibly empty if there are no definitions
+ */
+ public Set<MimeTypeDetectorDefinition<? extends DnaConfiguration>> mimeTypeDetectors() {
+ // Get the children under the 'dna:mimeTypeDetectors' node ...
+ Set<String> names = getNamesOfComponentsUnder(DnaLexicon.MIME_TYPE_DETECTORS);
+ names.addAll(this.mimeTypeDetectorDefinitions.keySet());
+ Set<MimeTypeDetectorDefinition<? extends DnaConfiguration>> results = new HashSet<MimeTypeDetectorDefinition<? extends DnaConfiguration>>();
+ for (String name : names) {
+ results.add(mimeTypeDetector(name));
+ }
+ return Collections.unmodifiableSet(results);
+ }
+
+ /**
+ * Get the list of repository source definitions.
+ *
+ * @return the unmodifiable set of definitions; never null but possibly empty if there are no definitions
+ */
+ public Set<RepositorySourceDefinition<? extends DnaConfiguration>> repositorySources() {
+ // Get the children under the 'dna:mimeTypeDetectors' node ...
+ Set<String> names = getNamesOfComponentsUnder(DnaLexicon.SOURCES);
+ names.addAll(this.repositorySourceDefinitions.keySet());
+ Set<RepositorySourceDefinition<? extends DnaConfiguration>> results = new HashSet<RepositorySourceDefinition<? extends DnaConfiguration>>();
+ for (String name : names) {
+ results.add(repositorySource(name));
+ }
+ return Collections.unmodifiableSet(results);
+ }
+
+ /**
+ * Get the list of sequencer definitions.
+ *
+ * @return the unmodifiable set of definitions; never null but possibly empty if there are no definitions
+ */
+ public Set<SequencerDefinition<? extends DnaConfiguration>> sequencers() {
+ // Get the children under the 'dna:mimeTypeDetectors' node ...
+ Set<String> names = getNamesOfComponentsUnder(DnaLexicon.SEQUENCERS);
+ names.addAll(this.sequencerDefinitions.keySet());
+ Set<SequencerDefinition<? extends DnaConfiguration>> results = new HashSet<SequencerDefinition<? extends DnaConfiguration>>();
+ for (String name : names) {
+ results.add(sequencer(name));
+ }
+ return Collections.unmodifiableSet(results);
+ }
+
+ /**
+ * Obtain or create a definition for the {@link MimeTypeDetector MIME type detector} with the supplied name or identifier. A
+ * new definition will be created if there currently is no MIME type detector defined with the supplied name.
+ *
+ * @param name the name or identifier of the detector
+ * @return the details of the MIME type detector definition; never null
+ */
+ public MimeTypeDetectorDefinition<? extends DnaConfiguration> mimeTypeDetector( String name ) {
+ return mimeTypeDetectorDefinition(this, name);
+ }
+
+ /**
+ * Obtain or create a definition for the {@link RepositorySource} with the supplied name or identifier. A new definition will
+ * be created if there currently is no repository source defined with the supplied name.
+ *
+ * @param name the name or identifier of the repository source
+ * @return the details of the repository source definition; never null
+ */
+ public RepositorySourceDefinition<? extends DnaConfiguration> repositorySource( String name ) {
+ return repositorySourceDefinition(this, name);
+ }
+
+ /**
+ * Obtain or create a definition for the {@link StreamSequencer sequencer} with the supplied name or identifier. A new
+ * definition will be created if there currently is no sequencer defined with the supplied name.
+ *
+ * @param name the name or identifier of the sequencer
+ * @return the details of the sequencer definition; never null
+ */
+ public SequencerDefinition<? extends DnaConfiguration> sequencer( String name ) {
+ return sequencerDefinition(this, name);
+ }
+
+ /**
+ * Convenience method to make the code that sets up this configuration easier to read. This method simply returns this object.
+ *
+ * @return this configuration component; never null
+ */
+ public DnaConfiguration and() {
+ return this;
+ }
+
+ /**
+ * Construct an engine that reflects the current state of this configuration. This method always creates a new instance.
+ *
+ * @return the resulting engine; never null
+ */
+ public DnaEngine build() {
save();
- return new DnaEngine(builder.getExecutionContext(), builder.configurationSource);
+ return new DnaEngine(getExecutionContext(), getConfigurationDefinition());
}
- protected Graph graph() {
- return builder.graph();
+ /**
+ * Interface that defines the ability to obtain the configuration component.
+ *
+ * @param <ReturnType> the interface returned from these methods
+ */
+ public interface Returnable<ReturnType> {
+ /**
+ * Return the configuration component.
+ *
+ * @return the configuration component; never null
+ */
+ ReturnType and();
}
- protected ConfigurationRepository configurationRepository() {
- return builder.configurationSource;
+ /**
+ * Interface that defines the ability to remove the configuration component.
+ *
+ * @param <ReturnType> the configuration interface returned from these methods
+ */
+ public interface Removable<ReturnType> {
+ /**
+ * Remove this configuration component.
+ *
+ * @return the configuration; never null
+ */
+ ReturnType remove();
}
- public static class Builder<ReturnType> extends Configurator<ReturnType>
- implements Configurator.Initializer<ReturnType>, Configurator.SequencerConfigurator<ReturnType>,
- Configurator.RepositorySourceConfigurator<ReturnType>, Configurator.MimeDetectorConfigurator<ReturnType> {
+ /**
+ * The interface used to set a description on a component.
+ *
+ * @param <ReturnType> the interface returned from these methods
+ */
+ public interface SetDescription<ReturnType> {
+ /**
+ * Specify the description of this component.
+ *
+ * @param description the description; may be null or empty
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setDescription( String description );
- private Path sourcesPath;
- private Path sequencersPath;
- private Path detectorsPath;
+ /**
+ * Get the description of this component.
+ *
+ * @return the description, or null if there is no description
+ */
+ String getDescription();
+ }
+ /**
+ * Interface for configuring the JavaBean-style properties of an object.
+ *
+ * @param <ReturnType> the interface returned after the property has been set.
+ * @author Randall Hauch
+ */
+ public interface SetProperties<ReturnType> {
/**
- * Specify a new {@link ExecutionContext} that should be used for this DNA instance.
+ * Set the property value to an integer.
*
- * @param context the new context, or null if a default-constructed execution context should be used
- * @param builder the builder object returned from all the methods
- * @throws IllegalArgumentException if the supplied context reference is null
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
*/
- public Builder( ExecutionContext context,
- ReturnType builder ) {
- super(context, builder);
+ ReturnType setProperty( String beanPropertyName,
+ int value );
+
+ /**
+ * Set the property value to a long number.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ long value );
+
+ /**
+ * Set the property value to a short.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ short value );
+
+ /**
+ * Set the property value to a boolean.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ boolean value );
+
+ /**
+ * Set the property value to a float.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ float value );
+
+ /**
+ * Set the property value to a double.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ double value );
+
+ /**
+ * Set the property value to a string.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ String value );
+
+ /**
+ * Set the property value to an object.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ Object value );
+
+ /**
+ * Set the property values to an object.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param values the array of new values for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ Object[] values );
+
+ /**
+ * Get the property.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @return the property object, or null if there is no such property
+ */
+ Property getProperty( String beanPropertyName );
+ }
+
+ /**
+ * The interface used to configure the class used for a component.
+ *
+ * @param <ComponentClassType> the class or interface that the component is to implement
+ * @param <ReturnType> the interface returned from these methods
+ */
+ public interface ChooseClass<ComponentClassType, ReturnType> {
+
+ /**
+ * Specify the name of the class that should be instantiated for the instance. The classpath information will need to be
+ * defined using the returned interface.
+ *
+ * @param classname the name of the class that should be instantiated
+ * @return the interface used to define the classpath information; never null
+ * @throws IllegalArgumentException if the class name is null, empty, blank, or not a valid class name
+ */
+ LoadedFrom<ReturnType> usingClass( String classname );
+
+ /**
+ * Specify the class that should be instantiated for the instance. Because the class is already available to this class
+ * loader, there is no need to specify the classloader information.
+ *
+ * @param clazz the class that should be instantiated
+ * @return the next component to continue configuration; never null
+ * @throws DnaConfigurationException if the class could not be accessed and instantiated (if needed)
+ * @throws IllegalArgumentException if the class reference is null
+ */
+ ReturnType usingClass( Class<? extends ComponentClassType> clazz );
+ }
+
+ /**
+ * Interface for specifying from where the component's class is to be loaded.
+ *
+ * @param <ReturnType> the interface returned from these methods
+ */
+ public interface LoadedFrom<ReturnType> {
+ /**
+ * Specify the names of the classloaders that form the classpath for the component, from which the component's class (and
+ * its dependencies) can be loaded. The names correspond to the names supplied to the
+ * {@link ExecutionContext#getClassLoader(String...)} methods.
+ *
+ * @param classPathNames the names for the classloaders, as passed to the {@link ClassLoaderFactory} implementation (e.g.,
+ * the {@link ExecutionContext}).
+ * @return the next component to continue configuration; never null
+ * @see #loadedFromClasspath()
+ * @see ExecutionContext#getClassLoader(String...)
+ */
+ ReturnType loadedFrom( String... classPathNames );
+
+ /**
+ * Specify that the component (and its dependencies) will be found on the current (or
+ * {@link Thread#getContextClassLoader() current context}) classloader.
+ *
+ * @return the next component to continue configuration; never null
+ * @see #loadedFrom(String...)
+ * @see ExecutionContext#getClassLoader(String...)
+ */
+ ReturnType loadedFromClasspath();
+ }
+
+ /**
+ * Interface for a component that has a name.
+ */
+ public interface HasName {
+ /**
+ * Get the name.
+ *
+ * @return the name; never null
+ */
+ String getName();
+ }
+
+ /**
+ * Interface used to set up and define a MIME type detector instance.
+ *
+ * @param <ReturnType> the type of the configuration component that owns this definition object
+ */
+ public interface MimeTypeDetectorDefinition<ReturnType>
+ extends Returnable<ReturnType>, SetDescription<MimeTypeDetectorDefinition<ReturnType>>,
+ SetProperties<MimeTypeDetectorDefinition<ReturnType>>,
+ ChooseClass<MimeTypeDetector, MimeTypeDetectorDefinition<ReturnType>>, Removable<ReturnType> {
+ }
+
+ /**
+ * Interface used to set up and define a RepositorySource instance.
+ *
+ * @param <ReturnType> the type of the configuration component that owns this definition object
+ */
+ public interface RepositorySourceDefinition<ReturnType>
+ extends Returnable<ReturnType>, SetDescription<RepositorySourceDefinition<ReturnType>>,
+ SetProperties<RepositorySourceDefinition<ReturnType>>,
+ ChooseClass<RepositorySource, RepositorySourceDefinition<ReturnType>>, Removable<ReturnType>, HasName {
+
+ /**
+ * Set the retry limit on the repository source. This is equivalent to calling {@link #setProperty(String, int)} with "
+ * {@link DnaLexicon#RETRY_LIMIT dna:retryLimit}" as the property name.
+ *
+ * @param retryLimit the retry limit
+ * @return this definition, for method chaining purposes
+ * @see RepositorySource#setRetryLimit(int)
+ */
+ RepositorySourceDefinition<ReturnType> setRetryLimit( int retryLimit );
+ }
+
+ /**
+ * Interface used to set up and define a {@link StreamSequencer sequencer} instance.
+ *
+ * @param <ReturnType> the type of the configuration component that owns this definition object
+ */
+ public interface SequencerDefinition<ReturnType>
+ extends Returnable<ReturnType>, SetDescription<SequencerDefinition<ReturnType>>,
+ SetProperties<SequencerDefinition<ReturnType>>, ChooseClass<StreamSequencer, SequencerDefinition<ReturnType>>,
+ Removable<ReturnType> {
+
+ /**
+ * Specify the input {@link PathExpression path expression} represented as a string, which determines when this sequencer
+ * will be executed.
+ *
+ * @param inputPathExpression the path expression for nodes that, when they change, will be passed as an input to the
+ * sequencer
+ * @return the interface used to specify the output path expression; never null
+ */
+ PathExpressionOutput<ReturnType> sequencingFrom( String inputPathExpression );
+
+ /**
+ * Specify the input {@link PathExpression path expression}, which determines when this sequencer will be executed.
+ *
+ * @param inputPathExpression the path expression for nodes that, when they change, will be passed as an input to the
+ * sequencer
+ * @return the interface used to continue specifying the configuration of the sequencer
+ */
+ SequencerDefinition<ReturnType> sequencingFrom( PathExpression inputPathExpression );
+
+ /**
+ * Get the path expressions from the saved configuration.
+ *
+ * @return the set of path expressions; never null but possibly empty
+ */
+ Set<PathExpression> getPathExpressions();
+ }
+
+ /**
+ * Interface used to specify the output path expression for a
+ * {@link DnaConfiguration.SequencerDefinition#sequencingFrom(PathExpression) sequencer configuration}.
+ *
+ * @param <ReturnType>
+ */
+ public interface PathExpressionOutput<ReturnType> {
+ /**
+ * Specify the output {@link PathExpression path expression}, which determines where this sequencer's output will be
+ * placed.
+ *
+ * @param outputExpression the path expression for the location(s) where output generated by the sequencer is to be placed
+ * @return the interface used to continue specifying the configuration of the sequencer
+ */
+ SequencerDefinition<ReturnType> andOutputtingTo( String outputExpression );
+ }
+
+ /**
+ * Utility method to construct a definition object for the detector with the supplied name and return type.
+ *
+ * @param <ReturnType> the type of the return object
+ * @param returnObject the return object
+ * @param name the name of the detector
+ * @return the definition for the detector
+ */
+ @SuppressWarnings( "unchecked" )
+ protected <ReturnType extends DnaConfiguration> MimeTypeDetectorDefinition<ReturnType> mimeTypeDetectorDefinition( ReturnType returnObject,
+ String name ) {
+ MimeTypeDetectorDefinition<ReturnType> definition = (MimeTypeDetectorDefinition<ReturnType>)mimeTypeDetectorDefinitions.get(name);
+ if (definition == null) {
+ definition = new MimeTypeDetectorBuilder<ReturnType>(returnObject, changes(), path(), DnaLexicon.MIME_TYPE_DETECTORS,
+ name(name));
+ mimeTypeDetectorDefinitions.put(name, definition);
}
+ return definition;
+ }
- public DnaEngine buildDnaEngine() {
- return new DnaEngine(context, configurationSource);
+ /**
+ * Utility method to construct a definition object for the repository source with the supplied name and return type.
+ *
+ * @param <ReturnType> the type of the return object
+ * @param returnObject the return object
+ * @param name the name of the repository source
+ * @return the definition for the repository source
+ */
+ @SuppressWarnings( "unchecked" )
+ protected <ReturnType extends DnaConfiguration> RepositorySourceDefinition<ReturnType> repositorySourceDefinition( ReturnType returnObject,
+ String name ) {
+ RepositorySourceDefinition<ReturnType> definition = (RepositorySourceDefinition<ReturnType>)repositorySourceDefinitions.get(name);
+ if (definition == null) {
+ definition = new SourceBuilder<ReturnType>(returnObject, changes(), path(), DnaLexicon.SOURCES, name(name));
+ repositorySourceDefinitions.put(name, definition);
}
+ return definition;
+ }
- protected Path sourcesPath() {
- // Make sure the "dna:sources" node is there
- if (sourcesPath == null) {
- Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.SOURCES);
- Node node = graph().createIfMissing(path).andReturn();
- this.sourcesPath = node.getLocation().getPath();
+ /**
+ * Utility method to construct a definition object for the sequencer with the supplied name and return type.
+ *
+ * @param <ReturnType> the type of the return object
+ * @param returnObject the return object
+ * @param name the name of the sequencer
+ * @return the definition for the sequencer
+ */
+ @SuppressWarnings( "unchecked" )
+ protected <ReturnType extends DnaConfiguration> SequencerDefinition<ReturnType> sequencerDefinition( ReturnType returnObject,
+ String name ) {
+ SequencerDefinition<ReturnType> definition = (SequencerDefinition<ReturnType>)sequencerDefinitions.get(name);
+ if (definition == null) {
+ definition = new SequencerBuilder<ReturnType>(returnObject, changes(), path(), DnaLexicon.SEQUENCERS, name(name));
+ sequencerDefinitions.put(name, definition);
+ }
+ return definition;
+ }
+
+ protected static class BaseReturnable<ReturnType> implements Returnable<ReturnType> {
+ protected final ReturnType returnObject;
+
+ protected BaseReturnable( ReturnType returnObject ) {
+ this.returnObject = returnObject;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration.Returnable#and()
+ */
+ public ReturnType and() {
+ return returnObject;
+ }
+ }
+
+ /**
+ * Base class for {@link Returnable} types that work on a node in the graph.
+ *
+ * @param <ReturnType> the type to be returned
+ * @param <ThisType> the type to be returned by the set properties, set description, etc. methods
+ */
+ protected static abstract class GraphReturnable<ReturnType, ThisType> extends BaseReturnable<ReturnType>
+ implements SetDescription<ThisType>, SetProperties<ThisType>, Removable<ReturnType> {
+ protected final ExecutionContext context;
+ protected final Graph.Batch batch;
+ protected final Path path;
+ private Map<Name, Property> properties = new HashMap<Name, Property>();
+
+ protected GraphReturnable( ReturnType returnObject,
+ Graph.Batch batch,
+ Path path,
+ Name... names ) {
+ super(returnObject);
+ assert batch != null;
+ assert path != null;
+ assert names.length > 0;
+ this.context = batch.getGraph().getContext();
+ this.batch = batch;
+ // Make sure there are nodes down to the supplied path ...
+ createIfMissing(path, names).and();
+ this.path = context.getValueFactories().getPathFactory().create(path, names);
+ try {
+ properties = batch.getGraph().getPropertiesByName().on(this.path);
+ } catch (PathNotFoundException e) {
+ // The node doesn't exist yet (wasn't yet saved)
+ properties = new HashMap<Name, Property>();
}
- return this.sourcesPath;
}
- protected Path sequencersPath() {
- // Make sure the "dna:sequencers" node is there
- if (sequencersPath == null) {
- Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.SEQUENCERS);
- Node node = graph().createIfMissing(path).andReturn();
- this.sequencersPath = node.getLocation().getPath();
+ /**
+ * Create the node at the supplied path under the current path, and return the Create operation for the last node created.
+ * The caller <i>must</i> call {@link Graph.Create#and()} to complete the operation.
+ *
+ * @param child the name of the child
+ * @param segments the segments in the remainder of the path
+ * @return the newly-created but incomplete operation
+ */
+ protected Graph.Create<Graph.Batch> createIfMissing( Name child,
+ String... segments ) {
+ Path nodePath = context.getValueFactories().getPathFactory().create(path, child);
+ Graph.Create<Graph.Batch> result = batch.createIfMissing(nodePath);
+ for (String name : segments) {
+ result.and();
+ nodePath = context.getValueFactories().getPathFactory().create(nodePath, name);
+ result = batch.createIfMissing(nodePath);
}
- return this.sequencersPath;
+ return result;
}
- protected Path detectorsPath() {
- // Make sure the "dna:mimeTypeDetectors" node is there
- if (detectorsPath == null) {
- Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.MIME_TYPE_DETECTORS);
- Node node = graph().createIfMissing(path).andReturn();
- this.detectorsPath = node.getLocation().getPath();
+ /**
+ * Create the node at the supplied path under the current path, and return the Create operation for the last node created.
+ * The caller <i>must</i> call {@link Graph.Create#and()} to complete the operation.
+ *
+ * @param segment the name segment for the child
+ * @return the newly-created but incomplete operation
+ */
+ protected Graph.Create<Graph.Batch> createIfMissing( Name segment ) {
+ Path nodePath = context.getValueFactories().getPathFactory().create(path, segment);
+ Graph.Create<Graph.Batch> result = batch.createIfMissing(nodePath);
+ return result;
+ }
+
+ /**
+ * Create the node at the supplied path under the current path, and return the Create operation for the last node created.
+ * The caller <i>must</i> call {@link Graph.Create#and()} to complete the operation.
+ *
+ * @param path the path to the node
+ * @param segments the segments in the remainder of the path
+ * @return the newly-created but incomplete operation
+ */
+ protected Graph.Create<Graph.Batch> createIfMissing( Path path,
+ Name... segments ) {
+ Path nodePath = path;
+ Graph.Create<Graph.Batch> result = null;
+ for (Name name : segments) {
+ if (result != null) result.and();
+ nodePath = context.getValueFactories().getPathFactory().create(nodePath, name);
+ result = batch.createIfMissing(nodePath);
}
- return this.detectorsPath;
+ return result;
}
+ protected Path subpath( Name... segments ) {
+ return context.getValueFactories().getPathFactory().create(path, segments);
+ }
+
+ protected abstract ThisType thisType();
+
+ public String getName() {
+ return path.getLastSegment().getName().getString(context.getNamespaceRegistry());
+ }
+
+ public ThisType setDescription( String description ) {
+ return setProperty(DnaLexicon.DESCRIPTION, description);
+ }
+
+ public String getDescription() {
+ Property property = getProperty(DnaLexicon.DESCRIPTION);
+ if (property != null && !property.isEmpty()) {
+ return context.getValueFactories().getStringFactory().create(property.getFirstValue());
+ }
+ return null;
+ }
+
+ protected ThisType setProperty( Name propertyName,
+ Object value ) {
+ // Set the property via the batch ...
+ batch.set(propertyName).on(path).to(value).and();
+ // Record that we changed this property ...
+ properties.put(propertyName, context.getPropertyFactory().create(propertyName, value));
+ return thisType();
+ }
+
+ public ThisType setProperty( String propertyName,
+ Object value ) {
+ return setProperty(context.getValueFactories().getNameFactory().create(propertyName), value);
+ }
+
+ public ThisType setProperty( Name propertyName,
+ Object[] values ) {
+ // Set the property via the batch ...
+ batch.set(propertyName).on(path).to(values).and();
+ // Record that we changed this property ...
+ properties.put(propertyName, context.getPropertyFactory().create(propertyName, values));
+ return thisType();
+ }
+
+ public ThisType setProperty( String propertyName,
+ Object[] values ) {
+ return setProperty(context.getValueFactories().getNameFactory().create(propertyName), values);
+ }
+
+ public ThisType setProperty( String beanPropertyName,
+ boolean value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public ThisType setProperty( String beanPropertyName,
+ int value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public ThisType setProperty( String beanPropertyName,
+ short value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public ThisType setProperty( String beanPropertyName,
+ long value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public ThisType setProperty( String beanPropertyName,
+ double value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public ThisType setProperty( String beanPropertyName,
+ float value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public ThisType setProperty( String beanPropertyName,
+ String value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public Property getProperty( String beanPropertyName ) {
+ return properties.get(context.getValueFactories().getNameFactory().create(beanPropertyName));
+ }
+
+ public Property getProperty( Name beanPropertyName ) {
+ return properties.get(beanPropertyName);
+ }
+
+ public ReturnType remove() {
+ batch.delete(path);
+ properties.clear();
+ return and();
+ }
+ }
+
+ /**
+ * Base class for {@link Returnable} types that work on a node in the graph.
+ *
+ * @param <ReturnType> the type to be returned
+ * @param <ThisType> the type to be returned by the set properties, set description, etc. methods
+ * @param <ComponentType> the type of the component being configured
+ */
+ protected static abstract class GraphComponentBuilder<ReturnType, ThisType, ComponentType>
+ extends GraphReturnable<ReturnType, ThisType> implements ChooseClass<ComponentType, ThisType> {
+ protected GraphComponentBuilder( ReturnType returnObject,
+ Graph.Batch batch,
+ Path path,
+ Name... names ) {
+ super(returnObject, batch, path, names);
+ }
+
+ public LoadedFrom<ThisType> usingClass( final String classname ) {
+ return new LoadedFrom<ThisType>() {
+ public ThisType loadedFromClasspath() {
+ return setProperty(DnaLexicon.CLASSNAME, classname);
+ }
+
+ public ThisType loadedFrom( String... classpath ) {
+ List<String> classpaths = new ArrayList<String>();
+ // Ignore any null, zero-length, or duplicate elements ...
+ for (String value : classpath) {
+ if (value == null) continue;
+ value = value.trim();
+ if (value.length() == 0) continue;
+ if (!classpaths.contains(value)) classpaths.add(value);
+ }
+ if (classpaths.size() != 0) {
+ classpath = classpaths.toArray(new String[classpaths.size()]);
+ setProperty(DnaLexicon.CLASSPATH, classpath);
+ }
+ return setProperty(DnaLexicon.CLASSNAME, classname);
+ }
+ };
+ }
+
+ public ThisType usingClass( Class<? extends ComponentType> componentClass ) {
+ return setProperty(DnaLexicon.CLASSNAME, componentClass.getCanonicalName());
+ }
+ }
+
+ protected static class MimeTypeDetectorBuilder<ReturnType>
+ extends GraphComponentBuilder<ReturnType, MimeTypeDetectorDefinition<ReturnType>, MimeTypeDetector>
+ implements MimeTypeDetectorDefinition<ReturnType> {
+ protected MimeTypeDetectorBuilder( ReturnType returnObject,
+ Graph.Batch batch,
+ Path path,
+ Name... names ) {
+ super(returnObject, batch, path, names);
+ }
+
+ @Override
+ protected MimeTypeDetectorBuilder<ReturnType> thisType() {
+ return this;
+ }
+
+ }
+
+ protected static class SourceBuilder<ReturnType>
+ extends GraphComponentBuilder<ReturnType, RepositorySourceDefinition<ReturnType>, RepositorySource>
+ implements RepositorySourceDefinition<ReturnType> {
+ protected SourceBuilder( ReturnType returnObject,
+ Graph.Batch batch,
+ Path path,
+ Name... names ) {
+ super(returnObject, batch, path, names);
+ }
+
+ @Override
+ protected RepositorySourceDefinition<ReturnType> thisType() {
+ return this;
+ }
+
+ public RepositorySourceDefinition<ReturnType> setRetryLimit( int retryLimit ) {
+ return setProperty(DnaLexicon.RETRY_LIMIT, retryLimit);
+ }
+
+ @Override
+ public RepositorySourceDefinition<ReturnType> setProperty( String propertyName,
+ Object value ) {
+ Name name = context.getValueFactories().getNameFactory().create(propertyName);
+ // Check the "standard" names that should be prefixed with 'dna:'
+ if (name.getLocalName().equals(DnaLexicon.RETRY_LIMIT.getLocalName())) name = DnaLexicon.RETRY_LIMIT;
+ if (name.getLocalName().equals(DnaLexicon.DESCRIPTION.getLocalName())) name = DnaLexicon.DESCRIPTION;
+ return super.setProperty(name, value);
+ }
+
+ @Override
+ public Property getProperty( Name name ) {
+ // Check the "standard" names that should be prefixed with 'dna:'
+ if (name.getLocalName().equals(DnaLexicon.RETRY_LIMIT.getLocalName())) name = DnaLexicon.RETRY_LIMIT;
+ if (name.getLocalName().equals(DnaLexicon.DESCRIPTION.getLocalName())) name = DnaLexicon.DESCRIPTION;
+ return super.getProperty(name);
+ }
+ }
+
+ protected static class SequencerBuilder<ReturnType>
+ extends GraphComponentBuilder<ReturnType, SequencerDefinition<ReturnType>, StreamSequencer>
+ implements SequencerDefinition<ReturnType> {
+
+ protected SequencerBuilder( ReturnType returnObject,
+ Graph.Batch batch,
+ Path path,
+ Name... names ) {
+ super(returnObject, batch, path, names);
+ }
+
+ @Override
+ protected SequencerDefinition<ReturnType> thisType() {
+ return this;
+ }
+
+ public Set<PathExpression> getPathExpressions() {
+ Set<PathExpression> expressions = new HashSet<PathExpression>();
+ try {
+ Property existingExpressions = getProperty(DnaLexicon.PATH_EXPRESSION);
+ if (existingExpressions != null) {
+ for (Object existing : existingExpressions.getValuesAsArray()) {
+ String existingExpression = context.getValueFactories().getStringFactory().create(existing);
+ expressions.add(PathExpression.compile(existingExpression));
+ }
+ }
+ } catch (PathNotFoundException e) {
+ // Nothing saved yet ...
+ }
+ return expressions;
+ }
+
+ public SequencerDefinition<ReturnType> sequencingFrom( PathExpression expression ) {
+ CheckArg.isNotNull(expression, "expression");
+ Set<PathExpression> compiledExpressions = getPathExpressions();
+ compiledExpressions.add(expression);
+ String[] strings = new String[compiledExpressions.size()];
+ int index = 0;
+ for (PathExpression compiledExpression : compiledExpressions) {
+ strings[index++] = compiledExpression.getExpression();
+ }
+ setProperty(DnaLexicon.PATH_EXPRESSION, strings);
+ return this;
+ }
+
+ public PathExpressionOutput<ReturnType> sequencingFrom( final String fromPathExpression ) {
+ CheckArg.isNotEmpty(fromPathExpression, "fromPathExpression");
+ return new PathExpressionOutput<ReturnType>() {
+ public SequencerDefinition<ReturnType> andOutputtingTo( String into ) {
+ CheckArg.isNotEmpty(into, "into");
+ return sequencingFrom(PathExpression.compile(fromPathExpression + " => " + into));
+ }
+ };
+ }
+ }
+
+ /**
+ * Representation of the current configuration content.
+ */
+ @Immutable
+ public static class ConfigurationDefinition {
+ private final ClassLoaderFactory classLoaderFactory;
+ private final RepositorySource source;
+ private final Path path;
+ private final String workspace;
+ private final ExecutionContext context;
+ private Graph graph;
+
+ protected ConfigurationDefinition( RepositorySource source,
+ String workspace,
+ Path path,
+ ExecutionContext context,
+ ClassLoaderFactory classLoaderFactory ) {
+ this.source = source;
+ this.path = path != null ? path : RootPath.INSTANCE;
+ this.workspace = workspace;
+ this.context = context;
+ this.classLoaderFactory = classLoaderFactory != null ? classLoaderFactory : new StandardClassLoaderFactory();
+ }
+
/**
- * {@inheritDoc}
+ * Get the repository source where the configuration content may be found
*
- * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationSource()
+ * @return the source for the configuration repository; never null
*/
- public ChooseClass<RepositorySource, ConfigSourceDetails<ReturnType>> withConfigurationSource() {
- return new ConfigurationRepositoryClassChooser<ReturnType>(builder);
+ public RepositorySource getRepositorySource() {
+ return source;
}
-
+
/**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.Initializer#configurationSource()
+ * Get the path in the configuration repository where the configuration content may be found
+ *
+ * @return the path to the configuration content; never null
*/
- public ConfigSourceDetails<ReturnType> configurationSource() {
- return configurationSource;
+ public Path getPath() {
+ return path;
}
/**
- * {@inheritDoc}
+ * Get the name of the workspace used for the configuration repository.
*
- * @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String)
+ * @return the name of the workspace, or null if the default workspace should be used
*/
- public ChooseClass<StreamSequencer, SequencerDetails<ReturnType>> addSequencer( String id ) {
- CheckArg.isNotEmpty(id, "id");
- // Now create the "dna:sequencer" node with the supplied id ...
- Path path = createOrReplaceNode(sequencersPath(), id, DnaLexicon.READABLE_NAME, id);
- SequencerDetails<ReturnType> details = new GraphSequencerDetails<ReturnType>(path, builder);
- return new ClassChooser<StreamSequencer, SequencerDetails<ReturnType>>(path, details);
+ public String getWorkspace() {
+ return workspace;
}
/**
- * {@inheritDoc}
+ * @return context
+ */
+ public ExecutionContext getContext() {
+ return context;
+ }
+
+ /**
+ * @return classLoaderFactory
+ */
+ public ClassLoaderFactory getClassLoaderFactory() {
+ return classLoaderFactory;
+ }
+
+ /**
+ * Return a copy of this configuration that uses the supplied path instead of this object's {@link #getPath() path}.
*
- * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(java.lang.String)
+ * @param path the desired path for the new configuration; if null, then "/" is used
+ * @return the new configuration
*/
- public ChooseClass<RepositorySource, RepositorySourceDetails<ReturnType>> addSource( String id ) {
- CheckArg.isNotEmpty(id, "id");
- // Now create the "dna:source" node with the supplied id ...
- Path path = createOrReplaceNode(sourcesPath(), id, DnaLexicon.READABLE_NAME, id);
- RepositorySourceDetails<ReturnType> details = new GraphRepositorySourceDetails<ReturnType>(path, builder);
- return new ClassChooser<RepositorySource, RepositorySourceDetails<ReturnType>>(path, details);
+ public ConfigurationDefinition with( Path path ) {
+ return new ConfigurationDefinition(source, workspace, path, context, classLoaderFactory);
}
/**
- * {@inheritDoc}
+ * Return a copy of this configuration that uses the supplied workspace name instead of this object's
+ * {@link #getWorkspace() workspace}.
*
- * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(org.jboss.dna.graph.connector.RepositorySource)
+ * @param workspace the desired workspace name for the new configuration; if null, then the default workspace will be used
+ * @return the new configuration
*/
- public ReturnType addSource( RepositorySource source ) {
- CheckArg.isNotNull(source, "source");
- CheckArg.isNotEmpty(source.getName(), "source.getName()");
- String name = source.getName();
- RepositorySourceDetails<ReturnType> details = addSource(source.getName()).usingClass(source.getClass().getName())
- .loadedFromClasspath();
- // Record all of the bean properties ...
- Path sourcePath = pathFactory().create(sourcesPath(), name);
- recordBeanPropertiesInGraph(sourcePath, source);
- return details.and();
+ public ConfigurationDefinition withWorkspace( String workspace ) {
+ return new ConfigurationDefinition(source, workspace, path, context, classLoaderFactory);
}
/**
- * {@inheritDoc}
+ * Return a copy of this configuration that uses the supplied class loader factory instead of this object's
+ * {@link #getClassLoaderFactory() class loader factory}.
*
- * @see org.jboss.dna.repository.Configurator.MimeDetectorConfigurator#addMimeTypeDetector(java.lang.String)
+ * @param classLoaderFactory the classloader factory, or null if the default factory should be used
+ * @return the new configuration
*/
- public ChooseClass<MimeTypeDetector, MimeTypeDetectorDetails<ReturnType>> addMimeTypeDetector( String id ) {
- CheckArg.isNotEmpty(id, "id");
- // Now create the "dna:sequencer" node with the supplied id ...
- Path detectorPath = createOrReplaceNode(detectorsPath(), id, DnaLexicon.READABLE_NAME, id);
- MimeTypeDetectorDetails<ReturnType> details = new GraphMimeTypeDetectorDetails<ReturnType>(detectorPath, builder);
- return new ClassChooser<MimeTypeDetector, MimeTypeDetectorDetails<ReturnType>>(detectorPath, details);
+ public ConfigurationDefinition with( ClassLoaderFactory classLoaderFactory ) {
+ return new ConfigurationDefinition(source, workspace, path, context, classLoaderFactory);
}
/**
- * {@inheritDoc}
+ * Obtain a graph to this configuration repository. This method will always return the same graph instance.
*
- * @see org.jboss.dna.repository.Configurator#nameFor(java.lang.String)
+ * @return the graph; never null
*/
- @Override
- protected Name nameFor( String name ) {
- Name result = NAMES_TO_MAP.get(name);
- if (result == null) result = context.getValueFactories().getNameFactory().create(name);
- return result;
+ public Graph graph() {
+ if (graph == null) {
+ graph = Graph.create(source, context);
+ if (workspace != null) graph.useWorkspace(workspace);
+ }
+ return graph;
}
}
-
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -33,6 +33,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.collection.SimpleProblems;
+import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.JcrLexicon;
@@ -67,10 +68,10 @@
public static final String CONFIGURATION_REPOSITORY_NAME = "dna:configuration";
- private final Configurator.ConfigurationRepository configuration;
+ protected final DnaConfiguration.ConfigurationDefinition configuration;
private final ConfigurationScanner scanner;
private final Problems problems;
- private final ExecutionContext context;
+ protected final ExecutionContext context;
private final RepositoryService repositoryService;
private final SequencingService sequencingService;
@@ -79,8 +80,8 @@
private final RepositoryConnectionFactory connectionFactory;
- DnaEngine( ExecutionContext context,
- Configurator.ConfigurationRepository configuration ) {
+ protected DnaEngine( ExecutionContext context,
+ DnaConfiguration.ConfigurationDefinition configuration ) {
this.problems = new SimpleProblems();
// Use the configuration's context ...
@@ -119,7 +120,7 @@
connectionFactory = new RepositoryConnectionFactory() {
public RepositoryConnection createConnection( String sourceName ) throws RepositorySourceException {
RepositorySource source = DnaEngine.this.getRepositorySource(sourceName);
- if (sourceName == null) {
+ if (source == null) {
throw new RepositorySourceException(sourceName);
}
@@ -151,8 +152,10 @@
*
* @param repositoryName the name of the repository source
* @return the source, or null if no source with the given name exists
+ * @throws IllegalStateException if this engine was not {@link #start() started}
*/
public final RepositorySource getRepositorySource( String repositoryName ) {
+ checkRunning();
return repositoryService.getRepositoryLibrary().getSource(repositoryName);
}
@@ -160,8 +163,10 @@
* Get a factory of connections, backed by the RepositorySor
*
* @return the connection factory; never null
+ * @throws IllegalStateException if this engine was not {@link #start() started}
*/
public final RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ checkRunning();
return connectionFactory;
}
@@ -169,17 +174,41 @@
* Get the repository service.
*
* @return the repository service owned by this engine; never null
+ * @throws IllegalStateException if this engine was not {@link #start() started}
*/
public final RepositoryService getRepositoryService() {
+ checkRunning();
return repositoryService;
}
/**
+ * Get a graph to the underlying source.
+ *
+ * @param sourceName the name of the source
+ * @return the graph
+ * @throws IllegalArgumentException if the source name is null
+ * @throws RepositorySourceException if a source with the supplied name does not exist
+ * @throws IllegalStateException if this engine was not {@link #start() started}
+ */
+ public final Graph getGraph( String sourceName ) {
+ CheckArg.isNotNull(sourceName, "sourceName");
+ checkRunning();
+ Graph graph = Graph.create(sourceName, getRepositoryService().getRepositoryLibrary(), getExecutionContext());
+ if (configuration.getRepositorySource().getName().equals(sourceName) && configuration.getWorkspace() != null) {
+ // set the workspace ...
+ graph.useWorkspace(configuration.getWorkspace());
+ }
+ return graph;
+ }
+
+ /**
* Get the sequencing service.
*
* @return the sequencing service owned by this engine; never null
+ * @throws IllegalStateException if this engine was not {@link #start() started}
*/
public final SequencingService getSequencingService() {
+ checkRunning();
return sequencingService;
}
@@ -187,11 +216,20 @@
* Return the component that is able to detect MIME types given the name of a stream and a stream.
*
* @return the MIME type detector used by this engine; never null
+ * @throws IllegalStateException if this engine was not {@link #start() started}
*/
protected final MimeTypeDetector getMimeTypeDetector() {
+ checkRunning();
return detectors;
}
+ protected final boolean checkRunning() {
+ if (repositoryService.getAdministrator().isStarted() && sequencingService.getAdministrator().isStarted()) {
+ return true;
+ }
+ throw new IllegalStateException(RepositoryI18n.engineIsNotRunning.text());
+ }
+
/*
* Lifecycle methods
*/
@@ -249,17 +287,30 @@
}
/**
+ * Get a graph to the configuration content.
+ *
+ * @return a graph to the configuration content
+ */
+ protected Graph getConfigurationGraph() {
+ Graph result = Graph.create(configuration.getRepositorySource(), context);
+ if (configuration.getWorkspace() != null) {
+ result.useWorkspace(configuration.getWorkspace());
+ }
+ return result;
+ }
+
+ /**
* The component responsible for reading the configuration repository and (eventually) for propagating changes in the
* configuration repository into the services.
*/
protected class ConfigurationScanner {
private final Problems problems;
private final ExecutionContext context;
- private final Configurator.ConfigurationRepository configurationRepository;
+ private final DnaConfiguration.ConfigurationDefinition configurationRepository;
protected ConfigurationScanner( Problems problems,
ExecutionContext context,
- Configurator.ConfigurationRepository configurationRepository ) {
+ DnaConfiguration.ConfigurationDefinition configurationRepository ) {
this.problems = problems;
this.context = context;
this.configurationRepository = configurationRepository;
@@ -278,7 +329,7 @@
skipProperties.add(DnaLexicon.DESCRIPTION);
skipProperties.add(DnaLexicon.CLASSNAME);
skipProperties.add(DnaLexicon.CLASSPATH);
- skipProperties.add(DnaLexicon.PATH_EXPRESSIONS);
+ skipProperties.add(DnaLexicon.PATH_EXPRESSION);
Set<String> skipNamespaces = new HashSet<String>();
skipNamespaces.add(JcrLexicon.Namespace.URI);
skipNamespaces.add(JcrNtLexicon.Namespace.URI);
@@ -287,6 +338,7 @@
for (Location detectorLocation : subgraph.getRoot().getChildren()) {
Node node = subgraph.getNode(detectorLocation);
String name = stringValueOf(node, DnaLexicon.READABLE_NAME);
+ if (name == null) name = stringValueOf(node);
String desc = stringValueOf(node, DnaLexicon.DESCRIPTION);
String classname = stringValueOf(node, DnaLexicon.CLASSNAME);
String[] classpath = stringValuesOf(node, DnaLexicon.CLASSPATH);
@@ -323,7 +375,7 @@
skipProperties.add(DnaLexicon.DESCRIPTION);
skipProperties.add(DnaLexicon.CLASSNAME);
skipProperties.add(DnaLexicon.CLASSPATH);
- skipProperties.add(DnaLexicon.PATH_EXPRESSIONS);
+ skipProperties.add(DnaLexicon.PATH_EXPRESSION);
Set<String> skipNamespaces = new HashSet<String>();
skipNamespaces.add(JcrLexicon.Namespace.URI);
skipNamespaces.add(JcrNtLexicon.Namespace.URI);
@@ -332,10 +384,11 @@
for (Location sequencerLocation : subgraph.getRoot().getChildren()) {
Node sequencerNode = subgraph.getNode(sequencerLocation);
String name = stringValueOf(sequencerNode, DnaLexicon.READABLE_NAME);
+ if (name == null) name = stringValueOf(sequencerNode);
String desc = stringValueOf(sequencerNode, DnaLexicon.DESCRIPTION);
String classname = stringValueOf(sequencerNode, DnaLexicon.CLASSNAME);
String[] classpath = stringValuesOf(sequencerNode, DnaLexicon.CLASSPATH);
- String[] expressionStrings = stringValuesOf(sequencerNode, DnaLexicon.PATH_EXPRESSIONS);
+ String[] expressionStrings = stringValuesOf(sequencerNode, DnaLexicon.PATH_EXPRESSION);
List<PathExpression> pathExpressions = new ArrayList<PathExpression>();
if (expressionStrings != null) {
for (String expressionString : expressionStrings) {
@@ -376,6 +429,10 @@
return configs;
}
+ private String stringValueOf( Node node ) {
+ return node.getLocation().getPath().getLastSegment().getString(context.getNamespaceRegistry());
+ }
+
private String stringValueOf( Node node,
Name propertyName ) {
Property property = node.getProperty(propertyName);
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaLexicon.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaLexicon.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaLexicon.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -37,7 +37,7 @@
public static final Name DESCRIPTION = new BasicName(Namespace.URI, "description");
public static final Name SEQUENCERS = new BasicName(Namespace.URI, "sequencers");
public static final Name SEQUENCER = new BasicName(Namespace.URI, "sequencer");
- public static final Name PATH_EXPRESSIONS = new BasicName(Namespace.URI, "pathExpressions");
+ public static final Name PATH_EXPRESSION = new BasicName(Namespace.URI, "pathExpression");
public static final Name JNDI_NAME = new BasicName(Namespace.URI, "jndiName");
public static final Name MIME_TYPE_DETECTORS = new BasicName(Namespace.URI, "mimeTypeDetectors");
public static final Name MIME_TYPE_DETECTOR = new BasicName(Namespace.URI, "mimeTypeDetector");
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -122,6 +122,9 @@
// Repository
public static I18n errorStartingRepositoryService;
+ // Engine
+ public static I18n engineIsNotRunning;
+
static {
try {
I18n.initialize(RepositoryI18n.class);
Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -1,512 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.repository.config;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.Graph;
-import org.jboss.dna.graph.Node;
-import org.jboss.dna.graph.Workspace;
-import org.jboss.dna.graph.connector.RepositorySource;
-import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.basic.RootPath;
-import org.xml.sax.SAXException;
-
-/**
- *
- */
-public class DnaConfiguration {
-
- protected static final String DEFAULT_WORKSPACE_NAME = "";
- protected static final String DEFAULT_PATH = "/";
-
- private final ExecutionContext context;
- private ConfigurationContent configurationContent;
-
- /**
- * Create a new configuration, using a default-constructed {@link ExecutionContext}.
- */
- public DnaConfiguration() {
- this(new ExecutionContext());
- }
-
- /**
- * Create a new configuration using the supplied {@link ExecutionContext}.
- *
- * @param context the execution context
- * @throws IllegalArgumentException if the path is null or empty
- */
- public DnaConfiguration( ExecutionContext context ) {
- CheckArg.isNotNull(context, "context");
- this.context = context;
- }
-
- /**
- * Load the configuration from a file at the given path.
- *
- * @param pathToConfigurationFile the path the file containing the configuration information
- * @return this configuration object, for convenience and method chaining
- * @throws IOException if there is an error or problem reading the file at the supplied location
- * @throws SAXException if the file is not a valid XML format
- * @throws IllegalArgumentException if the path is null or empty
- */
- public DnaConfiguration loadFrom( String pathToConfigurationFile ) throws IOException, SAXException {
- CheckArg.isNotEmpty(pathToConfigurationFile, "pathToConfigurationFile");
- return loadFrom(new File(pathToConfigurationFile));
- }
-
- /**
- * Load the configuration from a file.
- *
- * @param configurationFile the file containing the configuration information
- * @return this configuration object, for convenience and method chaining
- * @throws IOException if there is an error or problem reading the supplied file
- * @throws SAXException if the file is not a valid XML format
- * @throws IllegalArgumentException if the file reference is null
- */
- public DnaConfiguration loadFrom( File configurationFile ) throws IOException, SAXException {
- CheckArg.isNotNull(configurationFile, "configurationFile");
- InputStream stream = new FileInputStream(configurationFile);
- try {
- return loadFrom(stream);
- } finally {
- stream.close();
- }
- }
-
- /**
- * Load the configuration from a file at the supplied URL.
- *
- * @param urlToConfigurationFile the URL of the file containing the configuration information
- * @return this configuration object, for convenience and method chaining
- * @throws IOException if there is an error or problem reading the file at the supplied URL
- * @throws SAXException if the file is not a valid XML format
- * @throws IllegalArgumentException if the URL is null
- */
- public DnaConfiguration loadFrom( URL urlToConfigurationFile ) throws IOException, SAXException {
- CheckArg.isNotNull(urlToConfigurationFile, "urlToConfigurationFile");
- InputStream stream = urlToConfigurationFile.openStream();
- try {
- return loadFrom(stream);
- } finally {
- stream.close();
- }
- }
-
- /**
- * Load the configuration from a file at the supplied URL.
- *
- * @param configurationFileInputStream the stream with the configuration information
- * @return this configuration object, for convenience and method chaining
- * @throws IOException if there is an error or problem reading the file at the supplied URL
- * @throws SAXException if the file is not a valid XML format
- * @throws IllegalArgumentException if the stream is null
- */
- public DnaConfiguration loadFrom( InputStream configurationFileInputStream ) throws IOException, SAXException {
- CheckArg.isNotNull(configurationFileInputStream, "configurationFileInputStream");
-
- // Create the in-memory repository source in which the content will be stored ...
- InMemoryRepositorySource source = new InMemoryRepositorySource();
- source.setName("Configuration Repository");
- source.setDefaultWorkspaceName(DEFAULT_WORKSPACE_NAME);
-
- // Import the information into the source ...
- Path path = path(DEFAULT_PATH);
- Graph graph = Graph.create(source, context);
- graph.importXmlFrom(configurationFileInputStream).into(path);
-
- // The file was imported successfully, so now create the content information ...
- configurationContent = new ConfigurationContent(source, null, path, context);
- return this;
- }
-
- /**
- * Load the configuration from the repository content using the supplied repository source. This method assumes that the
- * supplied source has already been configured and is ready to {@link RepositorySource#getConnection() create connections}.
- * Also, the default workspace of the source will be used, and the configuration content may be found directly under the root
- * node.
- *
- * @param source the source that defines the repository with the configuration content
- * @return this configuration object, for convenience and method chaining
- * @throws IllegalArgumentException if the source is null
- */
- public DnaConfiguration loadFrom( RepositorySource source ) {
- return loadFrom(source, null, null);
- }
-
- /**
- * Load the configuration from the repository content using the workspace in the supplied repository source. This method
- * assumes that the supplied source has already been configured and is ready to {@link RepositorySource#getConnection() create
- * connections}. Also, the configuration content may be found directly under the root node.
- *
- * @param source the source that defines the repository with the configuration content
- * @param workspaceName the name of the workspace with the configuration content, or null if the source's default workspace
- * should be used
- * @return this configuration object, for convenience and method chaining
- * @throws IllegalArgumentException if the source is null
- */
- public DnaConfiguration loadFrom( RepositorySource source,
- String workspaceName ) {
- CheckArg.isNotNull(source, "source");
- return loadFrom(source, workspaceName, null);
- }
-
- /**
- * Load the configuration from the repository content at the supplied path in the workspace in the supplied repository source.
- * This method assumes that the supplied source has already been configured and is ready to
- * {@link RepositorySource#getConnection() create connections}.
- *
- * @param source the source that defines the repository with the configuration content
- * @param workspaceName the name of the workspace with the configuration content, or null if the source's default workspace
- * should be used
- * @param pathInWorkspace the path to the parent node under which the configuration content may be found, or null if the
- * content may be found under the root node
- * @return this configuration object, for convenience and method chaining
- * @throws IllegalArgumentException if the source is null
- */
- public DnaConfiguration loadFrom( RepositorySource source,
- String workspaceName,
- String pathInWorkspace ) {
- CheckArg.isNotNull(source, "source");
-
- // Verify connectivity ...
- Graph graph = Graph.create(source, context);
- if (workspaceName != null) {
- Workspace workspace = graph.useWorkspace(workspaceName); // should throw exception if not connectable
- assert workspace.getRoot() != null;
- }
-
- // Verify the path ...
- Path path = pathInWorkspace != null ? path(pathInWorkspace) : path(DEFAULT_PATH);
- Node parent = graph.getNodeAt(path);
- assert parent != null;
-
- // Now create the content information ...
- configurationContent = new ConfigurationContent(source, workspaceName, path, context);
- return this;
- }
-
- protected ConfigurationContent getConfigurationContent() {
- return configurationContent;
- }
-
- protected Path path( String path ) {
- return context.getValueFactories().getPathFactory().create(path);
- }
-
- public MimeTypeDetectorDetails<? extends DnaConfiguration> mimeTypeDetector( String name ) {
- return new MimeTypeDetectorBuilder<DnaConfiguration>(this);
- }
-
- /**
- * Construct an engine that reflects the current state of this configuration. This method always creates a new instance.
- *
- * @return the resulting engine; never null
- */
- public DnaEngine build() {
- return new DnaEngine();
- }
-
- public interface Returnable<ReturnType> {
- /**
- * Return the configuration component.
- *
- * @return the configuration component; never null
- */
- ReturnType and();
- }
-
- protected static class BaseReturnable<ReturnType> implements Returnable<ReturnType> {
- protected final ReturnType returnObject;
-
- protected BaseReturnable( ReturnType returnObject ) {
- this.returnObject = returnObject;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration.Returnable#and()
- */
- public ReturnType and() {
- return returnObject;
- }
- }
-
- /**
- * Interface used to set up and build a RepositorySource instance.
- *
- * @param <ReturnType> the type of the configuration component
- */
- public interface MimeTypeDetectorDetails<ReturnType> extends Returnable<ReturnType> {
- }
-
- protected static class MimeTypeDetectorBuilder<ReturnType> extends BaseReturnable<ReturnType>
- implements MimeTypeDetectorDetails<ReturnType> {
- protected MimeTypeDetectorBuilder( ReturnType returnObject ) {
- super(returnObject);
- }
- }
-
- /**
- * Interface used to set up and build a RepositorySource instance.
- *
- * @param <ReturnType> the type of the configuration component
- */
- public interface RepositorySourceDetails<ReturnType>
- extends SetProperties<RepositorySourceDetails<ReturnType>>, Returnable<ReturnType> {
- }
-
- /**
- * Interface for configuring the JavaBean-style properties of an object.
- *
- * @param <ReturnType> the interface returned after the property has been set.
- * @author Randall Hauch
- */
- public interface SetProperties<ReturnType> {
- /**
- * Set the property value to an integer.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- int value );
-
- /**
- * Set the property value to a long number.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- long value );
-
- /**
- * Set the property value to a short.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- short value );
-
- /**
- * Set the property value to a boolean.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- boolean value );
-
- /**
- * Set the property value to a float.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- float value );
-
- /**
- * Set the property value to a double.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- double value );
-
- /**
- * Set the property value to a string.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- String value );
-
- /**
- * Set the property value to an object.
- *
- * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @param value the new value for the property
- * @return the next component to continue configuration; never null
- */
- ReturnType setProperty( String beanPropertyName,
- Object value );
- }
-
- protected class SourceDetails<ReturnType> extends BaseReturnable<ReturnType> implements RepositorySourceDetails<ReturnType> {
-
- protected SourceDetails( ReturnType returnObject ) {
- super(returnObject);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- int value ) {
- return setProperty(beanPropertyName, (Object)value);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- long value ) {
- return setProperty(beanPropertyName, (Object)value);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- short value ) {
- return setProperty(beanPropertyName, (Object)value);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- boolean value ) {
- return setProperty(beanPropertyName, (Object)value);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- float value ) {
- return setProperty(beanPropertyName, (Object)value);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- double value ) {
- return setProperty(beanPropertyName, (Object)value);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- String value ) {
- return setProperty(beanPropertyName, (Object)value);
- }
-
- public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
- Object value ) {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * Representation of the current configuration content.
- */
- @Immutable
- protected static class ConfigurationContent {
- private final RepositorySource source;
- private final Path path;
- private final String workspace;
- private final ExecutionContext context;
- private Graph graph;
-
- protected ConfigurationContent( RepositorySource source,
- String workspace,
- Path path,
- ExecutionContext context ) {
- this.source = source;
- this.path = path != null ? path : RootPath.INSTANCE;
- this.workspace = workspace;
- this.context = context;
- }
-
- /**
- * Get the repository source where the configuration content may be found
- *
- * @return the source for the configuration repository; never null
- */
- public RepositorySource getRepositorySource() {
- return source;
- }
-
- /**
- * Get the path in the configuration repository where the configuration content may be found
- *
- * @return the path to the configuration content; never null
- */
- public Path getPath() {
- return path;
- }
-
- /**
- * Get the name of the workspace used for the configuration repository.
- *
- * @return the name of the workspace, or null if the default workspace should be used
- */
- public String getWorkspace() {
- return workspace;
- }
-
- /**
- * @return context
- */
- public ExecutionContext getContext() {
- return context;
- }
-
- /**
- * Return a copy of this configuration that uses the supplied path instead of this object's {@link #getPath() path}.
- *
- * @param path the desired path for the new configuration; if null, then "/" is used
- * @return the new configuration
- */
- public ConfigurationContent with( Path path ) {
- return new ConfigurationContent(source, workspace, path, context);
- }
-
- /**
- * Return a copy of this configuration that uses the supplied workspace name instead of this object's
- * {@link #getWorkspace() workspace}.
- *
- * @param workspace the desired workspace name for the new configuration; if null, then the default workspace will be used
- * @return the new configuration
- */
- public ConfigurationContent withWorkspace( String workspace ) {
- return new ConfigurationContent(source, workspace, path, context);
- }
-
- /**
- * Obtain a graph to this configuration repository. This method will always return the same graph instance.
- *
- * @return the graph; never null
- */
- protected Graph graph() {
- if (graph == null) {
- graph = Graph.create(source, context);
- if (workspace != null) graph.useWorkspace(workspace);
- }
- return graph;
- }
- }
-}
Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -1,31 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.repository.config;
-
-/**
- *
- */
-public class DnaEngine {
-
-}
Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -1,145 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.repository.config;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import org.jboss.dna.graph.connector.RepositorySource;
-import org.xml.sax.SAXException;
-
-/**
- *
- */
-public class JcrConfiguration extends DnaConfiguration {
-
- /**
- * {@inheritDoc}
- *
- * @throws IOException
- * @throws SAXException
- * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.lang.String)
- */
- @Override
- public JcrConfiguration loadFrom( String pathToFile ) throws IOException, SAXException {
- super.loadFrom(pathToFile);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.io.File)
- */
- @Override
- public JcrConfiguration loadFrom( File configurationFile ) throws IOException, SAXException {
- super.loadFrom(configurationFile);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.net.URL)
- */
- @Override
- public JcrConfiguration loadFrom( URL urlToConfigurationFile ) throws IOException, SAXException {
- super.loadFrom(urlToConfigurationFile);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.io.InputStream)
- */
- @Override
- public JcrConfiguration loadFrom( InputStream configurationFileInputStream ) throws IOException, SAXException {
- super.loadFrom(configurationFileInputStream);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource)
- */
- @Override
- public JcrConfiguration loadFrom( RepositorySource source ) {
- super.loadFrom(source);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource,
- * java.lang.String)
- */
- @Override
- public JcrConfiguration loadFrom( RepositorySource source,
- String workspaceName ) {
- super.loadFrom(source, workspaceName);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource,
- * java.lang.String, java.lang.String)
- */
- @Override
- public JcrConfiguration loadFrom( RepositorySource source,
- String workspaceName,
- String pathInWorkspace ) {
- super.loadFrom(source, workspaceName, pathInWorkspace);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#mimeTypeDetector(java.lang.String)
- */
- @Override
- public MimeTypeDetectorDetails<JcrConfiguration> mimeTypeDetector( String name ) {
- return new MimeTypeDetectorBuilder<JcrConfiguration>(this);
- }
-
- public JcrConfiguration addRepository( String repositoryId ) {
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.config.DnaConfiguration#build()
- */
- @Override
- public JcrEngine build() {
- return new JcrEngine();
- }
-}
Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -1,98 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.repository.config;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsSame.sameInstance;
-import static org.junit.Assert.assertThat;
-import java.io.File;
-import java.net.URL;
-import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
-import org.junit.Test;
-
-/**
- *
- */
-public class JcrConfigurationTest {
-
- @Test
- public void shoulConfigureDnaFromFileUsingPath() throws Exception {
- DnaConfiguration config = new DnaConfiguration();
- config.loadFrom("some path");
-
- DnaEngine engine = config.build();
- assertThat(engine, is(notNullValue()));
- }
-
- @Test
- public void shoulConfigureDnaFromFile() throws Exception {
- DnaConfiguration config = new DnaConfiguration();
- config.loadFrom(new File("file:some path"));
-
- DnaEngine engine = config.build();
- assertThat(engine, is(notNullValue()));
- }
-
- @Test
- public void shoulConfigureDnaFromFileUsingURL() throws Exception {
- DnaConfiguration config = new DnaConfiguration();
- config.loadFrom(new URL("file:some path"));
-
- DnaEngine engine = config.build();
- assertThat(engine, is(notNullValue()));
- }
-
- @Test
- public void shoulConfigureDnaFromRepositorySource() throws Exception {
- InMemoryRepositorySource source = new InMemoryRepositorySource();
- DnaConfiguration config = new DnaConfiguration();
- config.loadFrom(source);
-
- DnaEngine engine = config.build();
- assertThat(engine, is(notNullValue()));
- }
-
- @Test
- public void shouldBeConfigurableAsDnaConfiguration() throws Exception {
- DnaConfiguration config = new DnaConfiguration();
- assertThat(config.loadFrom("some path"), is(sameInstance(config)));
- assertThat(config.addMimeTypeDetector("something").and(), is(sameInstance(config)));
-
- DnaEngine engine = config.build();
- assertThat(engine, is(notNullValue()));
- }
-
- @Test
- public void shouldBeConfigurableAsJcrConfiguration() throws Exception {
- JcrConfiguration config = new JcrConfiguration();
- config.loadFrom("some path").addRepository("some repository ID");
- assertThat(config.loadFrom("some path"), is(sameInstance(config)));
- assertThat(config.addMimeTypeDetector("something").and(), is(sameInstance(config)));
-
- JcrEngine engine = config.build();
- assertThat(engine, is(notNullValue()));
- }
-
-}
Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -1,31 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.repository.config;
-
-/**
- *
- */
-public class JcrEngine extends DnaEngine {
-
-}
Modified: trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
===================================================================
--- trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2009-06-03 20:10:19 UTC (rev 969)
@@ -100,3 +100,5 @@
unableToAccessClassUsingClasspath = Unable to access class "{0}" using classpath "{1}"
errorStartingRepositoryService = Error while starting repository service
+
+engineIsNotRunning = The engine is not running; make sure it was started.
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -27,15 +27,15 @@
import static org.jboss.dna.graph.IsNodeWithChildren.hasChild;
import static org.jboss.dna.graph.IsNodeWithProperty.hasProperty;
import static org.junit.Assert.assertThat;
-import java.util.UUID;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Subgraph;
-import org.jboss.dna.graph.cache.CachePolicy;
-import org.jboss.dna.graph.cache.ImmutableCachePolicy;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.repository.sequencer.MockSequencerA;
import org.jboss.dna.repository.sequencer.MockStreamSequencerA;
import org.junit.Before;
import org.junit.Test;
@@ -70,145 +70,268 @@
@Test
public void shouldHaveDefaultConfigurationSourceIfNotSpecified() {
- assertThat(configuration.graph(), is(notNullValue()));
+ assertThat(configuration.getConfigurationDefinition(), is(notNullValue()));
}
@Test
- public void shouldAllowSpecifyingConfigurationRepository() {
- DnaConfiguration config = configuration.withConfigurationSource()
- .usingClass("org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource")
- .loadedFromClasspath()
- .describedAs("description")
- .with("retryLimit")
- .setTo(5)
- .with("name")
- .setTo("repository name")
- .and()
- .save();
- assertThat(config, is(notNullValue()));
- assertThat(config.configurationRepository().getRepositorySource(), is(instanceOf(InMemoryRepositorySource.class)));
- InMemoryRepositorySource source = (InMemoryRepositorySource)config.configurationRepository().getRepositorySource();
- assertThat(source.getName(), is("repository name"));
- assertThat(source.getRetryLimit(), is(5));
- }
+ public void shouldLoadConfigurationFromFilePath() throws Exception {
+ File file = new File("src/test/resources/config/configRepository.xml");
+ assertThat(file.exists(), is(true));
+ assertThat(file.canRead(), is(true));
+ assertThat(file.isFile(), is(true));
- @Test
- public void shouldAllowAddingRepositorySourceInstance() {
- UUID rootUuid = UUID.randomUUID();
- CachePolicy cachePolicy = new ImmutableCachePolicy(100);
- InMemoryRepositorySource newSource = new InMemoryRepositorySource();
- newSource.setName("name");
- newSource.setDefaultCachePolicy(cachePolicy);
- newSource.setDefaultWorkspaceName("default workspace name");
- newSource.setRetryLimit(100);
- newSource.setRootNodeUuid(rootUuid);
+ configuration.loadFrom("src/test/resources/config/configRepository.xml");
- // Update the configuration and save it ...
- configuration.addSource(newSource).save();
+ assertThat(configuration.getProblems().isEmpty(), is(true));
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
+
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/name"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/name"), hasProperty(DnaLexicon.READABLE_NAME, "name"));
- assertThat(subgraph.getNode("/dna:sources/name"), hasProperty(DnaLexicon.RETRY_LIMIT, 100));
- assertThat(subgraph.getNode("/dna:sources/name"), hasProperty(DnaLexicon.DEFAULT_CACHE_POLICY, cachePolicy));
- assertThat(subgraph.getNode("/dna:sources/name"), hasProperty("defaultWorkspaceName", "default workspace name"));
- assertThat(subgraph.getNode("/dna:sources/name"), hasProperty("rootNodeUuid", rootUuid));
+ assertThat(subgraph.getNode("/dna:sources/Cars"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Cars"), hasProperty(DnaLexicon.RETRY_LIMIT, "3"));
+ assertThat(subgraph.getNode("/dna:sources/Cars"), hasProperty(DnaLexicon.CLASSNAME,
+ InMemoryRepositorySource.class.getName()));
+ assertThat(subgraph.getNode("/dna:sources/Aircraft"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Aircraft"), hasProperty("defaultWorkspaceName", "default"));
+ assertThat(subgraph.getNode("/dna:sources/Aircraft"), hasProperty(DnaLexicon.CLASSNAME,
+ InMemoryRepositorySource.class.getName()));
+ assertThat(subgraph.getNode("/dna:sources/Cache"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Cache"), hasProperty("defaultWorkspaceName", "default"));
+ assertThat(subgraph.getNode("/dna:sources/Cache"), hasProperty(DnaLexicon.CLASSNAME,
+ InMemoryRepositorySource.class.getName()));
+
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors").getChildren(), hasChild(segment("Detector")));
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors/Detector"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors/Detector"),
+ hasProperty(DnaLexicon.DESCRIPTION, "Standard extension-based MIME type detector"));
+ assertThat(subgraph.getNode("/dna:mimeTypeDetectors/Detector"),
+ hasProperty(DnaLexicon.CLASSNAME, ExtensionBasedMimeTypeDetector.class.getName()));
+
+ assertThat(subgraph.getNode("/dna:sequencers").getChildren(), hasChild(segment("Image Sequencer")));
+ assertThat(subgraph.getNode("/dna:sequencers/Image Sequencer"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sequencers/Image Sequencer"), hasProperty(DnaLexicon.DESCRIPTION,
+ "Image metadata sequencer"));
+ assertThat(subgraph.getNode("/dna:sequencers/Image Sequencer"),
+ hasProperty(DnaLexicon.CLASSNAME, "org.jboss.dna.sequencer.image.ImageMetadataSequencer"));
+ assertThat(subgraph.getNode("/dna:sequencers/Image Sequencer"), hasProperty(DnaLexicon.PATH_EXPRESSION,
+ "/foo/source => /foo/target",
+ "/bar/source => /bar/target"));
}
@Test
+ public void shoulLoadConfigurationFromFileObject() throws Exception {
+ File file = new File("src/test/resources/config/configRepository.xml");
+ assertThat(file.exists(), is(true));
+ assertThat(file.canRead(), is(true));
+ assertThat(file.isFile(), is(true));
+
+ configuration.loadFrom(new File("src/test/resources/config/configRepository.xml"));
+
+ assertThat(configuration.getProblems().isEmpty(), is(true));
+ }
+
+ @Test
+ public void shoulLoadConfigurationFromURL() throws Exception {
+ File file = new File("src/test/resources/config/configRepository.xml");
+ assertThat(file.exists(), is(true));
+ assertThat(file.canRead(), is(true));
+ assertThat(file.isFile(), is(true));
+ URL fileUrl = file.toURL();
+ assertThat(fileUrl, is(notNullValue()));
+
+ configuration.loadFrom(fileUrl);
+
+ assertThat(configuration.getProblems().isEmpty(), is(true));
+ }
+
+ @Test
+ public void shoulLoadConfigurationFromInputStream() throws Exception {
+ File file = new File("src/test/resources/config/configRepository.xml");
+ assertThat(file.exists(), is(true));
+ assertThat(file.canRead(), is(true));
+ assertThat(file.isFile(), is(true));
+ InputStream stream = new FileInputStream(file);
+ try {
+ configuration.loadFrom(stream);
+ } finally {
+ stream.close();
+ }
+
+ assertThat(configuration.getProblems().isEmpty(), is(true));
+ }
+
+ @Test
+ public void shoulLoadConfigurationFromRepositorySource() throws Exception {
+ InMemoryRepositorySource source = new InMemoryRepositorySource();
+ source.setName("name");
+ configuration.loadFrom(source);
+ assertThat(configuration.getProblems().isEmpty(), is(true));
+ DnaEngine engine = configuration.build();
+ assertThat(engine, is(notNullValue()));
+ assertThat(engine.getProblems().isEmpty(), is(true));
+ }
+
+ @Test
+ public void shouldLoadConfigurationEvenAfterAlreadyHavingLoadedConfiguration() throws Exception {
+ configuration.loadFrom("src/test/resources/config/configRepository.xml");
+ configuration.loadFrom(new File("src/test/resources/config/configRepository.xml"));
+ configuration.loadFrom(new File("src/test/resources/config/configRepository.xml").toURL());
+ assertThat(configuration.getProblems().isEmpty(), is(true));
+ }
+
+ @Test
+ public void shouldBuildEngineWithDefaultConfiguration() throws Exception {
+ assertThat(configuration.getProblems().isEmpty(), is(true));
+ DnaEngine engine = configuration.build();
+ assertThat(engine, is(notNullValue()));
+ assertThat(engine.getProblems().isEmpty(), is(true));
+ }
+
+ @Test
+ public void shouldLoadConfigurationFromInMemoryRepositorySource() {
+ InMemoryRepositorySource configSource = new InMemoryRepositorySource();
+ configSource.setName("config repo");
+ configuration.loadFrom(configSource).and().save();
+ assertThat(configuration, is(notNullValue()));
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ assertThat(content.getRepositorySource(), is(instanceOf(InMemoryRepositorySource.class)));
+ InMemoryRepositorySource source = (InMemoryRepositorySource)content.getRepositorySource();
+ assertThat(source.getName(), is(configSource.getName()));
+ assertThat(source.getRetryLimit(), is(configSource.getRetryLimit()));
+ }
+
+ @Test
public void shouldAllowAddingRepositorySourceByClassNameAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addSource("Source1")
+ configuration.repositorySource("Source1")
.usingClass(InMemoryRepositorySource.class.getName())
.loadedFromClasspath()
- .describedAs("description")
- .with("retryLimit")
- .setTo(5)
+ .setDescription("description")
+ .setRetryLimit(5)
.and()
.save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
InMemoryRepositorySource.class.getName()));
}
@Test
- public void shouldAllowAddingRepositorySourceByClassNameAndClasspathAndSettingProperties() {
+ public void shouldAllowSettingDescriptionOnRepositorySourceUsingPrefixedPropertyName() {
// Update the configuration and save it ...
- configuration.addSource("Source1")
+ configuration.repositorySource("Source1")
.usingClass(InMemoryRepositorySource.class.getName())
- .loadedFrom("cp1", "cp2")
- .describedAs("description")
- .with("retryLimit")
- .setTo(5)
+ .loadedFromClasspath()
+ .setProperty("dna:description", "desc")
.and()
.save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "desc"));
+ }
+
+ @Test
+ public void shouldAllowSettingDescriptionOnRepositorySourceUsingNonPrefixedPropertyName() {
+ // Update the configuration and save it ...
+ configuration.repositorySource("Source1")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .setProperty("description", "desc")
+ .and()
+ .save();
+
+ // Verify that the graph has been updated correctly ...
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
+ assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "desc"));
+ }
+
+ @Test
+ public void shouldAllowSettingRetryLimitOnRepositorySourceUsingPrefixedPropertyName() {
+ // Update the configuration and save it ...
+ configuration.repositorySource("Source1")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .setProperty("dna:retryLimit", 5)
+ .and()
+ .save();
+
+ // Verify that the graph has been updated correctly ...
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
+ assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSPATH, "cp1", "cp2"));
}
@Test
- public void shouldAllowAddingRepositorySourceByClassReferenceAndSettingProperties() {
+ public void shouldAllowSettingRetryLimitOnRepositorySourceUsingNonPrefixedPropertyName() {
// Update the configuration and save it ...
- configuration.addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("description")
- .with("retryLimit")
- .setTo(5)
+ configuration.repositorySource("Source1")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .setProperty("retryLimit", 5)
.and()
.save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
+ }
+
+ @Test
+ public void shouldAllowAddingRepositorySourceByClassNameAndClasspathAndSettingProperties() {
+ // Update the configuration and save it ...
+ configuration.repositorySource("Source1")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFrom("cp1", "cp2")
+ .setProperty("retryLimit", 5)
+ .and()
+ .save();
+
+ // Verify that the graph has been updated correctly ...
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
+ assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
InMemoryRepositorySource.class.getName()));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSPATH, "cp1", "cp2"));
}
@Test
- public void shouldAllowOverwritingRepositorySourceByRepositoryName() {
+ public void shouldAllowAddingRepositorySourceByClassReferenceAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addSource("Source1")
+ configuration.repositorySource("Source1")
.usingClass(InMemoryRepositorySource.class)
- .describedAs("description")
- .with("retryLimit")
- .setTo(3)
+ .setProperty("retryLimit", 5)
.and()
- .addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("new description")
- .with("retryLimit")
- .setTo(6)
- .and()
.save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources").getChildren(), hasChild(segment("Source1")));
assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 6));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "new description"));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
InMemoryRepositorySource.class.getName()));
}
@@ -216,27 +339,17 @@
@Test
public void shouldAllowAddingMimeTypeDetector() {
// Update the configuration and save it ...
- configuration.addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("description")
- .and()
- .addMimeTypeDetector("detector")
+ configuration.mimeTypeDetector("detector")
.usingClass(ExtensionBasedMimeTypeDetector.class)
- .describedAs("default detector")
+ .setDescription("default detector")
.and()
.save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
- assertThat(subgraph.getNode("/dna:sources").getChildren(), hasChild(segment("Source1")));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
assertThat(subgraph.getNode("/dna:mimeTypeDetectors").getChildren(), hasChild(segment("detector")));
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.READABLE_NAME, "detector"));
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.DESCRIPTION, "default detector"));
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"),
hasProperty(DnaLexicon.CLASSNAME, ExtensionBasedMimeTypeDetector.class.getName()));
@@ -245,15 +358,9 @@
@Test
public void shouldAllowAddingSequencer() {
// Update the configuration and save it ...
- configuration.addSource("Source1")
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("description")
- .named("A Source")
- .and()
- .addSequencer("sequencerA")
+ configuration.sequencer("sequencerA")
.usingClass(MockStreamSequencerA.class)
- .named("The (Main) Sequencer")
- .describedAs("Mock Sequencer A")
+ .setDescription("Mock Sequencer A")
.sequencingFrom("/foo/source")
.andOutputtingTo("/foo/target")
.sequencingFrom("/bar/source")
@@ -262,36 +369,32 @@
.save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
- assertThat(subgraph.getNode("/dna:sources").getChildren(), hasChild(segment("Source1")));
- assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "A Source"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
- InMemoryRepositorySource.class.getName()));
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
assertThat(subgraph.getNode("/dna:sequencers").getChildren(), hasChild(segment("sequencerA")));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.READABLE_NAME, "The (Main) Sequencer"));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.DESCRIPTION, "Mock Sequencer A"));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.CLASSNAME,
MockStreamSequencerA.class.getName()));
- System.out.println(subgraph.getNode("/dna:sequencers/sequencerA").getProperty(DnaLexicon.PATH_EXPRESSIONS));
- assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.PATH_EXPRESSIONS,
+ System.out.println(subgraph.getNode("/dna:sequencers/sequencerA").getProperty(DnaLexicon.PATH_EXPRESSION));
+ assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.PATH_EXPRESSION,
"/foo/source => /foo/target",
"/bar/source => /bar/target"));
}
@Test
public void shouldAllowConfigurationInMultipleSteps() {
- configuration.addSource("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description");
- configuration.addMimeTypeDetector("detector")
+ // Update the configuration and save it ...
+ configuration.repositorySource("Source1")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFrom("cp1", "cp2")
+ .setProperty("retryLimit", 5);
+ configuration.mimeTypeDetector("detector")
.usingClass(ExtensionBasedMimeTypeDetector.class)
- .describedAs("default detector");
- configuration.addSequencer("sequencerA")
- .usingClass(MockSequencerA.class.getName())
- .loadedFromClasspath()
- .named("The (Main) Sequencer")
- .describedAs("Mock Sequencer A")
+ .setDescription("default detector");
+ configuration.sequencer("sequencerA")
+ .usingClass(MockStreamSequencerA.class)
+ .setDescription("Mock Sequencer A")
.sequencingFrom("/foo/source")
.andOutputtingTo("/foo/target")
.sequencingFrom("/bar/source")
@@ -299,27 +402,29 @@
configuration.save();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
- assertThat(subgraph.getNode("/dna:sources").getChildren(), hasChild(segment("Source1")));
+ DnaConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition();
+ Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
+
+ assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/Source1"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.READABLE_NAME, "Source1"));
- assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.DESCRIPTION, "description"));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.RETRY_LIMIT, 5));
assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSNAME,
InMemoryRepositorySource.class.getName()));
+ assertThat(subgraph.getNode("/dna:sources/Source1"), hasProperty(DnaLexicon.CLASSPATH, "cp1", "cp2"));
+
assertThat(subgraph.getNode("/dna:mimeTypeDetectors").getChildren(), hasChild(segment("detector")));
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.READABLE_NAME, "detector"));
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.DESCRIPTION, "default detector"));
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"),
hasProperty(DnaLexicon.CLASSNAME, ExtensionBasedMimeTypeDetector.class.getName()));
+
assertThat(subgraph.getNode("/dna:sequencers").getChildren(), hasChild(segment("sequencerA")));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), is(notNullValue()));
- assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.READABLE_NAME, "The (Main) Sequencer"));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.DESCRIPTION, "Mock Sequencer A"));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.CLASSNAME,
- MockSequencerA.class.getName()));
- System.out.println(subgraph.getNode("/dna:sequencers/sequencerA").getProperty(DnaLexicon.PATH_EXPRESSIONS));
- assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.PATH_EXPRESSIONS,
+ MockStreamSequencerA.class.getName()));
+ System.out.println(subgraph.getNode("/dna:sequencers/sequencerA").getProperty(DnaLexicon.PATH_EXPRESSION));
+ assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.PATH_EXPRESSION,
"/foo/source => /foo/target",
"/bar/source => /bar/target"));
}
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -35,9 +35,11 @@
import javax.jcr.observation.Event;
import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector;
import org.jboss.dna.graph.mimetype.MimeTypeDetector;
import org.jboss.dna.repository.sequencer.MockStreamSequencerA;
import org.jboss.dna.repository.sequencer.SequencingService;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -53,6 +55,18 @@
public void beforeEach() {
}
+ @After
+ public void afterEach() throws Exception {
+ if (engine != null) {
+ try {
+ engine.shutdown();
+ engine.awaitTermination(3, TimeUnit.SECONDS);
+ } finally {
+ engine = null;
+ }
+ }
+ }
+
@Test
public void shouldAllowCreatingWithEmptyConfig() {
engine = new DnaConfiguration().build();
@@ -60,13 +74,10 @@
@Test
public void shouldAllowCreatingWithConfigRepository() throws InterruptedException {
- engine = new DnaConfiguration().withConfigurationSource()
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("config repo")
- .and()
- .build();
+ InMemoryRepositorySource configSource = new InMemoryRepositorySource();
+ configSource.setName("config repo");
+ engine = new DnaConfiguration().loadFrom(configSource).build();
+ engine.start();
assertThat(engine.getRepositorySource("config repo"), is(notNullValue()));
assertThat(engine.getRepositorySource("config repo"), is(instanceOf(InMemoryRepositorySource.class)));
@@ -81,19 +92,17 @@
}
@Test
- public void shouldAllowCreatingMultipleRepositories() throws Exception {
- engine = new DnaConfiguration().withConfigurationSource()
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("config repo")
+ public void shouldAllowCreatingMultipleRepositorySources() throws Exception {
+ InMemoryRepositorySource configSource = new InMemoryRepositorySource();
+ configSource.setName("config repo");
+ engine = new DnaConfiguration().loadFrom(configSource)
.and()
- .addSource("JCR")
+ .repositorySource("JCR")
.usingClass(InMemoryRepositorySource.class)
- .describedAs("Backing Repository for JCR Implementation")
- .with("name")
- .setTo("JCR")
+ .setDescription("Backing Repository for JCR Implementation")
+ .setProperty("name", "JCR")
.and()
+ .save()
.build();
// Start the engine ...
engine.start();
@@ -115,42 +124,48 @@
@Test
public void shouldAllowAddingMimeTypeDetectors() throws Exception {
- engine = new DnaConfiguration().withConfigurationSource()
+ InMemoryRepositorySource configSource = new InMemoryRepositorySource();
+ configSource.setName("config repo");
+ engine = new DnaConfiguration().loadFrom(configSource)
+ .and()
+ .repositorySource("JCR")
.usingClass(InMemoryRepositorySource.class)
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("config repo")
+ .setDescription("Backing Repository for JCR Implementation")
+ .setProperty("name", "JCR")
.and()
- .addMimeTypeDetector("default")
- .usingClass(MockMimeTypeDetector.class)
- .describedAs("Default MimeTypeDetector")
- .with("mimeType")
- .setTo("mock")
+ .mimeTypeDetector("default")
+ .usingClass(ExtensionBasedMimeTypeDetector.class)
+ .setDescription("Default MimeTypeDetector")
.and()
.build();
+ engine.start();
assertThat(engine.getRepositorySource("config repo"), is(notNullValue()));
assertThat(engine.getRepositorySource("config repo"), is(instanceOf(InMemoryRepositorySource.class)));
MimeTypeDetector detector = engine.getExecutionContext().getMimeTypeDetector();
- assertThat(detector.mimeTypeOf("test", new ByteArrayInputStream("This is useless data".getBytes())), is("mock"));
+ assertThat(detector.mimeTypeOf("test", new ByteArrayInputStream("This is useless data".getBytes())), is("text/plain"));
}
@Test
public void shouldAllowAddingSequencers() throws Exception {
- engine = new DnaConfiguration().withConfigurationSource()
+ InMemoryRepositorySource configSource = new InMemoryRepositorySource();
+ configSource.setName("config repo");
+ engine = new DnaConfiguration().loadFrom(configSource)
+ .and()
+ .repositorySource("JCR")
.usingClass(InMemoryRepositorySource.class)
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("config repo")
+ .setDescription("Backing Repository for JCR Implementation")
+ .setProperty("name", "JCR")
.and()
- .addSequencer("Mock Sequencer A")
+ .sequencer("Mock Sequencer A")
.usingClass(MockStreamSequencerA.class)
- .describedAs("A Mock Sequencer")
+ .setDescription("A Mock Sequencer")
.sequencingFrom("/**")
.andOutputtingTo("/")
.and()
.build();
+ engine.start();
assertThat(engine.getRepositorySource("config repo"), is(notNullValue()));
assertThat(engine.getRepositorySource("config repo"), is(instanceOf(InMemoryRepositorySource.class)));
Added: trunk/dna-repository/src/test/resources/config/configRepository.xml
===================================================================
--- trunk/dna-repository/src/test/resources/config/configRepository.xml (rev 0)
+++ trunk/dna-repository/src/test/resources/config/configRepository.xml 2009-06-03 20:10:19 UTC (rev 969)
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss DNA (http://www.jboss.org/dna)
+ ~
+ ~ See the COPYRIGHT.txt file distributed with this work for information
+ ~ regarding copyright ownership. Some portions may be licensed
+ ~ to Red Hat, Inc. under one or more contributor license agreements.
+ ~ See the AUTHORS.txt file in the distribution for a full listing of
+ ~ individual contributors.
+ ~
+ ~ JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ ~ is licensed to you under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ JBoss DNA is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<configuration xmlns:dna="http://www.jboss.org/dna/1.0"
+ xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+ <!-- Define the sources from which content is made available. -->
+ <dna:sources jcr:primaryType="nt:unstructured">
+ <dna:source jcr:name="Cars" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" dna:retryLimit="3" defaultWorkspaceName="default"/>
+ <dna:source jcr:name="Aircraft" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource">
+ <defaultWorkspaceName>default</defaultWorkspaceName>
+ </dna:source>
+ <dna:source jcr:name="Cache" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource">
+ <defaultWorkspaceName>default</defaultWorkspaceName>
+ </dna:source>
+ </dna:sources>
+ <!-- Define the sequencers. This is an optional section. -->
+ <dna:sequencers>
+ <dna:sequencer jcr:name="Image Sequencer" dna:classname="org.jboss.dna.sequencer.image.ImageMetadataSequencer">
+ <dna:description>Image metadata sequencer</dna:description>
+ <dna:pathExpression>/foo/source => /foo/target</dna:pathExpression>
+ <dna:pathExpression>/bar/source => /bar/target</dna:pathExpression>
+ </dna:sequencer>
+ </dna:sequencers>
+ <!-- Define the mime type detectors. This is an optional section. -->
+ <dna:mimeTypeDetectors>
+ <dna:mimeTypeDetector jcr:name="Detector">
+ <dna:description>Standard extension-based MIME type detector</dna:description>
+ <!--
+ Specify the implementation class (required), as a child element or attribute on parent element.
+ -->
+ <dna:classname>org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector</dna:classname>
+ <!--
+ Specify the classpath (optional) as an ordered list of 'names', where each name is significant to
+ the classpath factory. For example, a name could be an OSGI identifier or a Maven coordinate,
+ depending upon the classpath factory being used. If there is only one 'name' in the classpath,
+ it may be specified as an attribute on the 'mimeTypeDetector' element. If there is more than one
+ 'name', then they must be specified as child 'classpath' elements. Blank or empty values are ignored.
+ -->
+ <dna:classpath></dna:classpath>
+ <dna:classpath></dna:classpath>
+ </dna:mimeTypeDetector>
+ </dna:mimeTypeDetectors>
+</configuration>
\ No newline at end of file
Property changes on: trunk/dna-repository/src/test/resources/config/configRepository.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/docs/examples/gettingstarted/sequencers/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/pom.xml 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/docs/examples/gettingstarted/sequencers/pom.xml 2009-06-03 20:10:19 UTC (rev 969)
@@ -24,12 +24,6 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-common</artifactId>
- <version>${pom.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.dna</groupId>
<artifactId>dna-sequencer-images</artifactId>
<version>${pom.version}</version>
<scope>runtime</scope>
@@ -69,24 +63,44 @@
<artifactId>jcr</artifactId>
</dependency>
<!--
- Apache Jackrabbit (JCR Implementation) for repository implementation
+ Test cases use JUnit
-->
<dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-api</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-core</artifactId>
- </dependency>
<!--
- Test cases use JUnit
+ JAAS implementation (and dependencies)
-->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.jboss.security</groupId>
+ <artifactId>jboss-idtrust</artifactId>
+ <version>2.0.2.CR1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.security</groupId>
+ <artifactId>jboss-security-spi-bare</artifactId>
+ <version>2.0.2.SP6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.security</groupId>
+ <artifactId>jbosssx-bare</artifactId>
+ <version>2.0.2.SP6</version>
+ <exclusions>
+ <exclusion>
+ <groupId>apache-xalan</groupId>
+ <artifactId>xalan</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>apache-xalan</groupId>
+ <artifactId>serializer</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -41,16 +41,16 @@
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
-import javax.security.auth.login.LoginException;
-import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.jcr.JcrConfiguration;
import org.jboss.dna.jcr.JcrEngine;
+import org.jboss.dna.jcr.JcrRepository;
import org.jboss.dna.repository.sequencer.SequencingService;
import org.jboss.dna.repository.util.SessionFactory;
import org.jboss.dna.sequencer.image.ImageMetadataSequencer;
import org.jboss.dna.sequencer.java.JavaMetadataSequencer;
import org.jboss.dna.sequencer.mp3.Mp3MetadataSequencer;
+import org.jboss.security.config.IDTrustConfiguration;
/**
* @author Randall Hauch
@@ -63,52 +63,48 @@
public static final char[] DEFAULT_PASSWORD = "secret".toCharArray();
public static void main( String[] args ) {
- // Set up an execution context in which we'll run, and authenticate using JAAS ...
- ExecutionContext context = new ExecutionContext();
- String jaasAppContext = "myAppContext";
- String username = "jsmith";
- char[] password = "secrete".toCharArray();
+ // Set up the JAAS provider (IDTrust) and a policy file (which defines the "dna-jcr" login config name)
+ String configFile = "security/jaas.conf.xml";
+ IDTrustConfiguration idtrustConfig = new IDTrustConfiguration();
try {
- context.with(jaasAppContext, username, password);
- } catch (LoginException err) {
- System.err.println("Error authenticating \"" + username + "\". Check username and password and try again.");
+ idtrustConfig.config(configFile);
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
}
// Configure the DNA JCR engine ...
String repositoryId = "content";
String workspaceName = "default";
- JcrConfiguration config = new JcrConfiguration(context);
- config.withConfigurationSource().usingClass(InMemoryRepositorySource.class).usingWorkspace("default").under("/");
- // Set up an in-memory repository where the uploaded and sequenced content will be stored ...
- config.addSource(repositoryId)
+ JcrConfiguration config = new JcrConfiguration();
+ // Set up the in-memory source where we'll upload the content and where the sequenced output will be stored ...
+ config.repositorySource("store")
.usingClass(InMemoryRepositorySource.class)
- .withNodeTypes(ImageMetadataSequencer.class.getResource("org/jboss/dna/sequencer/image/images.cnd"))
- .withNodeTypes(Mp3MetadataSequencer.class.getResource("org/jboss/dna/sequencer/mp3/mp3.cnd"))
- .withNodeTypes(JavaMetadataSequencer.class.getResource("org/jboss/dna/sequencer/java/javaSource.cnd"))
- .named("Content Repository")
- .describedAs("The repository for our content")
- .with("defaultWorkspaceName")
- .setTo(workspaceName);
+ .setDescription("The repository for our content")
+ .setProperty("defaultWorkspaceName", workspaceName);
+ // Set up the JCR repository to use the source ...
+ config.repository(repositoryId)
+ .addNodeTypes(ImageMetadataSequencer.class.getResource("org/jboss/dna/sequencer/image/images.cnd"))
+ .addNodeTypes(Mp3MetadataSequencer.class.getResource("org/jboss/dna/sequencer/mp3/mp3.cnd"))
+ .addNodeTypes(JavaMetadataSequencer.class.getResource("org/jboss/dna/sequencer/java/javaSource.cnd"))
+ .setSource("store")
+ .setOption(JcrRepository.Option.JAAS_LOGIN_CONFIG_NAME, "dna-jcr");
// Set up the image sequencer ...
- config.addSequencer("images")
+ config.sequencer("Image Sequencer")
.usingClass("org.jboss.dna.sequencer.image.ImageMetadataSequencer")
.loadedFromClasspath()
- .describedAs("Sequences image files to extract the characteristics of the image")
- .named("Image Sequencer")
+ .setDescription("Sequences image files to extract the characteristics of the image")
.sequencingFrom("//(*.(jpg|jpeg|gif|bmp|pcx|png|iff|ras|pbm|pgm|ppm|psd)[*])/jcr:content[@jcr:data]")
.andOutputtingTo("/images/$1");
// Set up the MP3 sequencer ...
- config.addSequencer("mp3s")
+ config.sequencer("MP3 Sequencer")
.usingClass(Mp3MetadataSequencer.class)
- .named("MP3 Sequencer")
- .describedAs("Sequences mp3 files to extract the id3 tags of the audio file")
+ .setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
.sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
.andOutputtingTo("/mp3s/$1");
// Set up the Java source file sequencer ...
- config.addSequencer("javaSource")
+ config.sequencer("Java Sequencer")
.usingClass(JavaMetadataSequencer.class)
- .named("Java Sequencer")
- .describedAs("Sequences mp3 files to extract the id3 tags of the audio file")
+ .setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
.sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
.andOutputtingTo("/mp3s/$1");
Added: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/jaas.conf.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/jaas.conf.xml (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/jaas.conf.xml 2009-06-03 20:10:19 UTC (rev 969)
@@ -0,0 +1,24 @@
+<?xml version='1.0'?>
+
+<policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:security-config:5.0" xmlns="urn:jboss:security-config:5.0"
+ xmlns:jbxb="urn:jboss:security-config:5.0">
+ <application-policy name="dna-jcr">
+ <authentication>
+ <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
+ <module-option name="usersProperties">security/users.properties</module-option>
+ <module-option name="rolesProperties">security/roles.properties</module-option>
+ <module-option name="name">1.1</module-option>
+ <module-option name="succeed">true</module-option>
+ <module-option name="throwEx">false</module-option>
+ </login-module>
+ </authentication>
+<!--
+ <authorization>
+ <policy-module code="org.jboss.security.idtrust.impl.plugins.authorization.IDTrustAuthorizationModule">
+ <module-option name="roles">validuser</module-option>
+ </policy-module>
+ </authorization>
+-->
+ </application-policy>
+</policy>
Property changes on: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/jaas.conf.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/roles.properties
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/roles.properties (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/roles.properties 2009-06-03 20:10:19 UTC (rev 969)
@@ -0,0 +1,2 @@
+#<userName>=[readonly[.<workspaceName>] | readwrite[.<workspaceName>]][, [readonly[.<workspaceName>] | readwrite[.<workspaceName>]]]*
+jsmith=readwrite
Added: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/users.properties
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/users.properties (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/security/users.properties 2009-06-03 20:10:19 UTC (rev 969)
@@ -0,0 +1,2 @@
+# <username>=<password>
+jsmith=secret
Modified: trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -31,6 +31,12 @@
import java.net.MalformedURLException;
import java.net.URL;
import org.jboss.dna.common.util.FileUtil;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.jcr.JcrConfiguration;
+import org.jboss.dna.jcr.JcrRepository;
+import org.jboss.dna.sequencer.image.ImageMetadataSequencer;
+import org.jboss.dna.sequencer.java.JavaMetadataSequencer;
+import org.jboss.dna.sequencer.mp3.Mp3MetadataSequencer;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -57,23 +63,49 @@
// Get the URL of source (MySource.java), that have to be sequencing
this.javaSourceUrl = FileUtil.convertFileToURL("workspace/project1/src/org/acme/MySource.java");
- client = new SequencingClient();
- client.setWorkingDirectory("target/repositoryData");
- client.setJackrabbitConfigPath("src/main/resources/jackrabbitConfig.xml");
- FileUtil.delete("target/repositoryData");
+ String repositoryId = "content";
+ String workspaceName = "default";
+ JcrConfiguration config = new JcrConfiguration();
+ // Set up the in-memory source where we'll upload the content and where the sequenced output will be stored ...
+ config.repositorySource("store")
+ .usingClass(InMemoryRepositorySource.class)
+ .setDescription("The repository for our content")
+ .setProperty("defaultWorkspaceName", workspaceName);
+ // Set up the JCR repository to use the source ...
+ config.repository(repositoryId)
+ .addNodeTypes(ImageMetadataSequencer.class.getClassLoader().getResource("org/jboss/dna/sequencer/image/images.cnd"))
+ .addNodeTypes(Mp3MetadataSequencer.class.getClassLoader().getResource("org/jboss/dna/sequencer/mp3/mp3.cnd"))
+ .addNodeTypes(JavaMetadataSequencer.class.getClassLoader()
+ .getResource("org/jboss/dna/sequencer/java/javaSource.cnd"))
+ .setSource("store")
+ .setOption(JcrRepository.Option.JAAS_LOGIN_CONFIG_NAME, "dna-jcr");
+ // Set up the image sequencer ...
+ config.sequencer("Image Sequencer")
+ .usingClass("org.jboss.dna.sequencer.image.ImageMetadataSequencer")
+ .loadedFromClasspath()
+ .setDescription("Sequences image files to extract the characteristics of the image")
+ .sequencingFrom("//(*.(jpg|jpeg|gif|bmp|pcx|png|iff|ras|pbm|pgm|ppm|psd)[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/images/$1");
+ // Set up the MP3 sequencer ...
+ config.sequencer("MP3 Sequencer")
+ .usingClass(Mp3MetadataSequencer.class)
+ .setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
+ .sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/mp3s/$1");
+ // Set up the Java source file sequencer ...
+ config.sequencer("Java Sequencer")
+ .usingClass(JavaMetadataSequencer.class)
+ .setDescription("Sequences mp3 files to extract the id3 tags of the audio file")
+ .sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/mp3s/$1");
+
+ // Now start the client and tell it which repository and workspace to use ...
+ client = new SequencingClient(config, repositoryId, workspaceName);
}
@After
public void afterEach() throws Exception {
- try {
- client.shutdownDnaServices();
- } finally {
- try {
- client.shutdownRepository();
- } finally {
- FileUtil.delete("target/repositoryData");
- }
- }
+ if (client != null) client.shutdownRepository();
}
@Test
@@ -93,25 +125,14 @@
@Ignore
@Test
- public void shouldStartupAndShutdownRepositoryAndSequencingService() throws Exception {
- client.startRepository();
- client.startDnaServices();
- client.shutdownDnaServices();
- client.shutdownRepository();
- }
-
- @Ignore
- @Test
public void shouldUploadAndSequencePngFile() throws Exception {
client.setUserInterface(new MockUserInterface(this.pngImageUrl, "/a/b/caution.png", 1));
client.startRepository();
- client.startDnaServices();
client.uploadFile();
// Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
// and to then shut down the DNA services (which will block until all sequencing has been completed) ...
Thread.sleep(1000);
- client.shutdownDnaServices();
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
@@ -125,13 +146,11 @@
public void shouldUploadAndSequenceJpegFile() throws Exception {
client.setUserInterface(new MockUserInterface(this.jpegImageUrl, "/a/b/caution.jpeg", 1));
client.startRepository();
- client.startDnaServices();
client.uploadFile();
// Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
// and to then shut down the DNA services (which will block until all sequencing has been completed) ...
Thread.sleep(1000);
- client.shutdownDnaServices();
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
@@ -145,13 +164,11 @@
public void shouldUploadAndNotSequencePictFile() throws Exception {
client.setUserInterface(new MockUserInterface(this.pictImageUrl, "/a/b/caution.pict", 0));
client.startRepository();
- client.startDnaServices();
client.uploadFile();
// Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
// and to then shut down the DNA services (which will block until all sequencing has been completed) ...
Thread.sleep(1000);
- client.shutdownDnaServices();
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
@@ -165,13 +182,11 @@
public void shouldUploadAndSequenceMp3File() throws Exception {
client.setUserInterface(new MockUserInterface(this.mp3Url, "/a/b/test.mp3", 1));
client.startRepository();
- client.startDnaServices();
client.uploadFile();
// Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
// and to then shut down the DNA services (which will block until all sequencing has been completed) ...
Thread.sleep(1000);
- client.shutdownDnaServices();
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
@@ -198,13 +213,11 @@
public void shouldUploadAndSequenceJavaSourceFile() throws Exception {
client.setUserInterface(new MockUserInterface(this.javaSourceUrl, "/a/b/MySource.java", 1));
client.startRepository();
- client.startDnaServices();
client.uploadFile();
// Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
// and to then shut down the DNA services (which will block until all sequencing has been completed) ...
Thread.sleep(1000);
- client.shutdownDnaServices();
// The sequencers should have run, so perform the search.
// The mock user interface checks the results.
Modified: trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheRequestProcessor.java 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheRequestProcessor.java 2009-06-03 20:10:19 UTC (rev 969)
@@ -564,7 +564,8 @@
assert original != null;
assert newParent != null;
// Get or create the new node ...
- Path.Segment name = desiredName != null ? context.getValueFactories().getPathFactory().createSegment(desiredName) : (Path.Segment)original.getFqn().getLastElement();
+ Path.Segment name = desiredName != null ? context.getValueFactories().getPathFactory().createSegment(desiredName) : (Path.Segment)original.getFqn()
+ .getLastElement();
// Update the children to account for same-name siblings.
// This not only updates the FQN of the child nodes, but it also sets the property that stores the
@@ -639,11 +640,11 @@
ChildInfo info = new ChildInfo(childName, snsIndex);
childrenWithChangedName.add(info);
}
-
+
snsIndex++;
if (!foundBeforeNode) index++;
}
-
+
}
if (addChildWithName) {
// Make room for the new child at the end of the array ...
@@ -664,7 +665,7 @@
// Make sure that we add a record for the new node if it hasn't previously been added
ChildInfo info = new ChildInfo(null, index);
childrenWithChangedName.add(info);
-
+
}
Path.Segment newSegment = context.getValueFactories().getPathFactory().createSegment(changedName);
childNames[index] = newSegment;
@@ -760,8 +761,9 @@
// don't copy ...
} else {
// Append an updated segment ...
- Path.Segment newSegment = context.getValueFactories().getPathFactory().createSegment(childName.getName(),
- childName.getIndex() - 1);
+ Path.Segment newSegment = context.getValueFactories()
+ .getPathFactory()
+ .createSegment(childName.getName(), childName.getIndex() - 1);
newChildNames[index] = newSegment;
// Replace the child with the correct FQN ...
changeNodeName(cache, parent, childName, newSegment, context);
@@ -793,7 +795,9 @@
}
/**
- * Utility class used by the {@link #updateChildList(Cache, Node, Name, ExecutionContext, boolean)} method.
+ * Utility class used by the
+ * {@link JBossCacheRequestProcessor#updateChildList(Cache, Node, Name, org.jboss.dna.graph.property.Path.Segment, ExecutionContext, boolean)}
+ * method.
*
* @author Randall Hauch
*/
@@ -806,9 +810,10 @@
this.segment = childSegment;
this.childIndex = childIndex;
}
-
+
+ @Override
public String toString() {
- return (segment != null ? segment.getString() : "null") + "@" + childIndex;
+ return (segment != null ? segment.getString() : "null") + "@" + childIndex;
}
}
Modified: trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd 2009-06-03 20:09:11 UTC (rev 968)
+++ trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd 2009-06-03 20:10:19 UTC (rev 969)
@@ -107,7 +107,7 @@
* Single element annotation e.g. @Path("/book")
*/
[java:singleElementAnnotation] > nt:unstructured
- - java:singleElementAnnotationNam
+ - java:singleElementAnnotationName (string) mandatory
+ java:value (java:elementValue) = java:elementValue mandatory
/**
16 years, 6 months
DNA SVN: r968 - in trunk: dna-jcr/src/test/java/org/jboss/dna/jcr and 4 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-03 16:09:11 -0400 (Wed, 03 Jun 2009)
New Revision: 968
Added:
trunk/dna-cnd/src/test/resources/cnd/javaSource.cnd
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStubTest.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerA.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerB.java
trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.cnd
trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.cnd
Log:
DNA-436 Continued the work on the examples, with fairly substantial changes (simplification) to the configuration frameworks.
Added: trunk/dna-cnd/src/test/resources/cnd/javaSource.cnd
===================================================================
--- trunk/dna-cnd/src/test/resources/cnd/javaSource.cnd (rev 0)
+++ trunk/dna-cnd/src/test/resources/cnd/javaSource.cnd 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,257 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+/**
+ * @author Serge Pagop (serge.pagop(a)innoq.com)
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<java='http://www.jboss.org/dna/java/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+
+//------------------------------------------------------------------------------
+// B A S E T Y P E S
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// V E R S I O N I N G
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+/**
+ * Element-value
+ */
+[java:elementValue] > nt:unstructured
+ + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
+
+/**
+ * Modifiers
+ */
+[java:modifierDeclaration] > nt:unstructured
+ - java:modifierName (string) mandatory
+
+/**
+ * Expression element-value type
+ */
+[java:conditionalExpression] > nt:unstructured
+ - java:expression (string)
+
+/**
+ * Array initializer element-value type
+ */
+[java:elementValueArrayInitializer] > nt:unstructured
+ + java:elementValue (java:elementValue) = java:elementValue multiple
+
+/**
+ * Identifier
+ */
+[java:identifier] > nt:unstructured
+ - java:identifierName (String) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Element-value pair
+ */
+[java:elementValuePair] > nt:unstructured
+ + java:identifier (java:identifier) mandatory
+
+/**
+ * Annotation type
+ */
+[java:annotationDeclaration] > nt:unstructured
+ + java:annotationType (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
+
+/**
+ * Normal annotation e.g. @Entity(name="Customer")
+ */
+[java:normalAnnotation] > nt:unstructured
+ - java:normalAnnotationName (string) mandatory
+ + java:elementValuePair (java:elementValuePair)
+
+/**
+ * Marker annotation e.g. @GET
+ */
+[java:markerAnnotation] > nt:unstructured
+ - java:markerAnnotationName (string) mandatory
+
+/**
+ * Single element annotation e.g. @Path("/book")
+ */
+[java:singleElementAnnotation] > nt:unstructured
+ - java:singleElementAnnotationName (string) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Formal parameter
+ */
+[java:formalParameter] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType)
+
+/**
+ * Primitive type:
+ * - Integral type ('byte', 'short', 'int', 'long', 'char')
+ * - Floating point type ('float', 'double')
+ * - Boolean type ('boolean')
+ * - No return type ('void')
+ */
+[java:primitiveType] > nt:unstructured
+ - java:primitiveTypeDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:primitiveTypeName (string) mandatory
+ + java:primitiveVariable (java:variable) = java:variable
+
+ [java:variable] > nt:unstructured
+ - java:variableName (string) mandatory
+
+/**
+ * java:arrayType
+ */
+[java:arrayType] > nt:unstructured
+ - java:arrayTypeDescription (string)
+ + java:arrayTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:arrayTypeName (string) mandatory
+ + java:arrayTypeVariable (java:variable) = java:variable
+
+[java:simpleType] > nt:unstructured
+ - java:simpleTypeDescription (string)
+ + java:simpleTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:simpleTypeName (string) mandatory
+ + java:simpleTypeVariable (java:variable) = java:variable
+
+[java:qualifiedType] > nt:unstructured
+ - java:qualifiedTypeDescription (string)
+ + java:qualifiedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:qualifiedTypeName (string) mandatory
+ + java:qualifiedTypeVariable (java:variable) = java:variable
+
+[java:wildcardType] > nt:unstructured
+ - java:wildcardTypeDescription (string)
+ + java:wildcardTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:wildcardTypeName (string) mandatory
+ + java:wildcardTypeVariable (java:variable) = java:variable
+
+[java:parameterizedType] > nt:unstructured
+ - java:parameterizedTypeDescription (string)
+ + java:parameterizedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:parameterizedTypeName (string) mandatory
+ + java:parameterizedTypeVariable (java:variable) = java:variable
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:methodDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ + java:resultType (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory
+ - java:methodName (string) mandatory
+ + java:parameter (java:formalParameter) multiple
+
+/**
+ * Constructor declarations
+ */
+[java:constructorDeclaration] > nt:unstructured
+ - java:constructorDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:constructorName (string) mandatory
+ + java:parameter (java:formalParameter)
+
+
+/**
+ * Package declarations
+ */
+[java:packageDeclaration] > nt:unstructured
+ + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
+ - java:packageKeyword (string)
+ < 'package'
+ - java:packageName (string) mandatory
+
+/**
+ * Import declarations
+ */
+[java:singleTypeImportDeclaration] > nt:unstructured
+ - java:singleTypeImportkeyword (string) mandatory
+ < 'import'
+ - java:singleImportName (string) mandatory
+
+[java:typeImportOnDemandDeclaration] > nt:unstructured
+ - java:onDemandImportKeyword (string) mandatory
+ < 'import'
+ - java:onDemandImportName (string) mandatory
+
+ [java:importDeclaration] > nt:unstructured
+ + java:singleImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
+ + java:importOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
+
+
+/**
+ * Class declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:normalClassDeclaration] > nt:unstructured
+ - java:description (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:normalClassName (string) mandatory
+ + java:field (java:fieldType) = java:fieldType multiple
+ + java:method (java:methodDeclaration) = java:methodDeclaration multiple
+ + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
+
+[java:enumDeclaration] > nt:unstructured // TODO
+
+[java:classDeclaration] > nt:unstructured
+ + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
+ + java:enum (java:enumDeclaration) = java:enumDeclaration
+
+/**
+ * Interface declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+ //TODO
+[java:interfaceDeclaration] > nt:unstructured
+
+
+/**
+ * Compilation unit
+ */
+[java:compilationUnit] > nt:unstructured
+ + java:package (java:packageDeclaration) = java:packageDeclaration
+ + java:import (java:importDeclaration) = java:importDeclaration
+ + java:unitType (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStubTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStubTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStubTest.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,46 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.IOException;
+import java.util.Properties;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class InMemoryRepositoryStubTest {
+
+ @Test
+ public void shouldStartRepositoryStub() throws IOException {
+ Properties env = new Properties();
+ env.load(getClass().getClassLoader().getResourceAsStream("repositoryStubImpl.properties"));
+ InMemoryRepositoryStub stub = new InMemoryRepositoryStub(env);
+ assertThat(stub.getRepository(), is(notNullValue()));
+ }
+
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStubTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,512 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.config;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Node;
+import org.jboss.dna.graph.Workspace;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.basic.RootPath;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ */
+public class DnaConfiguration {
+
+ protected static final String DEFAULT_WORKSPACE_NAME = "";
+ protected static final String DEFAULT_PATH = "/";
+
+ private final ExecutionContext context;
+ private ConfigurationContent configurationContent;
+
+ /**
+ * Create a new configuration, using a default-constructed {@link ExecutionContext}.
+ */
+ public DnaConfiguration() {
+ this(new ExecutionContext());
+ }
+
+ /**
+ * Create a new configuration using the supplied {@link ExecutionContext}.
+ *
+ * @param context the execution context
+ * @throws IllegalArgumentException if the path is null or empty
+ */
+ public DnaConfiguration( ExecutionContext context ) {
+ CheckArg.isNotNull(context, "context");
+ this.context = context;
+ }
+
+ /**
+ * Load the configuration from a file at the given path.
+ *
+ * @param pathToConfigurationFile the path the file containing the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied location
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the path is null or empty
+ */
+ public DnaConfiguration loadFrom( String pathToConfigurationFile ) throws IOException, SAXException {
+ CheckArg.isNotEmpty(pathToConfigurationFile, "pathToConfigurationFile");
+ return loadFrom(new File(pathToConfigurationFile));
+ }
+
+ /**
+ * Load the configuration from a file.
+ *
+ * @param configurationFile the file containing the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the supplied file
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the file reference is null
+ */
+ public DnaConfiguration loadFrom( File configurationFile ) throws IOException, SAXException {
+ CheckArg.isNotNull(configurationFile, "configurationFile");
+ InputStream stream = new FileInputStream(configurationFile);
+ try {
+ return loadFrom(stream);
+ } finally {
+ stream.close();
+ }
+ }
+
+ /**
+ * Load the configuration from a file at the supplied URL.
+ *
+ * @param urlToConfigurationFile the URL of the file containing the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied URL
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the URL is null
+ */
+ public DnaConfiguration loadFrom( URL urlToConfigurationFile ) throws IOException, SAXException {
+ CheckArg.isNotNull(urlToConfigurationFile, "urlToConfigurationFile");
+ InputStream stream = urlToConfigurationFile.openStream();
+ try {
+ return loadFrom(stream);
+ } finally {
+ stream.close();
+ }
+ }
+
+ /**
+ * Load the configuration from a file at the supplied URL.
+ *
+ * @param configurationFileInputStream the stream with the configuration information
+ * @return this configuration object, for convenience and method chaining
+ * @throws IOException if there is an error or problem reading the file at the supplied URL
+ * @throws SAXException if the file is not a valid XML format
+ * @throws IllegalArgumentException if the stream is null
+ */
+ public DnaConfiguration loadFrom( InputStream configurationFileInputStream ) throws IOException, SAXException {
+ CheckArg.isNotNull(configurationFileInputStream, "configurationFileInputStream");
+
+ // Create the in-memory repository source in which the content will be stored ...
+ InMemoryRepositorySource source = new InMemoryRepositorySource();
+ source.setName("Configuration Repository");
+ source.setDefaultWorkspaceName(DEFAULT_WORKSPACE_NAME);
+
+ // Import the information into the source ...
+ Path path = path(DEFAULT_PATH);
+ Graph graph = Graph.create(source, context);
+ graph.importXmlFrom(configurationFileInputStream).into(path);
+
+ // The file was imported successfully, so now create the content information ...
+ configurationContent = new ConfigurationContent(source, null, path, context);
+ return this;
+ }
+
+ /**
+ * Load the configuration from the repository content using the supplied repository source. This method assumes that the
+ * supplied source has already been configured and is ready to {@link RepositorySource#getConnection() create connections}.
+ * Also, the default workspace of the source will be used, and the configuration content may be found directly under the root
+ * node.
+ *
+ * @param source the source that defines the repository with the configuration content
+ * @return this configuration object, for convenience and method chaining
+ * @throws IllegalArgumentException if the source is null
+ */
+ public DnaConfiguration loadFrom( RepositorySource source ) {
+ return loadFrom(source, null, null);
+ }
+
+ /**
+ * Load the configuration from the repository content using the workspace in the supplied repository source. This method
+ * assumes that the supplied source has already been configured and is ready to {@link RepositorySource#getConnection() create
+ * connections}. Also, the configuration content may be found directly under the root node.
+ *
+ * @param source the source that defines the repository with the configuration content
+ * @param workspaceName the name of the workspace with the configuration content, or null if the source's default workspace
+ * should be used
+ * @return this configuration object, for convenience and method chaining
+ * @throws IllegalArgumentException if the source is null
+ */
+ public DnaConfiguration loadFrom( RepositorySource source,
+ String workspaceName ) {
+ CheckArg.isNotNull(source, "source");
+ return loadFrom(source, workspaceName, null);
+ }
+
+ /**
+ * Load the configuration from the repository content at the supplied path in the workspace in the supplied repository source.
+ * This method assumes that the supplied source has already been configured and is ready to
+ * {@link RepositorySource#getConnection() create connections}.
+ *
+ * @param source the source that defines the repository with the configuration content
+ * @param workspaceName the name of the workspace with the configuration content, or null if the source's default workspace
+ * should be used
+ * @param pathInWorkspace the path to the parent node under which the configuration content may be found, or null if the
+ * content may be found under the root node
+ * @return this configuration object, for convenience and method chaining
+ * @throws IllegalArgumentException if the source is null
+ */
+ public DnaConfiguration loadFrom( RepositorySource source,
+ String workspaceName,
+ String pathInWorkspace ) {
+ CheckArg.isNotNull(source, "source");
+
+ // Verify connectivity ...
+ Graph graph = Graph.create(source, context);
+ if (workspaceName != null) {
+ Workspace workspace = graph.useWorkspace(workspaceName); // should throw exception if not connectable
+ assert workspace.getRoot() != null;
+ }
+
+ // Verify the path ...
+ Path path = pathInWorkspace != null ? path(pathInWorkspace) : path(DEFAULT_PATH);
+ Node parent = graph.getNodeAt(path);
+ assert parent != null;
+
+ // Now create the content information ...
+ configurationContent = new ConfigurationContent(source, workspaceName, path, context);
+ return this;
+ }
+
+ protected ConfigurationContent getConfigurationContent() {
+ return configurationContent;
+ }
+
+ protected Path path( String path ) {
+ return context.getValueFactories().getPathFactory().create(path);
+ }
+
+ public MimeTypeDetectorDetails<? extends DnaConfiguration> mimeTypeDetector( String name ) {
+ return new MimeTypeDetectorBuilder<DnaConfiguration>(this);
+ }
+
+ /**
+ * Construct an engine that reflects the current state of this configuration. This method always creates a new instance.
+ *
+ * @return the resulting engine; never null
+ */
+ public DnaEngine build() {
+ return new DnaEngine();
+ }
+
+ public interface Returnable<ReturnType> {
+ /**
+ * Return the configuration component.
+ *
+ * @return the configuration component; never null
+ */
+ ReturnType and();
+ }
+
+ protected static class BaseReturnable<ReturnType> implements Returnable<ReturnType> {
+ protected final ReturnType returnObject;
+
+ protected BaseReturnable( ReturnType returnObject ) {
+ this.returnObject = returnObject;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration.Returnable#and()
+ */
+ public ReturnType and() {
+ return returnObject;
+ }
+ }
+
+ /**
+ * Interface used to set up and build a RepositorySource instance.
+ *
+ * @param <ReturnType> the type of the configuration component
+ */
+ public interface MimeTypeDetectorDetails<ReturnType> extends Returnable<ReturnType> {
+ }
+
+ protected static class MimeTypeDetectorBuilder<ReturnType> extends BaseReturnable<ReturnType>
+ implements MimeTypeDetectorDetails<ReturnType> {
+ protected MimeTypeDetectorBuilder( ReturnType returnObject ) {
+ super(returnObject);
+ }
+ }
+
+ /**
+ * Interface used to set up and build a RepositorySource instance.
+ *
+ * @param <ReturnType> the type of the configuration component
+ */
+ public interface RepositorySourceDetails<ReturnType>
+ extends SetProperties<RepositorySourceDetails<ReturnType>>, Returnable<ReturnType> {
+ }
+
+ /**
+ * Interface for configuring the JavaBean-style properties of an object.
+ *
+ * @param <ReturnType> the interface returned after the property has been set.
+ * @author Randall Hauch
+ */
+ public interface SetProperties<ReturnType> {
+ /**
+ * Set the property value to an integer.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ int value );
+
+ /**
+ * Set the property value to a long number.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ long value );
+
+ /**
+ * Set the property value to a short.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ short value );
+
+ /**
+ * Set the property value to a boolean.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ boolean value );
+
+ /**
+ * Set the property value to a float.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ float value );
+
+ /**
+ * Set the property value to a double.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ double value );
+
+ /**
+ * Set the property value to a string.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ String value );
+
+ /**
+ * Set the property value to an object.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setProperty( String beanPropertyName,
+ Object value );
+ }
+
+ protected class SourceDetails<ReturnType> extends BaseReturnable<ReturnType> implements RepositorySourceDetails<ReturnType> {
+
+ protected SourceDetails( ReturnType returnObject ) {
+ super(returnObject);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ int value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ long value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ short value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ boolean value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ float value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ double value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ String value ) {
+ return setProperty(beanPropertyName, (Object)value);
+ }
+
+ public RepositorySourceDetails<ReturnType> setProperty( String beanPropertyName,
+ Object value ) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * Representation of the current configuration content.
+ */
+ @Immutable
+ protected static class ConfigurationContent {
+ private final RepositorySource source;
+ private final Path path;
+ private final String workspace;
+ private final ExecutionContext context;
+ private Graph graph;
+
+ protected ConfigurationContent( RepositorySource source,
+ String workspace,
+ Path path,
+ ExecutionContext context ) {
+ this.source = source;
+ this.path = path != null ? path : RootPath.INSTANCE;
+ this.workspace = workspace;
+ this.context = context;
+ }
+
+ /**
+ * Get the repository source where the configuration content may be found
+ *
+ * @return the source for the configuration repository; never null
+ */
+ public RepositorySource getRepositorySource() {
+ return source;
+ }
+
+ /**
+ * Get the path in the configuration repository where the configuration content may be found
+ *
+ * @return the path to the configuration content; never null
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * Get the name of the workspace used for the configuration repository.
+ *
+ * @return the name of the workspace, or null if the default workspace should be used
+ */
+ public String getWorkspace() {
+ return workspace;
+ }
+
+ /**
+ * @return context
+ */
+ public ExecutionContext getContext() {
+ return context;
+ }
+
+ /**
+ * Return a copy of this configuration that uses the supplied path instead of this object's {@link #getPath() path}.
+ *
+ * @param path the desired path for the new configuration; if null, then "/" is used
+ * @return the new configuration
+ */
+ public ConfigurationContent with( Path path ) {
+ return new ConfigurationContent(source, workspace, path, context);
+ }
+
+ /**
+ * Return a copy of this configuration that uses the supplied workspace name instead of this object's
+ * {@link #getWorkspace() workspace}.
+ *
+ * @param workspace the desired workspace name for the new configuration; if null, then the default workspace will be used
+ * @return the new configuration
+ */
+ public ConfigurationContent withWorkspace( String workspace ) {
+ return new ConfigurationContent(source, workspace, path, context);
+ }
+
+ /**
+ * Obtain a graph to this configuration repository. This method will always return the same graph instance.
+ *
+ * @return the graph; never null
+ */
+ protected Graph graph() {
+ if (graph == null) {
+ graph = Graph.create(source, context);
+ if (workspace != null) graph.useWorkspace(workspace);
+ }
+ return graph;
+ }
+ }
+}
Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaConfiguration.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,31 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.config;
+
+/**
+ *
+ */
+public class DnaEngine {
+
+}
Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/DnaEngine.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,145 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.config;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ */
+public class JcrConfiguration extends DnaConfiguration {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws IOException
+ * @throws SAXException
+ * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.lang.String)
+ */
+ @Override
+ public JcrConfiguration loadFrom( String pathToFile ) throws IOException, SAXException {
+ super.loadFrom(pathToFile);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.io.File)
+ */
+ @Override
+ public JcrConfiguration loadFrom( File configurationFile ) throws IOException, SAXException {
+ super.loadFrom(configurationFile);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.net.URL)
+ */
+ @Override
+ public JcrConfiguration loadFrom( URL urlToConfigurationFile ) throws IOException, SAXException {
+ super.loadFrom(urlToConfigurationFile);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(java.io.InputStream)
+ */
+ @Override
+ public JcrConfiguration loadFrom( InputStream configurationFileInputStream ) throws IOException, SAXException {
+ super.loadFrom(configurationFileInputStream);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource)
+ */
+ @Override
+ public JcrConfiguration loadFrom( RepositorySource source ) {
+ super.loadFrom(source);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource,
+ * java.lang.String)
+ */
+ @Override
+ public JcrConfiguration loadFrom( RepositorySource source,
+ String workspaceName ) {
+ super.loadFrom(source, workspaceName);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#loadFrom(org.jboss.dna.graph.connector.RepositorySource,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public JcrConfiguration loadFrom( RepositorySource source,
+ String workspaceName,
+ String pathInWorkspace ) {
+ super.loadFrom(source, workspaceName, pathInWorkspace);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#mimeTypeDetector(java.lang.String)
+ */
+ @Override
+ public MimeTypeDetectorDetails<JcrConfiguration> mimeTypeDetector( String name ) {
+ return new MimeTypeDetectorBuilder<JcrConfiguration>(this);
+ }
+
+ public JcrConfiguration addRepository( String repositoryId ) {
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.config.DnaConfiguration#build()
+ */
+ @Override
+ public JcrEngine build() {
+ return new JcrEngine();
+ }
+}
Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfiguration.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,98 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.config;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import java.io.File;
+import java.net.URL;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class JcrConfigurationTest {
+
+ @Test
+ public void shoulConfigureDnaFromFileUsingPath() throws Exception {
+ DnaConfiguration config = new DnaConfiguration();
+ config.loadFrom("some path");
+
+ DnaEngine engine = config.build();
+ assertThat(engine, is(notNullValue()));
+ }
+
+ @Test
+ public void shoulConfigureDnaFromFile() throws Exception {
+ DnaConfiguration config = new DnaConfiguration();
+ config.loadFrom(new File("file:some path"));
+
+ DnaEngine engine = config.build();
+ assertThat(engine, is(notNullValue()));
+ }
+
+ @Test
+ public void shoulConfigureDnaFromFileUsingURL() throws Exception {
+ DnaConfiguration config = new DnaConfiguration();
+ config.loadFrom(new URL("file:some path"));
+
+ DnaEngine engine = config.build();
+ assertThat(engine, is(notNullValue()));
+ }
+
+ @Test
+ public void shoulConfigureDnaFromRepositorySource() throws Exception {
+ InMemoryRepositorySource source = new InMemoryRepositorySource();
+ DnaConfiguration config = new DnaConfiguration();
+ config.loadFrom(source);
+
+ DnaEngine engine = config.build();
+ assertThat(engine, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldBeConfigurableAsDnaConfiguration() throws Exception {
+ DnaConfiguration config = new DnaConfiguration();
+ assertThat(config.loadFrom("some path"), is(sameInstance(config)));
+ assertThat(config.addMimeTypeDetector("something").and(), is(sameInstance(config)));
+
+ DnaEngine engine = config.build();
+ assertThat(engine, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldBeConfigurableAsJcrConfiguration() throws Exception {
+ JcrConfiguration config = new JcrConfiguration();
+ config.loadFrom("some path").addRepository("some repository ID");
+ assertThat(config.loadFrom("some path"), is(sameInstance(config)));
+ assertThat(config.addMimeTypeDetector("something").and(), is(sameInstance(config)));
+
+ JcrEngine engine = config.build();
+ assertThat(engine, is(notNullValue()));
+ }
+
+}
Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,31 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.config;
+
+/**
+ *
+ */
+public class JcrEngine extends DnaEngine {
+
+}
Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/config/JcrEngine.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerA.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerA.java (rev 0)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerA.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,79 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.dna.repository.sequencer;
+
+import java.io.InputStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.graph.sequencer.SequencerOutput;
+import org.jboss.dna.graph.sequencer.StreamSequencer;
+import org.jboss.dna.graph.sequencer.StreamSequencerContext;
+
+/**
+ * A mock stream sequencer that can be used for basic unit testing.
+ */
+@ThreadSafe
+public class MockStreamSequencerA implements StreamSequencer {
+
+ private AtomicInteger counter = new AtomicInteger();
+ private volatile CountDownLatch latch = new CountDownLatch(0);
+
+ public void setExpectedCount( int numExpected ) {
+ this.latch = new CountDownLatch(numExpected);
+ }
+
+ public boolean awaitExecution( long timeout,
+ TimeUnit unit ) throws InterruptedException {
+ return this.latch.await(timeout, unit);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.sequencer.StreamSequencer#sequence(java.io.InputStream,
+ * org.jboss.dna.graph.sequencer.SequencerOutput, org.jboss.dna.graph.sequencer.StreamSequencerContext)
+ */
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ StreamSequencerContext context ) {
+ // increment the counter and record the progress ...
+ this.counter.incrementAndGet();
+ this.latch.countDown();
+ }
+
+ public int getCounter() {
+ return this.counter.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "MockStreamSequencerA [" + this.getCounter() + "]";
+ }
+}
Property changes on: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerA.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerB.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerB.java (rev 0)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerB.java 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,79 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.dna.repository.sequencer;
+
+import java.io.InputStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.graph.sequencer.SequencerOutput;
+import org.jboss.dna.graph.sequencer.StreamSequencer;
+import org.jboss.dna.graph.sequencer.StreamSequencerContext;
+
+/**
+ * A mock stream sequencer that can be used for basic unit testing.
+ */
+@ThreadSafe
+public class MockStreamSequencerB implements StreamSequencer {
+
+ private AtomicInteger counter = new AtomicInteger();
+ private volatile CountDownLatch latch = new CountDownLatch(0);
+
+ public void setExpectedCount( int numExpected ) {
+ this.latch = new CountDownLatch(numExpected);
+ }
+
+ public boolean awaitExecution( long timeout,
+ TimeUnit unit ) throws InterruptedException {
+ return this.latch.await(timeout, unit);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.sequencer.StreamSequencer#sequence(java.io.InputStream,
+ * org.jboss.dna.graph.sequencer.SequencerOutput, org.jboss.dna.graph.sequencer.StreamSequencerContext)
+ */
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ StreamSequencerContext context ) {
+ // increment the counter and record the progress ...
+ this.counter.incrementAndGet();
+ this.latch.countDown();
+ }
+
+ public int getCounter() {
+ return this.counter.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "MockStreamSequencerB [" + this.getCounter() + "]";
+ }
+}
Property changes on: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/MockStreamSequencerB.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.cnd
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.cnd (rev 0)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.cnd 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,64 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+<air='http://jboss.org/dna/examples/aircraft/1.0'>
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[air:Aircraft] > nt:unstructured
+ - air:maker (string)
+ - air:model (string)
+ - air:designedBy (string)
+ - air:introduced (string) < '(19|20)\d{2}' // any 4 digit number starting with '19' or '20'
+ - air:range (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(nm|m|km|mi|ft)' // followed by 'nm', 'm', 'km', 'mi', or 'ft'
+ - air:maxSpeed (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(kt|mph|km/h|kmph)' // followed by 'kt', 'mph', 'km/h' or 'kmph'
+ - air:takeoffSpeed (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(kt|mph|km/h|kmph)' // followed by 'kt', 'mph', 'km/h' or 'kmph'
+ - air:cruiseSpeed (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(kt|mph|km/h|kmph)' // followed by 'kt', 'mph', 'km/h' or 'kmph'
+ - air:emptyWeight (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(lb|kg)' // followed by 'lb' or 'kg'
+ - air:maxWeight (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(lb|kg)' // followed by 'lb' or 'kg'
+ - air:rateOfClimb (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(ft|km|m)/(s|min)' // followed by 'ft/s', 'ft/min', 'km/s', 'km/min', 'm/s', or 'm/min'
+ - air:serviceCeiling (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(nm|m|km|mi|ft)' // followed by 'nm', 'm', 'km', 'mi', or 'ft'
+ - air:fuelCapacity (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*(lb|kg|gal|L)' // followed by 'lb', 'kg', 'gal', or 'L'
+ - air:crew (long) < '[0,)' // any non-negative value
+ - air:numberBuilt (string) // any integer (with optional ',' every 1000s place)
+ < '\d{1,3}(,?\d{3})*\s*[+]?' , // optionally followed by '+'
+ '([<>]\s*)?\d{1,3}(,?\d{3})*' // or prefixed by '<' or '>'
+ - air:url (string)
Added: trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.cnd
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.cnd (rev 0)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.cnd 2009-06-03 20:09:11 UTC (rev 968)
@@ -0,0 +1,50 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+<car='http://jboss.org/dna/examples/cars/1.0'>
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[car:Car] > nt:unstructured
+ - car:maker (string)
+ - car:model (string)
+ - car:year (string) < '(19|20)\d{2}' // any 4 digit number starting with '19' or '20'
+ - car:msrp (string) < '[$]\d{1,3}[,]?\d{3}([.]\d{2})?' // of the form "$X,XXX.ZZ", "$XX,XXX.ZZ" or "$XXX,XXX.ZZ"
+ // where '.ZZ' is optional
+ - car:userRating (long) < '[1,5]' // any value from 1 to 5 (inclusive)
+ - car:valueRating (long) < '[1,5]' // any value from 1 to 5 (inclusive)
+ - car:mpgCity (long) < '(0,]' // any value greater than 0
+ - car:mpgHighway (long) < '(0,]' // any value greater than 0
+ - car:lengthInInches (double) < '(0,]' // any value greater than 0
+ - car:wheelbaseInInches (double) < '(0,]' // any value greater than 0
+ - car:engine (string)
+
16 years, 6 months
DNA SVN: r967 - in trunk: dna-cnd/src/test/java/org/jboss/dna/cnd and 11 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-06-03 16:08:46 -0400 (Wed, 03 Jun 2009)
New Revision: 967
Added:
trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd
Removed:
trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd
Modified:
trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java
trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml
trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.xml
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
Log:
DNA-436 Continued the work on the examples, with fairly substantial changes (simplification) to the configuration frameworks.
Modified: trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java
===================================================================
--- trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -505,7 +505,7 @@
protected String propertyTypeNameFrom( CommonTree node,
int childType ) {
String text = stringFrom(node, childType);
- if (text.equals("*")) text = "undefined";
+ if ("*".equals(text)) text = "undefined";
String upperText = text.toUpperCase();
if (!VALID_PROPERTY_TYPES.contains(upperText)) {
recordError(node, CndI18n.expectedValidPropertyTypeName, text, VALID_PROPERTY_TYPES);
Modified: trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java
===================================================================
--- trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -446,6 +446,13 @@
assertThat(problems.size(), is(0));
}
+ @Test
+ public void shouldImportCndForJavaSequencer() throws Exception {
+ importer.importFrom(openCndFile("javaSource.cnd"), problems);
+ if (problems.size() != 0) printProblems();
+ assertThat(problems.size(), is(0));
+ }
+
public static final String[] NO_DEFAULTS = {};
public static final String[] NO_SUPERTYPES = {};
public static final String[] NO_VALUE_CONSTRAINTS = {};
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -1717,13 +1717,15 @@
}
public List<Location> under( Location at ) {
- return requests.readBlockOfChildren(at, getCurrentWorkspaceName(), startingIndex, blockSize).getChildren();
+ return requests.readBlockOfChildren(at, getCurrentWorkspaceName(), startingIndex, blockSize)
+ .getChildren();
}
};
}
public List<Location> startingAfter( final Location previousSibling ) {
- return requests.readNextBlockOfChildren(previousSibling, getCurrentWorkspaceName(), blockSize).getChildren();
+ return requests.readNextBlockOfChildren(previousSibling, getCurrentWorkspaceName(), blockSize)
+ .getChildren();
}
public List<Location> startingAfter( String pathOfPreviousSibling ) {
@@ -1941,7 +1943,7 @@
*/
public ImportInto<Conjunction<Graph>> importXmlFrom( final InputStream stream ) {
CheckArg.isNotNull(stream, "stream");
-
+
return new ImportInto<Conjunction<Graph>>() {
private boolean skipRootElement = false;
@@ -3513,6 +3515,19 @@
}
return new BatchResults(request);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Pending requests:\n");
+ sb.append(requestQueue.toString());
+ return sb.toString();
+ }
}
/**
@@ -5380,7 +5395,10 @@
}
public SubgraphNode getNode( Name relativePath ) {
- Path path = getGraph().getContext().getValueFactories().getPathFactory().create(getLocation().getPath(), relativePath);
+ Path path = getGraph().getContext()
+ .getValueFactories()
+ .getPathFactory()
+ .create(getLocation().getPath(), relativePath);
path = path.getNormalizedPath();
return getNode(path);
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -558,12 +558,15 @@
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append("{ ");
boolean hasPath = this.hasPath();
+ boolean hasProps = this.hasIdProperties();
if (hasPath) {
+ if (hasProps) {
+ sb.append("<");
+ }
sb.append(this.getPath());
}
- if (this.hasIdProperties()) {
+ if (hasProps) {
if (hasPath) sb.append(" && ");
sb.append("[");
boolean first = true;
@@ -573,8 +576,10 @@
sb.append(idProperty);
}
sb.append("]");
+ if (hasPath) {
+ sb.append("<");
+ }
}
- sb.append(" }");
return sb.toString();
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -248,7 +248,7 @@
* {@inheritDoc}
*/
public String getString() {
- return doGetString(null, DEFAULT_ENCODER, null);
+ return doGetString(null, null, null);
}
/**
@@ -625,6 +625,6 @@
*/
@Override
public String toString() {
- return getString(Path.URL_ENCODER);
+ return getString(Path.NO_OP_ENCODER);
}
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -681,6 +681,21 @@
return add(new DeleteBranchRequest(at, workspaceName));
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ for (Request request : requests) {
+ sb.append(request.toString());
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
protected class NodeChange {
protected final Location location;
protected final String workspaceName;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -34,6 +34,7 @@
public static final Name BASE = new BasicName(Namespace.URI, "base");
public static final Name NAMESPACE = new BasicName(Namespace.URI, "namespace");
public static final Name NODE_TYPES = new BasicName(Namespace.URI, "nodeTypes");
+ public static final Name REPOSITORIES = new BasicName(Namespace.URI, "repositories");
public static final Name ROOT = new BasicName(Namespace.URI, "root");
public static final Name SYSTEM = new BasicName(Namespace.URI, "system");
public static final Name URI = new BasicName(Namespace.URI, "uri");
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrConfiguration.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -23,20 +23,31 @@
*/
package org.jboss.dna.jcr;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import org.jboss.dna.cnd.CndImporter;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Node;
import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.io.Destination;
+import org.jboss.dna.graph.io.GraphBatchDestination;
import org.jboss.dna.graph.mimetype.MimeTypeDetector;
import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.sequencer.StreamSequencer;
import org.jboss.dna.repository.Configurator;
import org.jboss.dna.repository.DnaConfiguration;
import org.jboss.dna.repository.DnaConfigurationException;
-import org.jboss.dna.repository.DnaLexicon;
+import org.jboss.dna.repository.Configurator.And;
import org.jboss.dna.repository.Configurator.ChooseClass;
-import org.jboss.dna.repository.Configurator.ConfigRepositoryDetails;
+import org.jboss.dna.repository.Configurator.ConfigSourceDetails;
import org.jboss.dna.repository.Configurator.MimeTypeDetectorDetails;
-import org.jboss.dna.repository.Configurator.RepositoryDetails;
+import org.jboss.dna.repository.Configurator.RepositorySourceDetails;
+import org.jboss.dna.repository.Configurator.SequencerDetails;
+import org.jboss.dna.repository.Configurator.SetName;
/**
* A configuration builder for a {@link JcrEngine}. This class is an internal domain-specific language (DSL), and is designed to
@@ -56,8 +67,8 @@
* </pre>
*/
public class JcrConfiguration
- implements Configurator.Initializer<JcrConfiguration>, /*Configurator.SequencerConfigurator<JcrConfiguration>,*/
- Configurator.RepositoryConfigurator<JcrConfiguration>, Configurator.MimeDetectorConfigurator<JcrConfiguration>,
+ implements Configurator.Initializer<JcrConfiguration>, Configurator.SequencerConfigurator<JcrConfiguration>,
+ Configurator.RepositorySourceConfigurator<JcrConfiguration>, Configurator.MimeDetectorConfigurator<JcrConfiguration>,
Configurator.Builder<JcrEngine> {
private final JcrConfiguration.Builder<JcrConfiguration> builder;
@@ -91,44 +102,65 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationRepository()
+ * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationSource()
*/
- public ChooseClass<RepositorySource, ConfigRepositoryDetails<JcrConfiguration>> withConfigurationRepository() {
- return builder.withConfigurationRepository();
+ public ChooseClass<RepositorySource, ConfigSourceDetails<JcrConfiguration>> withConfigurationSource() {
+ return builder.withConfigurationSource();
}
- // /**
- // * {@inheritDoc}
- // *
- // * @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String)
- // */
- // public ChooseClass<Sequencer, SequencerDetails<JcrConfiguration>> addSequencer( String id ) {
- // CheckArg.isNotEmpty(id, "id");
- // return builder.addSequencer(id);
- // }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String)
+ */
+ public ChooseClass<StreamSequencer, SequencerDetails<JcrConfiguration>> addSequencer( String id ) {
+ CheckArg.isNotEmpty(id, "id");
+ return builder.addSequencer(id);
+ }
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(java.lang.String)
*/
- public ChooseClass<RepositorySource, JcrRepositoryDetails<JcrConfiguration>> addRepository( String id ) {
+ public ChooseClass<RepositorySource, RepositorySourceDetails<JcrConfiguration>> addSource( String id ) {
CheckArg.isNotEmpty(id, "id");
- return builder.addRepository(id);
+ return builder.addSource(id);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(org.jboss.dna.graph.connector.RepositorySource)
+ * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(org.jboss.dna.graph.connector.RepositorySource)
*/
- public JcrConfiguration addRepository( RepositorySource source ) {
+ public JcrConfiguration addSource( RepositorySource source ) {
CheckArg.isNotNull(source, "source");
CheckArg.isNotEmpty(source.getName(), "source.getName()");
- return builder.addRepository(source);
+ return builder.addSource(source);
}
/**
+ * Add a JCR repository to this configuration.
+ *
+ * @param id the identifier for this repository; may not be null or empty
+ * @return the interface used to configure the repository
+ */
+ public SourceSetter<JcrRepositoryDetails<JcrConfiguration>> addRepository( final String id ) {
+ CheckArg.isNotEmpty(id, "id");
+ final JcrConfiguration.Builder<JcrConfiguration> builder = this.builder;
+ return new SourceSetter<JcrRepositoryDetails<JcrConfiguration>>() {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrConfiguration.SourceSetter#usingSource(java.lang.String)
+ */
+ public JcrRepositoryDetails<JcrConfiguration> usingSource( String sourceId ) {
+ return builder.addRepository(id, sourceId);
+ }
+ };
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.repository.Configurator.MimeDetectorConfigurator#addMimeTypeDetector(java.lang.String)
@@ -161,9 +193,67 @@
return new JcrEngine(builder.buildDnaEngine());
}
+ /**
+ * The interface used to set the RepositorySource that should be used.
+ *
+ * @param <ReturnType> the interface returned from these methods
+ */
+ public interface SourceSetter<ReturnType> {
+ /**
+ * Set the repository source that should be used.
+ *
+ * @param sourceId that identifier of the repository source
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType usingSource( String sourceId );
+ }
+
public interface JcrRepositoryDetails<ReturnType>
- extends RepositoryDetails<ReturnType>, SetOptions<JcrRepositoryDetails<ReturnType>> {
+ extends SetOptions<JcrRepositoryDetails<ReturnType>>, SetNamespace<JcrRepositoryDetails<ReturnType>>,
+ SetName<JcrRepositoryDetails<ReturnType>>,
+ /* SetDescription<JcrRepositoryDetails<ReturnType>>, */
+ And<ReturnType> {
+ /**
+ * Specify that the CND in the supplied string should be loaded into the repository.
+ *
+ * @param cndContents the string containing the compact node definitions
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the string is null or empty
+ * @throws DnaConfigurationException if there is an error reading the CND contents
+ */
+ JcrRepositoryDetails<ReturnType> withNodeTypes( String cndContents );
+
+ /**
+ * Specify that the CND file is to be loaded into the repository.
+ *
+ * @param cndFile the CND file
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the file is null
+ * @throws DnaConfigurationException if there is an error reading the file
+ */
+ JcrRepositoryDetails<ReturnType> withNodeTypes( File cndFile );
+
+ /**
+ * Specify that the CND file is to be loaded into the repository.
+ *
+ * @param urlOfCndFile the URL of the CND file
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the URL is null
+ * @throws DnaConfigurationException if there is an error reading the content at the URL
+ */
+ JcrRepositoryDetails<ReturnType> withNodeTypes( URL urlOfCndFile );
+
+ /**
+ * Specify that the CND file is to be loaded into the repository.
+ *
+ * @param cndContent the stream containing the CND content
+ * @return this object for chained method invocation
+ * @throws IllegalArgumentException if the URL is null
+ * @throws DnaConfigurationException if there is an error reading the stream at the URL
+ */
+ JcrRepositoryDetails<ReturnType> withNodeTypes( InputStream cndContent );
+
}
/**
@@ -198,8 +288,41 @@
ReturnType setTo( String value );
}
+ /**
+ * Interface for setting a namespace for a {@link JcrRepository JCR repository}.
+ *
+ * @param <ReturnType> the interface returned after the option has been set.
+ */
+ public interface SetNamespace<ReturnType> {
+ /**
+ * Specify the repository option that is to be set. The value may be set using the interface returned by this method.
+ *
+ * @param uri the uri for the namespace
+ * @return the interface used to set the value for the property; never null
+ */
+ NamespaceSetter<ReturnType> withNamespace( String uri );
+ }
+
+ /**
+ * The interface used to set the prefix for a namespace.
+ *
+ * @param <ReturnType> the interface returned from these methods
+ * @see JcrConfiguration.SetNamespace#withNamespace(String)
+ */
+ public interface NamespaceSetter<ReturnType> {
+ /**
+ * Set the prefix for the namespace
+ *
+ * @param prefix the prefix for the namespace
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType usingPrefix( String prefix );
+ }
+
public static class Builder<ReturnType> extends DnaConfiguration.Builder<ReturnType> {
+ private Path repositoriesPath;
+
/**
* Specify a new {@link ExecutionContext} that should be used for this DNA instance.
*
@@ -216,42 +339,183 @@
return graph();
}
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(java.lang.String)
- */
- @Override
- public ChooseClass<RepositorySource, JcrRepositoryDetails<ReturnType>> addRepository( String id ) {
+ protected Path repositoriesPath() {
+ // Make sure the "dna:repositories" node is there
+ if (repositoriesPath == null) {
+ Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.REPOSITORIES);
+ Node node = graph().createIfMissing(path).andReturn();
+ this.repositoriesPath = node.getLocation().getPath();
+ }
+ return this.repositoriesPath;
+ }
+
+ public JcrRepositoryDetails<ReturnType> addRepository( String id,
+ String sourceId ) {
CheckArg.isNotEmpty(id, "id");
- // Now create the "dna:source" node with the supplied id ...
- Path path = createOrReplaceNode(sourcesPath(), id);
- JcrRepositoryDetails<ReturnType> details = new JcrGraphRepositoryDetails<ReturnType>(path, builder);
- return new ClassChooser<RepositorySource, JcrRepositoryDetails<ReturnType>>(path, details);
+ // Now create the "dna:repositories/id" node ...
+ Path path = createOrReplaceNode(repositoriesPath(), id);
+ configuration().set(DnaLexicon.SOURCE_NAME).to(sourceId).on(path);
+ return new JcrGraphRepositoryDetails<ReturnType>(path, builder);
}
- public class JcrGraphRepositoryDetails<RT> extends GraphRepositoryDetails<RT> implements JcrRepositoryDetails<RT> {
+ public class JcrGraphRepositoryDetails<RT> implements JcrRepositoryDetails<RT> {
+ private final Path path;
+ private final RT returnObject;
protected JcrGraphRepositoryDetails( Path path,
RT returnObject ) {
- super(path, returnObject);
+ this.path = path;
+ this.returnObject = returnObject;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetName#named(java.lang.String)
+ */
@SuppressWarnings( "synthetic-access" )
- public OptionSetter<JcrRepositoryDetails<RT>> with( final JcrRepository.Option option ) {
- final Path optionsPath = createOrReplaceNode(path(), DnaLexicon.OPTIONS);
+ public JcrRepositoryDetails<RT> named( String name ) {
+ configuration().set(DnaLexicon.READABLE_NAME).to(name).on(name);
+ return this;
+ }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrConfiguration.SetNamespace#withNamespace(java.lang.String)
+ */
+ @SuppressWarnings( "synthetic-access" )
+ public NamespaceSetter<JcrRepositoryDetails<RT>> withNamespace( final String uri ) {
+ final Path namespacesPath = createOrReplaceNode(path, DnaLexicon.NAMESPACES);
final JcrRepositoryDetails<RT> details = this;
+ return new NamespaceSetter<JcrRepositoryDetails<RT>>() {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrConfiguration.NamespaceSetter#usingPrefix(java.lang.String)
+ */
+ public JcrRepositoryDetails<RT> usingPrefix( String prefix ) {
+ Path nsPath = createOrReplaceNode(namespacesPath, prefix);
+ configuration().set(DnaLexicon.URI).to(uri).on(nsPath);
+ return details;
+ }
+ };
+ }
+ @SuppressWarnings( "synthetic-access" )
+ public OptionSetter<JcrRepositoryDetails<RT>> with( final JcrRepository.Option option ) {
+ final Path optionsPath = createOrReplaceNode(path, DnaLexicon.OPTIONS);
+ final JcrRepositoryDetails<RT> details = this;
return new OptionSetter<JcrRepositoryDetails<RT>>() {
public JcrRepositoryDetails<RT> setTo( String value ) {
Path optionPath = createOrReplaceNode(optionsPath, option.name());
configuration().set(DnaLexicon.VALUE).to(value).on(optionPath);
-
return details;
}
};
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.lang.String)
+ */
+ public JcrRepositoryDetails<RT> withNodeTypes( String content ) {
+ CheckArg.isNotEmpty(content, "content");
+ CndImporter importer = createCndImporter();
+ try {
+ importer.importFrom(content, getProblems(), "stream");
+ } catch (IOException e) {
+ throw new DnaConfigurationException(e);
+ }
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.net.URL)
+ */
+ public JcrRepositoryDetails<RT> withNodeTypes( URL url ) {
+ CheckArg.isNotNull(url, "url");
+ // Obtain the stream ...
+ InputStream stream = null;
+ boolean foundError = false;
+ try {
+ stream = url.openStream();
+ CndImporter importer = createCndImporter();
+ importer.importFrom(stream, getProblems(), url.toString());
+ } catch (IOException e) {
+ foundError = true;
+ throw new DnaConfigurationException(e);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ if (!foundError) {
+ throw new DnaConfigurationException(e);
+ }
+ }
+ }
+ }
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.io.File)
+ */
+ public JcrRepositoryDetails<RT> withNodeTypes( File file ) {
+ CheckArg.isNotNull(file, "file");
+ if (file.exists() && file.canRead()) {
+ CndImporter importer = createCndImporter();
+ try {
+ importer.importFrom(file, getProblems());
+ } catch (IOException e) {
+ throw new DnaConfigurationException(e);
+ }
+ return this;
+ }
+ throw new DnaConfigurationException(JcrI18n.fileDoesNotExist.text(file.getPath()));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrConfiguration.JcrRepositoryDetails#withNodeTypes(java.io.InputStream)
+ */
+ public JcrRepositoryDetails<RT> withNodeTypes( InputStream stream ) {
+ CndImporter importer = createCndImporter();
+ try {
+ importer.importFrom(stream, getProblems(), "stream");
+ } catch (IOException e) {
+ throw new DnaConfigurationException(e);
+ }
+ return this;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ protected CndImporter createCndImporter() {
+ // The node types will be loaded into 'dna:repositories/{repositoryName}/dna:nodeTypes/' ...
+ Path nodeTypesPath = createOrReplaceNode(path, DnaLexicon.NODE_TYPES);
+
+ // Now set up the destination ...
+ Destination destination = new GraphBatchDestination(graph().batch()); // will be executed
+
+ // And create the importer that will load the CND content into the repository ...
+ return new CndImporter(destination, nodeTypesPath);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.And#and()
+ */
+ public RT and() {
+ return returnObject;
+ }
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEngine.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -39,12 +39,14 @@
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.Node;
+import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.PathNotFoundException;
import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.basic.GraphNamespaceRegistry;
import org.jboss.dna.jcr.JcrRepository.Option;
import org.jboss.dna.repository.DnaEngine;
import org.jboss.dna.repository.RepositoryLibrary;
@@ -138,12 +140,13 @@
repositoriesLock.lock();
JcrRepository repository = repositories.get(repositoryName);
if (repository == null) {
- if (getRepositorySource(repositoryName) == null) {
+ try {
+ repository = doCreateJcrRepository(repositoryName);
+ } catch (PathNotFoundException e) {
// The repository name is not a valid repository ...
String msg = JcrI18n.repositoryDoesNotExist.text(repositoryName);
throw new RepositoryException(msg);
}
- repository = doCreateJcrRepository(repositoryName);
repositories.put(repositoryName, repository);
}
return repository;
@@ -155,50 +158,54 @@
protected JcrRepository doCreateJcrRepository( String repositoryName ) {
RepositoryConnectionFactory connectionFactory = getRepositoryConnectionFactory();
Map<String, String> descriptors = null;
-
- /*
- * Extract the JCR options from the configuration graph
- */
- String configurationName = dnaEngine.getRepositoryService().getConfigurationSourceName();
Map<Option, String> options = new HashMap<Option, String>();
+ // Read the subgraph that represents the repository ...
PathFactory pathFactory = getExecutionContext().getValueFactories().getPathFactory();
+ Path repositoriesPath = pathFactory.create(DnaLexicon.REPOSITORIES);
+ Path repositoryPath = pathFactory.create(repositoriesPath, repositoryName);
+ String configurationName = dnaEngine.getRepositoryService().getConfigurationSourceName();
Graph configuration = Graph.create(connectionFactory.createConnection(configurationName), getExecutionContext());
+ Subgraph subgraph = configuration.getSubgraphOfDepth(3).at(repositoryPath);
- try {
- Node sources = configuration.getNodeAt(pathFactory.create(DnaLexicon.SOURCES));
+ // Read the options ...
+ Node optionsNode = subgraph.getNode(DnaLexicon.OPTIONS);
+ if (optionsNode != null) {
+ for (Location optionLocation : optionsNode.getChildren()) {
+ Node optionNode = configuration.getNodeAt(optionLocation);
+ Path.Segment segment = optionLocation.getPath().getLastSegment();
+ Property valueProperty = optionNode.getProperty(DnaLexicon.VALUE);
+ if (valueProperty == null) continue;
+ Option option = Option.findOption(segment.getName().getLocalName());
+ if (option == null) continue;
+ options.put(option, valueProperty.getFirstValue().toString());
+ }
+ }
- /*
- * Hopefully, this can all get cleaned up when the connector layer supports queries
- */
- for (Location childLocation : sources.getChildren()) {
- Node source = configuration.getNodeAt(childLocation);
+ // Read the namespaces ...
+ ExecutionContext context = getExecutionContext();
+ Node namespacesNode = subgraph.getNode(DnaLexicon.NAMESPACES);
+ if (namespacesNode != null) {
+ GraphNamespaceRegistry registry = new GraphNamespaceRegistry(configuration, namespacesNode.getLocation().getPath(),
+ DnaLexicon.NAMESPACE_URI);
+ context = context.with(registry);
+ }
- Property nameProperty = source.getProperty("name");
- if (nameProperty != null && nameProperty.getFirstValue().toString().equals(repositoryName)) {
- for (Location optionsLocation : source.getChildren()) {
- if (DnaLexicon.OPTIONS.equals(optionsLocation.getPath().getLastSegment().getName())) {
- Node optionsNode = configuration.getNodeAt(optionsLocation);
+ // Create the repository ...
+ JcrRepository repository = new JcrRepository(context, connectionFactory, repositoryName, descriptors, options);
- for (Location optionLocation : optionsNode.getChildren()) {
- Path.Segment segment = optionLocation.getPath().getLastSegment();
- Node optionNode = configuration.getNodeAt(optionLocation);
- Property valueProperty = optionNode.getProperty(DnaLexicon.VALUE);
-
- options.put(Option.valueOf(segment.getName().getLocalName()), valueProperty.getFirstValue()
- .toString());
-
- }
-
- }
- }
- }
+ // Register all the the node types ...
+ Node nodeTypesNode = subgraph.getNode(DnaLexicon.NODE_TYPES);
+ if (nodeTypesNode != null) {
+ try {
+ repository.getRepositoryTypeManager().registerNodeTypes(subgraph, nodeTypesNode.getLocation());
+ } catch (RepositoryException e) {
+ // Error registering the node types ...
+ getProblems().addError(e, JcrI18n.errorRegisteringNodeTypes, repositoryName);
}
- } catch (PathNotFoundException pnfe) {
- // Must not be any configuration set up
}
- return new JcrRepository(getExecutionContext(), connectionFactory, repositoryName, descriptors, options);
+ return repository;
}
/*
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -44,6 +44,7 @@
public static I18n repositoryMustBeConfigured;
public static I18n sourceInUse;
public static I18n repositoryDoesNotExist;
+ public static I18n fileDoesNotExist;
public static I18n noNamespaceWithPrefix;
public static I18n noNamespaceWithUri;
@@ -59,6 +60,7 @@
public static I18n unableToRemapUriNotRegisteredInNamespaceRegistry;
public static I18n unableToRemapUriUsingPrefixUsedInNamespaceRegistry;
+ public static I18n errorRegisteringNodeTypes;
public static I18n errorWhileInitializingTheNamespaceRegistry;
public static I18n invalidRelativePath;
public static I18n invalidPathParameter;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -40,6 +40,7 @@
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.text.Inflector;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -90,7 +91,32 @@
* The {@link Configuration#getAppConfigurationEntry(String) JAAS application configuration name} that specifies which
* login modules should be used to validate credentials.
*/
- JAAS_LOGIN_CONFIG_NAME,
+ JAAS_LOGIN_CONFIG_NAME;
+
+ /**
+ * Determine the option given the option name. This does more than {@link Option#valueOf(String)}, since this method first
+ * tries to match the supplied string to the option's {@link Option#name() name}, then the uppercase version of the
+ * supplied string to the option's name, and finally if the supplied string is a camel-case version of the name (e.g.,
+ * "projectNodeTypes").
+ *
+ * @param option the string version of the option's name
+ * @return the matching Option instance, or null if an option could not be matched using the supplied value
+ */
+ public static Option findOption( String option ) {
+ if (option == null) return null;
+ Option result = Option.valueOf(option);
+ if (result != null) return result;
+ // Try an uppercased version ...
+ result = Option.valueOf(option.toUpperCase());
+ if (result != null) return result;
+ // Try a camel-case version ...
+ String underscored = Inflector.getInstance().underscore(option, '_');
+ if (underscored != null) {
+ result = Option.valueOf(underscored);
+ }
+
+ return result;
+ }
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -1292,19 +1292,98 @@
*/
List<JcrNodeType> registerNodeTypes( JcrNodeTypeSource nodeTypeSource )
throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, RepositoryException {
-
assert nodeTypeSource != null;
+ Graph nodeTypesGraph = nodeTypeSource.getNodeTypes();
+ Subgraph nodeTypesSubgraph = nodeTypesGraph.getSubgraphOfDepth(3).at("/");
+ return registerNodeTypes(nodeTypesSubgraph, nodeTypesSubgraph.getLocation());
+ }
- Graph nodeTypeBatch = nodeTypeSource.getNodeTypes();
+ /**
+ * Registers the node types from the given {@link JcrNodeTypeSource}.
+ * <p>
+ * The effect of this method is "all or nothing"; if an error occurs, no node types are registered or updated.
+ * </p>
+ * <p>
+ * <b>DNA Implementation Notes</b>
+ * </p>
+ * <p>
+ * DNA currently supports registration of batches of types with some constraints. DNA will allow types to be registered if
+ * they meet the following criteria:
+ * <ol>
+ * <li>Existing types cannot be modified in-place - They must be unregistered and re-registered</li>
+ * <li>Types must have a non-null, non-empty name</li>
+ * <li>If a primary item name is specified for the node type, it must match the name of a property OR a child node, not both</li>
+ * <li>Each type must have a valid set of supertypes - that is, the type's supertypes must meet the following criteria:
+ * <ol>
+ * <li>The type must have at least one supertype (unless the type is {@code nt:base}.</li>
+ * <li>No two supertypes {@code t1} and {@code t2} can declare each declare a property ({@code p1} and {@code p2}) with the
+ * same name and cardinality ({@code p1.isMultiple() == p2.isMultiple()}). Note that this does prohibit each {@code t1} and
+ * {@code t2} from having a common supertype (or super-supertype, etc.) that declares a property).</li>
+ * <li>No two supertypes {@code t1} and {@code t2} can declare each declare a child node ({@code n1} and {@code n2}) with the
+ * same name and SNS status ({@code p1.allowsSameNameSiblings() == p2.allowsSameNameSiblings()}). Note that this does prohibit
+ * each {@code t1} and {@code t2} from having a common supertype (or super-supertype, etc.) that declares a child node).</li>
+ * </ol>
+ * </li>
+ * <li>Each type must have a valid set of properties - that is, the type's properties must meet the following criteria:
+ * <ol>
+ * <li>Residual property definitions cannot be mandatory</li>
+ * <li>If the property is auto-created, it must specify a default value</li>
+ * <li>If the property is single-valued, it can only specify a single default value</li>
+ * <li>If the property overrides an existing property definition from a supertype, the new definition must be mandatory if the
+ * old definition was mandatory</li>
+ * <li>The property cannot override an existing property definition from a supertype if the ancestor definition is protected</li>
+ * <li>If the property overrides an existing property definition from a supertype that specifies value constraints, the new
+ * definition must have the same value constraints as the old definition. <i>This requirement may be relaxed in a future
+ * version of DNA.</i></li>
+ * <li>If the property overrides an existing property definition from a supertype, the new definition must have the same
+ * required type as the old definition or a required type that can ALWAYS be cast to the required type of the ancestor (see
+ * section 6.2.6 of the JCR 1.0.1 specification)</li>
+ * </ol>
+ * Note that an empty set of properties would meet the above criteria.</li>
+ * <li>The type must have a valid set of child nodes - that is, the types's child nodes must meet the following criteria:
+ * <ol>
+ * <li>Residual child node definitions cannot be mandatory</li>
+ * <li>If the child node is auto-created, it must specify a default primary type name</li>
+ * <li>All required primary types must already be fully registered with the type manager or must have been defined earlier in
+ * the batch. <i>This requirement may be relaxed in a future version of DNA.</i></li>
+ * <li>If the child node overrides an existing child node definition from a supertype, the new definition must be mandatory if
+ * the old definition was mandatory</li>
+ * <li>The child node cannot override an existing child node definition from a supertype if the ancestor definition is
+ * protected</li>
+ * <li>If the child node overrides an existing child node definition from a supertype, the required primary types of the new
+ * definition must be more restrictive than the required primary types of the old definition - that is, the new primary types
+ * must defined such that any type that satisfies all of the required primary types for the new definition must also satisfy
+ * all of the required primary types for the old definition. This requirement is analogous to the requirement that overriding
+ * property definitions have a required type that is always convertible to the required type of the overridden definition.</li>
+ * </ol>
+ * Note that an empty set of child nodes would meet the above criteria.</li>
+ * </p>
+ *
+ * @param nodeTypeSubgraph the subgraph containing the of {@link NodeType node types} to register
+ * @param locationOfParentOfNodeTypes the location of the parent node under which the node types are found
+ * @return the newly registered (or updated) {@link NodeType NodeTypes}
+ * @throws UnsupportedRepositoryOperationException if {@code allowUpdates == true}. DNA does not support this capability at
+ * this time but the parameter has been retained for API compatibility.
+ * @throws InvalidNodeTypeDefinitionException if the {@link NodeTypeDefinition} is invalid
+ * @throws NodeTypeExistsException if <code>allowUpdate</code> is false and the {@link NodeTypeDefinition} specifies a node
+ * type name that is already registered
+ * @throws RepositoryException if another error occurs
+ */
+ List<JcrNodeType> registerNodeTypes( Subgraph nodeTypeSubgraph,
+ Location locationOfParentOfNodeTypes )
+ throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, RepositoryException {
+ assert nodeTypeSubgraph != null;
+ assert locationOfParentOfNodeTypes != null;
+
NamespaceRegistry namespaces = this.context.getNamespaceRegistry();
- List<Location> nodeTypeLocations = nodeTypeBatch.getChildren().of("/");
+ List<Location> nodeTypeLocations = nodeTypeSubgraph.getNode(locationOfParentOfNodeTypes).getChildren();
List<JcrNodeType> typesPendingRegistration = new ArrayList<JcrNodeType>(nodeTypeLocations.size());
try {
nodeTypeManagerLock.writeLock().lock();
for (Location location : nodeTypeLocations) {
- Node nodeTypeNode = nodeTypeBatch.getNodeAt(location);
+ Node nodeTypeNode = nodeTypeSubgraph.getNode(location);
assert location.getPath() != null;
Name internalName = location.getPath().getLastSegment().getName();
@@ -1319,7 +1398,7 @@
List<JcrNodeType> supertypes = supertypesFor(nodeTypeNode, typesPendingRegistration);
// No need to re-parse the supertypes
- JcrNodeType nodeType = nodeTypeFrom(nodeTypeBatch.getSubgraphOfDepth(2).at(location), supertypes);
+ JcrNodeType nodeType = nodeTypeFrom(nodeTypeSubgraph, location, supertypes);
validate(nodeType, supertypes, typesPendingRegistration);
@@ -1383,8 +1462,9 @@
}
private JcrNodeType nodeTypeFrom( Subgraph nodeTypeGraph,
+ Location nodeTypeLocation,
List<JcrNodeType> supertypes ) {
- Node nodeTypeNode = nodeTypeGraph.getRoot();
+ Node nodeTypeNode = nodeTypeGraph.getNode(nodeTypeLocation);
List<Location> children = nodeTypeNode.getChildren();
List<JcrPropertyDefinition> properties = new ArrayList<JcrPropertyDefinition>(children.size());
@@ -1726,13 +1806,15 @@
for (JcrNodeDefinition ancestor : ancestors) {
if (ancestor.isProtected()) {
throw new InvalidNodeTypeDefinitionException(
- JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType().getName(),
+ JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType()
+ .getName(),
"child node"));
}
if (ancestor.isMandatory() && !node.isMandatory()) {
throw new InvalidNodeTypeDefinitionException(
- JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType().getName(),
+ JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType()
+ .getName(),
"child node"));
}
@@ -1797,15 +1879,16 @@
Value[] defaultValues = prop.getDefaultValues();
if (prop.isAutoCreated() && !prop.isProtected() && (defaultValues == null || defaultValues.length == 0)) {
- throw new InvalidNodeTypeDefinitionException(
- JcrI18n.autocreatedPropertyNeedsDefault.text(prop.getName(),
- prop.getDeclaringNodeType().getName()));
+ throw new InvalidNodeTypeDefinitionException(JcrI18n.autocreatedPropertyNeedsDefault.text(prop.getName(),
+ prop.getDeclaringNodeType()
+ .getName()));
}
if (!prop.isMultiple() && (defaultValues != null && defaultValues.length > 1)) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.singleValuedPropertyNeedsSingleValuedDefault.text(prop.getName(),
- prop.getDeclaringNodeType().getName()));
+ prop.getDeclaringNodeType()
+ .getName()));
}
Name propName = context.getValueFactories().getNameFactory().create(prop.getName());
@@ -1819,13 +1902,15 @@
for (JcrPropertyDefinition ancestor : ancestors) {
if (ancestor.isProtected()) {
throw new InvalidNodeTypeDefinitionException(
- JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType().getName(),
+ JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType()
+ .getName(),
"property"));
}
if (ancestor.isMandatory() && !prop.isMandatory()) {
throw new InvalidNodeTypeDefinitionException(
- JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType().getName(),
+ JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType()
+ .getName(),
"property"));
}
@@ -1836,14 +1921,16 @@
&& !Arrays.equals(ancestor.getValueConstraints(), prop.getValueConstraints())) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.constraintsChangedInSubtype.text(propName,
- ancestor.getDeclaringNodeType().getName()));
+ ancestor.getDeclaringNodeType()
+ .getName()));
}
if (!isAlwaysSafeConversion(prop.getRequiredType(), ancestor.getRequiredType())) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.cannotRedefineProperty.text(propName,
PropertyType.nameFromValue(prop.getRequiredType()),
- ancestor.getDeclaringNodeType().getName(),
+ ancestor.getDeclaringNodeType()
+ .getName(),
PropertyType.nameFromValue(ancestor.getRequiredType())));
}
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-06-03 20:08:46 UTC (rev 967)
@@ -34,6 +34,7 @@
repositoryMustBeConfigured = DNA repositories must be configured with either a repository source factory or a repository source.
sourceInUse = All sessions must end before a new repository source can be set
repositoryDoesNotExist = There is no repository named "{0}"
+fileDoesNotExist = Unable to find or read the file "{0}"
noNamespaceWithPrefix = There is no namespace with prefix "{0}"
noNamespaceWithUri = There is no namespace with URI "{0}"
@@ -49,6 +50,7 @@
unableToRemapUriNotRegisteredInNamespaceRegistry = Unable to remap the namespace "{1}" to prefix "{0}" because the URI is not already registered in the workspace's namespace registry
unableToRemapUriUsingPrefixUsedInNamespaceRegistry = Unable to remap the namespace "{1}" to prefix "{0}" because the prefix is already used as the prefix for the namespace "{2}" in the workspace's namespace registry
+errorRegisteringNodeTypes = Error while registering the node types for repository "{0}"
errorWhileInitializingTheNamespaceRegistry = Error while initializing the namespace registry for workspace "{0}"
invalidRelativePath = "{0}" is not a valid relative path
invalidPathParameter = The "{1}" parameter value "{0}" was not a valid path
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd 2009-06-03 20:08:46 UTC (rev 967)
@@ -1,12 +1,38 @@
/*
- * DNA Built-In Types
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
<nt = "http://www.jcp.org/jcr/nt/1.0">
<mix = "http://www.jcp.org/jcr/mix/1.0">
<dna = "http://www.jboss.org/dna/1.0">
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
[dna:namespace] > nt:base
- dna:uri (string) primary protected version
@@ -25,3 +51,4 @@
- * (undefined) version
+ jcr:system (dna:system) = dna:system autocreated mandatory protected ignore
+ * (nt:base) = nt:base multiple version
+
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -23,10 +23,10 @@
*/
package org.jboss.dna.jcr;
-import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import java.io.IOException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
@@ -72,7 +72,7 @@
@Test( expected = AssertionError.class )
public void shouldNotAllowNullTypeSource() throws Exception {
- repoTypeManager.registerNodeTypes(null);
+ repoTypeManager.registerNodeTypes((JcrNodeTypeSource)null);
}
@Test( expected = RepositoryException.class )
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -23,16 +23,13 @@
*/
package org.jboss.dna.jcr;
-import java.io.File;
import java.net.URI;
import java.util.Properties;
import org.apache.jackrabbit.test.RepositoryStub;
import org.jboss.dna.common.collection.Problem;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
-import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
-import org.jboss.dna.graph.io.GraphImporter;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.jcr.JcrRepository.Option;
import org.jboss.security.config.IDTrustConfiguration;
@@ -42,7 +39,7 @@
*/
public class InMemoryRepositoryStub extends RepositoryStub {
private static final String REPOSITORY_SOURCE_NAME = "Test Repository Source";
-
+
private JcrRepository repository;
static {
@@ -62,52 +59,57 @@
super(env);
// Create the in-memory (DNA) repository
- JcrEngine engine = new JcrConfiguration()
- .withConfigurationRepository()
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("configuration repository")
- .with("name").setTo("configuration")
- .and()
- .addRepository("JCR Repository")
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .with(Option.PROJECT_NODE_TYPES).setTo(Boolean.FALSE.toString())
- .describedAs("JCR Repository")
- .with("name").setTo(REPOSITORY_SOURCE_NAME)
- .and().build();
+ JcrEngine engine = new JcrConfiguration().withConfigurationSource()
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("configuration repository")
+ .usingWorkspace("configuration workspace")
+ .with("name")
+ .setTo("configuration repository")
+ .with("defaultWorkspaceName")
+ .setTo("configuration workspace")
+ .and()
+ .addSource("Store")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("JCR Repository persistent store")
+ .and()
+ .addRepository(REPOSITORY_SOURCE_NAME)
+ .usingSource("Store")
+ .withNodeTypes(getClass().getClassLoader().getResource("tck_test_types.cnd"))
+ .with(Option.PROJECT_NODE_TYPES)
+ .setTo(Boolean.FALSE.toString())
+ .and()
+ .build();
engine.start();
-
+
+ // Print all of the problems from the engine configuration ...
+ for (Problem problem : engine.getProblems()) {
+ System.err.println(problem);
+ }
+ if (engine.getProblems().hasErrors()) {
+ throw new IllegalStateException("Problems starting JCR repository");
+ }
+
ExecutionContext executionContext = engine.getExecutionContext();
executionContext.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI);
try {
repository = engine.getRepository(REPOSITORY_SOURCE_NAME);
- RepositoryNodeTypeManager nodeTypes = repository.getRepositoryTypeManager();
// Set up some sample nodes in the graph to match the expected test configuration
- Graph graph = Graph.create(repository.getRepositorySourceName(), engine.getRepositoryConnectionFactory(), executionContext);
- GraphImporter importer = new GraphImporter(graph);
+ Graph graph = Graph.create(repository.getRepositorySourceName(),
+ engine.getRepositoryConnectionFactory(),
+ executionContext);
Path destinationPath = executionContext.getValueFactories().getPathFactory().createRootPath();
+ // URI xmlContent = new File("src/test/resources/repositoryForTckTests.xml").toURI();
+ URI xmlContent = getClass().getClassLoader().getResource("repositoryForTckTests.xml").toURI();
+ graph.importXmlFrom(xmlContent).into(destinationPath);
- CndNodeTypeSource nodeTypeSource = new CndNodeTypeSource("/tck_test_types.cnd");
-
- for (Problem problem : nodeTypeSource.getProblems()) {
- System.err.println(problem);
- }
- if (!nodeTypeSource.isValid()) {
- throw new IllegalStateException("Problems loading TCK test node types");
- }
-
- nodeTypes.registerNodeTypes(nodeTypeSource);
-
- URI xmlContent = new File("src/test/resources/repositoryForTckTests.xml").toURI();
- importer.importXml(xmlContent, Location.create(destinationPath)).execute();
-
} catch (Exception ex) {
// The TCK tries to quash this exception. Print it out to be more obvious.
ex.printStackTrace();
- throw new IllegalStateException("Repository initialization failed.", ex);
+ throw new IllegalStateException("Failed to initialize the repository with text content.", ex);
}
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrConfigurationTest.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -32,10 +32,12 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.cache.ImmutableCachePolicy;
import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector;
import org.jboss.dna.graph.property.Path;
@@ -88,7 +90,7 @@
newSource.setRootNodeUuid(rootUuid);
// Update the configuration and save it ...
- configuration.addRepository(newSource).save();
+ configuration.addSource(newSource).save();
// Verify that the graph has been updated correctly ...
Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
@@ -102,9 +104,90 @@
}
@Test
+ public void shouldAllowSettingUpConfigurationRepositoryWithDifferentConfigurationSourceName() throws Exception {
+ JcrEngine engine = configuration.withConfigurationSource()
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("Configuration Repository")
+ .with("name")
+ .setTo("config")
+ .with("retryLimit")
+ .setTo(5)
+ .and()
+ .addSource("Source2")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("description")
+ .and()
+ .addRepository("JCR Repository")
+ .usingSource("Source2")
+ .with(Option.JAAS_LOGIN_CONFIG_NAME)
+ .setTo("test")
+ .and()
+ .build();
+ engine.start();
+ // Get a graph to the configuration source ...
+ RepositorySource configReposSource = engine.getRepositoryService().getRepositoryLibrary().getSource("config");
+ assertThat(configReposSource, is(notNullValue()));
+ assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
+ assertThat(configReposSource.getName(), is("config"));
+ InMemoryRepositorySource configSource = (InMemoryRepositorySource)configReposSource;
+ assertThat(configSource.getDefaultWorkspaceName(), is(""));
+ Graph graph = Graph.create("config", engine.getRepositoryService().getRepositoryLibrary(), context);
+ assertThat(graph, is(notNullValue()));
+ assertThat(graph.getNodeAt("/"), is(notNullValue()));
+
+ // Get the repository ...
+ JcrRepository repository = engine.getRepository("JCR Repository");
+ assertThat(repository, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldAllowSettingUpConfigurationRepositoryWithDifferentWorkspaceName() throws Exception {
+ JcrEngine engine = configuration.withConfigurationSource()
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("Configuration Repository")
+ .usingWorkspace("workspaceXYZ")
+ .with("name")
+ .setTo("config2")
+ .with("defaultWorkspaceName")
+ .setTo("workspaceXYZ")
+ .with("retryLimit")
+ .setTo(5)
+ .and()
+ .addSource("Source2")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("description")
+ .and()
+ .addRepository("JCR Repository")
+ .usingSource("Source2")
+ .with(Option.JAAS_LOGIN_CONFIG_NAME)
+ .setTo("test")
+ .and()
+ .build();
+ engine.start();
+ // Get a graph to the configuration source ...
+ RepositorySource configReposSource = engine.getRepositoryService().getRepositoryLibrary().getSource("config2");
+ assertThat(configReposSource, is(notNullValue()));
+ assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
+ assertThat(configReposSource.getName(), is("config2"));
+ InMemoryRepositorySource configSource = (InMemoryRepositorySource)configReposSource;
+ assertThat(configSource.getDefaultWorkspaceName(), is("workspaceXYZ"));
+ Graph graph = Graph.create("config2", engine.getRepositoryService().getRepositoryLibrary(), context);
+ assertThat(graph, is(notNullValue()));
+ assertThat(graph.getNodeAt("/"), is(notNullValue()));
+
+ // Get the repository ...
+ JcrRepository repository = engine.getRepository("JCR Repository");
+ assertThat(repository, is(notNullValue()));
+ }
+
+ @Test
public void shouldAllowAddingRepositorySourceByClassNameAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class.getName())
.loadedFromClasspath()
.describedAs("description")
@@ -126,7 +209,7 @@
@Test
public void shouldAllowAddingRepositorySourceByClassNameAndClasspathAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class.getName())
.loadedFrom("cp1", "cp2")
.describedAs("description")
@@ -149,7 +232,7 @@
@Test
public void shouldAllowAddingRepositorySourceByClassReferenceAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("description")
.with("retryLimit")
@@ -171,13 +254,13 @@
@Test
public void shouldAllowOverwritingRepositorySourceByRepositoryName() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("description")
.with("retryLimit")
.setTo(3)
.and()
- .addRepository("Source1")
+ .addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("new description")
.with("retryLimit")
@@ -200,7 +283,7 @@
@Test
public void shouldAllowAddingMimeTypeDetector() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("description")
.and()
@@ -228,7 +311,7 @@
@Test
public void shouldAllowConfigurationInMultipleSteps() {
- configuration.addRepository("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description");
+ configuration.addSource("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description");
configuration.addMimeTypeDetector("detector")
.usingClass(ExtensionBasedMimeTypeDetector.class)
.describedAs("default detector");
@@ -254,49 +337,59 @@
public void shouldAllowSpecifyingOptions() throws Exception {
// Update the configuration and save it ...
- JcrEngine engine = configuration.withConfigurationRepository()
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .describedAs("Configuration Repository")
- .with("name").setTo("configuration")
- .with("retryLimit")
- .setTo(5)
- .and()
- .addRepository("Source2")
- .usingClass(InMemoryRepositorySource.class.getName())
- .loadedFromClasspath()
- .with(Option.JAAS_LOGIN_CONFIG_NAME).setTo("test")
- .describedAs("description")
- .with("name").setTo("JCR Repository")
- .and()
- .build();
+ JcrEngine engine = configuration.withConfigurationSource()
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("Configuration Repository")
+ .with("name")
+ .setTo("configuration")
+ .with("retryLimit")
+ .setTo(5)
+ .and()
+ .addSource("Source2")
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("description")
+ .and()
+ .addRepository("JCR Repository")
+ .usingSource("Source2")
+ .with(Option.JAAS_LOGIN_CONFIG_NAME)
+ .setTo("test")
+ .and()
+ .build();
engine.start();
// Verify that the graph has been updated correctly ...
- Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
+ Subgraph subgraph = configuration.graph().getSubgraphOfDepth(6).at("/");
assertThat(subgraph.getNode("/dna:sources"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/Source2"), is(notNullValue()));
assertThat(subgraph.getNode("/dna:sources/Source2"), hasProperty(DnaLexicon.READABLE_NAME, "Source2"));
assertThat(subgraph.getNode("/dna:sources/Source2"), hasProperty(DnaLexicon.CLASSNAME,
InMemoryRepositorySource.class.getName()));
-
+ assertThat(subgraph.getNode("/dna:repositories"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository"), hasProperty(DnaLexicon.SOURCE_NAME, "Source2"));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository/dna:options"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:repositories/JCR Repository/dna:options/JAAS_LOGIN_CONFIG_NAME"),
+ hasProperty(DnaLexicon.VALUE, "test"));
+
JcrRepository repository = engine.getRepository("JCR Repository");
-
+
Map<Option, String> options = new HashMap<Option, String>();
options.put(Option.JAAS_LOGIN_CONFIG_NAME, "test");
options.put(Option.PROJECT_NODE_TYPES, "false");
assertThat(repository.getOptions(), is(options));
}
-
+
@Test
public void shouldAllowCreatingWithConfigRepository() throws InterruptedException {
- DnaEngine engine = new DnaConfiguration().withConfigurationRepository()
- .usingClass(InMemoryRepositorySource.class)
- .describedAs("Configuration Repository")
- .with("name")
- .setTo("config repo")
- .and()
- .build();
+ DnaEngine engine = new DnaConfiguration().withConfigurationSource()
+ .usingClass(InMemoryRepositorySource.class)
+ .describedAs("Configuration Repository")
+ .with("name")
+ .setTo("config repo")
+ .and()
+ .build();
assertThat(engine.getRepositorySource("config repo"), is(notNullValue()));
assertThat(engine.getRepositorySource("config repo"), is(instanceOf(InMemoryRepositorySource.class)));
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/Configurator.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -24,6 +24,8 @@
import java.util.ArrayList;
import java.util.List;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.text.Inflector;
@@ -40,6 +42,7 @@
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.ValueFormatException;
import org.jboss.dna.graph.property.basic.RootPath;
+import org.jboss.dna.graph.sequencer.StreamSequencer;
import org.jboss.dna.repository.sequencer.Sequencer;
/**
@@ -55,14 +58,22 @@
public interface SequencerConfigurator<ReturnType> {
/**
- * Add a new {@link Sequencer sequencer} to this configuration. The new sequencer will have the supplied name, and if the
- * name of an existing sequencer is used, this will replace the existing sequencer configuration.
+ * Add a new {@link StreamSequencer sequencer} to this configuration. The new sequencer will have the supplied name, and
+ * if the name of an existing sequencer is used, this will replace the existing sequencer configuration.
*
* @param id the identifier of the new sequencer
* @return the interface for choosing the class, which returns the interface used to configure the sequencer; never null
* @throws IllegalArgumentException if the sequencer name is null, empty, or otherwise invalid
*/
- public ChooseClass<Sequencer, SequencerDetails<ReturnType>> addSequencer( final String id );
+ public ChooseClass<StreamSequencer, SequencerDetails<ReturnType>> addSequencer( String id );
+
+ /**
+ * Get the details for the sequencer with the supplied identifier.
+ *
+ * @param id the identifier of the sequencer that is to be added
+ * @return the details for the repository source, or null if there is no such source in this configuration
+ */
+ public SequencerDetails<ReturnType> sequencer( String id );
}
/**
@@ -76,10 +87,17 @@
* default each configuration uses an internal transient repository for its configuration, but using this method will make
* the configuration use a different repository (that is perhaps shared with other processes).
*
- * @return the interface for choosing the class, which returns the interface used to configure the repository source that
- * will be used for the configuration repository; never null
+ * @return the interface for choosing the class, which returns the interface used to configure the source that will be
+ * used for the configuration repository; never null
*/
- public ChooseClass<RepositorySource, ConfigRepositoryDetails<ReturnType>> withConfigurationRepository();
+ public ChooseClass<RepositorySource, ConfigSourceDetails<ReturnType>> withConfigurationSource();
+
+ /**
+ * Get the details for the configuration repository source.
+ *
+ * @return the details for the configuration's repository source; never null
+ */
+ public ConfigSourceDetails<ReturnType> configurationSource();
}
/**
@@ -87,7 +105,7 @@
*
* @param <ReturnType> the type of interface to return after the repository source's configuration is completed
*/
- public interface RepositoryConfigurator<ReturnType> {
+ public interface RepositorySourceConfigurator<ReturnType> {
/**
* Add a new {@link RepositorySource repository} for this configuration. The new repository will have the supplied name,
* and if the name of an existing repository is used, this will replace the existing repository configuration.
@@ -96,9 +114,9 @@
* @return the interface for choosing the class, which returns the interface used to configure the repository source;
* never null
* @throws IllegalArgumentException if the repository name is null, empty, or otherwise invalid
- * @see #addRepository(RepositorySource)
+ * @see #addSource(RepositorySource)
*/
- public ChooseClass<RepositorySource, ? extends RepositoryDetails<ReturnType>> addRepository( final String id );
+ public ChooseClass<RepositorySource, RepositorySourceDetails<ReturnType>> addSource( final String id );
/**
* Add a new {@link RepositorySource repository} for this configuration. The new repository will have the supplied name,
@@ -107,9 +125,17 @@
* @param source the {@link RepositorySource} instance that should be used
* @return this configuration object, for method-chaining purposes
* @throws IllegalArgumentException if the repository source reference is null
- * @see #addRepository(String)
+ * @see #addSource(String)
*/
- public ReturnType addRepository( RepositorySource source );
+ public ReturnType addSource( RepositorySource source );
+
+ /**
+ * Get the details for the repository source with the supplied identifier.
+ *
+ * @param id the identifier of the repository that is to be added
+ * @return the details for the repository source, or null if there is no such source in this configuration
+ */
+ public RepositorySourceDetails<ReturnType> source( String id );
}
/**
@@ -127,6 +153,14 @@
* @throws IllegalArgumentException if the detector name is null, empty, or otherwise invalid
*/
public ChooseClass<MimeTypeDetector, MimeTypeDetectorDetails<ReturnType>> addMimeTypeDetector( final String id );
+
+ /**
+ * Get the details for the MIME type detector with the supplied identifier.
+ *
+ * @param id the identifier of the MIME type detector that is to be added
+ * @return the details for the MIME type detector, or null if there is no such detector in this configuration
+ */
+ public MimeTypeDetectorDetails<ReturnType> mimeTypeDetector( String id );
}
/**
@@ -149,9 +183,9 @@
*
* @param <ReturnType>
*/
- public interface RepositoryDetails<ReturnType>
- extends SetName<RepositoryDetails<ReturnType>>, SetDescription<RepositoryDetails<ReturnType>>,
- SetProperties<RepositoryDetails<ReturnType>>, And<ReturnType> {
+ public interface RepositorySourceDetails<ReturnType>
+ extends SetName<RepositorySourceDetails<ReturnType>>, SetDescription<RepositorySourceDetails<ReturnType>>,
+ SetProperties<RepositorySourceDetails<ReturnType>>, And<ReturnType> {
}
/**
@@ -159,16 +193,15 @@
*
* @param <ReturnType>
*/
- public interface ConfigRepositoryDetails<ReturnType>
- extends SetDescription<ConfigRepositoryDetails<ReturnType>>, SetProperties<ConfigRepositoryDetails<ReturnType>>,
- And<ReturnType> {
+ public interface ConfigSourceDetails<ReturnType>
+ extends SetDescription<ConfigSourceDetails<ReturnType>>, SetProperties<ConfigSourceDetails<ReturnType>>, And<ReturnType> {
/**
* Specify the path under which the configuration content is to be found. This path is assumed to be "/" by default.
*
* @param path the path to the configuration content in the configuration source; may not be null
* @return this instance for method chaining purposes; never null
*/
- public ConfigRepositoryDetails<ReturnType> under( String path );
+ public ConfigSourceDetails<ReturnType> under( String path );
/**
* Specify the path under which the configuration content is to be found. This path is assumed to be "/" by default.
@@ -176,7 +209,7 @@
* @param workspace the name of the workspace with the configuration content in the configuration source; may not be null
* @return this instance for method chaining purposes; never null
*/
- public ConfigRepositoryDetails<ReturnType> inWorkspace( String workspace );
+ public ConfigSourceDetails<ReturnType> usingWorkspace( String workspace );
}
/**
@@ -242,86 +275,84 @@
*/
public interface SetProperties<ReturnType> {
/**
- * Specify the name of the JavaBean-style property that is to be set. The value may be set using the interface returned by
- * this method.
+ * Set the property value to an integer.
*
* @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
- * @return the interface used to set the value for the property; never null
- */
- PropertySetter<ReturnType> with( String beanPropertyName );
- }
-
- /**
- * The interface used to set the value for a JavaBean-style property.
- *
- * @param <ReturnType> the interface returned from these methods
- * @author Randall Hauch
- * @see Configurator.SetProperties#with(String)
- */
- public interface PropertySetter<ReturnType> {
- /**
- * Set the property value to an integer.
- *
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( int value );
+ ReturnType setProperty( String beanPropertyName,
+ int value );
/**
* Set the property value to a long number.
*
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( long value );
+ ReturnType setProperty( String beanPropertyName,
+ long value );
/**
* Set the property value to a short.
*
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( short value );
+ ReturnType setProperty( String beanPropertyName,
+ short value );
/**
* Set the property value to a boolean.
*
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( boolean value );
+ ReturnType setProperty( String beanPropertyName,
+ boolean value );
/**
* Set the property value to a float.
*
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( float value );
+ ReturnType setProperty( String beanPropertyName,
+ float value );
/**
* Set the property value to a double.
*
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( double value );
+ ReturnType setProperty( String beanPropertyName,
+ double value );
/**
* Set the property value to a string.
*
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( String value );
+ ReturnType setProperty( String beanPropertyName,
+ String value );
/**
* Set the property value to an object.
*
+ * @param beanPropertyName the name of the JavaBean-style property (e.g., "retryLimit")
* @param value the new value for the property
* @return the next component to continue configuration; never null
*/
- ReturnType setTo( Object value );
+ ReturnType setProperty( String beanPropertyName,
+ Object value );
}
/**
@@ -378,10 +409,10 @@
/**
* Specify the human-readable name for this component.
*
- * @param description the description; may be null or empty
+ * @param name the name; may be null or empty
* @return the next component to continue configuration; never null
*/
- ReturnType named( String description );
+ ReturnType named( String name );
}
/**
@@ -434,6 +465,7 @@
protected ConfigurationRepository configurationSource;
private Graph graph;
private Graph.Batch batch;
+ private final Problems problems;
/**
* Specify a new {@link ExecutionContext} that should be used for this DNA instance.
@@ -448,12 +480,20 @@
CheckArg.isNotNull(builder, "builder");
this.context = context;
this.builder = builder;
+ this.problems = new SimpleProblems();
// Set up the default configuration repository ...
this.configurationSource = createDefaultConfigurationSource();
}
/**
+ * @return problems
+ */
+ public Problems getProblems() {
+ return problems;
+ }
+
+ /**
* Method that is used to set up the default configuration repository source. By default, this method sets up the
* {@link InMemoryRepositorySource} loaded from the classpath.
*
@@ -522,9 +562,28 @@
protected abstract Name nameFor( String name );
protected Path createOrReplaceNode( Path parentPath,
+ String id,
+ Name propertyName,
+ Object value ) {
+ Path path = pathFactory().create(parentPath, id);
+ configuration().create(path).with(propertyName, value).and();
+ return path;
+
+ }
+
+ protected Path createOrReplaceNode( Path parentPath,
+ Name id,
+ Name propertyName,
+ Object value ) {
+ Path path = pathFactory().create(parentPath, id);
+ configuration().create(path).with(propertyName, value).and();
+ return path;
+ }
+
+ protected Path createOrReplaceNode( Path parentPath,
String id ) {
Path path = pathFactory().create(parentPath, id);
- configuration().create(path).with(DnaLexicon.READABLE_NAME, id).and();
+ configuration().create(path).and();
return path;
}
@@ -532,7 +591,7 @@
protected Path createOrReplaceNode( Path parentPath,
Name id ) {
Path path = pathFactory().create(parentPath, id);
- configuration().create(path).with(DnaLexicon.READABLE_NAME, id).and();
+ configuration().create(path).and();
return path;
}
@@ -555,7 +614,7 @@
}
protected class ConfigurationRepositoryClassChooser<ReturnType>
- implements ChooseClass<RepositorySource, ConfigRepositoryDetails<ReturnType>> {
+ implements ChooseClass<RepositorySource, ConfigSourceDetails<ReturnType>> {
private final ReturnType returnObject;
@@ -564,10 +623,10 @@
this.returnObject = returnObject;
}
- public LoadedFrom<ConfigRepositoryDetails<ReturnType>> usingClass( final String className ) {
- return new LoadedFrom<ConfigRepositoryDetails<ReturnType>>() {
+ public LoadedFrom<ConfigSourceDetails<ReturnType>> usingClass( final String className ) {
+ return new LoadedFrom<ConfigSourceDetails<ReturnType>>() {
@SuppressWarnings( "unchecked" )
- public ConfigRepositoryDetails loadedFrom( String... classpath ) {
+ public ConfigSourceDetails loadedFrom( String... classpath ) {
ClassLoader classLoader = getExecutionContext().getClassLoader(classpath);
Class<? extends RepositorySource> clazz = null;
try {
@@ -580,7 +639,7 @@
}
@SuppressWarnings( "unchecked" )
- public ConfigRepositoryDetails loadedFromClasspath() {
+ public ConfigSourceDetails loadedFromClasspath() {
Class<? extends RepositorySource> clazz = null;
try {
clazz = (Class<? extends RepositorySource>)Class.forName(className);
@@ -592,7 +651,7 @@
};
}
- public ConfigRepositoryDetails<ReturnType> usingClass( Class<? extends RepositorySource> repositorySource ) {
+ public ConfigSourceDetails<ReturnType> usingClass( Class<? extends RepositorySource> repositorySource ) {
try {
Configurator.this.configurationSource = new ConfigurationRepository(repositorySource.newInstance());
} catch (InstantiationException err) {
@@ -606,7 +665,7 @@
}
}
- protected class ConfigurationSourceDetails<ReturnType> implements ConfigRepositoryDetails<ReturnType> {
+ protected class ConfigurationSourceDetails<ReturnType> implements ConfigSourceDetails<ReturnType> {
private final ReturnType returnObject;
protected ConfigurationSourceDetails( ReturnType returnObject ) {
@@ -619,7 +678,7 @@
*
* @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
*/
- public ConfigRepositoryDetails<ReturnType> describedAs( String description ) {
+ public ConfigSourceDetails<ReturnType> describedAs( String description ) {
Configurator.this.configurationSource = Configurator.this.configurationSource.withDescription(description);
return this;
}
@@ -627,20 +686,98 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.SetProperties#with(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, boolean)
*/
- public PropertySetter<ConfigRepositoryDetails<ReturnType>> with( String propertyName ) {
- return new BeanPropertySetter<ConfigRepositoryDetails<ReturnType>>(
- Configurator.this.configurationSource.getRepositorySource(),
- propertyName, this);
+ public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
+ boolean value ) {
+ return setProperty(propertyName, (Object)value);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.ConfigRepositoryDetails#inWorkspace(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, int)
*/
- public ConfigRepositoryDetails<ReturnType> inWorkspace( String workspace ) {
+ public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
+ int value ) {
+ return setProperty(propertyName, (Object)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, short)
+ */
+ public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
+ short value ) {
+ return setProperty(propertyName, (Object)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, long)
+ */
+ public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
+ long value ) {
+ return setProperty(propertyName, (Object)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, float)
+ */
+ public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
+ float value ) {
+ return setProperty(propertyName, (Object)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, double)
+ */
+ public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
+ double value ) {
+ return setProperty(propertyName, (Object)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.String)
+ */
+ public ConfigSourceDetails<ReturnType> setProperty( String propertyName,
+ String value ) {
+ return setProperty(propertyName, (Object)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.Object)
+ */
+ public ConfigSourceDetails<ReturnType> setProperty( String beanPropertyName,
+ Object value ) {
+ // Set the JavaBean-style property on the RepositorySource instance ...
+ Object javaBean = Configurator.this.configurationSource.getRepositorySource();
+ Reflection reflection = new Reflection(javaBean.getClass());
+ try {
+ reflection.invokeSetterMethodOnTarget(beanPropertyName, javaBean, value);
+ } catch (Throwable err) {
+ I18n msg = RepositoryI18n.errorSettingJavaBeanPropertyOnInstanceOfClass;
+ throw new DnaConfigurationException(msg.text(beanPropertyName, javaBean.getClass(), err.getMessage()), err);
+ }
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.ConfigSourceDetails#usingWorkspace(java.lang.String)
+ */
+ public ConfigSourceDetails<ReturnType> usingWorkspace( String workspace ) {
Configurator.this.configurationSource = Configurator.this.configurationSource.withWorkspace(workspace);
return this;
}
@@ -648,9 +785,9 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.ConfigRepositoryDetails#under(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.ConfigSourceDetails#under(java.lang.String)
*/
- public ConfigRepositoryDetails<ReturnType> under( String path ) {
+ public ConfigSourceDetails<ReturnType> under( String path ) {
CheckArg.isNotNull(path, "path");
Path newPath = getExecutionContext().getValueFactories().getPathFactory().create(path);
Configurator.this.configurationSource = Configurator.this.configurationSource.with(newPath);
@@ -724,174 +861,142 @@
}
}
- /**
- * Reusable implementation of {@link Configurator.PropertySetter} that sets the JavaBean-style property using reflection.
- *
- * @param <ReturnType>
- */
- protected class BeanPropertySetter<ReturnType> implements Configurator.PropertySetter<ReturnType> {
- private final Object javaBean;
- private final String beanPropertyName;
- private final ReturnType returnObject;
-
- protected BeanPropertySetter( Object javaBean,
- String beanPropertyName,
- ReturnType returnObject ) {
- assert javaBean != null;
- assert beanPropertyName != null;
- assert returnObject != null;
- this.javaBean = javaBean;
- this.beanPropertyName = beanPropertyName;
- this.returnObject = returnObject;
- }
-
- public ReturnType setTo( boolean value ) {
- return setTo((Object)value);
- }
-
- public ReturnType setTo( int value ) {
- return setTo((Object)value);
- }
-
- public ReturnType setTo( long value ) {
- return setTo((Object)value);
- }
-
- public ReturnType setTo( short value ) {
- return setTo((Object)value);
- }
-
- public ReturnType setTo( float value ) {
- return setTo((Object)value);
- }
-
- public ReturnType setTo( double value ) {
- return setTo((Object)value);
- }
-
- public ReturnType setTo( String value ) {
- return setTo((Object)value);
- }
-
- public ReturnType setTo( Object value ) {
- // Set the JavaBean-style property on the RepositorySource instance ...
- Reflection reflection = new Reflection(javaBean.getClass());
- try {
- reflection.invokeSetterMethodOnTarget(beanPropertyName, javaBean, value);
- } catch (Throwable err) {
- I18n msg = RepositoryI18n.errorSettingJavaBeanPropertyOnInstanceOfClass;
- throw new DnaConfigurationException(msg.text(beanPropertyName, javaBean.getClass(), err.getMessage()), err);
- }
- return returnObject;
- }
+ protected <ReturnType> GraphRepositorySourceDetails<ReturnType> createRepositoryDetails( Path path,
+ ReturnType returnObject ) {
+ return new GraphRepositorySourceDetails<ReturnType>(path, returnObject);
}
- /**
- * Reusable implementation of {@link Configurator.PropertySetter} that sets the property on the specified node in the
- * configuration graph.
- *
- * @param <ReturnType>
- */
- protected class GraphPropertySetter<ReturnType> implements Configurator.PropertySetter<ReturnType> {
+ protected class GraphRepositorySourceDetails<ReturnType> implements RepositorySourceDetails<ReturnType> {
private final Path path;
- private final String beanPropertyName;
private final ReturnType returnObject;
- protected GraphPropertySetter( Path path,
- String beanPropertyName,
- ReturnType returnObject ) {
+ protected GraphRepositorySourceDetails( Path path,
+ ReturnType returnObject ) {
assert path != null;
- assert beanPropertyName != null;
assert returnObject != null;
this.path = path;
- this.beanPropertyName = Inflector.getInstance().lowerCamelCase(beanPropertyName);
this.returnObject = returnObject;
}
- public ReturnType setTo( boolean value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ public Path path() {
+ return this.path;
}
- public ReturnType setTo( int value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ /**
+ * Get the name used for this source.
+ *
+ * @return the source's node name
+ */
+ public Name name() {
+ return path().getLastSegment().getName();
}
- public ReturnType setTo( long value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetName#named(java.lang.String)
+ */
+ public RepositorySourceDetails<ReturnType> named( String name ) {
+ configuration().set(DnaLexicon.READABLE_NAME).to(name).on(path);
+ return this;
}
- public ReturnType setTo( short value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
+ */
+ public RepositorySourceDetails<ReturnType> describedAs( String description ) {
+ configuration().set(DnaLexicon.DESCRIPTION).to(description).on(path);
+ return this;
}
- public ReturnType setTo( float value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, boolean)
+ */
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ boolean value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
}
- public ReturnType setTo( double value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, int)
+ */
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ int value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
}
- public ReturnType setTo( String value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, short)
+ */
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ short value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
}
- public ReturnType setTo( Object value ) {
- configuration().set(nameFor(beanPropertyName)).to(value).on(path);
- return returnObject;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, long)
+ */
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ long value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
}
- }
- protected class GraphRepositoryDetails<ReturnType> implements RepositoryDetails<ReturnType> {
- private final Path path;
- private final ReturnType returnObject;
-
- protected GraphRepositoryDetails( Path path,
- ReturnType returnObject ) {
- assert path != null;
- assert returnObject != null;
- this.path = path;
- this.returnObject = returnObject;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, float)
+ */
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ float value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
}
- protected Path path() {
- return this.path;
- }
-
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.SetName#named(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, double)
*/
- public RepositoryDetails<ReturnType> named( String name ) {
- configuration().set(DnaLexicon.READABLE_NAME).to(name).on(path);
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ double value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.String)
*/
- public RepositoryDetails<ReturnType> describedAs( String description ) {
- configuration().set(DnaLexicon.DESCRIPTION).to(description).on(path);
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ String value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
return this;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.SetProperties#with(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.Object)
*/
- public PropertySetter<RepositoryDetails<ReturnType>> with( String propertyName ) {
- return new GraphPropertySetter<RepositoryDetails<ReturnType>>(path, propertyName, this);
+ public RepositorySourceDetails<ReturnType> setProperty( String propertyName,
+ Object value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
}
/**
@@ -1005,15 +1110,94 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.SetProperties#with(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, boolean)
*/
- public PropertySetter<MimeTypeDetectorDetails<ReturnType>> with( String propertyName ) {
- return new GraphPropertySetter<MimeTypeDetectorDetails<ReturnType>>(path, propertyName, this);
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ boolean value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
}
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, int)
+ */
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ int value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, short)
+ */
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ short value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, long)
+ */
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ long value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, float)
+ */
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ float value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, double)
+ */
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ double value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.String)
+ */
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ String value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.SetProperties#setProperty(java.lang.String, java.lang.Object)
+ */
+ public MimeTypeDetectorDetails<ReturnType> setProperty( String propertyName,
+ Object value ) {
+ configuration().set(nameFor(propertyName)).to(value).on(path);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.repository.Configurator.SetDescription#describedAs(java.lang.String)
*/
public MimeTypeDetectorDetails<ReturnType> describedAs( String description ) {
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -34,20 +34,20 @@
import org.jboss.dna.graph.mimetype.MimeTypeDetector;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.sequencer.StreamSequencer;
import org.jboss.dna.repository.Configurator.ChooseClass;
-import org.jboss.dna.repository.Configurator.ConfigRepositoryDetails;
+import org.jboss.dna.repository.Configurator.ConfigSourceDetails;
import org.jboss.dna.repository.Configurator.ConfigurationRepository;
import org.jboss.dna.repository.Configurator.MimeTypeDetectorDetails;
-import org.jboss.dna.repository.Configurator.RepositoryDetails;
+import org.jboss.dna.repository.Configurator.RepositorySourceDetails;
import org.jboss.dna.repository.Configurator.SequencerDetails;
-import org.jboss.dna.repository.sequencer.Sequencer;
/**
*
*/
public class DnaConfiguration
implements Configurator.Initializer<DnaConfiguration>, Configurator.SequencerConfigurator<DnaConfiguration>,
- Configurator.RepositoryConfigurator<DnaConfiguration>, Configurator.MimeDetectorConfigurator<DnaConfiguration>,
+ Configurator.RepositorySourceConfigurator<DnaConfiguration>, Configurator.MimeDetectorConfigurator<DnaConfiguration>,
Configurator.Builder<DnaEngine> {
protected static final Map<String, Name> NAMES_TO_MAP;
@@ -94,28 +94,28 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationRepository()
+ * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationSource()
*/
- public ChooseClass<RepositorySource, ConfigRepositoryDetails<DnaConfiguration>> withConfigurationRepository() {
- return builder.withConfigurationRepository();
+ public ChooseClass<RepositorySource, ConfigSourceDetails<DnaConfiguration>> withConfigurationSource() {
+ return builder.withConfigurationSource();
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(java.lang.String)
*/
- public ChooseClass<RepositorySource, ? extends RepositoryDetails<DnaConfiguration>> addRepository( String id ) {
- return builder.addRepository(id);
+ public ChooseClass<RepositorySource, RepositorySourceDetails<DnaConfiguration>> addSource( String id ) {
+ return builder.addSource(id);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(org.jboss.dna.graph.connector.RepositorySource)
+ * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(org.jboss.dna.graph.connector.RepositorySource)
*/
- public DnaConfiguration addRepository( RepositorySource source ) {
- return builder.addRepository(source);
+ public DnaConfiguration addSource( RepositorySource source ) {
+ return builder.addSource(source);
}
/**
@@ -123,7 +123,7 @@
*
* @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String)
*/
- public ChooseClass<Sequencer, SequencerDetails<DnaConfiguration>> addSequencer( String id ) {
+ public ChooseClass<StreamSequencer, SequencerDetails<DnaConfiguration>> addSequencer( String id ) {
return builder.addSequencer(id);
}
@@ -165,7 +165,7 @@
public static class Builder<ReturnType> extends Configurator<ReturnType>
implements Configurator.Initializer<ReturnType>, Configurator.SequencerConfigurator<ReturnType>,
- Configurator.RepositoryConfigurator<ReturnType>, Configurator.MimeDetectorConfigurator<ReturnType> {
+ Configurator.RepositorySourceConfigurator<ReturnType>, Configurator.MimeDetectorConfigurator<ReturnType> {
private Path sourcesPath;
private Path sequencersPath;
@@ -187,10 +187,6 @@
return new DnaEngine(context, configurationSource);
}
- public ConfigurationRepository getConfigurationRepository() {
- return configurationSource;
- }
-
protected Path sourcesPath() {
// Make sure the "dna:sources" node is there
if (sourcesPath == null) {
@@ -224,49 +220,58 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationRepository()
+ * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationSource()
*/
- public ChooseClass<RepositorySource, ConfigRepositoryDetails<ReturnType>> withConfigurationRepository() {
+ public ChooseClass<RepositorySource, ConfigSourceDetails<ReturnType>> withConfigurationSource() {
return new ConfigurationRepositoryClassChooser<ReturnType>(builder);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.Configurator.Initializer#configurationSource()
+ */
+ public ConfigSourceDetails<ReturnType> configurationSource() {
+ return configurationSource;
+ }
/**
* {@inheritDoc}
*
* @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String)
*/
- public ChooseClass<Sequencer, SequencerDetails<ReturnType>> addSequencer( String id ) {
+ public ChooseClass<StreamSequencer, SequencerDetails<ReturnType>> addSequencer( String id ) {
CheckArg.isNotEmpty(id, "id");
// Now create the "dna:sequencer" node with the supplied id ...
- Path path = createOrReplaceNode(sequencersPath(), id);
+ Path path = createOrReplaceNode(sequencersPath(), id, DnaLexicon.READABLE_NAME, id);
SequencerDetails<ReturnType> details = new GraphSequencerDetails<ReturnType>(path, builder);
- return new ClassChooser<Sequencer, SequencerDetails<ReturnType>>(path, details);
+ return new ClassChooser<StreamSequencer, SequencerDetails<ReturnType>>(path, details);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(java.lang.String)
+ * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(java.lang.String)
*/
- public ChooseClass<RepositorySource, ? extends RepositoryDetails<ReturnType>> addRepository( String id ) {
+ public ChooseClass<RepositorySource, RepositorySourceDetails<ReturnType>> addSource( String id ) {
CheckArg.isNotEmpty(id, "id");
// Now create the "dna:source" node with the supplied id ...
- Path path = createOrReplaceNode(sourcesPath(), id);
- RepositoryDetails<ReturnType> details = new GraphRepositoryDetails<ReturnType>(path, builder);
- return new ClassChooser<RepositorySource, RepositoryDetails<ReturnType>>(path, details);
+ Path path = createOrReplaceNode(sourcesPath(), id, DnaLexicon.READABLE_NAME, id);
+ RepositorySourceDetails<ReturnType> details = new GraphRepositorySourceDetails<ReturnType>(path, builder);
+ return new ClassChooser<RepositorySource, RepositorySourceDetails<ReturnType>>(path, details);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(org.jboss.dna.graph.connector.RepositorySource)
+ * @see org.jboss.dna.repository.Configurator.RepositorySourceConfigurator#addSource(org.jboss.dna.graph.connector.RepositorySource)
*/
- public ReturnType addRepository( RepositorySource source ) {
+ public ReturnType addSource( RepositorySource source ) {
CheckArg.isNotNull(source, "source");
CheckArg.isNotEmpty(source.getName(), "source.getName()");
String name = source.getName();
- RepositoryDetails<ReturnType> details = addRepository(source.getName()).usingClass(source.getClass().getName())
- .loadedFromClasspath();
+ RepositorySourceDetails<ReturnType> details = addSource(source.getName()).usingClass(source.getClass().getName())
+ .loadedFromClasspath();
// Record all of the bean properties ...
Path sourcePath = pathFactory().create(sourcesPath(), name);
recordBeanPropertiesInGraph(sourcePath, source);
@@ -281,7 +286,7 @@
public ChooseClass<MimeTypeDetector, MimeTypeDetectorDetails<ReturnType>> addMimeTypeDetector( String id ) {
CheckArg.isNotEmpty(id, "id");
// Now create the "dna:sequencer" node with the supplied id ...
- Path detectorPath = createOrReplaceNode(detectorsPath(), id);
+ Path detectorPath = createOrReplaceNode(detectorsPath(), id, DnaLexicon.READABLE_NAME, id);
MimeTypeDetectorDetails<ReturnType> details = new GraphMimeTypeDetectorDetails<ReturnType>(detectorPath, builder);
return new ClassChooser<MimeTypeDetector, MimeTypeDetectorDetails<ReturnType>>(detectorPath, details);
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -147,7 +147,7 @@
CheckArg.isNotNull(context, "context");
if (pathToConfigurationRoot == null) pathToConfigurationRoot = context.getValueFactories()
.getPathFactory()
- .create("/jcr:system");
+ .create("/dna:system");
this.sources = sources;
this.pathToConfigurationRoot = pathToConfigurationRoot;
this.configurationSourceName = configurationSourceName;
@@ -304,6 +304,12 @@
path.getLastSegment().getName().getLocalName());
properties.put(JcrLexicon.NAME, nameProperty);
+ // Attempt to set the configuration information as bean properties,
+ // if they exist on the RepositorySource object and are not already set to some value ...
+ setBeanPropertyIfExistsAndNotSet(source, "configurationSourceName", getConfigurationSourceName());
+ setBeanPropertyIfExistsAndNotSet(source, "configurationWorkspaceName", getConfigurationWorkspaceName());
+ setBeanPropertyIfExistsAndNotSet(source, "configurationPath", stringFactory.create(path));
+
// Now set all the properties that we can, ignoring any property that doesn't fit the pattern ...
Reflection reflection = new Reflection(source.getClass());
for (Map.Entry<Name, Property> entry : properties.entrySet()) {
@@ -417,6 +423,21 @@
return source;
}
+ protected boolean setBeanPropertyIfExistsAndNotSet( Object target,
+ String propertyName,
+ Object value ) {
+ Reflection reflection = new Reflection(target.getClass());
+ try {
+ if (reflection.invokeGetterMethodOnTarget(propertyName, target) == null) {
+ reflection.invokeSetterMethodOnTarget(propertyName, target, value);
+ return true;
+ }
+ return false;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
/**
* {@inheritDoc}
*/
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -36,6 +36,7 @@
import org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.repository.sequencer.MockSequencerA;
+import org.jboss.dna.repository.sequencer.MockStreamSequencerA;
import org.junit.Before;
import org.junit.Test;
@@ -74,7 +75,7 @@
@Test
public void shouldAllowSpecifyingConfigurationRepository() {
- DnaConfiguration config = configuration.withConfigurationRepository()
+ DnaConfiguration config = configuration.withConfigurationSource()
.usingClass("org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource")
.loadedFromClasspath()
.describedAs("description")
@@ -103,7 +104,7 @@
newSource.setRootNodeUuid(rootUuid);
// Update the configuration and save it ...
- configuration.addRepository(newSource).save();
+ configuration.addSource(newSource).save();
// Verify that the graph has been updated correctly ...
Subgraph subgraph = configuration.graph().getSubgraphOfDepth(3).at("/");
@@ -119,7 +120,7 @@
@Test
public void shouldAllowAddingRepositorySourceByClassNameAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class.getName())
.loadedFromClasspath()
.describedAs("description")
@@ -141,7 +142,7 @@
@Test
public void shouldAllowAddingRepositorySourceByClassNameAndClasspathAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class.getName())
.loadedFrom("cp1", "cp2")
.describedAs("description")
@@ -164,7 +165,7 @@
@Test
public void shouldAllowAddingRepositorySourceByClassReferenceAndSettingProperties() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("description")
.with("retryLimit")
@@ -186,13 +187,13 @@
@Test
public void shouldAllowOverwritingRepositorySourceByRepositoryName() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("description")
.with("retryLimit")
.setTo(3)
.and()
- .addRepository("Source1")
+ .addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("new description")
.with("retryLimit")
@@ -215,7 +216,7 @@
@Test
public void shouldAllowAddingMimeTypeDetector() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("description")
.and()
@@ -244,13 +245,13 @@
@Test
public void shouldAllowAddingSequencer() {
// Update the configuration and save it ...
- configuration.addRepository("Source1")
+ configuration.addSource("Source1")
.usingClass(InMemoryRepositorySource.class)
.describedAs("description")
.named("A Source")
.and()
.addSequencer("sequencerA")
- .usingClass(MockSequencerA.class)
+ .usingClass(MockStreamSequencerA.class)
.named("The (Main) Sequencer")
.describedAs("Mock Sequencer A")
.sequencingFrom("/foo/source")
@@ -273,7 +274,7 @@
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.READABLE_NAME, "The (Main) Sequencer"));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.DESCRIPTION, "Mock Sequencer A"));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.CLASSNAME,
- MockSequencerA.class.getName()));
+ MockStreamSequencerA.class.getName()));
System.out.println(subgraph.getNode("/dna:sequencers/sequencerA").getProperty(DnaLexicon.PATH_EXPRESSIONS));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.PATH_EXPRESSIONS,
"/foo/source => /foo/target",
@@ -282,7 +283,7 @@
@Test
public void shouldAllowConfigurationInMultipleSteps() {
- configuration.addRepository("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description");
+ configuration.addSource("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description");
configuration.addMimeTypeDetector("detector")
.usingClass(ExtensionBasedMimeTypeDetector.class)
.describedAs("default detector");
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -36,7 +36,7 @@
import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.mimetype.MimeTypeDetector;
-import org.jboss.dna.repository.sequencer.MockSequencerA;
+import org.jboss.dna.repository.sequencer.MockStreamSequencerA;
import org.jboss.dna.repository.sequencer.SequencingService;
import org.junit.Before;
import org.junit.Test;
@@ -60,7 +60,7 @@
@Test
public void shouldAllowCreatingWithConfigRepository() throws InterruptedException {
- engine = new DnaConfiguration().withConfigurationRepository()
+ engine = new DnaConfiguration().withConfigurationSource()
.usingClass(InMemoryRepositorySource.class)
.describedAs("Configuration Repository")
.with("name")
@@ -82,13 +82,13 @@
@Test
public void shouldAllowCreatingMultipleRepositories() throws Exception {
- engine = new DnaConfiguration().withConfigurationRepository()
+ engine = new DnaConfiguration().withConfigurationSource()
.usingClass(InMemoryRepositorySource.class)
.describedAs("Configuration Repository")
.with("name")
.setTo("config repo")
.and()
- .addRepository("JCR")
+ .addSource("JCR")
.usingClass(InMemoryRepositorySource.class)
.describedAs("Backing Repository for JCR Implementation")
.with("name")
@@ -115,7 +115,7 @@
@Test
public void shouldAllowAddingMimeTypeDetectors() throws Exception {
- engine = new DnaConfiguration().withConfigurationRepository()
+ engine = new DnaConfiguration().withConfigurationSource()
.usingClass(InMemoryRepositorySource.class)
.describedAs("Configuration Repository")
.with("name")
@@ -138,14 +138,14 @@
@Test
public void shouldAllowAddingSequencers() throws Exception {
- engine = new DnaConfiguration().withConfigurationRepository()
+ engine = new DnaConfiguration().withConfigurationSource()
.usingClass(InMemoryRepositorySource.class)
.describedAs("Configuration Repository")
.with("name")
.setTo("config repo")
.and()
.addSequencer("Mock Sequencer A")
- .usingClass(MockSequencerA.class)
+ .usingClass(MockStreamSequencerA.class)
.describedAs("A Mock Sequencer")
.sequencingFrom("/**")
.andOutputtingTo("/")
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml 2009-06-03 20:08:46 UTC (rev 967)
@@ -24,31 +24,31 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<Aircraft xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+<Aircraft xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns="http://jboss.org/dna/examples/aircraft/1.0">
<Business>
- <nt:unstructured jcr:name="Gulfstream V" maker="Gulfstream" model="G-V" introduced="1995" range="5800nm" cruiseSpeed="488kt" crew="2" emptyWeight="46200lb" url="http://en.wikipedia.org/wiki/Gulfstream_V"/>
- <nt:unstructured jcr:name="Learjet 45" maker="Learjet" model="LJ45" introduced="1995" numberBuilt="264+" crew="2" emptyWeight="13695lb" range="2120nm" cruiseSpeed="457kt" url="http://en.wikipedia.org/wiki/Learjet_45"/>
+ <Aircraft jcr:name="Gulfstream V" maker="Gulfstream" model="G-V" introduced="1995" range="5800nm" cruiseSpeed="488kt" crew="2" emptyWeight="46200lb" url="http://en.wikipedia.org/wiki/Gulfstream_V"/>
+ <Aircraft jcr:name="Learjet 45" maker="Learjet" model="LJ45" introduced="1995" numberBuilt="264+" crew="2" emptyWeight="13695lb" range="2120nm" cruiseSpeed="457kt" url="http://en.wikipedia.org/wiki/Learjet_45"/>
</Business>
<Commercial>
- <nt:unstructured jcr:name="Boeing 777" maker="Boeing" model="777-200LR" introduced="1995" numberBuilt="731+" maxRange="7500nm" emptyWeight="326000lb" cruiseSpeed="560mph" url="http://en.wikipedia.org/wiki/Boeing_777"/>
- <nt:unstructured jcr:name="Boeing 767" maker="Boeing" model="767-200" introduced="1982" numberBuilt="966+" maxRange="3950nm" emptyWeight="176650lb" cruiseSpeed="530mph" url="http://en.wikipedia.org/wiki/Boeing_767"/>
- <nt:unstructured jcr:name="Boeing 787" maker="Boeing" model="787-3" introduced="2009" range="3050nm" emptyWeight="223000lb" cruiseSpeed="561mph" url="http://en.wikipedia.org/wiki/Boeing_787"/>
- <nt:unstructured jcr:name="Boeing 757" maker="Boeing" model="757-200" introduced="1983" numberBuilt="1050" range="3900nm" maxWeight="255000lb" cruiseSpeed="530mph" url="http://en.wikipedia.org/wiki/Boeing_757"/>
- <nt:unstructured jcr:name="Airbus A380" maker="Airbus" model="A380-800" introduced="2007" numberBuilt="18" range="8200nm" maxWeight="1235000lb" cruiseSpeed="647mph" url="http://en.wikipedia.org/wiki/Airbus_a380"/>
- <nt:unstructured jcr:name="Airbus A340" maker="Airbus" model="A340-200" introduced="1993" numberBuilt="354" range="8000nm" maxWeight="606300lb" cruiseSpeed="557mph" url="http://en.wikipedia.org/wiki/Airbus_A-340"/>
- <nt:unstructured jcr:name="Airbus A310" maker="Airbus" model="A310-200" introduced="1983" numberBuilt="255" cruiseSpeed="850km/h" emptyWeight="176312lb" range="3670nm" url="http://en.wikipedia.org/wiki/Airbus_A-310"/>
- <nt:unstructured jcr:name="Embraer RJ-175" maker="Embraer" model="ERJ170-200" introduced="2004" range="3334km" cruiseSpeed="481kt" emptyWeight="21810kg" url="http://en.wikipedia.org/wiki/EMBRAER_170"/>
+ <Aircraft jcr:name="Boeing 777" maker="Boeing" model="777-200LR" introduced="1995" numberBuilt="731+" maxRange="7500nm" emptyWeight="326000lb" cruiseSpeed="560mph" url="http://en.wikipedia.org/wiki/Boeing_777"/>
+ <Aircraft jcr:name="Boeing 767" maker="Boeing" model="767-200" introduced="1982" numberBuilt="966+" maxRange="3950nm" emptyWeight="176650lb" cruiseSpeed="530mph" url="http://en.wikipedia.org/wiki/Boeing_767"/>
+ <Aircraft jcr:name="Boeing 787" maker="Boeing" model="787-3" introduced="2009" range="3050nm" emptyWeight="223000lb" cruiseSpeed="561mph" url="http://en.wikipedia.org/wiki/Boeing_787"/>
+ <Aircraft jcr:name="Boeing 757" maker="Boeing" model="757-200" introduced="1983" numberBuilt="1050" range="3900nm" maxWeight="255000lb" cruiseSpeed="530mph" url="http://en.wikipedia.org/wiki/Boeing_757"/>
+ <Aircraft jcr:name="Airbus A380" maker="Airbus" model="A380-800" introduced="2007" numberBuilt="18" range="8200nm" maxWeight="1235000lb" cruiseSpeed="647mph" url="http://en.wikipedia.org/wiki/Airbus_a380"/>
+ <Aircraft jcr:name="Airbus A340" maker="Airbus" model="A340-200" introduced="1993" numberBuilt="354" range="8000nm" maxWeight="606300lb" cruiseSpeed="557mph" url="http://en.wikipedia.org/wiki/Airbus_A-340"/>
+ <Aircraft jcr:name="Airbus A310" maker="Airbus" model="A310-200" introduced="1983" numberBuilt="255" cruiseSpeed="850km/h" emptyWeight="176312lb" range="3670nm" url="http://en.wikipedia.org/wiki/Airbus_A-310"/>
+ <Aircraft jcr:name="Embraer RJ-175" maker="Embraer" model="ERJ170-200" introduced="2004" range="3334km" cruiseSpeed="481kt" emptyWeight="21810kg" url="http://en.wikipedia.org/wiki/EMBRAER_170"/>
</Commercial>
<Vintage>
- <nt:unstructured jcr:name="Fokker Trimotor" maker="Fokker" model="F.VII" introduced="1925" cruiseSpeed="170km/h" emptyWeight="3050kg" crew="2" url="http://en.wikipedia.org/wiki/Fokker_trimotor"/>
- <nt:unstructured jcr:name="P-38 Lightning" maker="Lockheed" model="P-38" designedBy="Kelly Johnson" introduced="1941" numberBuilt="10037" rateOfClimb="4750ft/min" range="1300mi" emptyWeight="12780lb" crew="1" url="http://en.wikipedia.org/wiki/P-38_Lightning"/>
- <nt:unstructured jcr:name="A6M Zero" maker="Mitsubishi" model="A6M" designedBy="Jiro Horikoshi" introduced="1940" numberBuilt="11000" crew="1" emptyWeight="3704lb" serviceCeiling="33000ft" maxSpeed="331mph" range="1929mi" rateOfClimb="3100ft/min" url="http://en.wikipedia.org/wiki/A6M_Zero"/>
- <nt:unstructured jcr:name="Bf 109" maker="Messerschmitt" model="Bf 109" introduced="1937" url="http://en.wikipedia.org/wiki/BF_109"/>
- <nt:unstructured jcr:name="Wright Flyer" maker="Wright Brothers" introduced="1903" range="852ft" maxSpeed="30mph" emptyWeight="605lb" crew="1"/>
+ <Aircraft jcr:name="Fokker Trimotor" maker="Fokker" model="F.VII" introduced="1925" cruiseSpeed="170km/h" emptyWeight="3050kg" crew="2" url="http://en.wikipedia.org/wiki/Fokker_trimotor"/>
+ <Aircraft jcr:name="P-38 Lightning" maker="Lockheed" model="P-38" designedBy="Kelly Johnson" introduced="1941" numberBuilt="10037" rateOfClimb="4750ft/min" range="1300mi" emptyWeight="12780lb" crew="1" url="http://en.wikipedia.org/wiki/P-38_Lightning"/>
+ <Aircraft jcr:name="A6M Zero" maker="Mitsubishi" model="A6M" designedBy="Jiro Horikoshi" introduced="1940" numberBuilt="11000" crew="1" emptyWeight="3704lb" serviceCeiling="33000ft" maxSpeed="331mph" range="1929mi" rateOfClimb="3100ft/min" url="http://en.wikipedia.org/wiki/A6M_Zero"/>
+ <Aircraft jcr:name="Bf 109" maker="Messerschmitt" model="Bf 109" introduced="1937" url="http://en.wikipedia.org/wiki/BF_109"/>
+ <Aircraft jcr:name="Wright Flyer" maker="Wright Brothers" introduced="1903" range="852ft" maxSpeed="30mph" emptyWeight="605lb" crew="1"/>
</Vintage>
<Homebuilt>
- <nt:unstructured jcr:name="Long-EZ" maker="Rutan Aircraft Factory" model="61" emptyWeight="760lb" fuelCapacity="200L" maxSpeed="185kt" since="1976" range="1200nm" url="http://en.wikipedia.org/wiki/Rutan_Long-EZ"/>
- <nt:unstructured jcr:name="Cirrus VK-30" maker="Cirrus Design" model="VK-30" emptyWeight="2400lb" maxLoad="1200lb" maxSpeed="250mph" rateOfClimb="1500ft/min" range="1300mi" url="http://en.wikipedia.org/wiki/Cirrus_VK-30"/>
- <nt:unstructured jcr:name="Van's RV-4" maker="Van's Aircraft" model="RV-4" introduced="1980" emptyWeight="905lb" maxLoad="500lb" maxSpeed="200mph" rateOfClimb="2450ft/min" range="725mi" url="http://en.wikipedia.org/wiki/Van%27s_Aircraft_RV-4"/>
+ <Aircraft jcr:name="Long-EZ" maker="Rutan Aircraft Factory" model="61" emptyWeight="760lb" fuelCapacity="200L" maxSpeed="185kt" since="1976" range="1200nm" url="http://en.wikipedia.org/wiki/Rutan_Long-EZ"/>
+ <Aircraft jcr:name="Cirrus VK-30" maker="Cirrus Design" model="VK-30" emptyWeight="2400lb" maxLoad="1200lb" maxSpeed="250mph" rateOfClimb="1500ft/min" range="1300mi" url="http://en.wikipedia.org/wiki/Cirrus_VK-30"/>
+ <Aircraft jcr:name="Van's RV-4" maker="Van's Aircraft" model="RV-4" introduced="1980" emptyWeight="905lb" maxLoad="500lb" maxSpeed="200mph" rateOfClimb="2450ft/min" range="725mi" url="http://en.wikipedia.org/wiki/Van%27s_Aircraft_RV-4"/>
</Homebuilt>
</Aircraft>
\ No newline at end of file
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.xml
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.xml 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/resources/cars.xml 2009-06-03 20:08:46 UTC (rev 967)
@@ -24,25 +24,27 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<Cars xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+<Cars xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ xmlns="http://jboss.org/dna/examples/cars/1.0">
<Hybrid>
- <nt:unstructured jcr:name="Toyota Prius" maker="Toyota" model="Prius" year="2008" msrp="$21,500" userRating="4.2" valueRating="5" mpgCity="48" mpgHighway="45"/>
- <nt:unstructured jcr:name="Toyota Highlander" maker="Toyota" model="Highlander" year="2008" msrp="$34,200" userRating="4" valueRating="5" mpgCity="27" mpgHighway="25"/>
- <nt:unstructured jcr:name="Nissan Altima" maker="Nissan" model="Altima" year="2008" msrp="$18,260" mpgCity="23" mpgHighway="32"/>
+ <Car jcr:name="Toyota Prius" maker="Toyota" model="Prius" year="2008" msrp="$21,500" userRating="4.2" valueRating="5" mpgCity="48" mpgHighway="45"/>
+ <Car jcr:name="Toyota Highlander" maker="Toyota" model="Highlander" year="2008" msrp="$34,200" userRating="4" valueRating="5" mpgCity="27" mpgHighway="25"/>
+ <Car jcr:name="Nissan Altima" maker="Nissan" model="Altima" year="2008" msrp="$18,260" mpgCity="23" mpgHighway="32"/>
</Hybrid>
<Sports>
- <nt:unstructured jcr:name="Aston Martin DB9" maker="Aston Martin" model="DB9" year="2008" msrp="$171,600" userRating="5" mpgCity="12" mpgHighway="19" lengthInInches="185.5" wheelbaseInInches="108.0" engine="5,935 cc 5.9 liters V 12"/>
- <nt:unstructured jcr:name="Infiniti G37" maker="Infiniti" model="G37" year="2008" msrp="$34,900" userRating="3.5" valueRating="4" mpgCity="18" mpgHighway="24" />
+ <Car jcr:name="Aston Martin DB9" maker="Aston Martin" model="DB9" year="2008" msrp="$171,600" userRating="5" mpgCity="12" mpgHighway="19" lengthInInches="185.5" wheelbaseInInches="108.0" engine="5,935 cc 5.9 liters V 12"/>
+ <Car jcr:name="Infiniti G37" maker="Infiniti" model="G37" year="2008" msrp="$34,900" userRating="3.5" valueRating="4" mpgCity="18" mpgHighway="24" />
</Sports>
<Luxury>
- <nt:unstructured jcr:name="Cadillac DTS" maker="Cadillac" model="DTS" year="2008" engine="3.6-liter V6" userRating="0"/>
- <nt:unstructured jcr:name="Bentley Continental" maker="Bentley" model="Continental" year="2008" msrp="$170,990" mpgCity="10" mpgHighway="17" />
- <nt:unstructured jcr:name="Lexus IS350" maker="Lexus" model="IS350" year="2008" msrp="$36,305" mpgCity="18" mpgHighway="25" userRating="4" valueRating="5" />
+ <Car jcr:name="Cadillac DTS" maker="Cadillac" model="DTS" year="2008" engine="3.6-liter V6" userRating="0"/>
+ <Car jcr:name="Bentley Continental" maker="Bentley" model="Continental" year="2008" msrp="$170,990" mpgCity="10" mpgHighway="17" />
+ <Car jcr:name="Lexus IS350" maker="Lexus" model="IS350" year="2008" msrp="$36,305" mpgCity="18" mpgHighway="25" userRating="4" valueRating="5" />
</Luxury>
<Utility>
- <nt:unstructured jcr:name="Land Rover LR2" maker="Land Rover" model="LR2" year="2008" msrp="$33,985" userRating="4.5" valueRating="5" mpgCity="16" mpgHighway="23" />
- <nt:unstructured jcr:name="Land Rover LR3" maker="Land Rover" model="LR3" year="2008" msrp="$48,525" userRating="5" valueRating="2" mpgCity="12" mpgHighway="17" />
- <nt:unstructured jcr:name="Hummer H3" maker="Hummer" model="H3" year="2008" msrp="$30,595" userRating="3.5" valueRating="4" mpgCity="13" mpgHighway="16" />
- <nt:unstructured jcr:name="Ford F-150" maker="Ford" model="F-150" year="2008" msrp="$23,910" userRating="4" valueRating="1" mpgCity="14" mpgHighway="20" />
+ <Car jcr:name="Land Rover LR2" maker="Land Rover" model="LR2" year="2008" msrp="$33,985" userRating="4.5" valueRating="5" mpgCity="16" mpgHighway="23" />
+ <Car jcr:name="Land Rover LR3" maker="Land Rover" model="LR3" year="2008" msrp="$48,525" userRating="5" valueRating="2" mpgCity="12" mpgHighway="17" />
+ <Car jcr:name="Hummer H3" maker="Hummer" model="H3" year="2008" msrp="$30,595" userRating="3.5" valueRating="4" mpgCity="13" mpgHighway="16" />
+ <Car jcr:name="Ford F-150" maker="Ford" model="F-150" year="2008" msrp="$23,910" userRating="4" valueRating="1" mpgCity="14" mpgHighway="20" />
</Utility>
</Cars>
\ No newline at end of file
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2009-06-03 20:08:46 UTC (rev 967)
@@ -24,14 +24,58 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<jcr:system xmlns:dna="http://www.jboss.org/dna/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
- <dna:namespaces jcr:primaryType="dna:namespaces">
- </dna:namespaces>
+<configuration xmlns="http://www.jboss.org/dna/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
<!-- Define the sources from which content is made available -->
- <dna:sources jcr:primaryType="nt:unstructured">
- <dna:source jcr:name="SourceA" jcr:primaryType="nt:unstructured" dna:name="Cars" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" dna:retryLimit="3" defaultWorkspaceName="default"/>
- <dna:source jcr:name="SourceB" jcr:primaryType="nt:unstructured" dna:name="Aircraft" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" defaultWorkspaceName="default"/>
- <dna:source jcr:name="SourceC" jcr:primaryType="nt:unstructured" dna:name="Vehicles" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" defaultWorkspaceName="default"/>
- <dna:source jcr:name="SourceD" jcr:primaryType="nt:unstructured" dna:name="Cache" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" defaultWorkspaceName="default"/>
- </dna:sources>
-</jcr:system>
\ No newline at end of file
+ <sources jcr:primaryType="nt:unstructured">
+ <source jcr:name="Cars" classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" retryLimit="3" defaultWorkspaceName="default"/>
+ <source jcr:name="Aircraft" classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource">
+ <defaultWorkspaceName>default</defaultWorkspaceName>
+ </source>
+ <source jcr:name="Vehicles">
+ <classname>org.jboss.dna.graph.connector.federated.FederatedRepositorySource</classname>
+ <workspaces>
+ <workspace jcr:name="default">
+ <projections>
+ <projection jcr:name="Main projection" source="Cars" workspace="default">
+ <projectionRules>/Vehicles => /</projectionRules>
+ </projection>
+ </projections>
+ </workspace>
+ </workspaces>
+ </source>
+ <source jcr:name="Cache" classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource">
+ <defaultWorkspaceName>default</defaultWorkspaceName>
+ </source>
+ </sources>
+ <!-- Define the JCR repositories -->
+ <repositories>
+ <repository jcr:name="cars">
+ <!-- Specify the source that should be used for the repository -->
+ <source>Cars</source>
+ <!-- Define the options for the JCR repository, using camelcase version of JcrRepository.Option names -->
+ <options jcr:primaryType="dna:options"/>
+ <!-- Define any custom node types. Importing CND files via JcrConfiguration is equivalent to specifying here. -->
+ <nodeTypes jcr:primaryType="dna:nodeTypes"/>
+ <!-- Define any namespaces for this repository, other than those already defined by JCR or DNA -->
+ <namespaces jcr:primaryType="dna:namespaces">
+ <car jcr:primaryType="dna:namespace" dna:uri="http://jboss.org/dna/examples/cars/1.0"/>
+ </namespaces>
+ </repository>
+ <repository jcr:name="vehicles">
+ <!-- Specify the source that should be used for the repository -->
+ <source>Vehicles</source>
+ <!-- Define the options for the JCR repository, using camelcase version of JcrRepository.Option names -->
+ <options jcr:primaryType="dna:options">
+ <projectNodeTypes jcr:primaryType="dna:option" dna:value="false"/>
+ <jaasLoginConfigName jcr:primaryType="dna:option" dna:value="dna-jcr"/>
+ </options>
+ <!-- Define any custom node types. Importing CND files via JcrConfiguration is equivalent to specifying here. -->
+ <nodeTypes jcr:primaryType="dna:nodeTypes"/>
+ <!-- Define any namespaces for this repository, other than those already defined by JCR, DNA or by imported content. -->
+ <namespaces jcr:primaryType="dna:namespaces">
+ <car jcr:primaryType="dna:namespace" dna:uri="http://jboss.org/dna/examples/cars/1.0"/>
+ <air jcr:primaryType="dna:namespace" dna:uri="http://jboss.org/dna/examples/aircraft/1.0"/>
+ </namespaces>
+ </repository>
+ </repositories>
+</configuration>
\ No newline at end of file
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/ConsoleInput.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -41,10 +41,8 @@
public ConsoleInput( final SequencingClient client ) {
try {
System.out.println();
- System.out.print("Starting repository and sequencing service ... ");
+ System.out.print("Starting DNA repository and sequencing service ... ");
client.startRepository();
- System.out.print("done.\nStarting sequencing service ... ");
- client.startDnaServices();
System.out.println("done.");
System.out.println();
@@ -101,9 +99,7 @@
try {
// Terminate ...
System.out.println();
- System.out.print("Shutting down sequencing service ... ");
- client.shutdownDnaServices();
- System.out.print("done.\nShutting down repository ... ");
+ System.out.print("Shutting down repository ... ");
client.shutdownRepository();
System.out.print("done.");
System.out.println();
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-06-03 20:08:46 UTC (rev 967)
@@ -23,7 +23,6 @@
*/
package org.jboss.example.dna.sequencer;
-import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
@@ -32,7 +31,6 @@
import java.util.Properties;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
-import javax.jcr.Credentials;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
@@ -41,73 +39,97 @@
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
-import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
-import org.apache.jackrabbit.core.TransientRepository;
-import org.jboss.dna.common.SystemFailureException;
+import javax.security.auth.login.LoginException;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.repository.sequencer.SequencerConfig;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.jcr.JcrConfiguration;
+import org.jboss.dna.jcr.JcrEngine;
import org.jboss.dna.repository.sequencer.SequencingService;
import org.jboss.dna.repository.util.SessionFactory;
-import org.jboss.dna.repository.util.SimpleSessionFactory;
+import org.jboss.dna.sequencer.image.ImageMetadataSequencer;
+import org.jboss.dna.sequencer.java.JavaMetadataSequencer;
+import org.jboss.dna.sequencer.mp3.Mp3MetadataSequencer;
/**
* @author Randall Hauch
*/
public class SequencingClient {
- public static final String DEFAULT_JACKRABBIT_CONFIG_PATH = "jackrabbitConfig.xml";
- public static final String DEFAULT_WORKING_DIRECTORY = "repositoryData";
public static final String DEFAULT_REPOSITORY_NAME = "repo";
public static final String DEFAULT_WORKSPACE_NAME = "default";
public static final String DEFAULT_USERNAME = "jsmith";
public static final char[] DEFAULT_PASSWORD = "secret".toCharArray();
public static void main( String[] args ) {
- SequencingClient client = new SequencingClient();
- client.setRepositoryInformation(DEFAULT_REPOSITORY_NAME, DEFAULT_WORKSPACE_NAME, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+ // Set up an execution context in which we'll run, and authenticate using JAAS ...
+ ExecutionContext context = new ExecutionContext();
+ String jaasAppContext = "myAppContext";
+ String username = "jsmith";
+ char[] password = "secrete".toCharArray();
+ try {
+ context.with(jaasAppContext, username, password);
+ } catch (LoginException err) {
+ System.err.println("Error authenticating \"" + username + "\". Check username and password and try again.");
+ }
+
+ // Configure the DNA JCR engine ...
+ String repositoryId = "content";
+ String workspaceName = "default";
+ JcrConfiguration config = new JcrConfiguration(context);
+ config.withConfigurationSource().usingClass(InMemoryRepositorySource.class).usingWorkspace("default").under("/");
+ // Set up an in-memory repository where the uploaded and sequenced content will be stored ...
+ config.addSource(repositoryId)
+ .usingClass(InMemoryRepositorySource.class)
+ .withNodeTypes(ImageMetadataSequencer.class.getResource("org/jboss/dna/sequencer/image/images.cnd"))
+ .withNodeTypes(Mp3MetadataSequencer.class.getResource("org/jboss/dna/sequencer/mp3/mp3.cnd"))
+ .withNodeTypes(JavaMetadataSequencer.class.getResource("org/jboss/dna/sequencer/java/javaSource.cnd"))
+ .named("Content Repository")
+ .describedAs("The repository for our content")
+ .with("defaultWorkspaceName")
+ .setTo(workspaceName);
+ // Set up the image sequencer ...
+ config.addSequencer("images")
+ .usingClass("org.jboss.dna.sequencer.image.ImageMetadataSequencer")
+ .loadedFromClasspath()
+ .describedAs("Sequences image files to extract the characteristics of the image")
+ .named("Image Sequencer")
+ .sequencingFrom("//(*.(jpg|jpeg|gif|bmp|pcx|png|iff|ras|pbm|pgm|ppm|psd)[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/images/$1");
+ // Set up the MP3 sequencer ...
+ config.addSequencer("mp3s")
+ .usingClass(Mp3MetadataSequencer.class)
+ .named("MP3 Sequencer")
+ .describedAs("Sequences mp3 files to extract the id3 tags of the audio file")
+ .sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/mp3s/$1");
+ // Set up the Java source file sequencer ...
+ config.addSequencer("javaSource")
+ .usingClass(JavaMetadataSequencer.class)
+ .named("Java Sequencer")
+ .describedAs("Sequences mp3 files to extract the id3 tags of the audio file")
+ .sequencingFrom("//(*.mp3[*])/jcr:content[@jcr:data]")
+ .andOutputtingTo("/mp3s/$1");
+
+ // Now start the client and tell it which repository and workspace to use ...
+ SequencingClient client = new SequencingClient(config, repositoryId, workspaceName);
client.setUserInterface(new ConsoleInput(client));
}
- private String repositoryName;
- private String workspaceName;
- private String username;
- private char[] password;
- private String jackrabbitConfigPath;
- private String workingDirectory;
- private Session keepAliveSession;
- private Repository repository;
- private SequencingService sequencingService;
+ private final String repositoryName;
+ private final String workspaceName;
+ private final JcrConfiguration configuration;
+ private JcrEngine engine;
private UserInterface userInterface;
- private ExecutionContext executionContext;
+ private Repository repository;
- public SequencingClient() {
- setJackrabbitConfigPath(DEFAULT_JACKRABBIT_CONFIG_PATH);
- setWorkingDirectory(DEFAULT_WORKING_DIRECTORY);
- setRepositoryInformation(DEFAULT_REPOSITORY_NAME, DEFAULT_WORKSPACE_NAME, DEFAULT_USERNAME, DEFAULT_PASSWORD);
- }
-
- protected void setWorkingDirectory( String workingDirectoryPath ) {
- this.workingDirectory = workingDirectoryPath != null ? workingDirectoryPath : DEFAULT_WORKING_DIRECTORY;
- }
-
- protected void setJackrabbitConfigPath( String jackrabbitConfigPath ) {
- this.jackrabbitConfigPath = jackrabbitConfigPath != null ? jackrabbitConfigPath : DEFAULT_JACKRABBIT_CONFIG_PATH;
- }
-
- protected void setRepositoryInformation( String repositoryName,
- String workspaceName,
- String username,
- char[] password ) {
- if (this.repository != null) {
- throw new IllegalArgumentException("Unable to set repository information when repository is already running");
- }
+ public SequencingClient( JcrConfiguration config,
+ String repositoryName,
+ String workspaceName ) {
+ this.configuration = config;
this.repositoryName = repositoryName != null ? repositoryName : DEFAULT_REPOSITORY_NAME;
this.workspaceName = workspaceName != null ? workspaceName : DEFAULT_WORKSPACE_NAME;
- this.username = username;
- this.password = password;
}
/**
@@ -127,53 +149,15 @@
public void startRepository() throws Exception {
if (this.repository == null) {
try {
+ // Start the DNA engine ...
+ this.engine = this.configuration.build();
+ this.engine.start();
- // Load the Jackrabbit configuration ...
- File configFile = new File(this.jackrabbitConfigPath);
- if (!configFile.exists()) {
- throw new SystemFailureException("The Jackrabbit configuration file cannot be found at "
- + configFile.getAbsoluteFile());
- }
- if (!configFile.canRead()) {
- throw new SystemFailureException("Unable to read the Jackrabbit configuration file at "
- + configFile.getAbsoluteFile());
- }
- String pathToConfig = configFile.getAbsolutePath();
+ // Now get the repository instance ...
+ this.repository = this.engine.getRepository(repositoryName);
- // Find the directory where the Jackrabbit repository data will be stored ...
- File workingDirectory = new File(this.workingDirectory);
- if (workingDirectory.exists()) {
- if (!workingDirectory.isDirectory()) {
- throw new SystemFailureException("Unable to create working directory at "
- + workingDirectory.getAbsolutePath());
- }
- }
- String workingDirectoryPath = workingDirectory.getAbsolutePath();
-
- // Get the Jackrabbit custom node definition (CND) file ...
- URL cndFile = Thread.currentThread().getContextClassLoader().getResource("jackrabbitNodeTypes.cnd");
-
- // Create the Jackrabbit repository instance and establish a session to keep the repository alive ...
- this.repository = new TransientRepository(pathToConfig, workingDirectoryPath);
- if (this.username != null) {
- Credentials credentials = new SimpleCredentials(this.username, this.password);
- this.keepAliveSession = this.repository.login(credentials, this.workspaceName);
- } else {
- this.keepAliveSession = this.repository.login();
- }
-
- try {
- // Register the node types (only valid the first time) ...
- JackrabbitNodeTypeManager mgr = (JackrabbitNodeTypeManager)this.keepAliveSession.getWorkspace()
- .getNodeTypeManager();
- mgr.registerNodeTypes(cndFile.openStream(), JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
- } catch (RepositoryException e) {
- if (!e.getMessage().contains("already exists")) throw e;
- }
-
} catch (Exception e) {
this.repository = null;
- this.keepAliveSession = null;
throw e;
}
}
@@ -187,104 +171,21 @@
public void shutdownRepository() throws Exception {
if (this.repository != null) {
try {
- this.keepAliveSession.logout();
+ this.engine.shutdown();
+ this.engine.awaitTermination(4, TimeUnit.SECONDS);
} finally {
this.repository = null;
- this.keepAliveSession = null;
}
}
}
/**
- * Start the DNA services.
- *
- * @throws Exception
- */
- public void startDnaServices() throws Exception {
- if (this.repository == null) {
- this.startRepository();
- }
- if (this.sequencingService == null) {
-
- // Create an execution context for the sequencing service. This execution context provides an environment
- // for the DNA services which knows about the JCR repositories, workspaces, and credentials used to
- // establish sessions to these workspaces.
- final String repositoryWorkspaceName = this.repositoryName + "/" + this.workspaceName;
- SimpleSessionFactory sessionFactory = new SimpleSessionFactory();
- sessionFactory.registerRepository(this.repositoryName, this.repository);
- if (this.username != null) {
- Credentials credentials = new SimpleCredentials(this.username, this.password);
- sessionFactory.registerCredentials(repositoryWorkspaceName, credentials);
- }
- this.executionContext = new ExecutionContext();
-
- // Create the sequencing service, passing in the execution context and the repository library ...
- this.sequencingService = new SequencingService();
- this.sequencingService.setExecutionContext(executionContext);
- // this.sequencingService.setRepositoryLibrary(repositoryLibrary);
-
- // Configure the sequencers. In this example, we only two sequencers that processes image and mp3 files.
- // So create a configurations. Note that the sequencing service expects the class to be on the thread's current
- // context
- // classloader, or if that's null the classloader that loaded the SequencingService class.
- //
- // Part of the configuration includes telling DNA which JCR paths should be processed by the sequencer.
- // These path expressions tell the service that this sequencer should be invoked on the "jcr:data" property
- // on the "jcr:content" child node of any node uploaded to the repository whose name ends with one of the
- // supported extensions, and the sequencer should place the generated output metadata in a node with the same name as
- // the file but immediately below the "/images" node. Path expressions can be fairly complex, and can even
- // specify that the generated information be placed in a different repository.
- //
- // Sequencer configurations can be added before or after the service is started, but here we do it before the service
- // is running.
- String name = "Image Sequencer";
- String desc = "Sequences image files to extract the characteristics of the image";
- String classname = "org.jboss.dna.sequencer.image.ImageMetadataSequencer";
- String[] classpath = null; // Use the current classpath
- String[] pathExpressions = {"//(*.(jpg|jpeg|gif|bmp|pcx|png|iff|ras|pbm|pgm|ppm|psd)[*])/jcr:content[@jcr:data] => /images/$1"};
- SequencerConfig imageSequencerConfig = new SequencerConfig(name, desc, classname, classpath, pathExpressions);
- this.sequencingService.addSequencer(imageSequencerConfig);
-
- // Set up the MP3 sequencer ...
- name = "Mp3 Sequencer";
- desc = "Sequences mp3 files to extract the id3 tags of the audio file";
- classname = "org.jboss.dna.sequencer.mp3.Mp3MetadataSequencer";
- String[] mp3PathExpressions = {"//(*.mp3[*])/jcr:content[@jcr:data] => /mp3s/$1"};
- SequencerConfig mp3SequencerConfig = new SequencerConfig(name, desc, classname, classpath, mp3PathExpressions);
- this.sequencingService.addSequencer(mp3SequencerConfig);
-
- // Set up the MP3 sequencer ...
- name = "Java Sequencer";
- desc = "Sequences java files to extract the characteristics of the java sources";
- classname = "org.jboss.dna.sequencer.java.JavaMetadataSequencer";
- String[] javaPathExpressions = {"//(*.java[*])/jcr:content[@jcr:data] => /java/$1"};
- SequencerConfig javaSequencerConfig = new SequencerConfig(name, desc, classname, classpath, javaPathExpressions);
- this.sequencingService.addSequencer(javaSequencerConfig);
- }
- // Start up the sequencing service ...
- this.sequencingService.getAdministrator().start();
- }
-
- /**
- * Shut down the DNA services.
- *
- * @throws Exception
- */
- public void shutdownDnaServices() throws Exception {
- if (this.sequencingService == null) return;
-
- // Shut down the service and wait until it's all shut down ...
- this.sequencingService.getAdministrator().shutdown();
- this.sequencingService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);
- }
-
- /**
* Get the sequencing statistics.
*
* @return the statistics; never null
*/
public SequencingService.Statistics getStatistics() {
- return this.sequencingService.getStatistics();
+ return this.engine.getSequencingService().getStatistics();
}
/**
@@ -538,7 +439,7 @@
* @throws RepositoryException
*/
protected Session createSession() throws RepositoryException {
- throw new UnsupportedOperationException();
+ return this.repository.login(workspaceName);
}
protected String getMimeType( URL file ) {
Deleted: trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd 2009-06-03 20:07:47 UTC (rev 966)
+++ trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd 2009-06-03 20:08:46 UTC (rev 967)
@@ -1,257 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-/**
- * @author Serge Pagop (serge.pagop(a)innoq.com)
- */
-
-//------------------------------------------------------------------------------
-// N A M E S P A C E S
-//------------------------------------------------------------------------------
-<java='http://www.jboss.org/dna/java/1.0'>
-<nt='http://www.jcp.org/jcr/nt/1.0'>
-<mix='http://www.jcp.org/jcr/mix/1.0'>
-
-//------------------------------------------------------------------------------
-// B A S E T Y P E S
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-// V E R S I O N I N G
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-// N O D E T Y P E S
-//------------------------------------------------------------------------------
-
-/**
- * Element-value
- */
-[java:elementValue] > nt:unstructured
- + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
-
-/**
- * Modifiers
- */
-[java:modifierDeclaration] > nt:unstructured
- - java:modifierName (string) mandatory
-
-/**
- * Expression element-value type
- */
-[java:conditionalExpression] > nt:unstructured
- - java:expression (string)
-
-/**
- * Array initializer element-value type
- */
-[java:elementValueArrayInitializer] > nt:unstructured
- + java:elementValue (java:elementValue) = java:elementValue multiple
-
-/**
- * Identifier
- */
-[java:identifier] > nt:unstructured
- - java:identifierName (String) mandatory
- + java:value (java:elementValue) = java:elementValue mandatory
-
-/**
- * Element-value pair
- */
-[java:elementValuePair] > nt:unstructured
- + java:identifier (java:identifier) mandatory
-
-/**
- * Annotation type
- */
-[java:annotationDeclaration] > nt:unstructured
- + java:annotationType (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
-
-/**
- * Normal annotation e.g. @Entity(name="Customer")
- */
-[java:normalAnnotation] > nt:unstructured
- - java:normalAnnotationName (string) mandatory
- + java:elementValuePair (java:elementValuePair)
-
-/**
- * Marker annotation e.g. @GET
- */
-[java:markerAnnotation] > nt:unstructured
- - java:markerAnnotationName (string) mandatory
-
-/**
- * Single element annotation e.g. @Path("/book")
- */
-[java:singleElementAnnotation] > nt:unstructured
- - java:singleElementAnnotationNam
- + java:value (java:elementValue) = java:elementValue mandatory
-
-/**
- * Formal parameter
- */
-[java:formalParameter] > nt:unstructured
- + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType)
-
-/**
- * Primitive type:
- * - Integral type ('byte', 'short', 'int', 'long', 'char')
- * - Floating point type ('float', 'double')
- * - Boolean type ('boolean')
- * - No return type ('void')
- */
-[java:primitiveType] > nt:unstructured
- - java:primitiveTypeDescription (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:primitiveTypeName (string) mandatory
- + java:primitiveVariable (java:variable) = java:variable
-
- [java:variable] > nt:unstructured
- - java:variableName (string) mandatory
-
-/**
- * java:arrayType
- */
-[java:arrayType] > nt:unstructured
- - java:arrayTypeDescription (string)
- + java:arrayTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:arrayTypeName (string) mandatory
- + java:arrayTypeVariable (java:variable) = java:variable
-
-[java:simpleType] > nt:unstructured
- - java:simpleTypeDescription (string)
- + java:simpleTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:simpleTypeName (string) mandatory
- + java:simpleTypeVariable (java:variable) = java:variable
-
-[java:qualifiedType] > nt:unstructured
- - java:qualifiedTypeDescription (string)
- + java:qualifiedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:qualifiedTypeName (string) mandatory
- + java:qualifiedTypeVariable (java:variable) = java:variable
-
-[java:wildcardType] > nt:unstructured
- - java:wildcardTypeDescription (string)
- + java:wildcardTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:wildcardTypeName (string) mandatory
- + java:wildcardTypeVariable (java:variable) = java:variable
-
-[java:parameterizedType] > nt:unstructured
- - java:parameterizedTypeDescription (string)
- + java:parameterizedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:parameterizedTypeName (string) mandatory
- + java:parameterizedTypeVariable (java:variable) = java:variable
-
-/**
- * Field type
- */
-[java:fieldType] > nt:unstructured
- + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory multiple
-
- /**
- * Method declaration
- */
-[java:methodDeclaration] > nt:unstructured
- - java:methodDescription (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- + java:resultType (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory
- - java:methodName (string) mandatory
- + java:parameter (java:formalParameter) multiple
-
-/**
- * Constructor declarations
- */
-[java:constructorDeclaration] > nt:unstructured
- - java:constructorDescription (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:constructorName (string) mandatory
- + java:parameter (java:formalParameter)
-
-
-/**
- * Package declarations
- */
-[java:packageDeclaration] > nt:unstructured
- + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
- - java:packageKeyword (string)
- < 'package'
- - java:packageName (string) mandatory
-
-/**
- * Import declarations
- */
-[java:singleTypeImportDeclaration] > nt:unstructured
- - java:singleTypeImportkeyword (string) mandatory
- < 'import'
- - java:singleImportName (string) mandatory
-
-[java:typeImportOnDemandDeclaration] > nt:unstructured
- - java:onDemandImportKeyword (string) mandatory
- < 'import'
- - java:onDemandImportName (string) mandatory
-
- [java:importDeclaration] > nt:unstructured
- + java:singleImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
- + java:importOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
-
-
-/**
- * Class declaration
- *
- * The body of class declares members (fields and methods and nested classes and interfaces),
- * instance and static initializers, and constructors
- */
-[java:normalClassDeclaration] > nt:unstructured
- - java:description (string)
- + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- - java:normalClassName (string) mandatory
- + java:field (java:fieldType) = java:fieldType multiple
- + java:method (java:methodDeclaration) = java:methodDeclaration multiple
- + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
-
-[java:enumDeclaration] > nt:unstructured // TODO
-
-[java:classDeclaration] > nt:unstructured
- + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
- + java:enum (java:enumDeclaration) = java:enumDeclaration
-
-/**
- * Interface declaration
- *
- * The body of class declares members (fields and methods and nested classes and interfaces),
- * instance and static initializers, and constructors
- */
- //TODO
-[java:interfaceDeclaration] > nt:unstructured
-
-
-/**
- * Compilation unit
- */
-[java:compilationUnit] > nt:unstructured
- + java:package (java:packageDeclaration) = java:packageDeclaration
- + java:import (java:importDeclaration) = java:importDeclaration
- + java:unitType (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
Copied: trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd (from rev 966, trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd)
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd (rev 0)
+++ trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/javaSource.cnd 2009-06-03 20:08:46 UTC (rev 967)
@@ -0,0 +1,257 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+/**
+ * @author Serge Pagop (serge.pagop(a)innoq.com)
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<java='http://www.jboss.org/dna/java/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+
+//------------------------------------------------------------------------------
+// B A S E T Y P E S
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// V E R S I O N I N G
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+/**
+ * Element-value
+ */
+[java:elementValue] > nt:unstructured
+ + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
+
+/**
+ * Modifiers
+ */
+[java:modifierDeclaration] > nt:unstructured
+ - java:modifierName (string) mandatory
+
+/**
+ * Expression element-value type
+ */
+[java:conditionalExpression] > nt:unstructured
+ - java:expression (string)
+
+/**
+ * Array initializer element-value type
+ */
+[java:elementValueArrayInitializer] > nt:unstructured
+ + java:elementValue (java:elementValue) = java:elementValue multiple
+
+/**
+ * Identifier
+ */
+[java:identifier] > nt:unstructured
+ - java:identifierName (String) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Element-value pair
+ */
+[java:elementValuePair] > nt:unstructured
+ + java:identifier (java:identifier) mandatory
+
+/**
+ * Annotation type
+ */
+[java:annotationDeclaration] > nt:unstructured
+ + java:annotationType (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
+
+/**
+ * Normal annotation e.g. @Entity(name="Customer")
+ */
+[java:normalAnnotation] > nt:unstructured
+ - java:normalAnnotationName (string) mandatory
+ + java:elementValuePair (java:elementValuePair)
+
+/**
+ * Marker annotation e.g. @GET
+ */
+[java:markerAnnotation] > nt:unstructured
+ - java:markerAnnotationName (string) mandatory
+
+/**
+ * Single element annotation e.g. @Path("/book")
+ */
+[java:singleElementAnnotation] > nt:unstructured
+ - java:singleElementAnnotationNam
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Formal parameter
+ */
+[java:formalParameter] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType)
+
+/**
+ * Primitive type:
+ * - Integral type ('byte', 'short', 'int', 'long', 'char')
+ * - Floating point type ('float', 'double')
+ * - Boolean type ('boolean')
+ * - No return type ('void')
+ */
+[java:primitiveType] > nt:unstructured
+ - java:primitiveTypeDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:primitiveTypeName (string) mandatory
+ + java:primitiveVariable (java:variable) = java:variable
+
+ [java:variable] > nt:unstructured
+ - java:variableName (string) mandatory
+
+/**
+ * java:arrayType
+ */
+[java:arrayType] > nt:unstructured
+ - java:arrayTypeDescription (string)
+ + java:arrayTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:arrayTypeName (string) mandatory
+ + java:arrayTypeVariable (java:variable) = java:variable
+
+[java:simpleType] > nt:unstructured
+ - java:simpleTypeDescription (string)
+ + java:simpleTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:simpleTypeName (string) mandatory
+ + java:simpleTypeVariable (java:variable) = java:variable
+
+[java:qualifiedType] > nt:unstructured
+ - java:qualifiedTypeDescription (string)
+ + java:qualifiedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:qualifiedTypeName (string) mandatory
+ + java:qualifiedTypeVariable (java:variable) = java:variable
+
+[java:wildcardType] > nt:unstructured
+ - java:wildcardTypeDescription (string)
+ + java:wildcardTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:wildcardTypeName (string) mandatory
+ + java:wildcardTypeVariable (java:variable) = java:variable
+
+[java:parameterizedType] > nt:unstructured
+ - java:parameterizedTypeDescription (string)
+ + java:parameterizedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:parameterizedTypeName (string) mandatory
+ + java:parameterizedTypeVariable (java:variable) = java:variable
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:methodDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ + java:resultType (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory
+ - java:methodName (string) mandatory
+ + java:parameter (java:formalParameter) multiple
+
+/**
+ * Constructor declarations
+ */
+[java:constructorDeclaration] > nt:unstructured
+ - java:constructorDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:constructorName (string) mandatory
+ + java:parameter (java:formalParameter)
+
+
+/**
+ * Package declarations
+ */
+[java:packageDeclaration] > nt:unstructured
+ + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
+ - java:packageKeyword (string)
+ < 'package'
+ - java:packageName (string) mandatory
+
+/**
+ * Import declarations
+ */
+[java:singleTypeImportDeclaration] > nt:unstructured
+ - java:singleTypeImportkeyword (string) mandatory
+ < 'import'
+ - java:singleImportName (string) mandatory
+
+[java:typeImportOnDemandDeclaration] > nt:unstructured
+ - java:onDemandImportKeyword (string) mandatory
+ < 'import'
+ - java:onDemandImportName (string) mandatory
+
+ [java:importDeclaration] > nt:unstructured
+ + java:singleImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
+ + java:importOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
+
+
+/**
+ * Class declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:normalClassDeclaration] > nt:unstructured
+ - java:description (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:normalClassName (string) mandatory
+ + java:field (java:fieldType) = java:fieldType multiple
+ + java:method (java:methodDeclaration) = java:methodDeclaration multiple
+ + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
+
+[java:enumDeclaration] > nt:unstructured // TODO
+
+[java:classDeclaration] > nt:unstructured
+ + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
+ + java:enum (java:enumDeclaration) = java:enumDeclaration
+
+/**
+ * Interface declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+ //TODO
+[java:interfaceDeclaration] > nt:unstructured
+
+
+/**
+ * Compilation unit
+ */
+[java:compilationUnit] > nt:unstructured
+ + java:package (java:packageDeclaration) = java:packageDeclaration
+ + java:import (java:importDeclaration) = java:importDeclaration
+ + java:unitType (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
16 years, 6 months