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...,
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
/**