Author: jverhaeg(a)redhat.com
Date: 2008-06-18 15:07:44 -0400 (Wed, 18 Jun 2008)
New Revision: 302
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java
trunk/sequencers/dna-sequencer-images/pom.xml
trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
trunk/sequencers/dna-sequencer-java/pom.xml
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
Log:
DNA-124: Created SequencerContext that provides access to input node's path and
properties, and replaces SequencerOutput as the provider of the namespace repository and
value factories. The replaced methods in SequencerOutput have been deprecated. Also
updated all sequencers affected by this change.
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
(rev 0)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -0,0 +1,170 @@
+/*
+ * 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.sequencers;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.Node;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.repository.RepositoryI18n;
+import org.jboss.dna.repository.util.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.sequencers.SequencerContext;
+import org.jboss.dna.spi.sequencers.StreamSequencer;
+
+/**
+ * Contains context information that is passed to {@link StreamSequencer stream
sequencers}, including information about the
+ * input node containing the data being sequenced.
+ *
+ * @author John Verhaeg
+ */
+@Immutable
+public class SequencerNodeContext implements SequencerContext {
+
+ private final ValueFactories factories;
+ private final Path path;
+ private final Set<Property> props;
+
+ SequencerNodeContext( Node input,
+ ExecutionContext context ) throws RepositoryException {
+ assert input != null;
+ assert context != null;
+ this.factories = context.getValueFactories();
+ path = factories.getPathFactory().create(input.getPath());
+ Set<Property> props = new HashSet<Property>();
+ for (PropertyIterator iter = input.getProperties(); iter.hasNext();) {
+ javax.jcr.Property jcrProp = iter.nextProperty();
+ Property prop;
+ if (jcrProp.getDefinition().isMultiple()) {
+ Value[] jcrVals = jcrProp.getValues();
+ Object[] vals = new Object[jcrVals.length];
+ int ndx = 0;
+ for (Value jcrVal : jcrVals) {
+ vals[ndx++] = convert(factories, jcrProp.getName(), jcrVal);
+ }
+ prop =
context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()),
vals);
+ } else {
+ Value jcrVal = jcrProp.getValue();
+ Object val = convert(factories, jcrProp.getName(), jcrVal);
+ prop =
context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()),
val);
+ }
+ props.add(prop);
+ }
+ this.props = Collections.unmodifiableSet(props);
+ }
+
+ private Object convert( ValueFactories factories,
+ String name,
+ Value jcrValue ) throws RepositoryException {
+ switch (jcrValue.getType()) {
+ case PropertyType.BINARY: {
+ return factories.getBinaryFactory().create(jcrValue.getStream());
+ }
+ case PropertyType.BOOLEAN: {
+ return factories.getBooleanFactory().create(jcrValue.getBoolean());
+ }
+ case PropertyType.DATE: {
+ return factories.getDateFactory().create(jcrValue.getDate());
+ }
+ case PropertyType.DOUBLE: {
+ return factories.getDoubleFactory().create(jcrValue.getDouble());
+ }
+ case PropertyType.LONG: {
+ return factories.getLongFactory().create(jcrValue.getLong());
+ }
+ case PropertyType.NAME: {
+ return factories.getNameFactory().create(jcrValue.getString());
+ }
+ case PropertyType.PATH: {
+ return factories.getPathFactory().create(jcrValue.getString());
+ }
+ case PropertyType.REFERENCE: {
+ return factories.getReferenceFactory().create(jcrValue.getString());
+ }
+ case PropertyType.STRING: {
+ return factories.getStringFactory().create(jcrValue.getString());
+ }
+ default: {
+ throw new
RepositoryException(RepositoryI18n.unknownPropertyValueType.text(name,
jcrValue.getType()));
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactories getFactories() {
+ return factories;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getInputPath()
+ */
+ public Path getInputPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getInputProperties()
+ */
+ public Set<Property> getInputProperties() {
+ return props;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.sequencers.SequencerContext#getInputProperty(org.jboss.dna.spi.graph.Name)
+ */
+ public Property getInputProperty( Name name ) {
+ ArgCheck.isNotNull(name, "name");
+ for (Property prop : props) {
+ if (name.equals(prop.getName())) {
+ return prop;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerOutput#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return factories.getNameFactory().getNamespaceRegistry();
+ }
+}
Property changes on:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -80,7 +80,7 @@
String sequencedPropertyName,
NodeChange changes,
Set<RepositoryNodePath> outputPaths,
- ExecutionContext context,
+ ExecutionContext execContext,
ProgressMonitor progressMonitor ) throws RepositoryException,
SequencerException {
// 'sequencedPropertyName' contains the name of the modified property on
'input' that resuled the call to this sequencer
// 'changes' contains all of the changes to this node that occurred in
the transaction.
@@ -100,13 +100,14 @@
progressMonitor.worked(10);
// Get the binary property with the image content, and build the image
metadata from the image ...
- SequencerOutputMap output = new
SequencerOutputMap(context.getValueFactories());
+ SequencerOutputMap output = new
SequencerOutputMap(execContext.getValueFactories());
InputStream stream = null;
Throwable firstError = null;
ProgressMonitor sequencingMonitor = progressMonitor.createSubtask(50);
try {
stream = imageDataProperty.getStream();
- this.streamSequencer.sequence(stream, output, sequencingMonitor);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
execContext);
+ this.streamSequencer.sequence(stream, output, sequencerContext,
sequencingMonitor);
} catch (Throwable t) {
// Record the error ...
firstError = t;
@@ -143,13 +144,13 @@
final String nodePath = outputPath.getNodePath();
// Create a session to the repository where the data should be
written ...
- session =
context.getSessionFactory().createSession(repositoryWorkspaceName);
+ session =
execContext.getSessionFactory().createSession(repositoryWorkspaceName);
// Find or create the output node in this session ...
- Node outputNode = context.getTools().findOrCreateNode(session,
nodePath);
+ Node outputNode = execContext.getTools().findOrCreateNode(session,
nodePath);
// Now save the image metadata to the output node ...
- if (saveOutput(outputNode, output, context)) {
+ if (saveOutput(outputNode, output, execContext)) {
session.save();
}
} finally {
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -35,6 +35,7 @@
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
import org.xml.sax.Attributes;
@@ -73,21 +74,19 @@
private static final String LEXICAL_HANDLER_FEATURE =
"http://xml.org/sax/properties/lexical-handler";
/**
- * <p>
* {@inheritDoc}
- * </p>
*
- * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(java.io.InputStream,
- * org.jboss.dna.spi.sequencers.SequencerOutput,
org.jboss.dna.common.monitor.ProgressMonitor)
+ * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(InputStream,
SequencerOutput, SequencerContext, ProgressMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor monitor ) {
monitor.beginTask(100.0, RepositoryI18n.sequencingXmlDocument);
XMLReader reader;
try {
reader = XMLReaderFactory.createXMLReader();
- Handler handler = new Handler(output, monitor);
+ Handler handler = new Handler(output, context, monitor);
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
// Ensure handler acting as entity resolver 2
@@ -113,16 +112,18 @@
}
}
- private class Handler extends DefaultHandler2 {
+ private final class Handler extends DefaultHandler2 {
- private ProgressMonitor monitor;
- private SequencerOutput output;
+ private final SequencerOutput output;
+ private final SequencerContext context;
+ private final ProgressMonitor monitor;
+
private double progress;
private Path path; // The DNA path of the node representing the current XML
element
// Cached instances of the name factory and commonly referenced names
- private NameFactory nameFactory;
+ private final NameFactory nameFactory;
private Name commentContentName;
private Name commentName;
private Name elementContentName;
@@ -133,11 +134,11 @@
private Map<Name, List<IndexedName>> nameToIndexedNamesMap = new
HashMap<Name, List<IndexedName>>();
// The stack of recursive maps being processed, with the head entry being the map
for the current path
- private LinkedList<Map<Name, List<IndexedName>>>
nameToIndexedNamesMapStack = new LinkedList<Map<Name,
List<IndexedName>>>();
+ private final LinkedList<Map<Name, List<IndexedName>>>
nameToIndexedNamesMapStack = new LinkedList<Map<Name,
List<IndexedName>>>();
// The stack of XML namespace in scope, with the head entry being namespace of
the closest ancestor element declaring a
// namespace.
- private LinkedList<String> nsStack = new LinkedList<String>();
+ private final LinkedList<String> nsStack = new LinkedList<String>();
// Builder used to concatenate concurrent lines of CDATA into a single value.
private StringBuilder cDataBuilder;
@@ -149,13 +150,18 @@
private String entity;
Handler( SequencerOutput output,
+ SequencerContext context,
ProgressMonitor monitor ) {
+ assert output != null;
+ assert monitor != null;
+ assert context != null;
this.output = output;
+ this.context = context;
this.monitor = monitor;
// Initialize path to a an empty path relative to the SequencerOutput's
target path.
- path = output.getFactories().getPathFactory().createRelativePath();
+ path = context.getFactories().getPathFactory().createRelativePath();
// Cache name factory since it is frequently used
- nameFactory = output.getFactories().getNameFactory();
+ nameFactory = context.getFactories().getNameFactory();
}
/**
@@ -574,7 +580,7 @@
indexedNames.add(indexedName);
// Add element name and the appropriate index to the path.
// Per the JCR spec, the index must be relative to same-name sibling nodes
- path = output.getFactories().getPathFactory().create(path, name,
indexedNames.size());
+ path = context.getFactories().getPathFactory().create(path, name,
indexedNames.size());
// Add the indexed name map to the stack and set the current map to the new
element's map
nameToIndexedNamesMapStack.addFirst(nameToIndexedNamesMap);
nameToIndexedNamesMap = indexedName.nameToIndexedNamesMap;
@@ -641,7 +647,7 @@
String uri ) throws SAXException {
stopIfCancelled();
// Register any unregistered namespaces
- NamespaceRegistry registry = output.getNamespaceRegistry();
+ NamespaceRegistry registry = context.getNamespaceRegistry();
if (!registry.isRegisteredNamespaceUri(uri)) {
registry.register(prefix, uri);
}
Added:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
(rev 0)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -0,0 +1,158 @@
+/*
+ * 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.sequencers;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.IOException;
+import java.util.Iterator;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
+import org.jboss.dna.repository.util.ExecutionContext;
+import org.jboss.dna.repository.util.JcrNamespaceRegistry;
+import org.jboss.dna.repository.util.JcrTools;
+import org.jboss.dna.repository.util.SessionFactory;
+import org.jboss.dna.repository.util.SimpleExecutionContext;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.sequencers.SequencerContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author John Verhaeg
+ */
+public class SequencerNodeContextTest extends AbstractJcrRepositoryTest {
+
+ private ExecutionContext execContext;
+ private Session session;
+ private JcrTools tools;
+
+ @Before
+ public void before() throws Exception {
+ final SessionFactory sessionFactory = new SessionFactory() {
+
+ public Session createSession( String name ) throws RepositoryException {
+ try {
+ return getRepository().login(getTestCredentials());
+ } catch (IOException error) {
+ throw new RepositoryException(error);
+ }
+ }
+ };
+ NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory,
"doesn't matter");
+ execContext = new SimpleExecutionContext(sessionFactory, registry, null, null);
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+ tools = new JcrTools();
+ }
+
+ @After
+ public void after() {
+ if (session != null) {
+ try {
+ session.logout();
+ } finally {
+ session = null;
+ }
+ }
+ }
+
+ private void verifyProperty( SequencerContext context,
+ String name,
+ Object... values ) {
+ Property prop =
context.getInputProperty(execContext.getValueFactories().getNameFactory().create(name));
+ assertThat(prop, notNullValue());
+ assertThat(prop.getName(),
is(execContext.getValueFactories().getNameFactory().create(name)));
+ assertThat(prop.isEmpty(), is(false));
+ assertThat(prop.size(), is(values.length));
+ assertThat(prop.isMultiple(), is(values.length > 1));
+ // TODO: Uncomment after DNA-163 has been addressed
+ // assertThat(prop.isSingle(), is(values.length == 1));
+ Iterator<?> iter = prop.getValues();
+ for (Object val : values) {
+ assertThat(iter.hasNext(), is(true));
+ assertThat(iter.next(), is(val));
+ }
+ }
+
+ @Test( expected = java.lang.AssertionError.class )
+ public void shouldNotAllowNullInputNode() throws Exception {
+ new SequencerNodeContext(null, execContext);
+ }
+
+ @Test( expected = java.lang.AssertionError.class )
+ public void shouldNotAllowNullValueFactories() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a");
+ new SequencerNodeContext(input, null);
+ }
+
+ @Test
+ public void shouldProvideNamespaceRegistry() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
execContext);
+ assertThat(sequencerContext.getNamespaceRegistry(), notNullValue());
+ }
+
+ @Test
+ public void shouldProvideValueFactories() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
execContext);
+ assertThat(sequencerContext.getFactories(), notNullValue());
+ }
+
+ @Test
+ public void shouldProvidePathToInput() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
execContext);
+ assertThat(sequencerContext.getInputPath(),
is(execContext.getValueFactories().getPathFactory().create("/a/b/c")));
+ }
+
+ @Test
+ public void shouldNeverReturnNullInputProperties() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
execContext);
+ assertThat(sequencerContext.getInputProperties(), notNullValue());
+ assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldProvideInputProperties() throws Exception {
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ input.setProperty("x", true);
+ input.setProperty("y", new String[] {"asdf",
"xyzzy"});
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
execContext);
+ assertThat(sequencerContext.getInputProperties(), notNullValue());
+ assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
+ assertThat(sequencerContext.getInputProperties().size(), is(3));
+ verifyProperty(sequencerContext,
+ NameFactory.JCR_PRIMARY_TYPE,
+
execContext.getValueFactories().getNameFactory().create("{http://www...);
+ verifyProperty(sequencerContext, "x", true);
+ verifyProperty(sequencerContext, "y", "asdf",
"xyzzy");
+ }
+}
Property changes on:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -35,6 +35,7 @@
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.observation.Event;
+import org.jboss.dna.common.collection.Problem;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.RecordingProgressMonitor;
@@ -47,6 +48,7 @@
import org.jboss.dna.repository.util.SimpleExecutionContext;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
import org.junit.After;
@@ -93,6 +95,7 @@
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor progressMonitor ) {
for (SequencerOutputMap.Entry entry : finalOutput) {
Path nodePath = entry.getPath();
@@ -125,6 +128,37 @@
}
}
+ protected void testSequencer( final StreamSequencer sequencer ) throws Exception {
+ StreamSequencer streamSequencer = new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ try {
+ sequencer.sequence(stream, output, context, progressMonitor);
+ } catch (AssertionError err) {
+ progressMonitor.getProblems().addError(err, null);
+ }
+ }
+ };
+ StreamSequencerAdapter adapter = new StreamSequencerAdapter(streamSequencer);
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+ Node inputNode = tools.findOrCreateNode(session, "/a/b/c");
+ Node outputNode = tools.findOrCreateNode(session, "/d/e");
+ inputNode.setProperty("sequencedProperty", new
ByteArrayInputStream(sampleData.getBytes()));
+ NodeChange nodeChange = new NodeChange(repositoryWorkspaceName,
inputNode.getPath(), Event.PROPERTY_CHANGED,
+
Collections.singleton("sequencedProperty"), null);
+ Set<RepositoryNodePath> outputPaths = new
HashSet<RepositoryNodePath>();
+ outputPaths.add(new RepositoryNodePath(repositoryWorkspaceName,
outputNode.getPath()));
+ sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
+ adapter.execute(inputNode, "sequencedProperty", nodeChange,
outputPaths, context, progressMonitor);
+ for (Problem problem : progressMonitor.getProblems()) {
+ throw (AssertionError)problem.getThrowable();
+ }
+ }
+
@Test
public void shouldNotHaveSequencerUponInstantiation() {
assertThat(sequencer.getConfiguration(), is(nullValue()));
@@ -338,4 +372,56 @@
public void shouldSequencerOutputProvideAccessToNamespaceRegistry() {
assertThat(sequencerOutput.getNamespaceRegistry(), notNullValue());
}
+
+ @Test
+ public void shouldPassNonNullInputStreamToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(stream, notNullValue());
+ }
+ });
+ }
+
+ @Test
+ public void shouldPassNonNullSequencerOutputToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(output, notNullValue());
+ }
+ });
+ }
+
+ @Test
+ public void shouldPassNonNullSequencerContextToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(context, notNullValue());
+ }
+ });
+ }
+
+ @Test
+ public void shouldPassNonNullProgressMonitorToSequencer() throws Exception {
+ testSequencer(new StreamSequencer() {
+
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
+ assertThat(progressMonitor, notNullValue());
+ }
+ });
+ }
}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/xml/XmlSequencerTest.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -32,11 +32,13 @@
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author John Verhaeg
@@ -52,20 +54,14 @@
private URL xml3;
private URL xml4;
private URL xsd;
+ @Mock
+ private SequencerContext context;
@Before
public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
sequencer = new XmlSequencer();
- output = new MockSequencerOutput() {
-
- @Override
- public void setProperty( Path nodePath,
- Name propertyName,
- Object... values ) {
- super.setProperty(nodePath, propertyName, values);
- // System.out.println(nodePath + "." + propertyName + " =
" + Arrays.asList(values));
- }
- };
+ output = new MockSequencerOutput();
monitor = new SimpleProgressMonitor("Test activity");
xml1 =
this.getClass().getClassLoader().getResource("jackrabbitInMemoryTestRepositoryConfig.xml");
assertThat(xml1, is(notNullValue()));
@@ -193,7 +189,7 @@
private void verifyDocument( URL url ) throws IOException {
stream = url.openStream();
assertThat(stream, is(notNullValue()));
- sequencer.sequence(stream, output, monitor);
+ sequencer.sequence(stream, output, context, monitor);
verifyName("", NameFactory.JCR_PRIMARY_TYPE, XmlSequencer.DOCUMENT);
}
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
(rev 0)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -0,0 +1,71 @@
+/*
+ * 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.spi.sequencers;
+
+import java.util.Set;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author John Verhaeg
+ */
+public interface SequencerContext {
+
+ /**
+ * Get the factories that can be used to create {@link Path paths} and other property
values.
+ *
+ * @return the collection of factories; never <code>null</code>.
+ */
+ ValueFactories getFactories();
+
+ /**
+ * Return the path of the input node containing the content being sequenced.
+ *
+ * @return input node's path.
+ */
+ Path getInputPath();
+
+ /**
+ * Return the set of properties from the input node containing the content being
sequenced.
+ *
+ * @return the input node's properties; never <code>null</code>.
+ */
+ Set<Property> getInputProperties();
+
+ /**
+ * Return the property with the supplied name from the input node containing the
content being sequenced.
+ *
+ * @param name
+ * @return the input node property, or <code>null</code> if none exists.
+ */
+ Property getInputProperty( Name name );
+
+ /**
+ * Convenience method to get the namespace registry used by the {@link
ValueFactories#getNameFactory() name value factory}.
+ *
+ * @return the namespace registry; never <code>null</code>.
+ */
+ NamespaceRegistry getNamespaceRegistry();
+}
Property changes on:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -28,74 +28,79 @@
/**
* Interface for sequencers to use to generate their output.
- *
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
public interface SequencerOutput {
- /**
- * Get the factories that can be used to create {@link Path paths} and other property
values.
- *
- * @return the collection of factories; never null
- */
- ValueFactories getFactories();
+ /**
+ * Get the factories that can be used to create {@link Path paths} and other property
values.
+ *
+ * @return the collection of factories; never null
+ * @deprecated Replaced by {@link SequencerContext#getFactories()}.
+ */
+ @Deprecated
+ ValueFactories getFactories();
- /**
- * Convenience method to get the namespace registry used by the {@link
ValueFactories#getNameFactory() name value factory}.
- *
- * @return the namespace registry; never <code>null</code>
- */
- NamespaceRegistry getNamespaceRegistry();
+ /**
+ * Convenience method to get the namespace registry used by the {@link
ValueFactories#getNameFactory() name value factory}.
+ *
+ * @return the namespace registry; never <code>null</code>
+ * @deprecated Replaced by {@link SequencerContext#getNamespaceRegistry()}.
+ */
+ @Deprecated
+ NamespaceRegistry getNamespaceRegistry();
- /**
- * Set the supplied property on the supplied node.
- * <p>
- * The {@link #getFactories() value factories} should be used to create paths, names,
and values. These factories can be used
- * to create new values or convert values from one property type to another. (Note that
each of the factories have methods
- * that create values from all of the property types.)
- * </p>
- * <p>
- * This method is provided as a convenience, but it identical to creating a {@link Path}
and {@link Name} using the
- * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name,
Object...)}.
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param propertyName the name of the property to be set
- * @param values the value(s) for the property; may be empty if any existing property is
to be removed
- */
- void setProperty( String nodePath,
- String propertyName,
- Object... values );
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names,
and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note
that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link
Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name,
Object...)}.
+ * </p>
+ *
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property
is to be removed
+ */
+ void setProperty( String nodePath,
+ String propertyName,
+ Object... values );
- /**
- * Set the supplied reference on the supplied node.
- * <p>
- * This method is provided as a convenience, but it identical to creating a {@link Path}
and {@link Name} using the
- * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name,
Object...)}.
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param propertyName the name of the property to be set
- * @param paths the paths to the referenced property, which may be absolute paths or
relative to the sequencer output node;
- * may be empty if any existing property is to be removed
- */
- void setReference( String nodePath,
- String propertyName,
- String... paths );
+ /**
+ * Set the supplied reference on the supplied node.
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link
Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name,
Object...)}.
+ * </p>
+ *
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param paths the paths to the referenced property, which may be absolute paths or
relative to the sequencer output node;
+ * may be empty if any existing property is to be removed
+ */
+ void setReference( String nodePath,
+ String propertyName,
+ String... paths );
- /**
- * Set the supplied property on the supplied node.
- * <p>
- * The {@link #getFactories() value factories} should be used to create paths, names,
and values. These factories can be used
- * to create new values or convert values from one property type to another. (Note that
each of the factories have methods
- * that create values from all of the property types.)
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param propertyName the name of the property to be set
- * @param values the value(s) for the property; may be empty if any existing property is
to be removed
- */
- void setProperty( Path nodePath,
- Name propertyName,
- Object... values );
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names,
and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note
that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ *
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property
is to be removed
+ */
+ void setProperty( Path nodePath,
+ Name propertyName,
+ Object... values );
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/StreamSequencer.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -30,6 +30,7 @@
* <p>
* Implementations must provide a no-argument constructor.
* </p>
+ *
* @author Randall Hauch
*/
public interface StreamSequencer {
@@ -58,11 +59,15 @@
* <p>
* Finally, the implementation should call {@link ProgressMonitor#done()} when the
operation has finished.
* </p>
- * @param stream the stream with the data to be sequenced; never null
- * @param output the output from the sequencing operation; never null
+ *
+ * @param stream the stream with the data to be sequenced; never
<code>null</code>
+ * @param output the output from the sequencing operation; never
<code>null</code>
+ * @param context the context for the sequencing operation; never
<code>null</code>
* @param progressMonitor the progress monitor that should be kept updated with the
sequencer's progress and that should be
- * frequently consulted as to whether this operation has been {@link
ProgressMonitor#isCancelled() cancelled}.
+ * frequently consulted as to whether this operation has been {@link
ProgressMonitor#isCancelled() cancelled}.
*/
- void sequence( InputStream stream, SequencerOutput output, ProgressMonitor
progressMonitor );
-
+ void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor );
}
Modified: trunk/sequencers/dna-sequencer-images/pom.xml
===================================================================
--- trunk/sequencers/dna-sequencer-images/pom.xml 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-images/pom.xml 2008-06-18 19:07:44 UTC (rev 302)
@@ -57,6 +57,10 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for
testing)
-->
Modified:
trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
===================================================================
---
trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -26,6 +26,7 @@
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -62,6 +63,7 @@
* vendors to store custom metadata. This structure could be mapped with each directory
(e.g. "EXIF" or "Nikon Makernote" or
* "IPTC") as the name of a child node, with the EXIF tags values stored as
either properties or child nodes.
* </p>
+ *
* @author Randall Hauch
*/
public class ImageMetadataSequencer implements StreamSequencer {
@@ -84,8 +86,13 @@
/**
* {@inheritDoc}
+ *
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ProgressMonitor)
*/
- public void sequence( InputStream stream, SequencerOutput output, ProgressMonitor
progressMonitor ) {
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
progressMonitor.beginTask(10, ImageSequencerI18n.sequencerTaskName);
ImageMetadata metadata = new ImageMetadata();
@@ -102,8 +109,8 @@
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
- NameFactory nameFactory = output.getFactories().getNameFactory();
- PathFactory pathFactory = output.getFactories().getPathFactory();
+ NameFactory nameFactory = context.getFactories().getNameFactory();
+ PathFactory pathFactory = context.getFactories().getPathFactory();
Path metadataNode = pathFactory.create(METADATA_NODE);
// Place the image metadata into the output map ...
Modified:
trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
---
trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -31,9 +31,12 @@
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author Randall Hauch
@@ -48,9 +51,12 @@
private URL cautionJpg;
private URL cautionPict;
private URL cautionPng;
+ @Mock
+ private SequencerContext context;
@Before
public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
this.sequencer = new ImageMetadataSequencer();
this.output = new MockSequencerOutput();
output.getNamespaceRegistry().register("image",
"http://jboss.org/dna/images/1.0");
@@ -78,7 +84,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("image:metadata",
"jcr:primaryType"), is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"), is(new Object[] {"image/jpeg"}));
assertThat(output.getPropertyValues("image:metadata",
"image:formatName"), is(new Object[] {"JPEG"}));
@@ -101,7 +107,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("image:metadata",
"jcr:primaryType"), is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"), is(new Object[] {"image/png"}));
assertThat(output.getPropertyValues("image:metadata",
"image:formatName"), is(new Object[] {"PNG"}));
@@ -122,7 +128,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"), is(new Object[] {"image/gif"}));
assertThat(output.getPropertyValues("image:metadata",
"image:formatName"), is(new Object[] {"GIF"}));
assertThat(output.getPropertyValues("image:metadata",
"image:width"), is(new Object[] {48}));
@@ -142,7 +148,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.hasProperties(), is(false));
}
Modified: trunk/sequencers/dna-sequencer-java/pom.xml
===================================================================
--- trunk/sequencers/dna-sequencer-java/pom.xml 2008-06-18 19:01:04 UTC (rev 301)
+++ trunk/sequencers/dna-sequencer-java/pom.xml 2008-06-18 19:07:44 UTC (rev 302)
@@ -63,6 +63,10 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for
testing)
-->
Modified:
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
===================================================================
---
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -27,6 +27,7 @@
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -48,29 +49,32 @@
*/
public class JavaMetadataSequencer implements StreamSequencer {
-
public static final String JAVA_COMPILATION_UNIT_NODE =
"java:compilationUnit";
public static final String JAVA_COMPILATION_UNIT_PRIMARY_TYPE =
"jcr:primaryType";
public static final String JAVA_PACKAGE_CHILD_NODE = "java:package";
- public static final String JAVA_PACKAGE_DECLARATION_CHILD_NODE
="java:packageDeclaration";
- public static final String JAVA_PACKAGE_NAME ="java:packageName";
- public static final String JAVA_ANNOTATION_CHILD_NODE ="java:annotation";
-
- private static final String SLASH ="/";
+ public static final String JAVA_PACKAGE_DECLARATION_CHILD_NODE =
"java:packageDeclaration";
+ public static final String JAVA_PACKAGE_NAME = "java:packageName";
+ public static final String JAVA_ANNOTATION_CHILD_NODE = "java:annotation";
-
- /* (non-Javadoc)
- * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(java.io.InputStream,
org.jboss.dna.spi.sequencers.SequencerOutput,
org.jboss.dna.common.monitor.ProgressMonitor)
+ private static final String SLASH = "/";
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.StreamSequencer#sequence(java.io.InputStream,
+ * org.jboss.dna.spi.sequencers.SequencerOutput,
org.jboss.dna.spi.sequencers.SequencerContext,
+ * org.jboss.dna.common.monitor.ProgressMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor progressMonitor ) {
progressMonitor.beginTask(10, JavaMetadataI18n.sequencerTaskName);
-
+
JavaMetadata javaMetadata = null;
- NameFactory nameFactory = output.getFactories().getNameFactory();
- PathFactory pathFactory = output.getFactories().getPathFactory();
-
+ NameFactory nameFactory = context.getFactories().getNameFactory();
+ PathFactory pathFactory = context.getFactories().getPathFactory();
+
try {
javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream),
null, progressMonitor.createSubtask(10));
if (progressMonitor.isCancelled()) return;
@@ -78,12 +82,18 @@
e.printStackTrace();
return;
}
- if(javaMetadata != null) {
+ if (javaMetadata != null) {
Path javaCompilationUnitNode =
pathFactory.create(JAVA_COMPILATION_UNIT_NODE);
- output.setProperty(javaCompilationUnitNode,
nameFactory.create(JAVA_COMPILATION_UNIT_PRIMARY_TYPE),
"java:compilationUnit");
- Path javaPackageDeclarationChildNode =
pathFactory.create(JAVA_COMPILATION_UNIT_NODE + SLASH + JAVA_PACKAGE_CHILD_NODE + SLASH +
JAVA_PACKAGE_DECLARATION_CHILD_NODE);
- output.setProperty(javaPackageDeclarationChildNode,
nameFactory.create(JAVA_PACKAGE_NAME), javaMetadata.getPackageMetadata().getName());
-
+ output.setProperty(javaCompilationUnitNode,
+ nameFactory.create(JAVA_COMPILATION_UNIT_PRIMARY_TYPE),
+ "java:compilationUnit");
+ Path javaPackageDeclarationChildNode =
pathFactory.create(JAVA_COMPILATION_UNIT_NODE + SLASH
+ +
JAVA_PACKAGE_CHILD_NODE + SLASH
+ +
JAVA_PACKAGE_DECLARATION_CHILD_NODE);
+ output.setProperty(javaPackageDeclarationChildNode,
+ nameFactory.create(JAVA_PACKAGE_NAME),
+ javaMetadata.getPackageMetadata().getName());
+
}
progressMonitor.done();
}
Modified:
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java
===================================================================
---
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -74,7 +74,7 @@
}
@After
- public void afterEach() throws Exception {
+ public void afterEach() {
try {
if (session != null) session.logout();
} finally {
@@ -98,7 +98,7 @@
}
@Test
- public void testMap() throws Exception {
+ public void testMap() {
Map<String, String> errors = new HashMap<String, String>();
errors.put("login", "field.isNull");
if (!errors.containsKey("login")) errors.put("login",
"field.regexp");
Modified:
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
===================================================================
---
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/sequencers/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -24,6 +24,7 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -32,9 +33,12 @@
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author Serge Pagop
@@ -45,14 +49,18 @@
private MockSequencerOutput output;
private ProgressMonitor progress;
private File source;
+ @Mock
+ private SequencerContext context;
@Before
- public void beforeEach() throws Exception {
- this.sequencer = new JavaMetadataSequencer();
- this.output = new MockSequencerOutput();
+ public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
+ sequencer = new JavaMetadataSequencer();
+ output = new MockSequencerOutput();
output.getNamespaceRegistry().register("java",
"http://jboss.org/dna/java/1.0");
this.progress = new SimpleProgressMonitor("Test java monitor
activity");
source = new File("src/test/resources/org/acme/MySource.java");
+ stub(context.getFactories()).toReturn(output.getFactories());
}
@After
@@ -74,7 +82,7 @@
public void shouldGenerateMetadataForJavaSourceFile() throws IOException {
content = getJavaSrc(source);
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, progress);
+ sequencer.sequence(content, output, context, progress);
assertThat(output.getPropertyValues("java:compilationUnit",
"jcr:primaryType"), is(new Object[] {"java:compilationUnit"}));
assertThat(output.getPropertyValues("java:compilationUnit/java:package/java:packageDeclaration",
"java:packageName"),
is(new Object[] {"org.acme"}));
Modified:
trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
===================================================================
---
trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -23,6 +23,7 @@
import java.io.InputStream;
import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -43,6 +44,7 @@
* </li>
* </ul>
* </p>
+ *
* @author Stefano Maestri
* @author Randall Hauch
*/
@@ -58,8 +60,13 @@
/**
* {@inheritDoc}
+ *
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ProgressMonitor)
*/
- public void sequence( InputStream stream, SequencerOutput output, ProgressMonitor
progressMonitor ) {
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context,
+ ProgressMonitor progressMonitor ) {
Mp3Metadata metadata = Mp3Metadata.instance(stream);
if (metadata != null) {
Modified:
trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
===================================================================
---
trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-06-18
19:01:04 UTC (rev 301)
+++
trunk/sequencers/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-06-18
19:07:44 UTC (rev 302)
@@ -31,6 +31,7 @@
import org.jboss.dna.sequencer.msoffice.powerpoint.PowerPointMetadataReader;
import org.jboss.dna.sequencer.msoffice.powerpoint.SlideMetadata;
import org.jboss.dna.sequencer.msoffice.word.WordMetadataReader;
+import org.jboss.dna.spi.sequencers.SequencerContext;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -114,6 +115,7 @@
*/
public void sequence( InputStream stream,
SequencerOutput output,
+ SequencerContext context,
ProgressMonitor progressMonitor ) {
progressMonitor.beginTask(10, MSOfficeMetadataI18n.sequencerTaskName);