Author: jverhaeg(a)redhat.com
Date: 2008-06-02 15:27:13 -0400 (Mon, 02 Jun 2008)
New Revision: 224
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
Log:
DNA-77: SequencerOutput setProperty and setReference method signatures need to be changed
http://jira.jboss.org/jira/browse/DNA-77
Added two methods to the SequencerOutput interface: a method to obtain the
org.jboss.dna.spi.graph.ValueFactories instance that can be used to create paths, names,
and other value objects (like binary objects, date-time instants, strings, doubles, etc.);
and a method to set the property values using a Path object for the node path, and a Name
object for the property name. The Path, Name, DateTime, Reference, Binary, ValueFactory,
and ValueFactories interfaces are all part of the SPI, and will be used by the federation
engine, connectors, and (now) sequencers. The existing SequencerOutput methods (that take
string paths and names) simply create the Path and Name objects and then delegate to the
new method.
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-06-02
19:14:06 UTC (rev 223)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-06-02
19:27:13 UTC (rev 224)
@@ -2,7 +2,7 @@
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
@@ -24,11 +24,13 @@
import java.util.HashMap;
import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.impl.BasicNamespaceRegistry;
+import org.jboss.dna.spi.graph.impl.StandardValueFactories;
/**
* @author Randall Hauch
@@ -36,86 +38,110 @@
@NotThreadSafe
public class MockSequencerOutput implements SequencerOutput {
- private final Map<Path, Object[]> properties;
- private final ValueFactories factories;
+ private final Map<Path, Object[]> properties;
+ private final ValueFactories factories;
- /**
- * @param factories the factories to be used to create output property values
- */
- public MockSequencerOutput( ValueFactories factories ) {
- ArgCheck.isNotNull(factories, "factories");
- this.properties = new HashMap<Path, Object[]>();
- this.factories = factories;
- }
+ /**
+ */
+ public MockSequencerOutput() {
+ this.properties = new HashMap<Path, Object[]>();
+ NamespaceRegistry registry = new BasicNamespaceRegistry();
+ registry.register("dna", "http://www.jboss.org/dna/1.0");
+ registry.register("jcr", "http://www.jcp.org/jcr/1.0");
+ registry.register("mix", "http://www.jcp.org/jcr/mix/1.0");
+ registry.register("nt", "http://www.jcp.org/jcr/nt/1.0");
+ factories = new StandardValueFactories(registry);
+ }
- /**
- * {@inheritDoc}
- */
- public ValueFactories getFactories() {
- return this.factories;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactories getFactories() {
+ return this.factories;
+ }
- /**
- * {@inheritDoc}
- */
- public void setProperty( Path nodePath, Name propertyName, Object... values ) {
- Path key = getKey(nodePath, propertyName);
- if (values == null || values.length == 0) {
- this.properties.remove(key);
- } else {
- this.properties.put(key, values);
- }
- }
+ /**
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerOutput#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return factories.getNameFactory().getNamespaceRegistry();
+ }
- /**
- * {@inheritDoc}
- */
- public void setProperty( String nodePath, String propertyName, Object... values ) {
- Path path = this.factories.getPathFactory().create(nodePath);
- Name name = this.factories.getNameFactory().create(propertyName);
- setProperty(path, name, values);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Path nodePath,
+ Name propertyName,
+ Object... values ) {
+ Path key = createKey(nodePath, propertyName);
+ if (values == null || values.length == 0) {
+ this.properties.remove(key);
+ } else {
+ this.properties.put(key, values);
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public void setReference( String nodePath, String propertyName, String... paths ) {
- PathFactory pathFactory = this.factories.getPathFactory();
- Path path = pathFactory.create(nodePath);
- Name name = this.factories.getNameFactory().create(propertyName);
- Object[] values = null;
- if (paths != null && paths.length != 0) {
- values = new Path[paths.length];
- for (int i = 0, len = paths.length; i != len; ++i) {
- String pathValue = paths[i];
- values[i] = pathFactory.create(pathValue);
- }
- }
- setProperty(path, name, values);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( String nodePath,
+ String propertyName,
+ Object... values ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ setProperty(path, name, values);
+ }
- public Object[] getPropertyValues( String nodePath, String property ) {
- Path key = getKey(nodePath, property);
- return this.properties.get(key);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setReference( String nodePath,
+ String propertyName,
+ String... paths ) {
+ PathFactory pathFactory = this.factories.getPathFactory();
+ Path path = pathFactory.create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ Object[] values = null;
+ if (paths != null && paths.length != 0) {
+ values = new Path[paths.length];
+ for (int i = 0, len = paths.length; i != len; ++i) {
+ String pathValue = paths[i];
+ values[i] = pathFactory.create(pathValue);
+ }
+ }
+ setProperty(path, name, values);
+ }
- public boolean hasProperty( String nodePath, String property ) {
- Path key = getKey(nodePath, property);
- return this.properties.containsKey(key);
- }
+ public Object[] getPropertyValues( String nodePath,
+ String property ) {
+ Path key = createKey(nodePath, property);
+ return this.properties.get(key);
+ }
- public boolean hasProperties() {
- return this.properties.size() > 0;
- }
+ public boolean hasProperty( String nodePath,
+ String property ) {
+ Path key = createKey(nodePath, property);
+ return this.properties.containsKey(key);
+ }
- protected Path getKey( String nodePath, String propertyName ) {
- Path path = this.factories.getPathFactory().create(nodePath);
- Name name = this.factories.getNameFactory().create(propertyName);
- return getKey(path, name);
- }
+ public boolean hasProperties() {
+ return this.properties.size() > 0;
+ }
- protected Path getKey( Path nodePath, Name propertyName ) {
- return this.factories.getPathFactory().create(nodePath, propertyName);
- }
+ protected Path createKey( String nodePath,
+ String propertyName ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ return createKey(path, name);
+ }
+ protected Path createKey( Path nodePath,
+ Name propertyName ) {
+ return this.factories.getPathFactory().create(nodePath, propertyName);
+ }
+
}