Author: rhauch
Date: 2008-11-10 15:21:55 -0500 (Mon, 10 Nov 2008)
New Revision: 617
Removed:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml
trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml
trunk/docs/reference/src/main/docbook/en-US/custom.dtd
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataTest.java
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerI18n.java
trunk/extensions/dna-sequencer-xml/src/test/java/org/jboss/dna/sequencer/xml/XmlSequencerTest.java
trunk/extensions/dna-sequencer-zip/pom.xml
trunk/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java
trunk/extensions/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java
Log:
DNA-248 - Simplify the ActivityMonitor framework
http://jira.jboss.com/jira/browse/DNA-248
Despite building the simplified Task framework (see attached patch file), and after
several days of thinking about it and a long discussion with John, it seems like this
ProgressMonitor/ActivityMonitor/Task framework is just overkill for what we need. And it
about 1900 LOC overkill. (Really, it started small and grew as we tried to generalize.
Mostly it was me that was driving it.)
Turns out that only the sequencing used this framework, and its arguable whether
there's any benefit to monitoring the progress and/or tasks for a singular sequencing
activity. The connector framework doesn't really need the overhead either, especially
when individual requests are so tiny and so many. So there really isn't a lot of
similarity between the two data points (sequencers and connectors). Rather than try to
force something to fit (really the purpose of this JIRA issue), it seems prudent to
recognize that we don't really have a well-defined need with well-understood
requirements, and that the best thing to do is to simply remove the
ProgressMonitor/ActivityMonitor framework.
In doing so, the sequencers became a little simpler. The XML sequencer became a fair
amount simpler. The code base became quite a bit smaller (>2400 LOC smaller). And we
really didn't lose any functionality. (Sure, we kind of lost cancellation of
sequencers, but that's probably not really true, either - it's quite possible that
the only way to REALLY cancel a sequencer that's been stuck reading from a stream is
to interrupt the thread, and the cancellation status wouldn't do that anyway.)
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-11-05
18:14:32 UTC (rev 616)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -48,8 +48,6 @@
public static I18n i18nRequiredToSuppliedParameterMismatch;
// Core-related fields
- public static I18n activityMonitorBeginTask;
- public static I18n activityMonitorStatus;
public static I18n argumentDidNotContainKey;
public static I18n argumentDidNotContainObject;
public static I18n argumentMayNotBeEmpty;
Modified: trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
===================================================================
---
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-11-10
20:21:55 UTC (rev 617)
@@ -37,8 +37,6 @@
i18nRequiredToSuppliedParameterMismatch = Internationalization field "{0}" in
{1}: {2}
# Core-related fields
-activityMonitorBeginTask = Beginning {0} ({1})
-activityMonitorStatus = {0}
argumentDidNotContainKey = "The {0} argument did not contain the expected key {1}
argumentDidNotContainObject = "The {0} argument did not contain the expected object
{1}
argumentMayNotBeEmpty = The {0} argument may not be empty
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -28,11 +28,9 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import java.util.List;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoAnnotations.Mock;
/**
* @author Randall Hauch
@@ -46,8 +44,6 @@
private SampleComponentConfig configA2;
private String validDescription;
private String[] validClasspath;
- @Mock
- private ActivityMonitor nullMonitor;
@Before
public void beforeEach() {
@@ -152,19 +148,19 @@
// The very first component instance should still be runnable ...
for (int i = 0; i != 10; ++i) {
- firstComponent.doSomething(nullMonitor);
+ firstComponent.doSomething();
}
assertThat(firstComponent.getCounter(), is(10));
// The second component instance should still be runnable ...
for (int i = 0; i != 10; ++i) {
- secondComponentA.doSomething(nullMonitor);
+ secondComponentA.doSomething();
}
assertThat(secondComponentA.getCounter(), is(10));
// The third component instance should still be runnable ...
for (int i = 0; i != 10; ++i) {
- firstComponentB.doSomething(nullMonitor);
+ firstComponentB.doSomething();
}
assertThat(firstComponentB.getCounter(), is(10));
}
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -24,8 +24,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* A sequencer that can be used for basic unit testing.
@@ -49,15 +47,9 @@
/**
* {@inheritDoc}
*/
- public void doSomething( ActivityMonitor activityMonitor ) {
- try {
- activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
- // increment the counter and record the progress ...
- this.counter.incrementAndGet();
- activityMonitor.worked(1);
- } finally {
- activityMonitor.done();
- }
+ public void doSomething() {
+ // increment the counter and record the progress ...
+ this.counter.incrementAndGet();
}
public int getCounter() {
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -24,8 +24,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* A sequencer that can be used for basic unit testing.
@@ -49,15 +47,9 @@
/**
* {@inheritDoc}
*/
- public void doSomething( ActivityMonitor activityMonitor ) {
- try {
- activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
- // increment the counter and record the progress ...
- this.counter.incrementAndGet();
- activityMonitor.worked(1);
- } finally {
- activityMonitor.done();
- }
+ public void doSomething() {
+ // increment the counter and record the progress ...
+ this.counter.incrementAndGet();
}
public int getCounter() {
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.common.component;
-import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* @author Randall Hauch
@@ -29,5 +28,5 @@
*/
public interface SampleComponent extends Component<SampleComponentConfig> {
- public void doSomething( ActivityMonitor activityMonitor );
+ public void doSomething();
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -27,9 +27,6 @@
import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.component.StandardClassLoaderFactory;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
-import org.jboss.dna.common.monitor.SimpleActivityMonitor;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.PropertyFactory;
@@ -117,16 +114,6 @@
/**
* {@inheritDoc}
*
- * @see
org.jboss.dna.graph.ExecutionContext#createActivityMonitor(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
- */
- public ActivityMonitor createActivityMonitor( I18n activityName,
- Object... activityNameParameters ) {
- return new SimpleActivityMonitor(activityName, activityNameParameters);
- }
-
- /**
- * {@inheritDoc}
- *
* @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
*/
public ClassLoader getClassLoader( String... classpath ) {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java 2008-11-05
18:14:32 UTC (rev 616)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -25,8 +25,6 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.component.ClassLoaderFactory;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Property;
@@ -46,18 +44,6 @@
public interface ExecutionContext extends ClassLoaderFactory {
/**
- * Creates a thread-safe activity monitor with the specified activity name. This
method should be used when the caller is
- * either not participating in an activity itself, or when a new activity needs to be
performed that is not considered a
- * subtask of the caller's activity.
- *
- * @param activityName The internationalization object representing the
activity's name.
- * @param activityNameParameters Any parameters needed to localize the activity's
name.
- * @return A new activity monitor
- */
- ActivityMonitor createActivityMonitor( I18n activityName,
- Object... activityNameParameters );
-
- /**
* @return the access control context; may be <code>null</code>
*/
AccessControlContext getAccessControlContext();
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java 2008-11-05
18:14:32 UTC (rev 616)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -24,8 +24,6 @@
import java.security.AccessControlContext;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.NameFactory;
@@ -152,16 +150,6 @@
/**
* {@inheritDoc}
*
- * @see
org.jboss.dna.graph.ExecutionContext#createActivityMonitor(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
- */
- public ActivityMonitor createActivityMonitor( I18n activityName,
- Object... activityNameParameters )
{
- return delegate.createActivityMonitor(activityName, activityNameParameters);
- }
-
- /**
- * {@inheritDoc}
- *
* @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
*/
public ClassLoader getClassLoader( String... classpath ) {
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -22,6 +22,7 @@
package org.jboss.dna.graph.sequencers;
import java.util.Set;
+import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Path;
@@ -60,4 +61,12 @@
* @return the MIME-type
*/
String getMimeType();
+
+ /**
+ * Get an interface that can be used to record various problems, warnings, and errors
that are not extreme enough to warrant
+ * throwing exceptions.
+ *
+ * @return the interface for recording problems; never null
+ */
+ Problems getProblems();
}
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -22,7 +22,6 @@
package org.jboss.dna.graph.sequencers;
import java.io.InputStream;
-import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* The interface for a DNA sequencer that processes a property as a stream to extract
information from the content and store in
@@ -44,31 +43,12 @@
* be called. If the sequencer implements this interface, then this method is called
with the property that is to be sequenced
* along with the interface used to register the output. The framework takes care of
all the rest.
* </p>
- * <p>
- * This operation should report progress to the supplied {@link ActivityMonitor}. At
the beginning of the operation, call
- * {@link ActivityMonitor#beginTask(double, org.jboss.dna.common.i18n.I18n,
Object...)} with a meaningful message describing
- * the operation and a total for the amount of work that will be done by this
sequencer. Then perform the sequencing work,
- * periodically reporting work by specifying the {@link
ActivityMonitor#worked(double) amount of work} that has was just
- * completed or by {@link ActivityMonitor#createSubtask(double) creating a subtask}
and reporting work against that subtask
- * monitor.
- * </p>
- * <p>
- * The implementation should also periodically check whether the operation has been
{@link ActivityMonitor#isCancelled()
- * cancelled}. If this method returns true, the implementation should abort all work
as soon as possible and close any
- * resources that were acquired or opened.
- * </p>
- * <p>
- * Finally, the implementation should call {@link ActivityMonitor#done()} when the
operation has finished.
- * </p>
*
* @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 activityMonitor the activity 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
ActivityMonitor#isCancelled() cancelled}.
*/
void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor );
+ SequencerContext context );
}
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -26,9 +26,8 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
-import org.jboss.dna.common.monitor.SimpleActivityMonitor;
+import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.properties.Name;
@@ -48,6 +47,7 @@
private final ValueFactories factories;
private final NamespaceRegistry registry = new BasicNamespaceRegistry();
+ private final Problems problems = new SimpleProblems();
public MockSequencerContext() {
registry.register("jcr", "http://www.jcp.org/jcr/1.0");
@@ -62,16 +62,6 @@
/**
* {@inheritDoc}
*
- * @see
org.jboss.dna.graph.ExecutionContext#createActivityMonitor(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
- */
- public ActivityMonitor createActivityMonitor( I18n activityName,
- Object... activityNameParameters ) {
- return new SimpleActivityMonitor(activityName, activityNameParameters);
- }
-
- /**
- * {@inheritDoc}
- *
* @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
*/
public ClassLoader getClassLoader( String... classpath ) {
@@ -117,6 +107,15 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.graph.sequencers.SequencerContext#getProblems()
+ */
+ public Problems getProblems() {
+ return problems;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext()
*/
public AccessControlContext getAccessControlContext() {
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 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryI18n.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -77,11 +77,7 @@
public static I18n errorFindingSequencersToRunAgainstNode;
public static I18n errorInRepositoryWhileFindingSequencersToRunAgainstNode;
public static I18n executionContextHasBeenClosed;
- public static I18n sequencerTask;
- public static I18n sequencerSubtask;
public static I18n unableToFindPropertyForSequencing;
- public static I18n sequencingPropertyOnNode;
- public static I18n writingOutputSequencedFromPropertyOnNodes;
// Properties
public static I18n errorReadingPropertiesFromContainerNode;
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -26,8 +26,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.component.Component;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.observation.NodeChangeListener;
import org.jboss.dna.repository.observation.NodeChanges;
@@ -52,7 +52,7 @@
* Execute the sequencing operation on the supplied node, which has recently been
created or changed. The implementation of
* this method is responsible for {@link JcrExecutionContext#getSessionFactory()
getting sessions}, modifying the appropriate
* nodes, {@link Session#save() saving} any changes made by this sequencer, and
{@link Session#logout() closing} all sessions
- * (and any other acquired resources), even in the case of {@link
ActivityMonitor#isCancelled() cancellation} or exceptions.
+ * (and any other acquired resources), even in the case of exceptions.
* <p>
* The {@link SequencingService} determines the sequencers that should be executed by
monitoring the changes to one or more
* workspaces (it is a {@link NodeChangeListener} registered with the {@link
ObservationService}). Changes in those workspaces
@@ -68,22 +68,6 @@
* Also, in such cases the sequencer's configuration may imply multiple output
nodes, so it is left to the sequencer to define
* the behavior in such cases.
* </p>
- * <p>
- * This operation should report progress to the supplied {@link ActivityMonitor}. At
the beginning of the operation, call
- * {@link ActivityMonitor#beginTask(double, org.jboss.dna.common.i18n.I18n,
Object...)} with a meaningful message describing
- * the operation and a total for the amount of work that will be done by this
sequencer. Then perform the sequencing work,
- * periodically reporting work by specifying the {@link
ActivityMonitor#worked(double) amount of work} that has was just
- * completed or by {@link ActivityMonitor#createSubtask(double) creating a subtask}
and reporting work against that subtask
- * monitor.
- * </p>
- * <p>
- * The implementation should also periodically check whether the operation has been
{@link ActivityMonitor#isCancelled()
- * cancelled}. If this method returns true, the implementation should abort all work
as soon as possible and close any
- * resources that were acquired or opened.
- * </p>
- * <p>
- * Finally, the implementation should call {@link ActivityMonitor#done()} when the
operation has finished.
- * </p>
*
* @param input the node that has recently been created or changed; never null
* @param sequencedPropertyName the name of the property that caused this sequencer
to be executed; never null and never empty
@@ -92,8 +76,7 @@
* @param outputPaths the paths to the nodes where the sequencing content should be
placed; never null and never empty, but
* the set may contain paths for non-existant nodes or may reference the
<code>input</code> node
* @param context the context in which this sequencer is executing; never null
- * @param activityMonitor the activity 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
ActivityMonitor#isCancelled() cancelled}.
+ * @param problems the interface used for recording problems; never null
* @throws RepositoryException if there is a problem while working with the
repository
* @throws SequencerException if there is an error in this sequencer
*/
@@ -102,6 +85,6 @@
NodeChange changes,
Set<RepositoryNodePath> outputPaths,
JcrExecutionContext context,
- ActivityMonitor activityMonitor ) throws RepositoryException,
SequencerException;
+ Problems problems ) throws RepositoryException, SequencerException;
}
Modified:
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 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -35,8 +35,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.Name;
@@ -65,15 +64,19 @@
private final Path path;
private final Set<Property> props;
private final JcrExecutionContext context;
+ private final Problems problems;
SequencerNodeContext( Node input,
javax.jcr.Property sequencedProperty,
- JcrExecutionContext context ) throws RepositoryException {
+ JcrExecutionContext context,
+ Problems problems ) throws RepositoryException {
assert input != null;
assert sequencedProperty != null;
assert context != null;
+ assert problems != null;
this.context = context;
this.sequencedProperty = sequencedProperty;
+ this.problems = problems;
this.factories = context.getValueFactories();
// Translate JCR path and property values to DNA constructs and cache them to
improve performance and prevent
// RepositoryException from being thrown by getters
@@ -142,16 +145,6 @@
/**
* {@inheritDoc}
*
- * @see
org.jboss.dna.graph.ExecutionContext#createActivityMonitor(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
- */
- public ActivityMonitor createActivityMonitor( I18n activityName,
- Object... activityNameParameters ) {
- return context.createActivityMonitor(activityName, activityNameParameters);
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext()
*/
public AccessControlContext getAccessControlContext() {
@@ -210,6 +203,15 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.graph.sequencers.SequencerContext#getProblems()
+ */
+ public Problems getProblems() {
+ return problems;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.graph.sequencers.SequencerContext#getMimeType()
*/
@SuppressWarnings( "null" )
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -43,12 +43,10 @@
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.component.ComponentLibrary;
import org.jboss.dna.common.component.StandardClassLoaderFactory;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
-import org.jboss.dna.common.monitor.LoggingActivityMonitor;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.common.util.Logger;
@@ -514,57 +512,37 @@
}
} else {
// Run each of those sequencers ...
- ActivityMonitor activityMonitor =
context.createActivityMonitor(RepositoryI18n.sequencerTask, changedNode);
- if (logger.isTraceEnabled()) {
- activityMonitor = new LoggingActivityMonitor(activityMonitor,
logger, Logger.Level.TRACE);
- }
- try {
- activityMonitor.beginTask(sequencerCalls.size(),
RepositoryI18n.sequencerTask, changedNode);
- for (Map.Entry<SequencerCall,
Set<RepositoryNodePath>> entry : sequencerCalls.entrySet()) {
- final SequencerCall sequencerCall = entry.getKey();
- final Set<RepositoryNodePath> outputPaths =
entry.getValue();
- final Sequencer sequencer = sequencerCall.getSequencer();
- final String sequencerName =
sequencer.getConfiguration().getName();
- final String propertyName =
sequencerCall.getSequencedPropertyName();
+ for (Map.Entry<SequencerCall, Set<RepositoryNodePath>>
entry : sequencerCalls.entrySet()) {
+ final SequencerCall sequencerCall = entry.getKey();
+ final Set<RepositoryNodePath> outputPaths =
entry.getValue();
+ final Sequencer sequencer = sequencerCall.getSequencer();
+ final String sequencerName =
sequencer.getConfiguration().getName();
+ final String propertyName =
sequencerCall.getSequencedPropertyName();
- // Get the paths to the nodes where the sequencer should
write it's output ...
- assert outputPaths != null && outputPaths.size() !=
0;
+ // Get the paths to the nodes where the sequencer should write
it's output ...
+ assert outputPaths != null && outputPaths.size() != 0;
- // Create a new execution context for each sequencer
- final Context executionContext = new Context(context);
- final ActivityMonitor sequenceMonitor =
activityMonitor.createSubtask(1);
+ // Create a new execution context for each sequencer
+ final Context executionContext = new Context(context);
+ final SimpleProblems problems = new SimpleProblems();
+ try {
+ sequencer.execute(node, propertyName, changedNode,
outputPaths, executionContext, problems);
+ } catch (RepositoryException e) {
+ logger.error(e,
RepositoryI18n.errorInRepositoryWhileSequencingNode, sequencerName, changedNode);
+ } catch (SequencerException e) {
+ logger.error(e, RepositoryI18n.errorWhileSequencingNode,
sequencerName, changedNode);
+ } finally {
try {
- sequenceMonitor.beginTask(100,
RepositoryI18n.sequencerSubtask, sequencerName);
- sequencer.execute(node,
- propertyName,
- changedNode,
- outputPaths,
- executionContext,
- sequenceMonitor.createSubtask(80)); //
80%
- } catch (RepositoryException e) {
- logger.error(e,
RepositoryI18n.errorInRepositoryWhileSequencingNode, sequencerName, changedNode);
- } catch (SequencerException e) {
- logger.error(e, RepositoryI18n.errorWhileSequencingNode,
sequencerName, changedNode);
+ // Save the changes made by each sequencer ...
+ if (session != null) session.save();
} finally {
- try {
- // Save the changes made by each sequencer ...
- if (session != null) session.save();
- sequenceMonitor.worked(10); // 90% of
sequenceMonitor
- } finally {
- try {
- // And always close the context.
- // This closes all sessions that may have been
created by the sequencer.
- executionContext.close();
- } finally {
- sequenceMonitor.done(); // 100% of
sequenceMonitor
- }
- }
+ // And always close the context.
+ // This closes all sessions that may have been created by
the sequencer.
+ executionContext.close();
}
}
- this.statistics.recordNodeSequenced();
- } finally {
- activityMonitor.done();
}
+ this.statistics.recordNodeSequenced();
}
} finally {
if (session != null) session.logout();
@@ -608,16 +586,6 @@
/**
* {@inheritDoc}
*
- * @see
org.jboss.dna.graph.ExecutionContext#createActivityMonitor(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
- */
- public ActivityMonitor createActivityMonitor( I18n activityName,
- Object... activityNameParameters )
{
- return delegate.createActivityMonitor(activityName, activityNameParameters);
- }
-
- /**
- * {@inheritDoc}
- *
* @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
*/
public ClassLoader getClassLoader( String... classpath ) {
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-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -31,7 +31,7 @@
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.Binary;
import org.jboss.dna.graph.properties.DateTime;
@@ -82,88 +82,71 @@
NodeChange changes,
Set<RepositoryNodePath> outputPaths,
JcrExecutionContext execContext,
- ActivityMonitor activityMonitor ) throws RepositoryException,
SequencerException {
+ Problems problems ) throws RepositoryException,
SequencerException {
// 'sequencedPropertyName' contains the name of the modified property on
'input' that resulted in the call to this
// sequencer.
// 'changes' contains all of the changes to this node that occurred in
the transaction.
// 'outputPaths' contains the paths of the node(s) where this sequencer
is to save it's data.
+ // Get the property that contains the data, given by 'propertyName' ...
+ Property sequencedProperty = null;
try {
- activityMonitor.beginTask(100, RepositoryI18n.sequencingPropertyOnNode,
sequencedPropertyName, input.getPath());
+ sequencedProperty = input.getProperty(sequencedPropertyName);
+ } catch (PathNotFoundException e) {
+ String msg =
RepositoryI18n.unableToFindPropertyForSequencing.text(sequencedPropertyName,
input.getPath());
+ throw new SequencerException(msg, e);
+ }
- // Get the property that contains the data, given by 'propertyName'
...
- Property sequencedProperty = null;
- try {
- sequencedProperty = input.getProperty(sequencedPropertyName);
- } catch (PathNotFoundException e) {
- String msg =
RepositoryI18n.unableToFindPropertyForSequencing.text(sequencedPropertyName,
input.getPath());
- throw new SequencerException(msg, e);
+ // Get the binary property with the image content, and build the image metadata
from the image ...
+ SequencerOutputMap output = new
SequencerOutputMap(execContext.getValueFactories());
+ InputStream stream = null;
+ Throwable firstError = null;
+ try {
+ stream = sequencedProperty.getStream();
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
+ this.streamSequencer.sequence(stream, output, sequencerContext);
+ } catch (Throwable t) {
+ // Record the error ...
+ firstError = t;
+ } finally {
+ if (stream != null) {
+ // Always close the stream, recording the error if we've not yet seen
an error
+ try {
+ stream.close();
+ } catch (Throwable t) {
+ if (firstError == null) firstError = t;
+ } finally {
+ stream = null;
+ }
}
- activityMonitor.worked(10);
+ if (firstError != null) {
+ // Wrap and throw the first error that we saw ...
+ throw new SequencerException(firstError);
+ }
+ }
- // Get the binary property with the image content, and build the image
metadata from the image ...
- SequencerOutputMap output = new
SequencerOutputMap(execContext.getValueFactories());
- InputStream stream = null;
- Throwable firstError = null;
- ActivityMonitor sequencingMonitor = activityMonitor.createSubtask(50);
+ // Find each output node and save the image metadata there ...
+ for (RepositoryNodePath outputPath : outputPaths) {
+ Session session = null;
try {
- stream = sequencedProperty.getStream();
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext);
- this.streamSequencer.sequence(stream, output, sequencerContext,
sequencingMonitor);
- } catch (Throwable t) {
- // Record the error ...
- firstError = t;
- } finally {
- sequencingMonitor.done();
- if (stream != null) {
- // Always close the stream, recording the error if we've not yet
seen an error
- try {
- stream.close();
- } catch (Throwable t) {
- if (firstError == null) firstError = t;
- } finally {
- stream = null;
- }
- }
- if (firstError != null) {
- // Wrap and throw the first error that we saw ...
- throw new SequencerException(firstError);
- }
- }
+ // Get the name of the repository workspace and the path to the output
node
+ final String repositoryWorkspaceName =
outputPath.getRepositoryWorkspaceName();
+ final String nodePath = outputPath.getNodePath();
- // Find each output node and save the image metadata there ...
- ActivityMonitor writingActivity = activityMonitor.createSubtask(40);
- writingActivity.beginTask(outputPaths.size(),
-
RepositoryI18n.writingOutputSequencedFromPropertyOnNodes,
- sequencedPropertyName,
- input.getPath(),
- outputPaths.size());
- for (RepositoryNodePath outputPath : outputPaths) {
- Session session = null;
- try {
- // Get the name of the repository workspace and the path to the
output node
- final String repositoryWorkspaceName =
outputPath.getRepositoryWorkspaceName();
- final String nodePath = outputPath.getNodePath();
+ // Create a session to the repository where the data should be written
...
+ session =
execContext.getSessionFactory().createSession(repositoryWorkspaceName);
- // Create a session to the repository where the data should be
written ...
- session =
execContext.getSessionFactory().createSession(repositoryWorkspaceName);
+ // Find or create the output node in this session ...
+ Node outputNode = execContext.getTools().findOrCreateNode(session,
nodePath);
- // Find or create the output node in this session ...
- Node outputNode = execContext.getTools().findOrCreateNode(session,
nodePath);
-
- // Now save the image metadata to the output node ...
- if (saveOutput(outputNode, output, execContext)) {
- session.save();
- }
- } finally {
- writingActivity.worked(1);
- // Always close the session ...
- if (session != null) session.logout();
+ // Now save the image metadata to the output node ...
+ if (saveOutput(outputNode, output, execContext)) {
+ session.save();
}
+ } finally {
+ // Always close the session ...
+ if (session != null) session.logout();
}
- writingActivity.done();
- } finally {
- activityMonitor.done();
}
}
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 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/main/resources/org/jboss/dna/repository/RepositoryI18n.properties 2008-11-10
20:21:55 UTC (rev 617)
@@ -62,11 +62,7 @@
errorInRepositoryWhileFindingSequencersToRunAgainstNode = Error in repository while
finding sequencers to run against node {0}
errorFindingSequencersToRunAgainstNode = Error finding sequencers to run against node
{0}
executionContextHasBeenClosed = This execution context has been closed and may not be
used to create another session
-sequencerTask = Sequencing {0}
-sequencerSubtask = running {0}
unableToFindPropertyForSequencing = Unable to find the {0} property while sequencing node
{1}
-sequencingPropertyOnNode = Sequencing the {0} property on node {1}
-writingOutputSequencedFromPropertyOnNodes = Writing the output of the sequencing of the
{0} property on node {1} to {2} nodes
errorReadingPropertiesFromContainerNode = Error reading properties from property
container node {0}
requiredPropertyOnNodeWasExpectedToBeStringValue = The required {0} property on node {1}
was expected to be a string value
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -28,8 +28,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import javax.jcr.Node;
import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.JcrExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
@@ -71,16 +70,10 @@
NodeChange changes,
Set<RepositoryNodePath> outputPaths,
JcrExecutionContext context,
- ActivityMonitor activityMonitor ) {
- try {
- activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
- // increment the counter and record the progress ...
- this.counter.incrementAndGet();
- this.latch.countDown();
- activityMonitor.worked(1);
- } finally {
- activityMonitor.done();
- }
+ Problems problems ) {
+ // increment the counter and record the progress ...
+ this.counter.incrementAndGet();
+ this.latch.countDown();
}
public int getCounter() {
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -28,8 +28,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import javax.jcr.Node;
import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.JcrExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
@@ -71,16 +70,10 @@
NodeChange changes,
Set<RepositoryNodePath> outputPaths,
JcrExecutionContext context,
- ActivityMonitor activityMonitor ) {
- try {
- activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
- // increment the counter and record the progress ...
- this.counter.incrementAndGet();
- this.latch.countDown();
- activityMonitor.worked(1);
- } finally {
- activityMonitor.done();
- }
+ Problems problems ) {
+ // increment the counter and record the progress ...
+ this.counter.incrementAndGet();
+ this.latch.countDown();
}
public int getCounter() {
Modified:
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 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -29,6 +29,8 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Property;
@@ -52,6 +54,7 @@
private JcrExecutionContext execContext;
private Session session;
private JcrTools tools;
+ private Problems problems;
@Mock
private javax.jcr.Property sequencedProperty;
@@ -73,6 +76,7 @@
startRepository();
session = getRepository().login(getTestCredentials());
tools = new JcrTools();
+ problems = new SimpleProblems();
}
@After
@@ -105,46 +109,46 @@
@Test( expected = java.lang.AssertionError.class )
public void shouldNotAllowNullInputNode() throws Exception {
- new SequencerNodeContext(null, sequencedProperty, execContext);
+ new SequencerNodeContext(null, sequencedProperty, execContext, problems);
}
@Test( expected = java.lang.AssertionError.class )
public void shouldNotAllowNullSequencedProperty() throws Exception {
Node input = tools.findOrCreateNode(session, "/a");
- new SequencerNodeContext(input, null, execContext);
+ new SequencerNodeContext(input, null, execContext, problems);
}
@Test( expected = java.lang.AssertionError.class )
public void shouldNotAllowNullExecutionContext() throws Exception {
Node input = tools.findOrCreateNode(session, "/a");
- new SequencerNodeContext(input, sequencedProperty, null);
+ new SequencerNodeContext(input, sequencedProperty, null, problems);
}
@Test
public void shouldProvideNamespaceRegistry() throws Exception {
Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
assertThat(sequencerContext.getNamespaceRegistry(), notNullValue());
}
@Test
public void shouldProvideValueFactories() throws Exception {
Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
assertThat(sequencerContext.getValueFactories(), notNullValue());
}
@Test
public void shouldProvidePathToInput() throws Exception {
Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
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,
sequencedProperty, execContext);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
assertThat(sequencerContext.getInputProperties(), notNullValue());
assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
}
@@ -154,7 +158,7 @@
Node input = tools.findOrCreateNode(session, "/a/b/c");
input.setProperty("x", true);
input.setProperty("y", new String[] {"asdf",
"xyzzy"});
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
assertThat(sequencerContext.getInputProperties(), notNullValue());
assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
assertThat(sequencerContext.getInputProperties().size(), is(3));
@@ -168,7 +172,7 @@
@Test
public void shouldProvideMimeType() throws Exception {
Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext);
+ SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
assertThat(sequencerContext.getMimeType(), is("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-11-05
18:14:32 UTC (rev 616)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -35,10 +35,9 @@
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.observation.Event;
+import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
-import org.jboss.dna.common.monitor.ActivityMonitor;
-import org.jboss.dna.common.monitor.CapturedActivityInfo;
-import org.jboss.dna.common.monitor.RecordingActivityMonitor;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.sequencers.SequencerContext;
@@ -70,8 +69,8 @@
private SequencerOutputMap sequencerOutput;
private String sampleData = "The little brown fox didn't something
bad.";
private JcrExecutionContext context;
- private RecordingActivityMonitor activityMonitor;
private String repositoryWorkspaceName = "something";
+ private Problems problems;
@Before
public void beforeEach() {
@@ -83,10 +82,10 @@
return createTestSession();
}
};
+ problems = new SimpleProblems();
NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory,
"doesn't matter");
this.context = new BasicJcrExecutionContext(sessionFactory, registry, null,
null);
this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories());
- this.activityMonitor = new
RecordingActivityMonitor(StreamSequencerAdapterTest.class.getName());
final SequencerOutputMap finalOutput = sequencerOutput;
this.streamSequencer = new StreamSequencer() {
@@ -96,8 +95,7 @@
*/
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
+ SequencerContext context ) {
for (SequencerOutputMap.Entry entry : finalOutput) {
Path nodePath = entry.getPath();
for (SequencerOutputMap.PropertyValue property :
entry.getPropertyValues()) {
@@ -134,13 +132,8 @@
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
- try {
- sequencer.sequence(stream, output, context, activityMonitor);
- } catch (AssertionError err) {
- activityMonitor.captureError(err);
- }
+ SequencerContext context ) {
+ sequencer.sequence(stream, output, context);
}
};
StreamSequencerAdapter adapter = new StreamSequencerAdapter(streamSequencer);
@@ -154,10 +147,7 @@
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, activityMonitor);
- for (CapturedActivityInfo info :
activityMonitor.getStatus().getCapturedInformation()) {
- if (info.isError()) throw info.getThrowable();
- }
+ adapter.execute(inputNode, "sequencedProperty", nodeChange,
outputPaths, context, problems);
}
@Test
@@ -219,7 +209,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, problems);
}
@Test( expected = SequencerException.class )
@@ -252,7 +242,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer, which should cause the exception ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, problems);
}
@Test
@@ -285,7 +275,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, problems);
// Check to see that the output nodes have been created ...
assertThat(session.getRootNode().hasNode("d/e"), is(true));
@@ -317,7 +307,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, problems);
// Check to see that the "/d/e" node has been created ...
assertThat(session.getRootNode().hasNode("d/e"), is(true));
@@ -351,7 +341,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, problems);
// Check to see that the output nodes have been created ...
assertThat(session.getRootNode().hasNode("d/e"), is(true));
@@ -380,8 +370,7 @@
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
+ SequencerContext context ) {
assertThat(stream, notNullValue());
}
});
@@ -393,8 +382,7 @@
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
+ SequencerContext context ) {
assertThat(output, notNullValue());
}
});
@@ -406,23 +394,10 @@
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
+ SequencerContext context ) {
assertThat(context, notNullValue());
}
});
}
- @Test
- public void shouldPassNonNullActivityMonitorToSequencer() throws Throwable {
- testSequencer(new StreamSequencer() {
-
- public void sequence( InputStream stream,
- SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
- assertThat(activityMonitor, notNullValue());
- }
- });
- }
}
Modified: trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml
===================================================================
---
trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml 2008-11-10
20:21:55 UTC (rev 617)
@@ -183,17 +183,19 @@
*
* @param stream the stream with the data to be sequenced; never null
* @param output the output from the sequencing operation; never null
- * @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 cancelled.
+ * @param context the context for the sequencing operation; never null
*/
- void sequence( InputStream stream, SequencerOutput output, ProgressMonitor
progressMonitor );
+ void sequence( InputStream stream, SequencerOutput output, SequencerContext context
);
]]></programlisting>
<para>The job of a stream sequencer is to process the data in the supplied
stream, and place into the <code>SequencerOutput</code>
any information that is to go into the JCR repository. JBoss DNA figures out when
your sequencer should be called
(of course, using the sequencing configuration you'll add in a bit), and then
makes sure the generated information
is saved in the correct place in the repository.
</para>
+ <para>The <code>SequencerContext</code> provides information about
+ the current sequencing operation, including the location and properties of the node
being sequenced, the MIME type
+ of the node being sequenced, and a location to record problems that aren't severe
enough to warrant throwing an exception.
+ </para>
<para>The <code>SequencerOutput</code> class is fairly easy to use.
There are basically two methods you need to call.
One method sets the property values, while the other sets references to other nodes
in the repository. Use these
methods to describe the properties of the nodes you want to create, using relative
paths for the nodes and
@@ -261,9 +263,7 @@
* {@inheritDoc}
*/
public void sequence( InputStream stream, SequencerOutput output,
- ProgressMonitor progressMonitor ) {
- progressMonitor.beginTask(10, ImageSequencerI18n.sequencerTaskName);
-
+ SequencerContext context ) {
ImageMetadata metadata = new ImageMetadata();
metadata.setInput(stream);
metadata.setDetermineImageNumber(true);
@@ -273,8 +273,6 @@
if (!metadata.check()) {
metadata = null;
}
- progressMonitor.worked(5);
- if (progressMonitor.isCancelled()) return;
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
@@ -294,8 +292,6 @@
output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_WIDTH_INCHES,
metadata.getPhysicalWidthInch());
output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_HEIGHT_INCHES,
metadata.getPhysicalHeightInch());
}
-
- progressMonitor.done();
}
}
]]></programlisting>
@@ -304,22 +300,7 @@
and with the <code>image:metadata</code> node type. No mixins are
defined for the node, but several properties are set on the node
using the values obtained from the image metadata. After this method returns, the
constructed graph will be saved to the repository
in all of the places defined by its configuration. (This is why only relative paths
are used in the sequencer.)
- </para>
- <para>Also note how the progress monitor is used. Reporting progress through
the supplied <code>ProgressMonitor</code> is very easy, and it ensures that
JBoss DNA
- can accurately monitor and report the status of sequencing activities to the users.
At the beginning of the operation, call
- <code>beginTask(...)</code> with a meaningful message describing
- the operation and a total for the amount of work that will be done by this
sequencer. Then perform the sequencing work,
- periodically reporting work by specifying the incremental amount of work with the
<code>worked(double)</code> method, or
- by creating a subtask with the <code>createSubtask(double)</code> method
and reporting work against that subtask
- monitor.
- </para>
- <para>Your method should periodically use the ProgressMonitor's
<code>isCancelled()</code> method to check whether the operation has been
- cancelled.. If this method returns true, the implementation should abort all work
as
- soon as possible and close any resources that were acquired or opened.
- </para>
- <para>
- Finally, when your sequencing operation is completed, it should call
<code>done()</code> on the progress monitor.
- </para>
+ </para>
</sect1>
<sect1 id="testing_custom_sequencers">
<title>Testing custom sequencers</title>
@@ -338,11 +319,11 @@
<programlisting role="JAVA"><![CDATA[
Sequencer sequencer = new ImageMetadataSequencer();
MockSequencerOutput output = new MockSequencerOutput();
-ProgressMonitor progress = new SimpleProgressMonitor("Test activity");
+MockSequencerContext context = new MockSequencerContext();
InputStream stream = null;
try {
stream =
this.getClass().getClassLoader().getResource("caution.gif").openStream();
- sequencer.sequence(stream,output,progress); // writes to 'output'
+ sequencer.sequence(stream,output,context); // writes to 'output'
assertThat(output.getPropertyValues("image:metadata",
"jcr:primaryType"),
is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"),
@@ -357,11 +338,11 @@
<programlisting role="JAVA"><![CDATA[
Sequencer sequencer = new ImageMetadataSequencer();
MockSequencerOutput output = new MockSequencerOutput();
-ProgressMonitor progress = new SimpleProgressMonitor("Test activity");
+MockSequencerContext context = new MockSequencerContext();
InputStream stream = null;
try {
stream =
this.getClass().getClassLoader().getResource("caution.pict").openStream();
- sequencer.sequence(stream,output,progress); // writes to 'output'
+ sequencer.sequence(stream,output,context); // writes to 'output'
assertThat(output.hasProperties(), is(false));
assertThat(output.hasReferences(), is(false));
} finally {
Modified: trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml 2008-11-05 18:14:32
UTC (rev 616)
+++ trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml 2008-11-10 20:21:55
UTC (rev 617)
@@ -601,17 +601,19 @@
*
* @param stream the stream with the data to be sequenced; never null
* @param output the output from the sequencing operation; never null
- * @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 cancelled.
+ * @param context the context for the sequencing operation; never null
*/
- void sequence( &InputStream; stream, &SequencerOutput; output,
&ProgressMonitor; progressMonitor );
+ void sequence( &InputStream; stream, &SequencerOutput; output,
&SequencerContext; context );
</programlisting>
<para>The job of a stream sequencer is to process the data in the supplied
stream, and place into the &SequencerOutput;
any information that is to go into the JCR repository. JBoss DNA figures out when
your sequencer should be called
(of course, using the sequencing configuration you'll add in a bit), and then
makes sure the generated information
is saved in the correct place in the repository.
</para>
+ <para>The &SequencerContext; provides information about
+ the current sequencing operation, including the location and properties of the node
being sequenced, the MIME type
+ of the node being sequenced, and a location to record problems that aren't
severe enough to warrant throwing an exception.
+ </para>
<para>The &SequencerOutput; class is fairly easy to use. There are
basically two methods you need to call.
One method sets the property values, while the other sets references to other nodes
in the repository. Use these
methods to describe the properties of the nodes you want to create, using relative
paths for the nodes and
@@ -679,9 +681,7 @@
* {@inheritDoc}
*/
public void sequence( &InputStream; stream, &SequencerOutput; output,
- &ProgressMonitor; progressMonitor ) {
- progressMonitor.beginTask(10, &ImageSequencerI18n;.sequencerTaskName);
-
+ &SequencerContext; context ) {
&ImageMetadata; metadata = new &ImageMetadata;();
metadata.setInput(stream);
metadata.setDetermineImageNumber(true);
@@ -691,9 +691,6 @@
if (!metadata.check()) {
metadata = null;
}
- progressMonitor.worked(5);
- if (progressMonitor.isCancelled()) return;
-
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
// Place the image metadata into the output map ...
@@ -712,8 +709,6 @@
output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_WIDTH_INCHES,
metadata.getPhysicalWidthInch());
output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_HEIGHT_INCHES,
metadata.getPhysicalHeightInch());
}
-
- progressMonitor.done();
}
}
</programlisting>
@@ -723,21 +718,6 @@
using the values obtained from the image metadata. After this method returns, the
constructed graph will be saved to the repository
in all of the places defined by its configuration. (This is why only relative paths
are used in the sequencer.)
</para>
- <para>Also note how the progress monitor is used. Reporting progress through
the supplied &ProgressMonitor;> is very easy, and it ensures that JBoss DNA
- can accurately monitor and report the status of sequencing activities to the users.
At the beginning of the operation, call
- <code>beginTask(...)</code> with a meaningful message describing
- the operation and a total for the amount of work that will be done by this
sequencer. Then perform the sequencing work,
- periodically reporting work by specifying the incremental amount of work with the
<code>worked(double)</code> method, or
- by creating a subtask with the <code>createSubtask(double)</code>
method and reporting work against that subtask
- monitor.
- </para>
- <para>Your method should periodically use the &ProgressMonitor;'s
<code>isCancelled()</code> method to check whether the operation has been
- cancelled.. If this method returns true, the implementation should abort all work
as
- soon as possible and close any resources that were acquired or opened.
- </para>
- <para>
- Finally, when your sequencing operation is completed, it should call
<code>done()</code> on the progress monitor.
- </para>
</sect2>
<sect2 id="testing_custom_sequencers">
<title>Testing custom sequencers</title>
@@ -755,12 +735,12 @@
this example code does not do any error handling and does not make all the
assertions a real test would.</para>
<programlisting>
&StreamSequencer; sequencer = new &ImageMetadataSequencer;();
-MockSequencerOutput output = new MockSequencerOutput();
-&ProgressMonitor; progress = new &SimpleProgressMonitor;("Test
activity");
+&MockSequencerOutput; output = new &MockSequencerOutput;();
+&MockSequencerContext; context = new &MockSequencerContext;();
&InputStream; stream = null;
try {
stream =
this.getClass().getClassLoader().getResource("caution.gif").openStream();
- sequencer.sequence(stream,output,progress); // writes to 'output'
+ sequencer.sequence(stream,output,context); // writes to 'output'
assertThat(output.getPropertyValues("image:metadata",
"jcr:primaryType"),
is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"),
@@ -774,12 +754,12 @@
<para>It's also useful to test that a sequencer produces no output for
something it should not understand:</para>
<programlisting>
&Sequencer; sequencer = new &ImageMetadataSequencer;();
-MockSequencerOutput output = new MockSequencerOutput();
-&ProgressMonitor; progress = new &SimpleProgressMonitor;("Test
activity");
+&MockSequencerOutput; output = new &MockSequencerOutput;();
+&MockSequencerContext; context = new &MockSequencerContext;();
&InputStream; stream = null;
try {
stream =
this.getClass().getClassLoader().getResource("caution.pict").openStream();
- sequencer.sequence(stream,output,progress); // writes to 'output'
+ sequencer.sequence(stream,output,context); // writes to 'output'
assertThat(output.hasProperties(), is(false));
assertThat(output.hasReferences(), is(false));
} finally {
Modified: trunk/docs/reference/src/main/docbook/en-US/custom.dtd
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/custom.dtd 2008-11-05 18:14:32 UTC (rev
616)
+++ trunk/docs/reference/src/main/docbook/en-US/custom.dtd 2008-11-10 20:21:55 UTC (rev
617)
@@ -45,8 +45,6 @@
<!-- Types in dna-common -->
<!ENTITY Logger "<ulink
url='&API;common/util/Logger.html'><interface>Logger</interface></ulink>">
-<!ENTITY ProgressMonitor "<ulink
url='&API;common/monitor/ProgressMonitor.html'><interface>ProgressMonitor</interface></ulink>">
-<!ENTITY SimpleProgressMonitor "<ulink
url='&API;common/monitor/SimpleProgressMonitor.html'><classname>SimpleProgressMonitor</classname></ulink>">
<!ENTITY ClassLoaderFactory "<ulink
url='&API;common/component/ClassLoaderFactory.html'><interface>ClassLoaderFactory</interface></ulink>">
<!ENTITY StandardClassLoaderFactory "<ulink
url='&API;common/component/ClassLoaderFactory.html'><classname>StandardClassLoaderFactory</classname></ulink>">
@@ -63,7 +61,10 @@
<!ENTITY RepositoryConnection "<ulink
url='&API;graph/connectors/RepositoryConnection.html'><interface>RepositoryConnection</interface></ulink>">
<!ENTITY StreamSequencer "<ulink
url='&API;graph/sequencers/StreamSequencer.html'><interface>StreamSequencer</interface></ulink>">
<!ENTITY SequencerOutput "<ulink
url='&API;graph/sequencers/SequencerOutput.html'><interface>SequencerOutput</interface></ulink>">
+<!ENTITY SequencerContext "<ulink
url='&API;graph/sequencers/SequencerContext.html'><interface>SequencerContext</interface></ulink>">
<!ENTITY MimeTypeDetector "<ulink
url='&API;graph/mimetype/MimeTypeDetector.html'><interface>MimeTypeDetector</interface></ulink>">
+<!ENTITY MockSequencerOutput "<ulink
url='&API;graph/sequencers/MockSequencerOutput.html'><interface>MockSequencerOutput</interface></ulink>">
+<!ENTITY MockSequencerContext "<ulink
url='&API;graph/sequencers/MockSequencerContext.html'><interface>MockSequencerContext</interface></ulink>">
<!-- Types in dna-repository -->
Modified:
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -22,7 +22,6 @@
package org.jboss.dna.sequencer.images;
import java.io.InputStream;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.properties.NameFactory;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
@@ -87,13 +86,11 @@
/**
* {@inheritDoc}
*
- * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ActivityMonitor)
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext)
*/
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
- activityMonitor.beginTask(10, ImageSequencerI18n.sequencerTaskName);
+ SequencerContext context ) {
ImageMetadata metadata = new ImageMetadata();
metadata.setInput(stream);
@@ -104,8 +101,6 @@
if (!metadata.check()) {
metadata = null;
}
- activityMonitor.worked(5);
- if (activityMonitor.isCancelled()) return;
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
@@ -129,7 +124,5 @@
output.setProperty(metadataNode,
nameFactory.create(IMAGE_PHYSICAL_WIDTH_INCHES), metadata.getPhysicalWidthInch());
output.setProperty(metadataNode,
nameFactory.create(IMAGE_PHYSICAL_HEIGHT_INCHES), metadata.getPhysicalHeightInch());
}
-
- activityMonitor.done();
}
}
Modified:
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
---
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -28,8 +28,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.MockSequencerContext;
import org.jboss.dna.graph.sequencers.MockSequencerOutput;
import org.jboss.dna.graph.sequencers.SequencerContext;
@@ -46,7 +44,6 @@
private ImageMetadataSequencer sequencer;
private InputStream content;
private MockSequencerOutput output;
- private ActivityMonitor activityMonitor;
private URL cautionGif;
private URL cautionJpg;
private URL cautionPict;
@@ -59,7 +56,6 @@
context = new MockSequencerContext();
context.getNamespaceRegistry().register("image",
"http://jboss.org/dna/images/1.0");
output = new MockSequencerOutput(context);
- activityMonitor = context.createActivityMonitor(MockI18n.passthrough, "Test
Activity");
cautionGif =
this.getClass().getClassLoader().getResource("caution.gif");
cautionJpg =
this.getClass().getClassLoader().getResource("caution.jpg");
cautionPict =
this.getClass().getClassLoader().getResource("caution.pict");
@@ -83,7 +79,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, activityMonitor);
+ sequencer.sequence(content, output, context);
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"}));
@@ -106,7 +102,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, activityMonitor);
+ sequencer.sequence(content, output, context);
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"}));
@@ -127,7 +123,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, activityMonitor);
+ sequencer.sequence(content, output, context);
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}));
@@ -147,7 +143,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, activityMonitor);
+ sequencer.sequence(content, output, context);
assertThat(output.hasProperties(), is(false));
}
Modified:
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -25,7 +25,6 @@
import java.io.InputStream;
import java.util.List;
import org.apache.commons.lang.StringUtils;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.properties.NameFactory;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
@@ -175,22 +174,17 @@
* {@inheritDoc}
*
* @see org.jboss.dna.graph.sequencers.StreamSequencer#sequence(java.io.InputStream,
- * org.jboss.dna.graph.sequencers.SequencerOutput,
org.jboss.dna.graph.sequencers.SequencerContext,
- * org.jboss.dna.common.monitor.ActivityMonitor)
+ * org.jboss.dna.graph.sequencers.SequencerOutput,
org.jboss.dna.graph.sequencers.SequencerContext)
*/
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
- activityMonitor.beginTask(10, JavaMetadataI18n.sequencerTaskName);
-
+ SequencerContext context ) {
JavaMetadata javaMetadata = null;
NameFactory nameFactory = context.getValueFactories().getNameFactory();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
try {
- javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream),
null, activityMonitor.createSubtask(10));
- if (activityMonitor.isCancelled()) return;
+ javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream),
null);
} catch (IOException e) {
e.printStackTrace();
return;
@@ -720,7 +714,5 @@
// enumeration declaration
}
}
-
- activityMonitor.done();
}
}
Modified:
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java
===================================================================
---
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -24,7 +24,6 @@
import java.io.InputStream;
import java.util.List;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.sequencer.java.AbstractJavaMetadata;
import org.jboss.dna.sequencer.java.CompilationUnitParser;
import org.jboss.dna.sequencer.java.JavaMetadataUtil;
@@ -53,15 +52,12 @@
* @param inputStream - the <code>InputStream</code> in our case a
<code>FileInputStream</code> of the java file.
* @param length - the length of the java file.
* @param encoding - the encoding that can be used.
- * @param activityMonitor - The basic <code>ActivityMonitor</code> that
facilitates the updating and monitoring of progress
- * towards the completion of an activity.
* @return the new instace of <code>JavaMetadata</code>
* @see java.io.File#length()
*/
public static JavaMetadata instance( InputStream inputStream,
long length,
- String encoding,
- ActivityMonitor activityMonitor ) {
+ String encoding ) {
JavaMetadata javaMetadata = new JavaMetadata();
char[] source = null;
Modified:
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
===================================================================
---
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -29,8 +29,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.MockSequencerContext;
import org.jboss.dna.graph.sequencers.MockSequencerOutput;
import org.jboss.dna.graph.sequencers.SequencerContext;
@@ -46,7 +44,6 @@
private JavaMetadataSequencer sequencer;
private InputStream content;
private MockSequencerOutput output;
- private ActivityMonitor activityMonitor;
private File source;
private SequencerContext context;
@@ -56,7 +53,6 @@
context.getNamespaceRegistry().register("java",
"http://jboss.org/dna/java/1.0");
sequencer = new JavaMetadataSequencer();
output = new MockSequencerOutput(context);
- this.activityMonitor = context.createActivityMonitor(MockI18n.passthrough,
"Test java monitor activity");
source = new
File("src/test/workspace/projectX/src/org/acme/MySource.java");
}
@@ -79,7 +75,7 @@
public void shouldGenerateMetadataForJavaSourceFile() throws IOException {
content = getJavaSrc(source);
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, activityMonitor);
+ sequencer.sequence(content, output, context);
assertThat(output.getPropertyValues("java:compilationUnit",
"jcr:primaryType"), is(new Object[] {"java:compilationUnit"}));
// support sequencing package declaration( FQL name of the package). Not
supported is to get information for package
Modified:
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataTest.java
===================================================================
---
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataTest.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -69,7 +69,7 @@
public void beforeEach() throws Exception {
source = new
File("src/test/workspace/projectX/src/org/acme/MySource.java");
stream = getJavaSrc(source);
- javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream),
null, null);
+ javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream),
null);
rootNode =
CompilationUnitParser.runJLS3Conversion(JavaMetadataUtil.getJavaSourceFromTheInputStream(getJavaSrc(source),
source.length(),
null), true);
@@ -185,19 +185,18 @@
assertThat(parameterizedFieldMetadata2.getType(), is("A"));
assertThat(parameterizedFieldMetadata2.getVariables().get(0).getName(),
is("o"));
-
SimpleTypeFieldMetadata simpleFieldMetadata =
(SimpleTypeFieldMetadata)fields.get(4);
assertNotNull(simpleFieldMetadata);
assertTrue(simpleFieldMetadata.getModifiers().size() > 0);
assertThat(simpleFieldMetadata.getType(), is("X"));
assertThat(simpleFieldMetadata.getVariables().get(0).getName(),
is("x"));
-
+
ArrayTypeFieldMetadata arrayTypeFieldMetadata1 =
(ArrayTypeFieldMetadata)fields.get(5);
assertNotNull(arrayTypeFieldMetadata1);
assertTrue(arrayTypeFieldMetadata1.getModifiers().size() > 0);
assertThat(arrayTypeFieldMetadata1.getType(), is("int"));
assertThat(arrayTypeFieldMetadata1.getVariables().get(0).getName(),
is("ia"));
-
+
ArrayTypeFieldMetadata arrayTypeFieldMetadata2 =
(ArrayTypeFieldMetadata)fields.get(6);
assertNotNull(arrayTypeFieldMetadata2);
assertTrue(arrayTypeFieldMetadata2.getModifiers().size() > 0);
@@ -250,7 +249,7 @@
assertNotNull(methodTypeMemberMetadata5);
assertThat(methodTypeMemberMetadata5.getName(),
is("doSomething"));
assertTrue(methodTypeMemberMetadata5.getParameters().size() > 0);
-
+
MethodTypeMemberMetadata methodTypeMemberMetadata6 =
(MethodTypeMemberMetadata)methods.get(6);
assertTrue(methodTypeMemberMetadata6.getModifiers().size() == 1);
assertEquals(methodTypeMemberMetadata6.getReturnType().getType(),
"double");
Modified:
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -22,7 +22,6 @@
package org.jboss.dna.sequencer.mp3;
import java.io.InputStream;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.SequencerOutput;
import org.jboss.dna.graph.sequencers.StreamSequencer;
@@ -62,12 +61,11 @@
/**
* {@inheritDoc}
*
- * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ActivityMonitor)
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext)
*/
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
+ SequencerContext context ) {
Mp3Metadata metadata = Mp3Metadata.instance(stream);
if (metadata != null) {
Modified:
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.SequencerOutput;
import org.jboss.dna.graph.sequencers.StreamSequencer;
@@ -115,12 +114,9 @@
*/
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
- activityMonitor.beginTask(10, MSOfficeMetadataI18n.sequencerTaskName);
+ SequencerContext context ) {
MSOfficeMetadata metadata = MSOfficeMetadataReader.instance(stream);
- activityMonitor.worked(3);
String mimeType = context.getMimeType();
@@ -147,7 +143,7 @@
} else {
return;
}
- activityMonitor.worked(1);
+
// process PowerPoint specific metadata
if (mimeType.equals("application/vnd.ms-powerpoint")) { // replace true
with check if it's ppt file being sequenced
try {
@@ -165,7 +161,6 @@
context.getLogger(this.getClass()).debug(e, "Error while extracting
the PowerPoint metadata");
}
}
- activityMonitor.worked(2);
if (mimeType.equals("application/vnd.ms-word")) {
// Sometime in the future this will sequence WORD Table of contents.
@@ -177,7 +172,6 @@
}
}
- activityMonitor.worked(2);
if (mimeType.equals("application/vnd.ms-excel")) {
try {
@@ -193,7 +187,5 @@
context.getLogger(this.getClass()).debug(e, "Error while extracting
the Excel metadata");
}
}
- activityMonitor.worked(2);
- activityMonitor.done();
}
}
Modified:
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -27,7 +27,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.properties.Name;
@@ -39,7 +38,6 @@
import org.jboss.dna.graph.sequencers.StreamSequencer;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
@@ -62,18 +60,15 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.sequencers.StreamSequencer#sequence(InputStream,
SequencerOutput, SequencerContext,
- * ActivityMonitor)
+ * @see org.jboss.dna.graph.sequencers.StreamSequencer#sequence(InputStream,
SequencerOutput, SequencerContext)
*/
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor monitor ) {
- monitor.beginTask(100.0, XmlSequencerI18n.sequencingXmlDocument);
+ SequencerContext context ) {
XMLReader reader;
try {
reader = XMLReaderFactory.createXMLReader();
- Handler handler = new Handler(output, context, monitor);
+ Handler handler = new Handler(output, context);
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
// Ensure handler acting as entity resolver 2
@@ -90,9 +85,7 @@
reader.parse(new InputSource(stream));
} catch (Exception error) {
context.getLogger(getClass()).error(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
- monitor.captureError(error, XmlSequencerI18n.fatalErrorSequencingXmlDocument,
error);
- } finally {
- monitor.done();
+ context.getProblems().addError(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
}
}
@@ -120,10 +113,7 @@
private final SequencerOutput output;
private final SequencerContext context;
- private final ActivityMonitor 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
@@ -150,14 +140,11 @@
private String entity;
Handler( SequencerOutput output,
- SequencerContext context,
- ActivityMonitor monitor ) {
+ SequencerContext context ) {
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 = context.getValueFactories().getPathFactory().createRelativePath();
// Cache name factory since it is frequently used
@@ -169,30 +156,12 @@
* {@inheritDoc}
* </p>
*
- * @see org.xml.sax.ext.DefaultHandler2#attributeDecl(java.lang.String,
java.lang.String, java.lang.String,
- * java.lang.String, java.lang.String)
- */
- @Override
- public void attributeDecl( String name,
- String name2,
- String type,
- String mode,
- String value ) throws SAXException {
- stopIfCancelled();
- }
-
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
* @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
*/
@Override
public void characters( char[] ch,
int start,
- int length ) throws SAXException {
- stopIfCancelled();
+ int length ) {
String content = String.valueOf(ch, start, length);
// Check if data should be appended to previously parsed CDATA
if (cDataBuilder == null) {
@@ -215,7 +184,6 @@
cDataBuilder.append(ch, start, length);
// Text within builder will be output at the end of CDATA
}
- updateProgress();
}
/**
@@ -228,14 +196,12 @@
@Override
public void comment( char[] ch,
int start,
- int length ) throws SAXException {
- stopIfCancelled();
+ int length ) {
// Output separate nodes for each comment since multiple are allowed
startElement(DnaXmlLexicon.COMMENT);
output.setProperty(path, JcrLexicon.PRIMARY_TYPE, DnaXmlLexicon.COMMENT);
output.setProperty(path, DnaXmlLexicon.COMMENT_CONTENT, String.valueOf(ch,
start, length));
endElement();
- updateProgress();
}
/**
@@ -243,30 +209,15 @@
* {@inheritDoc}
* </p>
*
- * @see org.xml.sax.ext.DefaultHandler2#elementDecl(java.lang.String,
java.lang.String)
- */
- @Override
- public void elementDecl( String name,
- String model ) throws SAXException {
- stopIfCancelled();
- }
-
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
* @see org.xml.sax.ext.DefaultHandler2#endCDATA()
*/
@Override
- public void endCDATA() throws SAXException {
- stopIfCancelled();
+ public void endCDATA() {
// Output CDATA built in characters() method
output.setProperty(path, DnaXmlLexicon.CDATA_CONTENT,
cDataBuilder.toString());
endElement();
// Null-out builder to free memory
cDataBuilder = null;
- updateProgress();
}
private void endContent() {
@@ -287,30 +238,6 @@
}
}
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
- * @see org.xml.sax.helpers.DefaultHandler#endDocument()
- */
- @Override
- public void endDocument() throws SAXException {
- stopIfCancelled();
- }
-
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
- * @see org.xml.sax.ext.DefaultHandler2#endDTD()
- */
- @Override
- public void endDTD() throws SAXException {
- stopIfCancelled();
- }
-
private void endElement() {
// Recover parent's path, namespace, and indexedName map, clearing the
ended element's map to free memory
path = path.getParent();
@@ -329,12 +256,10 @@
@Override
public void endElement( String uri,
String localName,
- String name ) throws SAXException {
- stopIfCancelled();
+ String name ) {
// Check if content still needs to be output
endContent();
endElement();
- updateProgress();
}
/**
@@ -345,10 +270,8 @@
* @see org.xml.sax.ext.DefaultHandler2#endEntity(java.lang.String)
*/
@Override
- public void endEntity( String name ) throws SAXException {
- stopIfCancelled();
+ public void endEntity( String name ) {
entity = null;
- updateProgress();
}
/**
@@ -361,7 +284,7 @@
@Override
public void error( SAXParseException error ) {
context.getLogger(XmlSequencer.class).error(error,
XmlSequencerI18n.errorSequencingXmlDocument, error);
- monitor.captureError(error, XmlSequencerI18n.errorSequencingXmlDocument,
error);
+ context.getProblems().addError(error,
XmlSequencerI18n.errorSequencingXmlDocument, error);
}
/**
@@ -374,8 +297,7 @@
@Override
public void externalEntityDecl( String name,
String publicId,
- String systemId ) throws SAXException {
- stopIfCancelled();
+ String systemId ) {
// Add "synthetic" entity container to path to help prevent name
collisions with XML elements
Name entityName = DnaDtdLexicon.ENTITY;
startElement(entityName);
@@ -384,7 +306,6 @@
output.setProperty(path, nameFactory.create(DnaDtdLexicon.PUBLIC_ID),
publicId);
output.setProperty(path, nameFactory.create(DnaDtdLexicon.SYSTEM_ID),
systemId);
endElement();
- updateProgress();
}
/**
@@ -397,7 +318,7 @@
@Override
public void fatalError( SAXParseException error ) {
context.getLogger(XmlSequencer.class).error(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
- monitor.captureError(error, XmlSequencerI18n.fatalErrorSequencingXmlDocument,
error);
+ context.getProblems().addError(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
}
private Name getDefaultPrimaryType() {
@@ -412,26 +333,11 @@
* {@inheritDoc}
* </p>
*
- * @see org.xml.sax.helpers.DefaultHandler#ignorableWhitespace(char[], int, int)
- */
- @Override
- public void ignorableWhitespace( char[] ch,
- int start,
- int length ) throws SAXException {
- stopIfCancelled();
- }
-
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
* @see org.xml.sax.ext.DefaultHandler2#internalEntityDecl(java.lang.String,
java.lang.String)
*/
@Override
public void internalEntityDecl( String name,
- String value ) throws SAXException {
- stopIfCancelled();
+ String value ) {
// Add "synthetic" entity container to path to help prevent name
collisions with XML elements
Name entityName = DnaDtdLexicon.ENTITY;
startElement(entityName);
@@ -439,7 +345,6 @@
output.setProperty(path, DnaDtdLexicon.NAME, name);
output.setProperty(path, DnaDtdLexicon.VALUE, value);
endElement();
- updateProgress();
}
/**
@@ -447,26 +352,11 @@
* {@inheritDoc}
* </p>
*
- * @see org.xml.sax.helpers.DefaultHandler#notationDecl(java.lang.String,
java.lang.String, java.lang.String)
- */
- @Override
- public void notationDecl( String name,
- String publicId,
- String systemId ) throws SAXException {
- stopIfCancelled();
- }
-
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
* @see
org.xml.sax.helpers.DefaultHandler#processingInstruction(java.lang.String,
java.lang.String)
*/
@Override
public void processingInstruction( String target,
- String data ) throws SAXException {
- stopIfCancelled();
+ String data ) {
// Output separate nodes for each instruction since multiple are allowed
Name name = DnaXmlLexicon.PROCESSING_INSTRUCTION;
startElement(name);
@@ -474,7 +364,6 @@
output.setProperty(path, DnaXmlLexicon.TARGET, target);
output.setProperty(path, DnaXmlLexicon.PROCESSING_INSTRUCTION_CONTENT,
data);
endElement();
- updateProgress();
}
/**
@@ -482,28 +371,14 @@
* {@inheritDoc}
* </p>
*
- * @see org.xml.sax.helpers.DefaultHandler#skippedEntity(java.lang.String)
- */
- @Override
- public void skippedEntity( String name ) throws SAXException {
- stopIfCancelled();
- }
-
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
* @see org.xml.sax.ext.DefaultHandler2#startCDATA()
*/
@Override
- public void startCDATA() throws SAXException {
- stopIfCancelled();
+ public void startCDATA() {
// Output separate nodes for each CDATA since multiple are allowed
startElement(DnaXmlLexicon.CDATA);
// Prepare builder for concatenating consecutive lines of CDATA
cDataBuilder = new StringBuilder();
- updateProgress();
}
/**
@@ -514,10 +389,8 @@
* @see org.xml.sax.helpers.DefaultHandler#startDocument()
*/
@Override
- public void startDocument() throws SAXException {
- stopIfCancelled();
+ public void startDocument() {
output.setProperty(path, JcrLexicon.PRIMARY_TYPE, DnaXmlLexicon.DOCUMENT);
- updateProgress();
}
/**
@@ -530,12 +403,10 @@
@Override
public void startDTD( String name,
String publicId,
- String systemId ) throws SAXException {
- stopIfCancelled();
+ String systemId ) {
output.setProperty(path, DnaDtdLexicon.NAME, name);
output.setProperty(path, DnaDtdLexicon.PUBLIC_ID, publicId);
output.setProperty(path, DnaDtdLexicon.SYSTEM_ID, systemId);
- updateProgress();
}
private void startElement( Name name ) {
@@ -579,8 +450,7 @@
public void startElement( String uri,
String localName,
String name,
- Attributes attributes ) throws SAXException {
- stopIfCancelled();
+ Attributes attributes ) {
// Look for the "jcr:name" attribute, and use that if it's
there
Name type = getDefaultPrimaryType();
Name nameObj = nameFactory.create(name);
@@ -611,7 +481,6 @@
}
output.setProperty(path, nameFactory.create(ns.length() == 0 ?
inheritedNs : ns, attrLocalName), value);
}
- updateProgress();
}
/**
@@ -622,10 +491,8 @@
* @see org.xml.sax.ext.DefaultHandler2#startEntity(java.lang.String)
*/
@Override
- public void startEntity( String name ) throws SAXException {
- stopIfCancelled();
+ public void startEntity( String name ) {
entity = name;
- updateProgress();
}
/**
@@ -637,58 +504,25 @@
*/
@Override
public void startPrefixMapping( String prefix,
- String uri ) throws SAXException {
- stopIfCancelled();
+ String uri ) {
// Register any unregistered namespaces
NamespaceRegistry registry = context.getNamespaceRegistry();
if (!registry.isRegisteredNamespaceUri(uri)) {
registry.register(prefix, uri);
}
- updateProgress();
}
- private void stopIfCancelled() throws SAXException {
- if (monitor.isCancelled()) {
- throw new
SAXException(XmlSequencerI18n.canceledSequencingXmlDocument.text());
- }
- }
-
/**
* <p>
* {@inheritDoc}
* </p>
*
- * @see org.xml.sax.helpers.DefaultHandler#unparsedEntityDecl(java.lang.String,
java.lang.String, java.lang.String,
- * java.lang.String)
- */
- @Override
- public void unparsedEntityDecl( String name,
- String publicId,
- String systemId,
- String notationName ) throws SAXException {
- stopIfCancelled();
- }
-
- private void updateProgress() {
- if (progress == 100.0) {
- progress = 1;
- } else {
- progress++;
- }
- monitor.worked(progress);
- }
-
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
* @see
org.xml.sax.helpers.DefaultHandler#warning(org.xml.sax.SAXParseException)
*/
@Override
public void warning( SAXParseException warning ) {
context.getLogger(XmlSequencer.class).warn(warning,
XmlSequencerI18n.warningSequencingXmlDocument);
- monitor.captureWarning(warning,
XmlSequencerI18n.warningSequencingXmlDocument, warning);
+ context.getProblems().addWarning(warning,
XmlSequencerI18n.warningSequencingXmlDocument, warning);
}
}
Modified:
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerI18n.java
===================================================================
---
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerI18n.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerI18n.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -34,7 +34,7 @@
public static I18n errorSequencingXmlDocument;
public static I18n fatalErrorSequencingXmlDocument;
- public static I18n sequencingXmlDocument;
+ // public static I18n sequencingXmlDocument;
public static I18n canceledSequencingXmlDocument;
public static I18n warningSequencingXmlDocument;
Modified:
trunk/extensions/dna-sequencer-xml/src/test/java/org/jboss/dna/sequencer/xml/XmlSequencerTest.java
===================================================================
---
trunk/extensions/dna-sequencer-xml/src/test/java/org/jboss/dna/sequencer/xml/XmlSequencerTest.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-xml/src/test/java/org/jboss/dna/sequencer/xml/XmlSequencerTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -28,8 +28,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.sequencers.MockSequencerContext;
import org.jboss.dna.graph.sequencers.MockSequencerOutput;
@@ -61,7 +59,6 @@
private XmlSequencer sequencer;
private InputStream stream;
private MockSequencerOutput output;
- private ActivityMonitor monitor;
private URL xml1;
private URL xml2;
private URL xml3;
@@ -74,7 +71,6 @@
sequencer = new XmlSequencer();
context = new MockSequencerContext();
output = new MockSequencerOutput(context);
- monitor = context.createActivityMonitor(MockI18n.passthrough, "Test
activity");
xml1 =
this.getClass().getClassLoader().getResource("jackrabbitInMemoryTestRepositoryConfig.xml");
assertThat(xml1, is(notNullValue()));
xml2 = this.getClass().getClassLoader().getResource("master.xml");
@@ -201,7 +197,7 @@
private void verifyDocument( URL url ) throws IOException {
stream = url.openStream();
assertThat(stream, is(notNullValue()));
- sequencer.sequence(stream, output, context, monitor);
+ sequencer.sequence(stream, output, context);
verifyName("", "jcr:primaryType", DOCUMENT);
}
Modified: trunk/extensions/dna-sequencer-zip/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-zip/pom.xml 2008-11-05 18:14:32 UTC (rev 616)
+++ trunk/extensions/dna-sequencer-zip/pom.xml 2008-11-10 20:21:55 UTC (rev 617)
@@ -33,6 +33,14 @@
<artifactId>junit-dep</artifactId>
<version>4.4</version>
</dependency>
+ <dependency>
+ <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/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -26,7 +26,6 @@
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.SequencerOutput;
import org.jboss.dna.graph.sequencers.StreamSequencer;
@@ -41,13 +40,11 @@
* {@inheritDoc}
*
* @see org.jboss.dna.graph.sequencers.StreamSequencer#sequence(java.io.InputStream,
- * org.jboss.dna.graph.sequencers.SequencerOutput,
org.jboss.dna.graph.sequencers.SequencerContext,
- * org.jboss.dna.common.monitor.ActivityMonitor)
+ * org.jboss.dna.graph.sequencers.SequencerOutput,
org.jboss.dna.graph.sequencers.SequencerContext)
*/
public void sequence( InputStream stream,
SequencerOutput output,
- SequencerContext context,
- ActivityMonitor activityMonitor ) {
+ SequencerContext context ) {
try {
ZipInputStream in = new ZipInputStream(stream);
ZipEntry entry = in.getNextEntry();
Modified:
trunk/extensions/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java
===================================================================
---
trunk/extensions/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java 2008-11-05
18:14:32 UTC (rev 616)
+++
trunk/extensions/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java 2008-11-10
20:21:55 UTC (rev 617)
@@ -24,6 +24,7 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
import java.io.InputStream;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.junit.After;
@@ -55,8 +56,8 @@
InputStream is = getTestZip("testzip.zip");
ZipSequencer zs = new ZipSequencer();
SequencingOutputTestClass seqtest = new SequencingOutputTestClass();
- SequencerContext context = null;
- zs.sequence(is, seqtest, context, null);
+ SequencerContext context = mock(SequencerContext.class);
+ zs.sequence(is, seqtest, context);
assertThat(seqtest.properties.get(2).getPath(), is("zip:content/test
subfolder/test2.txt/jcr:content"));
}