Author: rhauch
Date: 2009-04-22 10:05:41 -0400 (Wed, 22 Apr 2009)
New Revision: 846
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfigurationException.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/mimetype/MimeTypeDetectorConfig.java
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
trunk/dna-repository/src/test/java/org/jboss/dna/repository/mimetype/AbstractMimeTypeTest.java
Log:
DNA-58 Create repository configuration and component
Applied the second patch, which added DnaConfiguration and DnaEngine classes (along with
test cases), and the MimeTypeDetectorConfig class (and its test cases).
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
(rev 0)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -0,0 +1,917 @@
+/*
+ * 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.HashMap;
+import java.util.List;
+import java.util.Map;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.component.ClassLoaderFactory;
+import org.jboss.dna.common.i18n.I18n;
+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.PathExpression;
+import org.jboss.dna.graph.sequencer.StreamSequencer;
+import org.jboss.dna.repository.mimetype.MimeTypeDetectorConfig;
+import org.jboss.dna.repository.sequencer.Sequencer;
+import org.jboss.dna.repository.sequencer.SequencerConfig;
+import org.jboss.dna.repository.sequencer.StreamSequencerAdapter;
+
+/**
+ */
+@Immutable
+public class DnaConfiguration {
+
+ protected RepositorySource configurationSource;
+ protected String configurationSourceDescription;
+ protected Graph configuration;
+ private final ExecutionContext context;
+
+ /**
+ * Mapping of repository names to configured repositories
+ */
+ protected final Map<String, DnaRepositoryDetails> repositories;
+ protected final Map<String, DnaMimeTypeDetectorDetails> mimeTypeDetectors;
+ protected final Map<String, DnaSequencerDetails> sequencers;
+
+ /**
+ * Create a new configuration for DNA.
+ */
+ public DnaConfiguration() {
+ this(new ExecutionContext());
+ }
+
+ /**
+ * 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
+ */
+ public DnaConfiguration( ExecutionContext context ) {
+ this.context = context;
+ this.repositories = new HashMap<String, DnaRepositoryDetails>();
+ this.mimeTypeDetectors = new HashMap<String,
DnaMimeTypeDetectorDetails>();
+ this.sequencers = new HashMap<String, DnaSequencerDetails>();
+
+ // Set up the default configuration repository ...
+ this.configurationSource = createDefaultConfigurationSource();
+
+ }
+
+ private DnaConfiguration( DnaConfiguration source ) {
+ this.configuration = source.configuration;
+ this.configurationSource = source.configurationSource;
+ this.context = source.context;
+ this.configurationSourceDescription = source.configurationSourceDescription;
+ this.repositories = new HashMap<String,
DnaRepositoryDetails>(source.repositories);
+ this.mimeTypeDetectors = new HashMap<String,
DnaMimeTypeDetectorDetails>(source.mimeTypeDetectors);
+ this.sequencers = new HashMap<String,
DnaSequencerDetails>(source.sequencers);
+ }
+
+ private DnaConfiguration with( String repositoryName,
+ DnaRepositoryDetails details ) {
+ DnaConfiguration newConfig = new DnaConfiguration(this);
+ newConfig.repositories.put(repositoryName, details);
+
+ return newConfig;
+ }
+
+ protected ExecutionContext getExecutionContext() {
+ return this.context;
+ }
+
+ protected Graph getConfiguration() {
+ if (this.configuration == null) {
+ this.configuration = Graph.create(configurationSource, context);
+ }
+ return this.configuration;
+ }
+
+ /**
+ * 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 RepositorySource createDefaultConfigurationSource() {
+ this.withConfigurationRepository()
+ .usingClass(InMemoryRepositorySource.class.getName())
+ .loadedFromClasspath()
+ .describedAs("Configuration Repository")
+ .with("name")
+ .setTo("Configuration");
+ return configurationSource;
+ }
+
+ /**
+ * 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 repository source that will
+ * be used for the configuration repository; never null
+ */
+ public ChooseClass<RepositorySource, RepositoryDetails>
withConfigurationRepository() {
+ return addRepository(DnaEngine.CONFIGURATION_REPOSITORY_NAME);
+ }
+
+ /**
+ * 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 name the name 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 #addRepository(RepositorySource)
+ */
+ public ChooseClass<RepositorySource, RepositoryDetails> addRepository( final
String name ) {
+ return new ClassChooser<RepositorySource, RepositoryDetails>() {
+
+ @Override
+ protected RepositoryDetails getComponentBuilder( String className,
+ String... classpath ) {
+ try {
+ Class<?> clazz = Class.forName(className);
+ Object newInstance = clazz.newInstance();
+ assert newInstance instanceof RepositorySource;
+
+ DnaRepositoryDetails details = new
DnaRepositoryDetails((RepositorySource)newInstance);
+ DnaConfiguration.this.repositories.put(name, details);
+
+ return details;
+ } catch (Exception ex) {
+ throw new DnaConfigurationException(ex);
+ }
+ }
+ };
+ }
+
+ /**
+ * 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 #addRepository(String)
+ */
+ public DnaConfiguration addRepository( RepositorySource source ) {
+ return this.with(source.getName(), new DnaRepositoryDetails(source));
+ }
+
+ /**
+ * Add a new {@link Sequencer sequencer} to this configuration. The new sequencer
will have the supplied name, and if the name
+ * of an existing sequencer is used, this will replace the existing sequencer
configuration.
+ *
+ * @param name the name of the new sequencer
+ * @return the interface for choosing the class, which returns the interface used to
configure the sequencer; never null
+ * @throws IllegalArgumentException if the sequencer name is null, empty, or
otherwise invalid
+ */
+ public ChooseClass<Sequencer, SequencerDetails> addSequencer( final String name
) {
+ return new ClassChooser<Sequencer, SequencerDetails>() {
+
+ @Override
+ protected SequencerDetails getComponentBuilder( String className,
+ String... classpath ) {
+ try {
+ Class<?> clazz = Class.forName(className);
+ Object newInstance = clazz.newInstance();
+ assert newInstance instanceof Sequencer;
+
+ DnaSequencerDetails details = new DnaSequencerDetails(name,
(Sequencer)newInstance, classpath);
+ DnaConfiguration.this.sequencers.put(name, details);
+
+ return details;
+ } catch (Exception ex) {
+ throw new DnaConfigurationException(ex);
+ }
+ }
+ };
+ }
+
+ /**
+ * Add a new {@link StreamSequencer sequencer} to this configuration. The new stream
sequencer will have the supplied name,
+ * and if the name of an existing sequencer is used, this will replace the existing
sequencer configuration.
+ *
+ * @param name the name of the new sequencer
+ * @return the interface for choosing the class, which returns the interface used to
configure the stream sequencer; never
+ * null
+ * @throws IllegalArgumentException if the sequencer name is null, empty, or
otherwise invalid
+ */
+ public ChooseClass<StreamSequencer, SequencerDetails> addStreamSequencer( final
String name ) {
+ return new ClassChooser<StreamSequencer, SequencerDetails>() {
+
+ @Override
+ protected SequencerDetails getComponentBuilder( String className,
+ String... classpath ) {
+ try {
+ Class<?> clazz = Class.forName(className);
+ Object newInstance = clazz.newInstance();
+ assert newInstance instanceof StreamSequencer;
+
+ DnaSequencerDetails details = new DnaSequencerDetails(
+ name,
+ new
StreamSequencerAdapter((StreamSequencer)newInstance),
+ classpath);
+ DnaConfiguration.this.sequencers.put(name, details);
+
+ return details;
+ } catch (Exception ex) {
+ throw new DnaConfigurationException(ex);
+ }
+ }
+ };
+ }
+
+ /**
+ * 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 name the name 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>
addMimeTypeDetector( final String name ) {
+ return new ClassChooser<MimeTypeDetector, MimeTypeDetectorDetails>() {
+
+ @Override
+ protected MimeTypeDetectorDetails getComponentBuilder( String className,
+ String... classpath )
{
+ try {
+ Class<?> clazz = Class.forName(className);
+ Object newInstance = clazz.newInstance();
+ assert newInstance instanceof MimeTypeDetector;
+
+ DnaMimeTypeDetectorDetails details = new
DnaMimeTypeDetectorDetails(name, (MimeTypeDetector)newInstance,
+
classpath);
+ DnaConfiguration.this.mimeTypeDetectors.put(name, details);
+
+ return details;
+ } catch (Exception ex) {
+ throw new DnaConfigurationException(ex);
+ }
+ }
+ };
+ }
+
+ /**
+ * Complete this configuration and create the corresponding engine.
+ *
+ * @return the new engine configured by this instance
+ */
+ public DnaEngine build() {
+ return new DnaEngine(this);
+ }
+
+ /**
+ * Interface used to configure a {@link RepositorySource repository}.
+ */
+ public interface RepositoryDetails
+ extends SetDescription<RepositoryDetails>,
SetProperties<RepositoryDetails>, ConfigurationBuilder {
+
+ RepositorySource getRepositorySource();
+ }
+
+ /**
+ * Local implementation of the {@link MimeTypeDetectorDetails} interface that tracks
all of the user-provided configuration
+ * details.
+ */
+ protected class DnaMimeTypeDetectorDetails implements MimeTypeDetectorDetails {
+ final MimeTypeDetector mimeTypeDetector;
+ private String name;
+ private String description;
+ private Map<String, Object> properties;
+ private String className;
+ private String[] classpath;
+
+ protected DnaMimeTypeDetectorDetails( String name,
+ MimeTypeDetector mimeTypeDetector,
+ String[] classpath ) {
+ this.mimeTypeDetector = mimeTypeDetector;
+ this.name = name;
+ this.description = mimeTypeDetector.getClass().getName();
+ this.properties = new HashMap<String, Object>();
+ this.className = mimeTypeDetector.getClass().getName();
+ this.classpath = classpath;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ protected String getDescription() {
+ return description;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.SetDescription#describedAs(java.lang.String)
+ */
+ public MimeTypeDetectorDetails describedAs( String description ) {
+ this.description = description;
+ return this;
+ }
+
+ public PropertySetter<MimeTypeDetectorDetails> with( final String
propertyName ) {
+ return new MappingPropertySetter<MimeTypeDetectorDetails>(propertyName,
this);
+ }
+
+ public MimeTypeDetector getMimeTypeDetector() {
+ return mimeTypeDetector;
+ }
+
+ MimeTypeDetectorConfig getMimeTypeDetectorConfig() {
+ return new MimeTypeDetectorConfig(name, description, properties, className,
classpath);
+ }
+
+ public DnaConfiguration and() {
+ return DnaConfiguration.this;
+ }
+
+ }
+
+ /**
+ * Local implementation of the {@link RepositoryDetails} interface that tracks all of
the user-provided configuration details.
+ */
+ protected class DnaRepositoryDetails implements RepositoryDetails {
+ private final RepositorySource source;
+ private final String description;
+ private Map<String, Object> properties;
+
+ protected DnaRepositoryDetails( RepositorySource source ) {
+ this.source = source;
+ this.description = source.getName();
+ this.properties = new HashMap<String, Object>();
+ }
+
+ protected DnaRepositoryDetails( RepositorySource source,
+ String description ) {
+ this.source = source;
+ this.description = description;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ protected String getDescription() {
+ return description;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.SetDescription#describedAs(java.lang.String)
+ */
+ public RepositoryDetails describedAs( String description ) {
+ return new DnaRepositoryDetails(this.source, description);
+ }
+
+ public PropertySetter<RepositoryDetails> with( final String propertyName )
{
+ return new BeanPropertySetter<RepositoryDetails>(source, propertyName,
this);
+ }
+
+ public RepositorySource getRepositorySource() {
+ return source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration.ConfigurationBuilder#and()
+ */
+ public DnaConfiguration and() {
+ return DnaConfiguration.this;
+ }
+ }
+
+ /**
+ * Local implementation of the {@link SequencerDetails} interface that tracks all of
the user-provided configuration details.
+ */
+ protected class DnaSequencerDetails implements SequencerDetails {
+ private final Sequencer sequencer;
+ private String name;
+ private String description;
+ private Map<String, Object> properties;
+ private String className;
+ private String[] classpath;
+ final List<PathExpression> sourcePathExpressions;
+ final List<PathExpression> targetPathExpressions;
+
+ protected DnaSequencerDetails( String name,
+ Sequencer sequencer,
+ String[] classpath ) {
+ this.sequencer = sequencer;
+ this.name = name;
+ this.description = sequencer.getClass().getName();
+ this.properties = new HashMap<String, Object>();
+ this.className = sequencer.getClass().getName();
+ this.classpath = classpath;
+ this.sourcePathExpressions = new ArrayList<PathExpression>();
+ this.targetPathExpressions = new ArrayList<PathExpression>();
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ protected String getDescription() {
+ return description;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.SetDescription#describedAs(java.lang.String)
+ */
+ public SequencerDetails describedAs( String description ) {
+ this.description = description;
+ return this;
+ }
+
+ public PropertySetter<SequencerDetails> with( final String propertyName )
{
+ return new MappingPropertySetter<SequencerDetails>(propertyName,
this);
+ }
+
+ public Sequencer getSequencer() {
+ return sequencer;
+ }
+
+ SequencerConfig getSequencerConfig() {
+ return new SequencerConfig(this.name, this.description, this.properties,
this.className, this.classpath);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.repository.DnaConfiguration.ConfigurationBuilder#and()
+ */
+ public DnaConfiguration and() {
+ return DnaConfiguration.this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.SequencerDetails#sequencingFrom(java.lang.String)
+ */
+ public PathExpressionOutput sequencingFrom( String inputExpressionPath ) {
+ return this.sequencingFrom(PathExpression.compile(inputExpressionPath));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.SequencerDetails#sequencingFrom(org.jboss.dna.graph.property.PathExpression)
+ */
+ public PathExpressionOutput sequencingFrom( final PathExpression
inputExpressionPath ) {
+ final DnaSequencerDetails details = this;
+ return new PathExpressionOutput() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.PathExpressionOutput#andOutputtingTo(java.lang.String)
+ */
+ public DnaSequencerDetails andOutputtingTo( final String
outputExpressionPath ) {
+ details.sourcePathExpressions.add(inputExpressionPath);
+
details.targetPathExpressions.add(PathExpression.compile(outputExpressionPath));
+ return details;
+ }
+ };
+ }
+
+ }
+
+ /**
+ * Interface used to configure a {@link Sequencer sequencer}.
+ */
+ public interface SequencerDetails extends SetDescription<SequencerDetails>,
ConfigurationBuilder {
+
+ /**
+ * 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 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 specify the output path expression; never null
+ */
+ PathExpressionOutput sequencingFrom( PathExpression inputPathExpression );
+ }
+
+ /**
+ * Interface used to specify the output path expression for a {@link
SequencerDetails#sequencingFrom(PathExpression) sequencer
+ * configuration}.
+ */
+ public interface PathExpressionOutput {
+ /**
+ * 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 andOutputtingTo( String outputExpression );
+ }
+
+ /**
+ * Interface used to configure a {@link MimeTypeDetector MIME type detector}.
+ */
+ public interface MimeTypeDetectorDetails
+ extends SetDescription<MimeTypeDetectorDetails>,
SetProperties<MimeTypeDetectorDetails>, ConfigurationBuilder {
+ }
+
+ /**
+ * 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 the name of the JavaBean-style property that is to be set. The value
may be set using the interface returned by
+ * this method.
+ *
+ * @param beanPropertyName the name of the JavaBean-style property (e.g.,
"retryLimit")
+ * @return the interface used to set the value for the property; never null
+ */
+ PropertySetter<ReturnType> with( String beanPropertyName );
+ }
+
+ /**
+ * The interface used to set the value for a JavaBean-style property.
+ *
+ * @param <ReturnType> the interface returned from these methods
+ * @author Randall Hauch
+ * @see SetProperties#with(String)
+ */
+ public interface PropertySetter<ReturnType> {
+ /**
+ * Set the property value to an integer.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( int value );
+
+ /**
+ * Set the property value to a long number.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( long value );
+
+ /**
+ * Set the property value to a short.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( short value );
+
+ /**
+ * Set the property value to a boolean.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( boolean value );
+
+ /**
+ * Set the property value to a float.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( float value );
+
+ /**
+ * Set the property value to a double.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( double value );
+
+ /**
+ * Set the property value to a string.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( String value );
+
+ /**
+ * Set the property value to an object.
+ *
+ * @param value the new value for the property
+ * @return the next component to continue configuration; never null
+ */
+ ReturnType setTo( 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 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 );
+ }
+
+ /**
+ * 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 classes that can return a reference to their DNA configuration.
+ */
+ public interface ConfigurationBuilder {
+
+ Map<String, Object> getProperties();
+
+ /**
+ * Return a reference to the enclosing configuration so that it can be built or
further configured.
+ *
+ * @return a reference to the enclosing configuration
+ */
+ DnaConfiguration and();
+ }
+
+ /**
+ * Abstract implementation of {@link ChooseClass} that has a single abstract method
to obtain the interface that should be
+ * returned when the class name and classpath have been selected.
+ *
+ * @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.
+ * @author Randall Hauch
+ */
+ protected abstract class ClassChooser<ComponentClass, ReturnType> implements
ChooseClass<ComponentClass, ReturnType> {
+
+ protected abstract ReturnType getComponentBuilder( String className,
+ String... classpath );
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.ChooseClass#usingClass(java.lang.String)
+ */
+ public LoadedFrom<ReturnType> usingClass( final String classname ) {
+ CheckArg.isNotEmpty(classname, "classname");
+ return new LoadedFrom<ReturnType>() {
+ public ReturnType loadedFromClasspath() {
+ return getComponentBuilder(classname);
+ }
+
+ public ReturnType loadedFrom( String... classpath ) {
+ return getComponentBuilder(classname, classpath);
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.repository.DnaConfiguration.ChooseClass#usingClass(java.lang.Class)
+ */
+ public ReturnType usingClass( Class<? extends ComponentClass> clazz ) {
+ CheckArg.isNotNull(clazz, "clazz");
+ return getComponentBuilder(clazz.getName());
+ }
+ }
+
+ /**
+ * Utility method to instantiate a class.
+ *
+ * @param <T> the interface or superclass that the instantiated object is to
implement
+ * @param interfaceType the interface or superclass type that the instantiated object
is to implement
+ * @param className the name of the class
+ * @param classloaderNames the names of the class loaders
+ * @return the new instance
+ */
+ @SuppressWarnings( "unchecked" )
+ protected <T> T instantiate( Class<T> interfaceType,
+ String className,
+ String... classloaderNames ) {
+ // Load the class and create the instance ...
+ try {
+ Class<?> clazz =
getExecutionContext().getClassLoader(classloaderNames).loadClass(className);
+ return (T)clazz.newInstance();
+ } catch (Throwable err) {
+ I18n msg = RepositoryI18n.errorCreatingInstanceOfClass;
+ throw new DnaConfigurationException(msg.text(className, err.getMessage()),
err);
+ }
+ }
+
+ /**
+ * Reusable implementation of {@link PropertySetter} that sets the JavaBean-style
property using reflection.
+ *
+ * @param <ReturnType>
+ * @author Randall Hauch
+ */
+ protected class BeanPropertySetter<ReturnType> implements
PropertySetter<ReturnType> {
+ private final Object javaBean;
+ private final String beanPropertyName;
+ private final ReturnType returnObject;
+
+ protected BeanPropertySetter( Object javaBean,
+ String beanPropertyName,
+ ReturnType returnObject ) {
+ assert javaBean != null;
+ assert beanPropertyName != null;
+ assert returnObject != null;
+ this.javaBean = javaBean;
+ this.beanPropertyName = beanPropertyName;
+ this.returnObject = returnObject;
+ }
+
+ public ReturnType setTo( boolean value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( int value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( long value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( short value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( float value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( double value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( String value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( Object value ) {
+ // Set the JavaBean-style property on the RepositorySource instance ...
+ Reflection reflection = new Reflection(javaBean.getClass());
+ try {
+ reflection.invokeSetterMethodOnTarget(beanPropertyName, javaBean,
value);
+ } catch (Throwable err) {
+ I18n msg = RepositoryI18n.errorSettingJavaBeanPropertyOnInstanceOfClass;
+ throw new DnaConfigurationException(msg.text(beanPropertyName,
javaBean.getClass(), err.getMessage()), err);
+ }
+ return returnObject;
+ }
+ }
+
+ /**
+ * Reusable implementation of {@link PropertySetter} that aggregates the properties
to set to be placed into a map
+ *
+ * @param <ReturnType>
+ * @author Randall Hauch
+ */
+ protected class MappingPropertySetter<ReturnType extends ConfigurationBuilder>
implements PropertySetter<ReturnType> {
+ private final String beanPropertyName;
+ private final ReturnType returnObject;
+
+ protected MappingPropertySetter( String beanPropertyName,
+ ReturnType returnObject ) {
+ assert beanPropertyName != null;
+ assert returnObject != null;
+ this.beanPropertyName = beanPropertyName;
+ this.returnObject = returnObject;
+ }
+
+ public ReturnType setTo( boolean value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( int value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( long value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( short value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( float value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( double value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( String value ) {
+ return setTo((Object)value);
+ }
+
+ public ReturnType setTo( Object value ) {
+ returnObject.getProperties().put(beanPropertyName, value);
+ return returnObject;
+ }
+ }
+}
Property changes on:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfigurationException.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfigurationException.java
(rev 0)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfigurationException.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class DnaConfigurationException extends RuntimeException {
+
+ /**
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ *
+ */
+ public DnaConfigurationException() {
+ }
+
+ /**
+ * @param message
+ */
+ public DnaConfigurationException( String message ) {
+ super(message);
+
+ }
+
+ /**
+ * @param cause
+ */
+ public DnaConfigurationException( Throwable cause ) {
+ super(cause);
+
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public DnaConfigurationException( String message,
+ Throwable cause ) {
+ super(message, cause);
+
+ }
+
+}
Property changes on:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfigurationException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
(rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -0,0 +1,152 @@
+/*
+ * 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.Arrays;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.repository.DnaConfiguration.DnaMimeTypeDetectorDetails;
+import org.jboss.dna.repository.DnaConfiguration.DnaRepositoryDetails;
+import org.jboss.dna.repository.DnaConfiguration.DnaSequencerDetails;
+import org.jboss.dna.repository.observation.ObservationService;
+import org.jboss.dna.repository.sequencer.SequencingService;
+import org.jboss.dna.repository.service.AdministeredService;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public class DnaEngine {
+
+ public static final String CONFIGURATION_REPOSITORY_NAME =
"dna:configuration";
+
+ private final ExecutionContext context;
+ private final List<AdministeredService> services;
+
+ private final RepositoryService repositoryService;
+ private final ObservationService observationService;
+ private final SequencingService sequencingService;
+ private final ExecutorService executorService;
+
+ private final RepositoryConnectionFactory connectionFactory;
+
+ DnaEngine( DnaConfiguration configuration ) {
+ this.context = new ExecutionContext();
+
+ DnaRepositoryDetails configSource =
configuration.repositories.get(CONFIGURATION_REPOSITORY_NAME);
+ assert configSource != null : "Must specify a repository source named "
+ CONFIGURATION_REPOSITORY_NAME;
+
+ // Use a magic number for now
+ executorService = new ScheduledThreadPoolExecutor(10);
+
+ observationService = null; // new ObservationService(null);
+
+ RepositoryLibrary library = new RepositoryLibrary();
+ for (DnaRepositoryDetails details : configuration.repositories.values()) {
+ // Adding configuration source to the library until proven wrong!
+ library.addSource(details.getRepositorySource());
+ }
+
+ for (DnaMimeTypeDetectorDetails details :
configuration.mimeTypeDetectors.values()) {
+
library.getMimeTypeDetectors().addDetector(details.getMimeTypeDetectorConfig());
+ }
+ repositoryService = new RepositoryService(library,
configSource.getRepositorySource().getName(), "", context);
+
+ sequencingService = new SequencingService();
+ sequencingService.setExecutorService(executorService);
+ for (DnaSequencerDetails details : configuration.sequencers.values()) {
+ sequencingService.addSequencer(details.getSequencerConfig());
+ }
+
+ this.services = Arrays.asList(new AdministeredService[] { /* observationService,
*/repositoryService, sequencingService,});
+
+ connectionFactory = new RepositoryConnectionFactory() {
+ public RepositoryConnection createConnection( String sourceName ) throws
RepositorySourceException {
+ RepositorySource source =
DnaEngine.this.getRepositorySource(sourceName);
+ if (sourceName == null) {
+ throw new RepositorySourceException(sourceName);
+ }
+
+ return source.getConnection();
+ }
+ };
+ }
+
+ /*
+ * Lookup methods
+ */
+ public final ExecutionContext getExecutionContext() {
+ return context;
+ }
+
+ public final RepositorySource getRepositorySource( String repositoryName ) {
+ return repositoryService.getRepositorySourceManager().getSource(repositoryName);
+ }
+
+ public final RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ return connectionFactory;
+ }
+
+ public final RepositoryService getRepositoryService() {
+ return repositoryService;
+ }
+
+ public final ObservationService getObservationService() {
+ return observationService;
+ }
+
+ public final SequencingService getSequencingService() {
+ return sequencingService;
+ }
+
+ /*
+ * Lifecycle methods
+ */
+
+ public void start() {
+ for (AdministeredService service : services) {
+ service.getAdministrator().start();
+ }
+ }
+
+ public void shutdown() {
+ for (AdministeredService service : services) {
+ service.getAdministrator().shutdown();
+ }
+
+ try {
+ executorService.awaitTermination(10 * 60, TimeUnit.SECONDS); // No
TimeUnit.MINUTES in JDK 5
+ } catch (InterruptedException ie) {
+ // Reset the thread's status and continue this method ...
+ Thread.interrupted();
+ }
+ executorService.shutdown();
+ }
+}
Property changes on:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-04-22
13:38:14 UTC (rev 845)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -1,137 +1,142 @@
-/*
- * 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;
-
-import java.util.Locale;
-import java.util.Set;
-import org.jboss.dna.common.i18n.I18n;
-
-/**
- * @author Randall Hauch
- * @author John Verhaeg
- */
-public final class RepositoryI18n {
-
- // Services and Repository
- public static I18n invalidStateString;
- public static I18n serviceShutdowAndMayNotBeStarted;
- public static I18n serviceShutdowAndMayNotBePaused;
- public static I18n serviceNotShutdowAndMayNotBeTerminated;
- public static I18n unableToFindRepositoryInJndi;
- public static I18n unableToRegisterRepositoryInJndi;
- public static I18n unableToUnregisterRepositoryInJndi;
- public static I18n unableToRemoveRepository;
- public static I18n unableToFindRepositoryWithName;
- public static I18n errorProcessingEvents;
- public static I18n errorFindingPropertyNameInPropertyAddedEvent;
- public static I18n errorFindingPropertyNameInPropertyChangedEvent;
- public static I18n errorFindingPropertyNameInPropertyRemovedEvent;
-
- // Rules
- public static I18n unableToObtainJsr94RuleAdministrator;
- public static I18n errorUsingJsr94RuleAdministrator;
- public static I18n unableToObtainJsr94ServiceProvider;
- public static I18n errorAddingOrUpdatingRuleSet;
- public static I18n errorRollingBackRuleSetAfterUpdateFailed;
- public static I18n errorReadingRulesAndProperties;
- public static I18n errorDeregisteringRuleSetBeforeUpdatingIt;
- public static I18n errorRecreatingRuleSet;
- public static I18n errorRemovingRuleSet;
- public static I18n errorRemovingRuleSetUponShutdown;
- public static I18n unableToFindRuleSet;
- public static I18n errorExecutingRuleSetWithGlobalsAndFacts;
- public static I18n unableToBuildRuleSetRegularExpressionPattern;
-
- public static I18n errorObtainingSessionToRepositoryWorkspace;
- public static I18n errorWritingProblemsOnRuleSet;
-
- public static I18n federationServiceName;
- public static I18n observationServiceName;
- public static I18n ruleServiceName;
-
- // Sequencing
- public static I18n sequencingServiceName;
- public static I18n unableToChangeExecutionContextWhileRunning;
- public static I18n unableToStartSequencingServiceWithoutExecutionContext;
- public static I18n errorWhileSequencingNode;
- public static I18n errorInRepositoryWhileSequencingNode;
- public static I18n errorFindingSequencersToRunAgainstNode;
- public static I18n errorInRepositoryWhileFindingSequencersToRunAgainstNode;
- public static I18n executionContextHasBeenClosed;
- public static I18n unableToFindPropertyForSequencing;
-
- // Properties
- public static I18n errorReadingPropertiesFromContainerNode;
- public static I18n requiredPropertyOnNodeWasExpectedToBeStringValue;
- public static I18n optionalPropertyOnNodeWasExpectedToBeStringValue;
- public static I18n requiredPropertyOnNodeWasExpectedToBeStringArrayValue;
- public static I18n optionalPropertyOnNodeWasExpectedToBeStringArrayValue;
- public static I18n requiredPropertyOnNodeCouldNotBeRead;
- public static I18n optionalPropertyOnNodeCouldNotBeRead;
- public static I18n requiredPropertyIsMissingFromNode;
- public static I18n errorGettingRequiredPropertyFromNode;
- public static I18n errorGettingOptionalPropertyFromNode;
- public static I18n errorClosingBinaryStreamForPropertyFromNode;
- public static I18n requiredNodeDoesNotExistRelativeToNode;
- public static I18n errorGettingNodeRelativeToNode;
- public static I18n unknownPropertyValueType;
-
- // Path expressions
- public static I18n pathExpressionIsInvalid;
- public static I18n pathExpressionMayNotBeBlank;
- public static I18n pathExpressionHasInvalidSelect;
- public static I18n pathExpressionHasInvalidMatch;
-
- // Observation
- public static I18n
errorUnregisteringWorkspaceListenerWhileShuttingDownObservationService;
-
- // General
- public static I18n invalidRepositoryNodePath;
- public static I18n unableToLoadClassUsingClasspath;
- public static I18n unableToInstantiateClassUsingClasspath;
- public static I18n unableToAccessClassUsingClasspath;
-
- // Repository
- public static I18n errorStartingRepositoryService;
-
- static {
- try {
- I18n.initialize(RepositoryI18n.class);
- } catch (final Exception err) {
- System.err.println(err);
- }
- }
-
- public static Set<Locale> getLocalizationProblemLocales() {
- return I18n.getLocalizationProblemLocales(RepositoryI18n.class);
- }
-
- public static Set<String> getLocalizationProblems() {
- return I18n.getLocalizationProblems(RepositoryI18n.class);
- }
-
- public static Set<String> getLocalizationProblems( Locale locale ) {
- return I18n.getLocalizationProblems(RepositoryI18n.class, locale);
- }
-}
+/*
+ * 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;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public final class RepositoryI18n {
+
+ // Configuration
+ public static I18n errorCreatingInstanceOfClass;
+ public static I18n errorCreatingInstanceOfClassUsingClassLoaders;
+ public static I18n errorSettingJavaBeanPropertyOnInstanceOfClass;
+
+ // Services and Repository
+ public static I18n invalidStateString;
+ public static I18n serviceShutdowAndMayNotBeStarted;
+ public static I18n serviceShutdowAndMayNotBePaused;
+ public static I18n serviceNotShutdowAndMayNotBeTerminated;
+ public static I18n unableToFindRepositoryInJndi;
+ public static I18n unableToRegisterRepositoryInJndi;
+ public static I18n unableToUnregisterRepositoryInJndi;
+ public static I18n unableToRemoveRepository;
+ public static I18n unableToFindRepositoryWithName;
+ public static I18n errorProcessingEvents;
+ public static I18n errorFindingPropertyNameInPropertyAddedEvent;
+ public static I18n errorFindingPropertyNameInPropertyChangedEvent;
+ public static I18n errorFindingPropertyNameInPropertyRemovedEvent;
+
+ // Rules
+ public static I18n unableToObtainJsr94RuleAdministrator;
+ public static I18n errorUsingJsr94RuleAdministrator;
+ public static I18n unableToObtainJsr94ServiceProvider;
+ public static I18n errorAddingOrUpdatingRuleSet;
+ public static I18n errorRollingBackRuleSetAfterUpdateFailed;
+ public static I18n errorReadingRulesAndProperties;
+ public static I18n errorDeregisteringRuleSetBeforeUpdatingIt;
+ public static I18n errorRecreatingRuleSet;
+ public static I18n errorRemovingRuleSet;
+ public static I18n errorRemovingRuleSetUponShutdown;
+ public static I18n unableToFindRuleSet;
+ public static I18n errorExecutingRuleSetWithGlobalsAndFacts;
+ public static I18n unableToBuildRuleSetRegularExpressionPattern;
+
+ public static I18n errorObtainingSessionToRepositoryWorkspace;
+ public static I18n errorWritingProblemsOnRuleSet;
+
+ public static I18n federationServiceName;
+ public static I18n observationServiceName;
+ public static I18n ruleServiceName;
+
+ // Sequencing
+ public static I18n sequencingServiceName;
+ public static I18n unableToChangeExecutionContextWhileRunning;
+ public static I18n unableToStartSequencingServiceWithoutExecutionContext;
+ public static I18n errorWhileSequencingNode;
+ public static I18n errorInRepositoryWhileSequencingNode;
+ public static I18n errorFindingSequencersToRunAgainstNode;
+ public static I18n errorInRepositoryWhileFindingSequencersToRunAgainstNode;
+ public static I18n executionContextHasBeenClosed;
+ public static I18n unableToFindPropertyForSequencing;
+
+ // Properties
+ public static I18n errorReadingPropertiesFromContainerNode;
+ public static I18n requiredPropertyOnNodeWasExpectedToBeStringValue;
+ public static I18n optionalPropertyOnNodeWasExpectedToBeStringValue;
+ public static I18n requiredPropertyOnNodeWasExpectedToBeStringArrayValue;
+ public static I18n optionalPropertyOnNodeWasExpectedToBeStringArrayValue;
+ public static I18n requiredPropertyOnNodeCouldNotBeRead;
+ public static I18n optionalPropertyOnNodeCouldNotBeRead;
+ public static I18n requiredPropertyIsMissingFromNode;
+ public static I18n errorGettingRequiredPropertyFromNode;
+ public static I18n errorGettingOptionalPropertyFromNode;
+ public static I18n errorClosingBinaryStreamForPropertyFromNode;
+ public static I18n requiredNodeDoesNotExistRelativeToNode;
+ public static I18n errorGettingNodeRelativeToNode;
+ public static I18n unknownPropertyValueType;
+
+ // Path expressions
+ public static I18n pathExpressionIsInvalid;
+ public static I18n pathExpressionMayNotBeBlank;
+ public static I18n pathExpressionHasInvalidSelect;
+ public static I18n pathExpressionHasInvalidMatch;
+
+ // Observation
+ public static I18n
errorUnregisteringWorkspaceListenerWhileShuttingDownObservationService;
+
+ // General
+ public static I18n invalidRepositoryNodePath;
+ public static I18n unableToLoadClassUsingClasspath;
+ public static I18n unableToInstantiateClassUsingClasspath;
+ public static I18n unableToAccessClassUsingClasspath;
+
+ // Repository
+ public static I18n errorStartingRepositoryService;
+
+ static {
+ try {
+ I18n.initialize(RepositoryI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set<Locale> getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(RepositoryI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems() {
+ return I18n.getLocalizationProblems(RepositoryI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(RepositoryI18n.class, locale);
+ }
+}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/mimetype/MimeTypeDetectorConfig.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/mimetype/MimeTypeDetectorConfig.java 2009-04-22
13:38:14 UTC (rev 845)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/mimetype/MimeTypeDetectorConfig.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -23,6 +23,7 @@
*/
package org.jboss.dna.repository.mimetype;
+import java.util.Map;
import org.jboss.dna.common.component.ComponentConfig;
/**
@@ -32,8 +33,9 @@
public MimeTypeDetectorConfig( String name,
String description,
+ Map<String, Object> properties,
String classname,
String[] classpath ) {
- super(name, description, classname, classpath);
+ super(name, description, properties, classname, classpath);
}
}
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-04-22
13:38:14 UTC (rev 845)
+++
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2009-04-22
14:05:41 UTC (rev 846)
@@ -21,6 +21,10 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
#
+errorCreatingInstanceOfClass = Attempt to create instance of {0} resulted in error: {1}
+errorCreatingInstanceOfClassUsingClassLoaders = Attempt to create instance of {0} using
classloader path {1} resulted in error: {2}
+errorSettingJavaBeanPropertyOnInstanceOfClass = Attempt to set {0} property on {1}
instance resulted in error: {2}
+
invalidStateString = Invalid state parameter "{0}"
serviceShutdowAndMayNotBeStarted = The {0} has been shutdown and may not be (re)started
serviceShutdowAndMayNotBePaused = The {0} has been shutdown and my not be paused
Added:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
(rev 0)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -0,0 +1,215 @@
+/*
+ * 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 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.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import org.jboss.dna.graph.ExecutionContext;
+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.repository.DnaConfiguration.DnaSequencerDetails;
+import org.jboss.dna.repository.sequencer.MockSequencerA;
+import org.jboss.dna.repository.sequencer.MockSequencerB;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class DnaConfigurationTest {
+
+ private ExecutionContext context;
+ private DnaConfiguration configuration;
+
+ @Before
+ public void beforeEach() {
+ context = new ExecutionContext();
+ configuration = new DnaConfiguration();
+ }
+
+ @Test
+ public void shouldAllowCreatingWithNoArguments() {
+ configuration = new DnaConfiguration();
+ }
+
+ @Test
+ public void shouldAllowCreatingWithSpecifiedExecutionContext() {
+ configuration = new DnaConfiguration(context);
+ }
+
+ @Test
+ public void shouldAllowSpecifyingConfigurationRepository() {
+ DnaConfiguration config = configuration.withConfigurationRepository()
+
.usingClass("org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource")
+ .loadedFromClasspath()
+ .describedAs("description")
+ .with("retryLimit")
+ .setTo(5)
+ .with("name")
+ .setTo("repository name")
+ .and();
+ assertThat(config, is(notNullValue()));
+ assertThat(config.repositories.get(null), is(nullValue()));
+ }
+
+ @Test
+ public void shouldAllowAddingRepositorySourceInstance() {
+ RepositorySource newSource = mock(RepositorySource.class);
+ configuration.addRepository(newSource);
+ }
+
+ @Test
+ public void shouldAllowAddingRepositorySourceByClassNameAndSettingProperties() {
+ DnaConfiguration config =
configuration.addRepository(DnaEngine.CONFIGURATION_REPOSITORY_NAME)
+
.usingClass("org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource")
+ .loadedFromClasspath()
+ .describedAs("description")
+ .with("retryLimit")
+ .setTo(5)
+ .with("name")
+ .setTo("repository name")
+ .and();
+ assertThat(config, is(notNullValue()));
+
+ RepositorySource source =
config.repositories.get(DnaEngine.CONFIGURATION_REPOSITORY_NAME).getRepositorySource();
+ assertThat(source, is(notNullValue()));
+ assertThat(source, is(instanceOf(InMemoryRepositorySource.class)));
+
+ InMemoryRepositorySource isource = (InMemoryRepositorySource)source;
+ assertThat(isource.getRetryLimit(), is(5));
+ assertThat(isource.getName(), is("repository name"));
+ }
+
+ @Test
+ public void shouldAllowAddingRepositorySourceByClassReferenceAndSettingProperties()
{
+ DnaConfiguration config =
configuration.addRepository(DnaEngine.CONFIGURATION_REPOSITORY_NAME)
+
.usingClass(InMemoryRepositorySource.class)
+ .describedAs("description")
+ .with("retryLimit")
+ .setTo(5)
+ .with("name")
+ .setTo("repository name")
+ .and();
+
+ assertThat(config, is(notNullValue()));
+ assertThat(config.repositories.get(null), is(nullValue()));
+
+ RepositorySource source =
config.repositories.get(DnaEngine.CONFIGURATION_REPOSITORY_NAME).getRepositorySource();
+ assertThat(source, is(notNullValue()));
+ assertThat(source, is(instanceOf(InMemoryRepositorySource.class)));
+
+ InMemoryRepositorySource isource = (InMemoryRepositorySource)source;
+ assertThat(isource.getRetryLimit(), is(5));
+ assertThat(isource.getName(), is("repository name"));
+ }
+
+ @Test
+ public void shouldAllowOverwritingRepositorySourceByRepositoryName() {
+ DnaConfiguration config =
configuration.addRepository(DnaEngine.CONFIGURATION_REPOSITORY_NAME)
+
.usingClass(InMemoryRepositorySource.class)
+ .describedAs("description")
+ .with("retryLimit")
+ .setTo(3)
+ .and()
+
.addRepository(DnaEngine.CONFIGURATION_REPOSITORY_NAME)
+
.usingClass(InMemoryRepositorySource.class)
+ .describedAs("description")
+ .with("name")
+ .setTo("repository name")
+ .and();
+
+ assertThat(config, is(notNullValue()));
+ assertThat(config.repositories.get(null), is(nullValue()));
+
+ RepositorySource source =
config.repositories.get(DnaEngine.CONFIGURATION_REPOSITORY_NAME).getRepositorySource();
+ assertThat(source, is(notNullValue()));
+ assertThat(source, is(instanceOf(InMemoryRepositorySource.class)));
+
+ InMemoryRepositorySource isource = (InMemoryRepositorySource)source;
+ // This relies on the default retry limit for an InMemoryRepositorySource being
0
+ // If the original source was not overwritten, this would be 3
+ assertThat(isource.getRetryLimit(), is(0));
+ assertThat(isource.getName(), is("repository name"));
+ }
+
+ @Test
+ public void shouldAllowAddingMimeTypeDetector() {
+ RepositorySource newSource = mock(RepositorySource.class);
+ MimeTypeDetector newDetector = mock(MimeTypeDetector.class);
+ DnaConfiguration config = configuration.addRepository(newSource)
+ .addMimeTypeDetector("default")
+ .usingClass(newDetector.getClass())
+ .describedAs("default mime type
detector")
+ .and();
+
+ assertThat(config, is(notNullValue()));
+
assertThat(config.mimeTypeDetectors.get("default").getMimeTypeDetector(),
instanceOf(MimeTypeDetector.class));
+ assertThat(config.mimeTypeDetectors.get("invalid name"),
is(nullValue()));
+ assertThat(config.mimeTypeDetectors.get("default").getDescription(),
is("default mime type detector"));
+ }
+
+ @Test
+ public void shouldAllowAddingSequencer() {
+ RepositorySource newSource = mock(RepositorySource.class);
+
+ DnaConfiguration config = configuration.addRepository(newSource)
+ .addSequencer("sequencerA")
+ .usingClass(MockSequencerA.class)
+ .describedAs("Mock Sequencer
A")
+ .sequencingFrom("/foo/source")
+ .andOutputtingTo("/foo/target")
+ .sequencingFrom("/bar/source")
+ .andOutputtingTo("/bar/target")
+ .and()
+ .addSequencer("sequencerB")
+ .usingClass(MockSequencerB.class)
+ .sequencingFrom("/baz/source")
+ .andOutputtingTo("/baz/target")
+ .describedAs("Mock Sequencer
B")
+ .and();
+
+ assertThat(config, is(notNullValue()));
+ assertThat(config.sequencers.get("default"), is(nullValue()));
+ assertThat(config.sequencers.get("sequencerA").getSequencer(),
instanceOf(MockSequencerA.class));
+ assertThat(config.sequencers.get("sequencerB").getSequencer(),
instanceOf(MockSequencerB.class));
+
+ DnaSequencerDetails detailsA = config.sequencers.get("sequencerA");
+ assertThat(detailsA.getDescription(), is("Mock Sequencer A"));
+ assertThat(detailsA.sourcePathExpressions.size(), is(2));
+ assertThat(detailsA.sourcePathExpressions.get(0).toString(),
is("/foo/source"));
+ assertThat(detailsA.targetPathExpressions.get(0).toString(),
is("/foo/target"));
+ assertThat(detailsA.sourcePathExpressions.get(1).toString(),
is("/bar/source"));
+ assertThat(detailsA.targetPathExpressions.get(1).toString(),
is("/bar/target"));
+
+ DnaSequencerDetails detailsB = config.sequencers.get("sequencerB");
+ assertThat(detailsB.getDescription(), is("Mock Sequencer B"));
+ assertThat(detailsB.sourcePathExpressions.size(), is(1));
+ assertThat(detailsB.sourcePathExpressions.get(0).toString(),
is("/baz/source"));
+ assertThat(detailsB.targetPathExpressions.get(0).toString(),
is("/baz/target"));
+ }
+
+}
Property changes on:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
(rev 0)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -0,0 +1,191 @@
+/*
+ * 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;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
+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.MimeTypeDetector;
+import org.jboss.dna.repository.mimetype.MimeTypeDetectors;
+import org.jboss.dna.repository.observation.NodeChanges;
+import org.jboss.dna.repository.sequencer.MockSequencerA;
+import org.jboss.dna.repository.sequencer.SequencingService;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+
+public class DnaEngineTest {
+
+ private DnaEngine engine;
+
+ @Before
+ public void beforeEach() {
+ }
+
+ @Test
+ public void shouldAllowCreatingWithEmptyConfig() {
+ engine = new DnaConfiguration().build();
+ }
+
+ @Test
+ public void shouldAllowCreatingWithConfigRepository() throws InterruptedException {
+ engine = new DnaConfiguration()
+ .withConfigurationRepository()
+ .usingClass(InMemoryRepositorySource.class)
+ .describedAs("Configuration Repository")
+ .with("name").setTo("config repo")
+ .and().build();
+
+ assertThat(engine.getRepositorySource("config repo"),
is(notNullValue()));
+ assertThat(engine.getRepositorySource("config repo"),
is(instanceOf(InMemoryRepositorySource.class)));
+
+ RepositoryLibrary library =
engine.getRepositoryService().getRepositorySourceManager();
+ assertThat(library.getConnectionPool("config repo").getInUseCount(),
is(0));
+
+ RepositoryConnection connection = library.getConnectionPool("config
repo").getConnection();
+ assertThat(connection.ping(500, TimeUnit.MILLISECONDS), is(true));
+ connection.close();
+
+ }
+
+ @Test
+ public void shouldAllowCreatingMultipleRepositories() throws Exception {
+ engine = new DnaConfiguration()
+ .withConfigurationRepository()
+ .usingClass(InMemoryRepositorySource.class)
+ .describedAs("Configuration Repository")
+ .with("name").setTo("config repo")
+ .and().addRepository("JCR")
+ .usingClass(InMemoryRepositorySource.class)
+ .describedAs("Backing Repository for JCR Implementation")
+ .with("name").setTo("JCR")
+ .and().build();
+
+ assertThat(engine.getRepositorySource("config repo"),
is(notNullValue()));
+ assertThat(engine.getRepositorySource("config repo"),
is(instanceOf(InMemoryRepositorySource.class)));
+
+ assertThat(engine.getRepositorySource("JCR"), is(notNullValue()));
+ assertThat(engine.getRepositorySource("JCR"),
is(instanceOf(InMemoryRepositorySource.class)));
+ assertThat(engine.getRepositorySource("JCR").getName(),
is("JCR"));
+
+ RepositoryLibrary library =
engine.getRepositoryService().getRepositorySourceManager();
+ RepositoryConnection connection =
library.getConnectionPool("JCR").getConnection();
+ assertThat(connection.ping(500, TimeUnit.MILLISECONDS), is(true));
+ connection.close();
+
+ }
+
+ @Test
+ public void shouldAllowAddingMimeTypeDetectors() throws Exception {
+ engine = new DnaConfiguration()
+ .withConfigurationRepository()
+ .usingClass(InMemoryRepositorySource.class)
+ .describedAs("Configuration Repository")
+ .with("name").setTo("config repo")
+ .and().addMimeTypeDetector("default")
+ .usingClass(MockMimeTypeDetector.class)
+ .describedAs("Default MimeTypeDetector")
+ .with("mimeType").setTo("mock")
+ .and().build();
+
+ assertThat(engine.getRepositorySource("config repo"),
is(notNullValue()));
+ assertThat(engine.getRepositorySource("config repo"),
is(instanceOf(InMemoryRepositorySource.class)));
+
+ RepositoryLibrary library =
engine.getRepositoryService().getRepositorySourceManager();
+ MimeTypeDetectors detectors = library.getMimeTypeDetectors();
+
+ assertThat(detectors.mimeTypeOf("test", new
ByteArrayInputStream("This is useless data".getBytes())),
is("mock"));
+ }
+
+ @Test
+ public void shouldAllowAddingSequencers() throws Exception {
+ engine = new DnaConfiguration()
+ .withConfigurationRepository()
+ .usingClass(InMemoryRepositorySource.class)
+ .describedAs("Configuration Repository")
+ .with("name").setTo("config repo")
+ .and().addSequencer("Mock Sequencer A")
+ .usingClass(MockSequencerA.class)
+ .describedAs("A Mock Sequencer")
+ .sequencingFrom("/**").andOutputtingTo("/")
+ .and().build();
+
+ assertThat(engine.getRepositorySource("config repo"),
is(notNullValue()));
+ assertThat(engine.getRepositorySource("config repo"),
is(instanceOf(InMemoryRepositorySource.class)));
+
+ SequencingService sequencer = engine.getSequencingService();
+ assertThat(sequencer.getStatistics().getNumberOfNodesSequenced(), is(0L));
+
+ NodeChanges changes = NodeChanges.create("", Arrays.asList(new Event[]
{ }));
+ sequencer.onNodeChanges(changes);
+
+ assertThat(sequencer.getStatistics().getNumberOfNodesSequenced(), is(0L));
+
+ Event e1 = mock(Event.class);
+ stub(e1.getType()).toReturn(Event.NODE_ADDED);
+ stub(e1.getPath()).toReturn("/test");
+ stub(e1.getUserID()).toReturn("Test");
+
+// changes = NodeChanges.create("", Arrays.asList(new Event[] { e1,
}));
+// sequencer.onNodeChanges(changes);
+//
+// // Shutdown the engine to force all pending tasks to complete
+// engine.shutdown();
+//
+// assertThat(sequencer.getStatistics().getNumberOfNodesSequenced(), is(1L));
+
+ }
+
+ public static class MockMimeTypeDetector implements MimeTypeDetector {
+ private String mimeType = "";
+
+ public MockMimeTypeDetector() {
+
+ }
+
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
+ public String mimeTypeOf( String name,
+ InputStream is ) {
+ return mimeType;
+ }
+ }
+
+
+}
Property changes on:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaEngineTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/mimetype/AbstractMimeTypeTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/mimetype/AbstractMimeTypeTest.java 2009-04-22
13:38:14 UTC (rev 845)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/mimetype/AbstractMimeTypeTest.java 2009-04-22
14:05:41 UTC (rev 846)
@@ -28,6 +28,7 @@
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.InputStream;
+import java.util.Collections;
import org.jboss.dna.graph.mimetype.MimeTypeDetector;
import org.junit.After;
import org.junit.Before;
@@ -45,7 +46,7 @@
protected AbstractMimeTypeTest( Class<? extends MimeTypeDetector> detector ) {
assertThat(detector, notNullValue());
- this.config = new MimeTypeDetectorConfig("MIME-Type Detector",
"MIME-Type Detector", detector.getName(), null);
+ this.config = new MimeTypeDetectorConfig("MIME-Type Detector",
"MIME-Type Detector", Collections.<String, Object>emptyMap(),
detector.getName(), null);
}
@Before