DNA SVN: r458 - trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-20 14:07:43 -0400 (Wed, 20 Aug 2008)
New Revision: 458
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
Log:
Updated TODO waiting on DNA-163 to be done.
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-08-20 17:14:49 UTC (rev 457)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java 2008-08-20 18:07:43 UTC (rev 458)
@@ -30,11 +30,11 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
+import org.jboss.dna.repository.util.BasicJcrExecutionContext;
import org.jboss.dna.repository.util.JcrExecutionContext;
import org.jboss.dna.repository.util.JcrNamespaceRegistry;
import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.SessionFactory;
-import org.jboss.dna.repository.util.BasicJcrExecutionContext;
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Property;
@@ -96,8 +96,7 @@
assertThat(prop.isEmpty(), is(false));
assertThat(prop.size(), is(values.length));
assertThat(prop.isMultiple(), is(values.length > 1));
- // TODO: Uncomment after DNA-163 has been addressed
- // assertThat(prop.isSingle(), is(values.length == 1));
+ assertThat(prop.isSingle(), is(values.length == 1));
Iterator<?> iter = prop.getValues();
for (Object val : values) {
assertThat(iter.hasNext(), is(true));
15 years, 9 months
DNA SVN: r457 - in trunk: extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-20 13:14:49 -0400 (Wed, 20 Aug 2008)
New Revision: 457
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/ProjectionParser.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
Log:
DNA-210 - Change repository connectors to use the new ExecutionContext logger
http://jira.jboss.com/jira/browse/DNA-210
Changed the connector implementations to use the new "getLogger(...)" methods on the ExecutionContext.
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-20 16:57:23 UTC (rev 456)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-20 17:14:49 UTC (rev 457)
@@ -29,6 +29,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
@@ -128,6 +130,10 @@
String path,
String propertyName,
Object... values ) {
+ Logger logger = context.getLogger(getClass());
+ if (logger.isTraceEnabled()) {
+ logger.trace("Setting property {0} on {1} to {2}", propertyName, path, StringUtil.readableString(values));
+ }
PathFactory pathFactory = context.getValueFactories().getPathFactory();
NameFactory nameFactory = context.getValueFactories().getNameFactory();
PropertyFactory propertyFactory = context.getPropertyFactory();
@@ -152,6 +158,7 @@
*/
public SimpleRepository create( ExecutionContext context,
String path ) {
+ context.getLogger(getClass()).trace("Creating node {0}", path);
PathFactory pathFactory = context.getValueFactories().getPathFactory();
Path pathObj = pathFactory.create(path);
Path ancestorPath = pathObj;
@@ -175,6 +182,7 @@
*/
public SimpleRepository delete( ExecutionContext context,
String path ) {
+ context.getLogger(getClass()).trace("Deleting node {0}", path);
PathFactory pathFactory = context.getValueFactories().getPathFactory();
Path pathObj = pathFactory.create(path);
List<Path> pathsToRemove = new LinkedList<Path>();
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-20 16:57:23 UTC (rev 456)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-20 17:14:49 UTC (rev 457)
@@ -756,7 +756,7 @@
executor = new FederatingCommandExecutor(context, configurationSourceName, projections, connectionFactory);
}
// Wrap the executor with a logging executor ...
- executor = new LoggingCommandExecutor(executor, Logger.getLogger(getClass()), Logger.Level.INFO);
+ executor = new LoggingCommandExecutor(executor, context.getLogger(getClass()), Logger.Level.INFO);
// The configuration projection (via "executor") will convert this path into a path that exists in the configuration
// repository
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java 2008-08-20 16:57:23 UTC (rev 456)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java 2008-08-20 17:14:49 UTC (rev 457)
@@ -162,7 +162,7 @@
if (rule != null) return rule;
} catch (Throwable err) {
String msg = "Error while parsing project rule definition \"{0}\" using {1}";
- Logger.getLogger(Projection.class).trace(err, msg, definition, method);
+ context.getLogger(Projection.class).trace(err, msg, definition, method);
}
}
return null;
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/ProjectionParser.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/ProjectionParser.java 2008-08-20 16:57:23 UTC (rev 456)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/ProjectionParser.java 2008-08-20 17:14:49 UTC (rev 457)
@@ -62,10 +62,8 @@
}
private final List<Method> parserMethods = new CopyOnWriteArrayList<Method>();
- protected final Logger logger;
public ProjectionParser() {
- this.logger = Logger.getLogger(this.getClass());
}
/**
@@ -184,6 +182,7 @@
ArgCheck.isNotNull(context, "env");
definition = definition != null ? definition.trim() : "";
if (definition.length() == 0) return null;
+ Logger logger = context.getLogger(getClass());
for (Method method : parserMethods) {
try {
Rule rule = (Rule)method.invoke(null, definition, context);
@@ -199,7 +198,7 @@
}
} catch (Throwable err) {
String msg = "Error while parsing project rule definition \"{0}\" using {1}";
- Logger.getLogger(Projection.class).trace(err, msg, definition, method);
+ logger.trace(err, msg, definition, method);
}
}
return null;
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-20 16:57:23 UTC (rev 456)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-20 17:14:49 UTC (rev 457)
@@ -134,6 +134,7 @@
this.defaultCachePolicy = defaultCachePolicy;
this.sourceProjections = sourceProjections;
this.connectionFactory = connectionFactory;
+ this.logger = context.getLogger(getClass());
this.connectionsBySourceName = new HashMap<String, RepositoryConnection>();
this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.UUID);
this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.MERGE_PLAN);
@@ -141,18 +142,10 @@
for (Projection projection : this.sourceProjections) {
this.sourceNames.add(projection.getSourceName());
}
- setLogger(null);
setMergingStrategy(null);
}
/**
- * @param logger Sets logger to the specified value.
- */
- public void setLogger( Logger logger ) {
- this.logger = logger != null ? logger : Logger.getLogger(getClass());
- }
-
- /**
* @param mergingStrategy Sets mergingStrategy to the specified value.
*/
public void setMergingStrategy( MergeStrategy mergingStrategy ) {
@@ -202,7 +195,7 @@
try {
connection.close();
} catch (Throwable t) {
- Logger.getLogger(getClass()).debug("Error while closing connection to {0}", connection.getSourceName());
+ logger.debug("Error while closing connection to {0}", connection.getSourceName());
}
}
connectionsBySourceName.clear();
Modified: trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-20 16:57:23 UTC (rev 456)
+++ trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-20 17:14:49 UTC (rev 457)
@@ -33,7 +33,6 @@
import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.dna.common.util.Logger;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
@@ -352,9 +351,9 @@
// Record the list of children as a property on the parent ...
// (Do this last, as it doesn't need to be done if there's an exception in the above logic)
- Logger.getLogger(getClass()).trace("Updating child list of {0} to: {1}",
- parent.getFqn(),
- StringUtil.readableString(childNames));
+ context.getLogger(getClass()).trace("Updating child list of {0} to: {1}",
+ parent.getFqn(),
+ StringUtil.readableString(childNames));
parent.put(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST, childNames); // replaces any existing value
if (addChildWithName) {
@@ -421,7 +420,7 @@
assert context != null;
if (existing.equals(newSegment)) return;
- Logger.getLogger(getClass()).trace("Renaming {0} to {1} under {2}", existing, newSegment, parent.getFqn());
+ context.getLogger(getClass()).trace("Renaming {0} to {1} under {2}", existing, newSegment, parent.getFqn());
Node<Name, Object> existingChild = parent.getChild(existing);
assert existingChild != null;
15 years, 9 months
DNA SVN: r456 - in trunk: dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-20 12:57:23 -0400 (Wed, 20 Aug 2008)
New Revision: 456
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/xml/XmlSequencer.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
Log:
DNA-209 - Change existing sequencers to use the ExecutionContext's logger
http://jira.jboss.com/jira/browse/DNA-209
Changed the SequencerNodeContext to expose the new "getLogger(...)" methods on the ExecutionContext (and JcrExecutionContext), and changed the sequencers that use a logger to get the logger using these methods.
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-08-20 16:09:15 UTC (rev 455)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-08-20 16:57:23 UTC (rev 456)
@@ -33,6 +33,7 @@
import javax.jcr.Value;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.repository.RepositoryI18n;
import org.jboss.dna.repository.mimetype.MimeType;
import org.jboss.dna.repository.util.JcrExecutionContext;
@@ -57,6 +58,7 @@
private final ValueFactories factories;
private final Path path;
private final Set<Property> props;
+ private final JcrExecutionContext context;
SequencerNodeContext( Node input,
javax.jcr.Property sequencedProperty,
@@ -64,6 +66,7 @@
assert input != null;
assert sequencedProperty != null;
assert context != null;
+ this.context = context;
this.sequencedProperty = sequencedProperty;
this.factories = context.getValueFactories();
// Translate JCR path and property values to DNA constructs and cache them to improve performance and prevent
@@ -207,4 +210,22 @@
public NamespaceRegistry getNamespaceRegistry() {
return factories.getNameFactory().getNamespaceRegistry();
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return context.getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.sequencers.SequencerContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return context.getLogger(name);
+ }
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-08-20 16:09:15 UTC (rev 455)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-08-20 16:57:23 UTC (rev 456)
@@ -105,7 +105,7 @@
// Parse XML document
reader.parse(new InputSource(stream));
} catch (Exception error) {
- LOGGER.error(error, RepositoryI18n.fatalErrorSequencingXmlDocument, error);
+ context.getLogger(getClass()).error(error, RepositoryI18n.fatalErrorSequencingXmlDocument, error);
monitor.getProblems().addError(error, RepositoryI18n.fatalErrorSequencingXmlDocument, error);
} finally {
monitor.done();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java 2008-08-20 16:09:15 UTC (rev 455)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerContext.java 2008-08-20 16:57:23 UTC (rev 456)
@@ -22,6 +22,7 @@
package org.jboss.dna.spi.sequencers;
import java.util.Set;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
@@ -75,4 +76,27 @@
* @return the namespace registry; never <code>null</code>.
*/
NamespaceRegistry getNamespaceRegistry();
+
+ /**
+ * Return a logger associated with this context. This logger records only those activities within the context and provide a
+ * way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log
+ * via this mechanism should <i>not</i> also {@link Logger#getLogger(Class) obtain a system logger}.
+ *
+ * @param clazz the class that is doing the logging
+ * @return the logger, named after <code>clazz</code>; never null
+ * @see #getLogger(String)
+ */
+ Logger getLogger( Class<?> clazz );
+
+ /**
+ * Return a logger associated with this context. This logger records only those activities within the context and provide a
+ * way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log
+ * via this mechanism should <i>not</i> also {@link Logger#getLogger(Class) obtain a system logger}.
+ *
+ * @param name the name for the logger
+ * @return the logger, named after <code>clazz</code>; never null
+ * @see #getLogger(Class)
+ */
+ Logger getLogger( String name );
+
}
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-08-20 16:09:15 UTC (rev 455)
+++ trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-08-20 16:57:23 UTC (rev 456)
@@ -25,7 +25,6 @@
import java.io.InputStream;
import java.util.List;
import org.jboss.dna.common.monitor.ProgressMonitor;
-import org.jboss.dna.common.util.Logger;
import org.jboss.dna.sequencer.msoffice.excel.ExcelMetadata;
import org.jboss.dna.sequencer.msoffice.excel.ExcelMetadataReader;
import org.jboss.dna.sequencer.msoffice.powerpoint.PowerPointMetadataReader;
@@ -163,7 +162,7 @@
}
} catch (IOException e) {
// There was an error reading, so log and continue ...
- Logger.getLogger(this.getClass()).debug(e, "Error while extracting the PowerPoint metadata");
+ context.getLogger(this.getClass()).debug(e, "Error while extracting the PowerPoint metadata");
}
}
progressMonitor.worked(2);
@@ -174,7 +173,7 @@
/*WordMetadata wordMetadata =*/WordMetadataReader.invoke(stream);
} catch (IOException e) {
// There was an error reading, so log and continue ...
- Logger.getLogger(this.getClass()).debug(e, "Error while extracting the Word document metadata");
+ context.getLogger(this.getClass()).debug(e, "Error while extracting the Word document metadata");
}
}
@@ -191,7 +190,7 @@
}
} catch (IOException e) {
// There was an error reading, so log and continue ...
- Logger.getLogger(this.getClass()).debug(e, "Error while extracting the Excel metadata");
+ context.getLogger(this.getClass()).debug(e, "Error while extracting the Excel metadata");
}
}
progressMonitor.worked(2);
15 years, 9 months
DNA SVN: r455 - in trunk: dna-spi/src/main/java/org/jboss/dna/spi and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-20 12:09:15 -0400 (Wed, 20 Aug 2008)
New Revision: 455
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java
Log:
DNA-201 - Provide a facility for clients to obtain context-level traces/logs of activity
http://jira.jboss.com/jira/browse/DNA-201
Added to ExecutionContext two "getLogger(...)" methods that mirror the signatures of the static methods on Logger.
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-08-20 15:44:54 UTC (rev 454)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-08-20 16:09:15 UTC (rev 455)
@@ -211,7 +211,6 @@
private Selector sequencerSelector = DEFAULT_SEQUENCER_SELECTOR;
private NodeFilter nodeFilter = DEFAULT_NODE_FILTER;
private ExecutorService executorService;
- private Logger logger = Logger.getLogger(this.getClass());
private final Statistics statistics = new Statistics();
private final Administrator administrator = new Administrator();
@@ -317,24 +316,6 @@
}
/**
- * Get the logger for this system
- *
- * @return the logger
- */
- public Logger getLogger() {
- return this.logger;
- }
-
- /**
- * Set the logger for this system.
- *
- * @param logger the logger, or null if the standard logging should be used
- */
- public void setLogger( Logger logger ) {
- this.logger = logger != null ? logger : Logger.getLogger(this.getClass());
- }
-
- /**
* @return executionContext
*/
public JcrExecutionContext getExecutionContext() {
@@ -498,6 +479,9 @@
* @param changedNode the node to be processed.
*/
protected void processChangedNode( NodeChange changedNode ) {
+ final JcrExecutionContext context = this.getExecutionContext();
+ final Logger logger = context.getLogger(getClass());
+ assert logger != null;
try {
final String repositoryWorkspaceName = changedNode.getRepositoryWorkspaceName();
Session session = null;
@@ -536,7 +520,7 @@
Node node = null;
if (!sequencers.isEmpty()) {
// Create a session that we'll use for all sequencing ...
- session = this.getExecutionContext().getSessionFactory().createSession(repositoryWorkspaceName);
+ session = context.getSessionFactory().createSession(repositoryWorkspaceName);
// Find the changed node ...
String relPath = changedNode.getAbsolutePath().replaceAll("^/+", "");
@@ -547,14 +531,14 @@
}
if (sequencers.isEmpty()) {
this.statistics.recordNodeSkipped();
- if (this.logger.isDebugEnabled()) {
- this.logger.trace("Skipping '{0}': no sequencers matched this condition", changedNode);
+ if (logger.isDebugEnabled()) {
+ logger.trace("Skipping '{0}': no sequencers matched this condition", changedNode);
}
} else {
// Run each of those sequencers ...
ProgressMonitor progressMonitor = new SimpleProgressMonitor(RepositoryI18n.sequencerTask.text(changedNode));
- if (this.logger.isTraceEnabled()) {
- progressMonitor = new LoggingProgressMonitor(progressMonitor, this.logger, Logger.Level.TRACE);
+ if (logger.isTraceEnabled()) {
+ progressMonitor = new LoggingProgressMonitor(progressMonitor, logger, Logger.Level.TRACE);
}
try {
progressMonitor.beginTask(sequencerCalls.size(), RepositoryI18n.sequencerTask, changedNode);
@@ -569,7 +553,7 @@
assert outputPaths != null && outputPaths.size() != 0;
// Create a new execution context for each sequencer
- final Context executionContext = new Context();
+ final Context executionContext = new Context(context);
final ProgressMonitor sequenceMonitor = progressMonitor.createSubtask(1);
try {
sequenceMonitor.beginTask(100, RepositoryI18n.sequencerSubtask, sequencerName);
@@ -580,12 +564,9 @@
executionContext,
sequenceMonitor.createSubtask(80)); // 80%
} catch (RepositoryException e) {
- this.logger.error(e,
- RepositoryI18n.errorInRepositoryWhileSequencingNode,
- sequencerName,
- changedNode);
+ logger.error(e, RepositoryI18n.errorInRepositoryWhileSequencingNode, sequencerName, changedNode);
} catch (SequencerException e) {
- this.logger.error(e, RepositoryI18n.errorWhileSequencingNode, sequencerName, changedNode);
+ logger.error(e, RepositoryI18n.errorWhileSequencingNode, sequencerName, changedNode);
} finally {
try {
// Save the changes made by each sequencer ...
@@ -611,9 +592,9 @@
if (session != null) session.logout();
}
} catch (RepositoryException e) {
- this.logger.error(e, RepositoryI18n.errorInRepositoryWhileFindingSequencersToRunAgainstNode, changedNode);
+ logger.error(e, RepositoryI18n.errorInRepositoryWhileFindingSequencersToRunAgainstNode, changedNode);
} catch (Throwable e) {
- this.logger.error(e, RepositoryI18n.errorFindingSequencersToRunAgainstNode, changedNode);
+ logger.error(e, RepositoryI18n.errorFindingSequencersToRunAgainstNode, changedNode);
}
}
@@ -624,8 +605,8 @@
private final Set<Session> sessions = new HashSet<Session>();
protected final AtomicBoolean closed = new AtomicBoolean(false);
- protected Context() {
- this.delegate = SequencingService.this.getExecutionContext();
+ protected Context( JcrExecutionContext context ) {
+ this.delegate = context;
final SessionFactory delegateSessionFactory = this.delegate.getSessionFactory();
this.factory = new SessionFactory() {
@@ -708,6 +689,24 @@
return this.delegate.getValueFactories();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return this.delegate.getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return this.delegate.getLogger(name);
+ }
+
protected synchronized void recordSession( Session session ) {
if (session != null) sessions.add(session);
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java 2008-08-20 15:44:54 UTC (rev 454)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java 2008-08-20 16:09:15 UTC (rev 455)
@@ -24,6 +24,7 @@
import java.security.AccessControlContext;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.PropertyFactory;
@@ -72,4 +73,26 @@
* @return the subject; never null
*/
Subject getSubject();
+
+ /**
+ * Return a logger associated with this context. This logger records only those activities within the context and provide a
+ * way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log
+ * via this mechanism should <i>not</i> also {@link Logger#getLogger(Class) obtain a system logger}.
+ *
+ * @param clazz the class that is doing the logging
+ * @return the logger, named after <code>clazz</code>; never null
+ * @see #getLogger(String)
+ */
+ Logger getLogger( Class<?> clazz );
+
+ /**
+ * Return a logger associated with this context. This logger records only those activities within the context and provide a
+ * way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log
+ * via this mechanism should <i>not</i> also {@link Logger#getLogger(Class) obtain a system logger}.
+ *
+ * @param name the name for the logger
+ * @return the logger, named after <code>clazz</code>; never null
+ * @see #getLogger(Class)
+ */
+ Logger getLogger( String name );
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java 2008-08-20 15:44:54 UTC (rev 454)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java 2008-08-20 16:09:15 UTC (rev 455)
@@ -25,6 +25,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.PathFactory;
@@ -204,6 +205,24 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return delegate.getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return delegate.getLogger(name);
+ }
+
+ /**
* @return delegate
*/
protected ExecutionContext getDelegate() {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java 2008-08-20 15:44:54 UTC (rev 454)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/BasicExecutionContext.java 2008-08-20 16:09:15 UTC (rev 455)
@@ -26,6 +26,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.PropertyFactory;
@@ -158,4 +159,22 @@
public ValueFactories getValueFactories() {
return valueFactories;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.Class)
+ */
+ public Logger getLogger( Class<?> clazz ) {
+ return Logger.getLogger(clazz);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLogger(java.lang.String)
+ */
+ public Logger getLogger( String name ) {
+ return Logger.getLogger(name);
+ }
}
15 years, 9 months
DNA SVN: r454 - in trunk: dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml and 7 other directories.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-20 11:44:54 -0400 (Wed, 20 Aug 2008)
New Revision: 454
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
Log:
DNA-208: Renamed Path.getAncestor() to getParent() and updated all referencing classes.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -206,7 +206,7 @@
return getRootNode();
}
// Since we don't know whether path refers to a node or property, get the parent contents, which must refer to a node
- Path parentPath = path.getAncestor();
+ Path parentPath = path.getParent();
BasicGetNodeCommand getNodeCommand = new BasicGetNodeCommand(parentPath);
execute(getNodeCommand);
// First search for a child with the last name in the path
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/xml/XmlSequencer.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -313,7 +313,7 @@
private void endElement() {
// Recover parent's path, namespace, and indexedName map, clearing the ended element's map to free memory
- path = path.getAncestor();
+ path = path.getParent();
nameToIndexedNamesMap.clear();
nameToIndexedNamesMap = nameToIndexedNamesMapStack.removeFirst();
nsStack.removeFirst();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -63,7 +63,7 @@
* This class simplifies working with paths and using a <code>Path</code> is often more efficient that processing and
* manipulating the equivalent <code>String</code>. This class can easily {@link #iterator() iterate} over the segments, return
* the {@link #size() number of segments}, {@link #compareTo(Path) compare} with other paths, {@link #resolve(Path) resolve}
- * relative paths, return the {@link #getAncestor() ancestor (or parent)}, determine whether one path is an
+ * relative paths, return the {@link #getParent() ancestor (or parent)}, determine whether one path is an
* {@link #isAncestorOf(Path) ancestor} or {@link #isDecendantOf(Path) decendent} of another path, and
* {@link #getCommonAncestor(Path) finding a common ancestor}.
* </p>
@@ -389,7 +389,7 @@
*
* @return the parent path, or this path if it is already the root
*/
- public Path getAncestor();
+ public Path getParent();
/**
* Return the path to the ancestor of the supplied degree. An ancestor of degree <code>x</code> is the path that is <code>x
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -98,7 +98,7 @@
}
/**
- * Get the lowest (closest) existing {@link Path#getAncestor() ancestor} of the {@link #getPath() non-existant path}.
+ * Get the lowest (closest) existing {@link Path#getParent() ancestor} of the {@link #getPath() non-existant path}.
* @return the lowest ancestor that does exist
*/
public Path getLowestAncestorThatDoesExist() {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -82,7 +82,7 @@
/**
* {@inheritDoc}
*/
- public Path getAncestor() {
+ public Path getParent() {
if (this.isRoot()) return null;
if (this.segments.size() == 1) return ROOT;
return subpath(0, this.segments.size() - 1);
@@ -435,7 +435,7 @@
if (relativePath.size() == 1) {
Segment onlySegment = relativePath.getSegment(0);
if (onlySegment.isSelfReference()) return this;
- if (onlySegment.isParentReference()) return this.getAncestor();
+ if (onlySegment.isParentReference()) return this.getParent();
}
List<Segment> segments = new ArrayList<Segment>(this.size() + relativePath.size());
segments.addAll(this.segments);
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -133,7 +133,7 @@
PropertyFactory propertyFactory = context.getPropertyFactory();
Path pathObj = pathFactory.create(path);
if (!pathObj.isRoot()) {
- create(context, pathObj.getAncestor().getString(context.getNamespaceRegistry()));
+ create(context, pathObj.getParent().getString(context.getNamespaceRegistry()));
}
Property property = propertyFactory.create(nameFactory.create(propertyName), values);
Map<Name, Property> properties = new HashMap<Name, Property>();
@@ -157,7 +157,7 @@
Path ancestorPath = pathObj;
while (!ancestorPath.isRoot()) {
data.putIfAbsent(ancestorPath, new HashMap<Name, Property>());
- ancestorPath = ancestorPath.getAncestor();
+ ancestorPath = ancestorPath.getParent();
}
Name uuidName = context.getValueFactories().getNameFactory().create(this.getUuidPropertyName());
UUID uuid = context.getValueFactories().getUuidFactory().create();
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -323,7 +323,7 @@
// Iterate through all of the properties, looking for any paths that are children of the path ...
List<Path.Segment> childSegments = new LinkedList<Path.Segment>();
for (Path path : data.keySet()) {
- if (!path.isRoot() && path.getAncestor().equals(targetPath)) {
+ if (!path.isRoot() && path.getParent().equals(targetPath)) {
childSegments.add(path.getLastSegment());
}
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -225,14 +225,14 @@
@Test
public void shouldReturnNoAncestorForRoot() {
- assertThat(BasicPath.ROOT.getAncestor(), nullValue());
+ assertThat(BasicPath.ROOT.getParent(), nullValue());
}
@Test
public void shouldReturnAncestorForNodeOtherThanRoot() {
- assertThat(path.getAncestor(), is(pathFactory.create("/dna:a/dna:b")));
- assertThat(path.getAncestor().getAncestor(), is(pathFactory.create("/dna:a")));
- assertThat(path.getAncestor().getAncestor().getAncestor(), is(ROOT));
+ assertThat(path.getParent(), is(pathFactory.create("/dna:a/dna:b")));
+ assertThat(path.getParent().getParent(), is(pathFactory.create("/dna:a")));
+ assertThat(path.getParent().getParent().getParent(), is(ROOT));
}
@Test
@@ -306,7 +306,7 @@
assertThat(common.isAncestorOf(path2), is(true));
assertThat(common.isAncestorOf(path3), is(false));
- assertThat(path1.getAncestor().isAncestorOf(path1), is(true));
+ assertThat(path1.getParent().isAncestorOf(path1), is(true));
for (int i = 1; i < path1.size(); ++i) {
assertThat(path1.getAncestor(i).isAncestorOf(path1), is(true));
}
@@ -332,7 +332,7 @@
assertThat(path2.isDecendantOf(common), is(true));
assertThat(path3.isDecendantOf(common), is(false));
- assertThat(path1.getAncestor().isAncestorOf(path1), is(true));
+ assertThat(path1.getParent().isAncestorOf(path1), is(true));
for (int i = 1; i < path1.size(); ++i) {
assertThat(path1.isDecendantOf(path1.getAncestor(i)), is(true));
}
@@ -844,7 +844,7 @@
@Test
public void shouldResolveRelativePathToParent() {
path = pathFactory.create("/a/b/c/d/e/f");
- assertThat(path.resolve(pathFactory.create("..")), is(path.getAncestor()));
+ assertThat(path.resolve(pathFactory.create("..")), is(path.getParent()));
assertThat(path.resolve(pathFactory.create("..")), hasSegments(pathFactory, "a", "b", "c", "d", "e"));
}
@@ -852,9 +852,9 @@
public void shouldResolveRelativePaths() {
path = pathFactory.create("/a/b/c/d/e/f");
assertThat(path.resolve(pathFactory.create("../../../../../..")), is(sameInstance(ROOT)));
- assertThat(path.resolve(pathFactory.create("../..")), is(path.getAncestor().getAncestor()));
+ assertThat(path.resolve(pathFactory.create("../..")), is(path.getParent().getParent()));
assertThat(path.resolve(pathFactory.create("../..")), hasSegments(pathFactory, "a", "b", "c", "d"));
- assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), is(path.getAncestor()));
+ assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), is(path.getParent()));
assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), hasSegments(pathFactory, "a", "b", "c", "d", "e"));
assertThat(path.resolve(pathFactory.create("../x")), hasSegments(pathFactory, "a", "b", "c", "d", "e", "x"));
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -310,11 +310,11 @@
// that already exists in the cache.
PathNotFoundException notFound = (PathNotFoundException)fromCache.getError();
Path lowestExistingAncestor = notFound.getLowestAncestorThatDoesExist();
- Path ancestor = path.getAncestor();
+ Path ancestor = path.getParent();
if (!ancestor.equals(lowestExistingAncestor)) {
// Load the nodes along the path below the existing ancestor, down to (but excluding) the desired path
- Path pathToLoad = path.getAncestor();
+ Path pathToLoad = path.getParent();
while (!pathToLoad.equals(lowestExistingAncestor)) {
loadContributionsFromSources(pathToLoad, null, contributions); // sourceNames may be null or empty
FederatedNode mergedNode = createFederatedNode(pathToLoad, contributions, true);
@@ -326,7 +326,7 @@
}
contributions.clear();
// Move to the next child along the path ...
- pathToLoad = pathToLoad.getAncestor();
+ pathToLoad = pathToLoad.getParent();
}
}
// At this point, all ancestors exist ...
@@ -366,7 +366,7 @@
FederatedNode mergedNode = createFederatedNode(path, contributions, true);
if (mergedNode == null) {
// No source had a contribution ...
- Path ancestor = path.getAncestor();
+ Path ancestor = path.getParent();
I18n msg = FederationI18n.nodeDoesNotExistAtPath;
fromCache.setError(new PathNotFoundException(path, ancestor, msg.text(path, ancestor)));
return fromCache;
Modified: trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
===================================================================
--- trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -203,7 +203,7 @@
assert pathToNewNode != null;
Path path = context.getValueFactories().getPathFactory().create(pathToNewNode);
if (path.isRoot()) return getRoot();
- Path parentPath = path.getAncestor();
+ Path parentPath = path.getParent();
Node parentNode = getNode(parentPath);
Name name = path.getLastSegment().getName();
return createNode(context, parentNode, name, null);
@@ -344,7 +344,7 @@
@Override
public void execute( CreateNodeCommand command ) {
Path path = command.getPath();
- Path parent = path.getAncestor();
+ Path parent = path.getParent();
// Look up the parent node, which must exist ...
Node parentNode = getNode(parent);
if (parentNode == null) {
@@ -420,7 +420,7 @@
Node node = getTargetNode(command);
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
- Node newParent = getNode(newPath.getAncestor());
+ Node newParent = getNode(newPath.getParent());
copyNode(getExecutionContext(), node, newParent, false);
}
@@ -429,7 +429,7 @@
Node node = getTargetNode(command);
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
- Node newParent = getNode(newPath.getAncestor());
+ Node newParent = getNode(newPath.getParent());
copyNode(getExecutionContext(), node, newParent, true);
}
@@ -438,7 +438,7 @@
Node node = getTargetNode(command);
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
- Node newParent = getNode(newPath.getAncestor());
+ Node newParent = getNode(newPath.getParent());
node.setParent(newParent);
}
Modified: trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-20 15:34:04 UTC (rev 453)
+++ trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-20 15:44:54 UTC (rev 454)
@@ -461,7 +461,7 @@
@Override
public void execute( CreateNodeCommand command ) {
Path path = command.getPath();
- Path parent = path.getAncestor();
+ Path parent = path.getParent();
// Look up the parent node, which must exist ...
Node<Name, Object> parentNode = getNode(parent);
@@ -559,7 +559,7 @@
Node<Name, Object> node = getNode(command.getPath());
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
- Node<Name, Object> newParent = getNode(newPath.getAncestor());
+ Node<Name, Object> newParent = getNode(newPath.getParent());
copyNode(node, newParent, false, null, getExecutionContext());
}
@@ -568,7 +568,7 @@
Node<Name, Object> node = getNode(command.getPath());
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
- Node<Name, Object> newParent = getNode(newPath.getAncestor());
+ Node<Name, Object> newParent = getNode(newPath.getParent());
copyNode(node, newParent, true, null, getExecutionContext());
}
@@ -579,7 +579,7 @@
Name uuidProperty = getUuidPropertyName(getExecutionContext());
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
- Node<Name, Object> newParent = getNode(newPath.getAncestor());
+ Node<Name, Object> newParent = getNode(newPath.getParent());
copyNode(node, newParent, recursive, uuidProperty, getExecutionContext());
// Now delete the old node ...
15 years, 9 months
DNA SVN: r453 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-20 11:34:04 -0400 (Wed, 20 Aug 2008)
New Revision: 453
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
Log:
DNA-178: Forgot to remove a compiler warning.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-20 15:19:52 UTC (rev 452)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-20 15:34:04 UTC (rev 453)
@@ -52,8 +52,9 @@
private final Session session;
private Set<Property> properties;
- private List<Segment> children;
+ // private List<Segment> children;
+
AbstractJcrNode( Session session ) {
assert session != null;
this.session = session;
@@ -556,7 +557,7 @@
void setChildren( List<Segment> children ) {
assert children != null;
- this.children = children;
+ // this.children = children;
}
void setProperties( Set<Property> properties ) {
15 years, 9 months
DNA SVN: r452 - in trunk/dna-jcr: src/main/java/org/jboss/dna/jcr and 2 other directories.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-20 11:19:52 -0400 (Wed, 20 Aug 2008)
New Revision: 452
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
Removed:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java
Modified:
trunk/dna-jcr/pom.xml
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
DNA-178: Completed basic functionality to retrieve nodes and properties
Modified: trunk/dna-jcr/pom.xml
===================================================================
--- trunk/dna-jcr/pom.xml 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/pom.xml 2008-08-20 15:19:52 UTC (rev 452)
@@ -38,6 +38,13 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
+ <artifactId>dna-spi</artifactId>
+ <version>${dna-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
<artifactId>dna-repository</artifactId>
</dependency>
<!--
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -23,7 +23,7 @@
import java.io.InputStream;
import java.util.Calendar;
-import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.jcr.Item;
import javax.jcr.ItemVisitor;
@@ -41,6 +41,8 @@
import javax.jcr.version.VersionHistory;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.graph.Path.Segment;
/**
* @author jverhaeg
@@ -49,13 +51,12 @@
abstract class AbstractJcrNode implements Node {
private final Session session;
- private final Set<Property> properties;
+ private Set<Property> properties;
+ private List<Segment> children;
- AbstractJcrNode( Session session,
- Set<Property> properties ) {
+ AbstractJcrNode( Session session ) {
assert session != null;
this.session = session;
- this.properties = (properties == null ? new HashSet<Property>() : properties);
}
/**
@@ -325,8 +326,8 @@
*/
public String getUUID() throws RepositoryException {
// TODO: Check if node is referenceable
- Property prop = getProperty("jcr:uuid");
- return (prop == null ? null : prop.getValue().getString());
+ Property prop = getProperty(DnaLexicon.UUID.getString());
+ return (prop == null ? null : prop.getString());
}
/**
@@ -553,6 +554,16 @@
throw new UnsupportedOperationException();
}
+ void setChildren( List<Segment> children ) {
+ assert children != null;
+ this.children = children;
+ }
+
+ void setProperties( Set<Property> properties ) {
+ assert properties != null;
+ this.properties = properties;
+ }
+
/**
* {@inheritDoc}
*
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -27,10 +27,13 @@
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
import javax.jcr.Property;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.nodetype.PropertyDefinition;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
/**
* @author jverhaeg
@@ -38,119 +41,46 @@
@NotThreadSafe
abstract class AbstractJcrProperty implements Property {
- private final Session session;
- private final String name;
+ private final Node node;
+ private final ExecutionContext executionContext;
+ private final Name name;
- AbstractJcrProperty( Session session,
- String name ) {
- assert session != null;
- this.session = session;
- assert name != null && name.length() > 0;
+ AbstractJcrProperty( Node node,
+ ExecutionContext executionContext,
+ Name name ) {
+ assert node != null;
+ assert executionContext != null;
+ assert name != null;
+ this.node = node;
+ this.executionContext = executionContext;
this.name = name;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getDate()
- */
- public Calendar getDate() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Property#getDefinition()
*/
public PropertyDefinition getDefinition() {
throw new UnsupportedOperationException();
}
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getDouble()
- */
- public double getDouble() {
- throw new UnsupportedOperationException();
+ ExecutionContext getExecutionContext() {
+ return executionContext;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getLength()
- */
- public long getLength() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getLengths()
- */
- public long[] getLengths() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getLong()
- */
- public long getLong() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Property#getNode()
*/
public Node getNode() {
- throw new UnsupportedOperationException();
+ return node;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getStream()
- */
- public InputStream getStream() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getString()
- */
- public String getString() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getType()
- */
- public int getType() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getValue()
- */
- public Value getValue() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Property#getValues()
*/
public Value[] getValues() {
@@ -280,7 +210,7 @@
* @see javax.jcr.Item#getName()
*/
public String getName() {
- return name;
+ return name.getString();
}
/**
@@ -306,8 +236,8 @@
*
* @see javax.jcr.Item#getSession()
*/
- public Session getSession() {
- return session;
+ public Session getSession() throws RepositoryException {
+ return node.getSession();
}
/**
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -1,127 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PathFactory;
-import org.jboss.dna.spi.graph.PropertyType;
-import org.jboss.dna.spi.graph.ValueFactories;
-import org.jboss.dna.spi.graph.commands.GraphCommand;
-import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
-
-/**
- * @author jverhaeg
- */
-class GraphTools {
-
- private final ExecutionContext executionContext;
- private Session session;
- private final RepositoryConnection connection;
-
- GraphTools( ExecutionContext executionContext,
- RepositoryConnection connection ) {
- assert executionContext != null;
- assert connection != null;
- this.executionContext = executionContext;
- this.connection = connection;
- }
-
- private void execute( GraphCommand... commands ) throws RepositoryException {
- try {
- connection.execute(executionContext, commands);
- } catch (RuntimeException error) {
- throw error;
- } catch (Exception error) {
- throw new RepositoryException(error);
- }
- }
-
- /**
- * @return connection
- */
- public RepositoryConnection getConnection() {
- return connection;
- }
-
- NodeContent getNodeContent( Path path ) throws RepositoryException {
- assert session != null;
- assert path != null;
- // Get root node from source
- ValueFactories valueFactories = executionContext.getValueFactories();
- PathFactory pathFactory = valueFactories.getPathFactory();
- BasicGetNodeCommand getRootNodeCommand = new BasicGetNodeCommand(path);
- execute(getRootNodeCommand);
- // Get primary type
- NameFactory nameFactory = valueFactories.getNameFactory();
- org.jboss.dna.spi.graph.Property primaryTypeProp = getRootNodeCommand.getPropertiesByName().get(nameFactory.create("jcr:primaryType"));
- org.jboss.dna.spi.graph.ValueFactory<String> stringFactory = valueFactories.getStringFactory();
- String primaryType = stringFactory.create(primaryTypeProp.getValues()).next();
- // Process node's properties
- NodeContent content = new NodeContent();
- org.jboss.dna.spi.graph.ValueFactory<Boolean> booleanFactory = valueFactories.getBooleanFactory();
- for (org.jboss.dna.spi.graph.Property prop : getRootNodeCommand.getProperties()) {
- // Get property definition from node's primary type
- BasicGetNodeCommand getPropDefCommand = new BasicGetNodeCommand(pathFactory.create("/dna:system/dna:jcr/"
- + primaryType + "/"
- + prop.getName()));
- execute(getPropDefCommand);
- // Create either a single- or multiple-valued property, as defined by the property definition
- org.jboss.dna.spi.graph.Property isMultipleProp = getPropDefCommand.getPropertiesByName().get(nameFactory.create("jcr:multiple"));
- org.jboss.dna.spi.graph.Property requiredTypeProp = getPropDefCommand.getPropertiesByName().get(nameFactory.create("jcr:requiredType"));
- String type = stringFactory.create(requiredTypeProp.getValues()).next();
- if (booleanFactory.create(isMultipleProp.getValues()).next().booleanValue()) {
- // jcrProps.add(new JcrMultiValuedProperty(dnaProp.getName(), type, dnaProp.getValues()));
- } else {
- Value jcrValue;
- ValueFactory jcrValueFactory = session.getValueFactory();
- if (PropertyType.BINARY.equals(type)) {
- jcrValue = jcrValueFactory.createValue(valueFactories.getBinaryFactory().create(prop.getValues()).next().getStream());
- } else {
- assert PropertyType.UUID.equals(type);
- jcrValue = jcrValueFactory.createValue(valueFactories.getStringFactory().create(prop.getValues()).next());
- }
- content.properties.add(new JcrProperty(session, prop.getName().toString(), jcrValue));
- }
- }
- return content;
- }
-
- void setSession( Session session ) {
- assert session != null;
- this.session = session;
- }
-
- class NodeContent {
-
- Set<Property> properties = new HashSet<Property>();
- }
-}
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -1,112 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import java.security.AccessControlContext;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
-import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.graph.NamespaceRegistry;
-import org.jboss.dna.spi.graph.PropertyFactory;
-import org.jboss.dna.spi.graph.ValueFactories;
-
-/**
- * @author jverhaeg
- */
-@NotThreadSafe
-class JcrExecutionContext implements ExecutionContext {
-
- private final ExecutionContext delegate;
- private final GraphTools tools;
-
- JcrExecutionContext( ExecutionContext delegate,
- RepositoryConnection connection ) {
- assert delegate != null;
- assert connection != null;
- this.delegate = delegate;
- tools = new GraphTools(delegate, connection);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.ExecutionContext#getAccessControlContext()
- */
- public AccessControlContext getAccessControlContext() {
- return delegate.getAccessControlContext();
- }
-
- GraphTools getGraphTools() {
- return tools;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.ExecutionContext#getLoginContext()
- */
- public LoginContext getLoginContext() {
- return delegate.getLoginContext();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.ExecutionContext#getNamespaceRegistry()
- */
- public NamespaceRegistry getNamespaceRegistry() {
- return delegate.getNamespaceRegistry();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.ExecutionContext#getPropertyFactory()
- */
- public PropertyFactory getPropertyFactory() {
- return delegate.getPropertyFactory();
- }
-
- RepositoryConnection getRepositoryConnection() {
- return tools.getConnection();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.ExecutionContext#getSubject()
- */
- public Subject getSubject() {
- return delegate.getSubject();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.ExecutionContext#getValueFactories()
- */
- public ValueFactories getValueFactories() {
- return delegate.getValueFactories();
- }
-}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -21,8 +21,6 @@
*/
package org.jboss.dna.jcr;
-import java.util.Locale;
-import java.util.Set;
import org.jboss.dna.common.i18n.I18n;
/**
@@ -31,10 +29,14 @@
*/
public final class JcrI18n {
+ public static I18n cannotConvertValue;
public static I18n credentialsMustProvideJaasMethod;
public static I18n credentialsMustReturnAccessControlContext;
public static I18n credentialsMustReturnLoginContext;
public static I18n defaultWorkspaceName;
+ public static I18n inputStreamConsumed;
+ public static I18n nonInputStreamConsumed;
+ public static I18n pathNotFound;
public static I18n repositoryMustBeConfigured;
public static I18n sourceInUse;
@@ -49,16 +51,4 @@
System.err.println(err);
}
}
-
- public static Set<Locale> getLocalizationProblemLocales() {
- return I18n.getLocalizationProblemLocales(JcrI18n.class);
- }
-
- public static Set<String> getLocalizationProblems() {
- return I18n.getLocalizationProblems(JcrI18n.class);
- }
-
- public static Set<String> getLocalizationProblems( Locale locale ) {
- return I18n.getLocalizationProblems(JcrI18n.class, locale);
- }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.jcr;
-import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
@@ -34,9 +33,8 @@
@NotThreadSafe
final class JcrNode extends AbstractJcrNode {
- JcrNode( Session session,
- Set<Property> properties ) {
- super(session, properties);
+ JcrNode( Session session ) {
+ super(session);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -21,22 +21,54 @@
*/
package org.jboss.dna.jcr;
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* @author jverhaeg
*/
final class JcrProperty extends AbstractJcrProperty {
- private Value value;
+ private JcrValue<?> jcrValue;
- JcrProperty( Session session,
- String name,
- Value value ) {
- super(session, name);
+ JcrProperty( Node node,
+ ExecutionContext executionContext,
+ Name name,
+ Object value ) {
+ super(node, executionContext, name);
assert value != null;
+ ValueFactories valueFactories = executionContext.getValueFactories();
+ if (value instanceof Boolean) {
+ jcrValue = new JcrValue<Boolean>(valueFactories, PropertyType.BOOLEAN, (Boolean)value);
+ } else if (value instanceof Date) {
+ jcrValue = new JcrValue<Date>(valueFactories, PropertyType.DATE, (Date)value);
+ } else if (value instanceof Calendar) {
+ jcrValue = new JcrValue<Calendar>(valueFactories, PropertyType.DATE, (Calendar)value);
+ } else if (value instanceof Double) {
+ jcrValue = new JcrValue<Double>(valueFactories, PropertyType.DOUBLE, (Double)value);
+ } else if (value instanceof Float) {
+ jcrValue = new JcrValue<Float>(valueFactories, PropertyType.DOUBLE, (Float)value);
+ } else if (value instanceof Integer) {
+ jcrValue = new JcrValue<Integer>(valueFactories, PropertyType.LONG, (Integer)value);
+ } else if (value instanceof Long) {
+ jcrValue = new JcrValue<Long>(valueFactories, PropertyType.LONG, (Long)value);
+ } else if (value instanceof UUID) {
+ jcrValue = new JcrValue<UUID>(valueFactories, PropertyType.STRING, (UUID)value);
+ } else if (value instanceof String) {
+ jcrValue = new JcrValue<String>(valueFactories, PropertyType.STRING, (String)value);
+ } else {
+ jcrValue = new JcrValue<Object>(valueFactories, PropertyType.BINARY, value);
+ }
}
/**
@@ -45,6 +77,87 @@
* @see javax.jcr.Property#getBoolean()
*/
public boolean getBoolean() throws RepositoryException {
- return value.getBoolean();
+ return jcrValue.getBoolean();
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDate()
+ */
+ public Calendar getDate() throws RepositoryException {
+ return jcrValue.getDate();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDouble()
+ */
+ public double getDouble() throws RepositoryException {
+ return jcrValue.getDouble();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLength()
+ */
+ public long getLength() throws RepositoryException {
+ return jcrValue.getLength();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLengths()
+ */
+ public long[] getLengths() throws ValueFormatException {
+ throw new ValueFormatException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLong()
+ */
+ public long getLong() throws RepositoryException {
+ return jcrValue.getLong();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getStream()
+ */
+ public InputStream getStream() throws RepositoryException {
+ return jcrValue.getStream();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getString()
+ */
+ public String getString() throws RepositoryException {
+ return jcrValue.getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getType()
+ */
+ public int getType() {
+ return jcrValue.getType();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValue()
+ */
+ public Value getValue() {
+ return jcrValue;
+ }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -21,22 +21,25 @@
*/
package org.jboss.dna.jcr;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.WeakHashMap;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
+import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.ExecutionContextFactory;
-import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
/**
@@ -48,13 +51,16 @@
* implementation to which this JCR implementation delegates.
* </p>
* <p>
- * If {@link Credentials} are used to login, implementations <em>must</em> also implement one of the following methods:
+ * If {@link Credentials credentials} are used to login, implementations <em>must</em> also implement one of the following
+ * methods:
*
* <pre>
* public {@link AccessControlContext} getAccessControlContext();
* public {@link LoginContext} getLoginContext();
* </pre>
*
+ * Note, {@link Session#getAttributeNames() attributes} on credentials are not supported. JCR {@link SimpleCredentials} are also
+ * not supported.
* </p>
*
* @author John Verhaeg
@@ -246,9 +252,8 @@
if (workspaceName == null) workspaceName = JcrI18n.defaultWorkspaceName.text();
// Create session
try {
- RepositoryConnection connection = connectionFactory.createConnection(workspaceName);
- assert connection != null;
- return new JcrSession(this, new JcrExecutionContext(execContext, connection), workspaceName);
+ return new JcrSession(this, execContext, workspaceName, connectionFactory.createConnection(workspaceName),
+ new WeakHashMap<String, WeakReference<Node>>());
} catch (InterruptedException error) {
throw new RepositoryException(error);
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -21,10 +21,8 @@
*/
package org.jboss.dna.jcr;
-import java.util.Set;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
-import javax.jcr.Property;
import javax.jcr.Session;
import net.jcip.annotations.NotThreadSafe;
@@ -34,9 +32,8 @@
@NotThreadSafe
final class JcrRootNode extends AbstractJcrNode {
- JcrRootNode( Session session,
- Set<Property> properties ) {
- super(session, properties);
+ JcrRootNode( Session session ) {
+ super(session);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -23,11 +23,17 @@
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.ref.WeakReference;
import java.security.Principal;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import javax.jcr.Credentials;
import javax.jcr.Item;
import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -36,7 +42,16 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.jcr.GraphTools.NodeContent;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
import org.xml.sax.ContentHandler;
/**
@@ -46,23 +61,28 @@
@NotThreadSafe
final class JcrSession implements Session {
- private final JcrRepository repository;
- private final JcrExecutionContext executionContext;
+ private final Repository repository;
+ private final ExecutionContext executionContext;
+ private RepositoryConnection connection;
+ private final Map<String, WeakReference<Node>> uuid2NodeMap;
private boolean isLive;
- private JcrWorkspace workspace;
- private Node rootNode;
+ private Workspace workspace;
+ private JcrRootNode rootNode;
- // private final Map<String, Node> uuid2NodeMap = new HashMap<String, Node>();
-
- JcrSession( JcrRepository repository,
- JcrExecutionContext executionContext,
- String workspaceName ) throws RepositoryException {
+ JcrSession( Repository repository,
+ ExecutionContext executionContext,
+ String workspaceName,
+ RepositoryConnection connection,
+ Map<String, WeakReference<Node>> uuid2NodeMap ) throws RepositoryException {
assert repository != null;
assert executionContext != null;
assert workspaceName != null;
+ assert connection != null;
+ assert uuid2NodeMap != null;
this.repository = repository;
this.executionContext = executionContext;
- executionContext.getGraphTools().setSession(this);
+ this.connection = connection;
+ this.uuid2NodeMap = uuid2NodeMap;
this.isLive = true;
// Following must be initialized after session's state is initialized
this.workspace = new JcrWorkspace(this, workspaceName);
@@ -87,6 +107,16 @@
throw new UnsupportedOperationException();
}
+ private void execute( GraphCommand... commands ) throws RepositoryException {
+ try {
+ connection.execute(executionContext, commands);
+ } catch (RuntimeException error) {
+ throw error;
+ } catch (Exception error) {
+ throw new RepositoryException(error);
+ }
+ }
+
/**
* {@inheritDoc}
*
@@ -141,7 +171,7 @@
* @see javax.jcr.Session#getAttribute(java.lang.String)
*/
public Object getAttribute( String name ) {
- throw new UnsupportedOperationException();
+ return null;
}
/**
@@ -150,7 +180,7 @@
* @see javax.jcr.Session#getAttributeNames()
*/
public String[] getAttributeNames() {
- throw new UnsupportedOperationException();
+ return StringUtil.EMPTY_STRING_ARRAY;
}
/**
@@ -168,8 +198,32 @@
*
* @see javax.jcr.Session#getItem(java.lang.String)
*/
- public Item getItem( String absPath ) {
- throw new UnsupportedOperationException();
+ public Item getItem( String absolutePath ) throws RepositoryException {
+ ArgCheck.isNotEmpty(absolutePath, "absolutePath");
+ // Return root node if path is "/"
+ Path path = executionContext.getValueFactories().getPathFactory().create(absolutePath);
+ if (path.isRoot()) {
+ return getRootNode();
+ }
+ // Since we don't know whether path refers to a node or property, get the parent contents, which must refer to a node
+ Path parentPath = path.getAncestor();
+ BasicGetNodeCommand getNodeCommand = new BasicGetNodeCommand(parentPath);
+ execute(getNodeCommand);
+ // First search for a child with the last name in the path
+ Name name = path.getLastSegment().getName();
+ for (Segment seg : getNodeCommand.getChildren()) {
+ if (seg.getName().equals(name)) {
+ return getNode(path);
+ }
+ }
+ // If a node isn't found & last segment contains no index, get parent node & search for a property with the last name in
+ // the path
+ Segment seg = path.getLastSegment();
+ if (!seg.hasIndex()) {
+ return getNode(parentPath).getProperty(seg.getString());
+ }
+ // If a property isn't found, throw a PathNotFoundException
+ throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
}
/**
@@ -208,6 +262,28 @@
throw new UnsupportedOperationException();
}
+ private Node getNode( Path path ) throws RepositoryException {
+ // Get node from source
+ BasicGetNodeCommand command = new BasicGetNodeCommand(path);
+ execute(command);
+ // First check if node already exists. We don't need to check for changes since that will be handled by an observer
+ org.jboss.dna.spi.graph.Property dnaUuidProp = command.getPropertiesByName().get(DnaLexicon.UUID);
+ if (dnaUuidProp != null) {
+ String uuid = executionContext.getValueFactories().getStringFactory().create(dnaUuidProp.getValues()).next();
+ WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+ if (ref != null) {
+ Node node = ref.get();
+ if (node != null) {
+ return node;
+ }
+ }
+ }
+ // If not create a new one & populate it
+ JcrNode node = new JcrNode(this);
+ populateNode(node, command);
+ return node;
+ }
+
/**
* {@inheritDoc}
*
@@ -232,16 +308,19 @@
* @see javax.jcr.Session#getRootNode()
*/
public Node getRootNode() throws RepositoryException {
- // If root has no UUID, populate its contents from source
+ // Return cached root node if available
if (rootNode != null) {
return rootNode;
}
// Get root node from source
- assert executionContext.getGraphTools() != null;
assert executionContext.getValueFactories() != null;
assert executionContext.getValueFactories().getPathFactory() != null;
- NodeContent content = executionContext.getGraphTools().getNodeContent(executionContext.getValueFactories().getPathFactory().createRootPath());
- rootNode = new JcrRootNode(this, content.properties);
+ rootNode = new JcrRootNode(this);
+ // Get root node from source
+ BasicGetNodeCommand getNodeCommand = new BasicGetNodeCommand(
+ executionContext.getValueFactories().getPathFactory().createRootPath());
+ execute(getNodeCommand);
+ populateNode(rootNode, getNodeCommand);
return rootNode;
}
@@ -329,9 +408,13 @@
* @see javax.jcr.Session#logout()
*/
public void logout() {
+ if (!isLive()) {
+ return;
+ }
try {
- if (executionContext.getRepositoryConnection() != null) {
- executionContext.getRepositoryConnection().close();
+ if (connection != null) {
+ connection.close();
+ connection = null;
}
assert executionContext.getLoginContext() != null;
executionContext.getLoginContext().logout();
@@ -353,6 +436,31 @@
throw new UnsupportedOperationException();
}
+ private void populateNode( AbstractJcrNode node,
+ BasicGetNodeCommand getNodeCommand ) throws RepositoryException {
+ // TODO: What do we do to validate node against its primary type?
+ assert node != null;
+ assert getNodeCommand != null;
+ // Create JCR children for corresponding DNA children
+ node.setChildren(getNodeCommand.getChildren());
+ // Create JCR properties for corresponding DNA properties
+ Set<Property> properties = new HashSet<Property>();
+ boolean uuidFound = false;
+ for (org.jboss.dna.spi.graph.Property dnaProp : getNodeCommand.getProperties()) {
+ if (DnaLexicon.UUID.equals(dnaProp.getName())) {
+ uuidFound = true;
+ }
+ properties.add(new JcrProperty(node, executionContext, dnaProp.getName(), dnaProp.getValues().next()));
+ }
+ // Ensure a UUID property exists
+ if (!uuidFound) {
+ properties.add(new JcrProperty(node, executionContext, DnaLexicon.UUID, UUID.randomUUID()));
+ }
+ node.setProperties(properties);
+ // Setup node to be retrieved by UUID
+ uuid2NodeMap.put(node.getUUID(), new WeakReference<Node>(node));
+ }
+
/**
* {@inheritDoc}
*
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @param <T> the type of value to create.
+ * @author jverhaeg
+ */
+@NotThreadSafe
+final class JcrValue<T> implements Value {
+
+ private final ValueFactories valueFactories;
+ private final int type;
+ private final T value;
+
+ JcrValue( ValueFactories valueFactories,
+ int type,
+ T value ) {
+ assert valueFactories != null;
+ assert type == PropertyType.BINARY || type == PropertyType.BOOLEAN || type == PropertyType.DATE
+ || type == PropertyType.DOUBLE || type == PropertyType.LONG || type == PropertyType.NAME
+ || type == PropertyType.PATH || type == PropertyType.REFERENCE || type == PropertyType.STRING;
+ assert value != null;
+ this.valueFactories = valueFactories;
+ this.type = type;
+ this.value = value;
+ }
+
+ private State state = State.NEVER_CONSUMED;
+
+ ValueFormatException createValueFormatException( Class<?> type ) {
+ return new ValueFormatException(JcrI18n.cannotConvertValue.text(value.getClass().getSimpleName(), type.getSimpleName()));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Value#getBoolean()
+ */
+ public boolean getBoolean() throws ValueFormatException {
+ nonInputStreamConsumed();
+ try {
+ boolean convertedValue = valueFactories.getBooleanFactory().create(value);
+ state = State.NON_INPUT_STREAM_CONSUMED;
+ return convertedValue;
+ } catch (RuntimeException error) {
+ throw createValueFormatException(boolean.class);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Value#getDate()
+ */
+ public Calendar getDate() throws ValueFormatException {
+ nonInputStreamConsumed();
+ try {
+ Calendar convertedValue = valueFactories.getDateFactory().create(value).toCalendar();
+ state = State.NON_INPUT_STREAM_CONSUMED;
+ return convertedValue;
+ } catch (RuntimeException error) {
+ throw createValueFormatException(Calendar.class);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Value#getDouble()
+ */
+ public double getDouble() throws ValueFormatException {
+ nonInputStreamConsumed();
+ try {
+ double convertedValue = valueFactories.getDoubleFactory().create(value);
+ state = State.NON_INPUT_STREAM_CONSUMED;
+ return convertedValue;
+ } catch (RuntimeException error) {
+ throw createValueFormatException(double.class);
+ }
+ }
+
+ long getLength() throws RepositoryException {
+ if (type == PropertyType.BINARY) {
+ return valueFactories.getBinaryFactory().create(value).getSize();
+ }
+ return getString().length();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Value#getLong()
+ */
+ public long getLong() throws ValueFormatException {
+ nonInputStreamConsumed();
+ try {
+ long convertedValue = valueFactories.getLongFactory().create(value);
+ state = State.NON_INPUT_STREAM_CONSUMED;
+ return convertedValue;
+ } catch (RuntimeException error) {
+ throw createValueFormatException(long.class);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Value#getStream()
+ */
+ public InputStream getStream() throws ValueFormatException {
+ if (state == State.NON_INPUT_STREAM_CONSUMED) {
+ throw new IllegalStateException(JcrI18n.nonInputStreamConsumed.text());
+ }
+ try {
+ InputStream convertedValue = valueFactories.getBinaryFactory().create(value).getStream();
+ state = State.INPUT_STREAM_CONSUMED;
+ return convertedValue;
+ } catch (RuntimeException error) {
+ throw createValueFormatException(InputStream.class);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Value#getString()
+ */
+ public String getString() throws ValueFormatException {
+ nonInputStreamConsumed();
+ try {
+ String convertedValue = valueFactories.getStringFactory().create(value);
+ state = State.NON_INPUT_STREAM_CONSUMED;
+ return convertedValue;
+ } catch (RuntimeException error) {
+ throw createValueFormatException(String.class);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Value#getType()
+ */
+ public int getType() {
+ return type;
+ }
+
+ void nonInputStreamConsumed() {
+ if (state == State.INPUT_STREAM_CONSUMED) {
+ throw new IllegalStateException(JcrI18n.inputStreamConsumed.text());
+ }
+ }
+
+ private enum State {
+ NEVER_CONSUMED,
+ INPUT_STREAM_CONSUMED,
+ NON_INPUT_STREAM_CONSUMED
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2008-08-20 15:19:52 UTC (rev 452)
@@ -19,10 +19,14 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
#
+cannotConvertValue = Cannot convert {0} value to {1}.
credentialsMustProvideJaasMethod = The Credentials class "{0}" must implement either "public LoginContext getLoginContext();" or "public AccessControlContext getAccessControlContext();".
credentialsMustReturnAccessControlContext = The "getAccessControlContext()" method in Credentials class "{0}" must not return a null.
credentialsMustReturnLoginContext = The "getLoginContext()" method in Credentials class "{0}" must not return a null.
defaultWorkspaceName = Default
+inputStreamConsumed = This value was already consumed as an input stream.
+nonInputStreamConsumed = This value was already consumed as a non-input stream.
+pathNotFound = No item exists at path {0}
repositoryMustBeConfigured = DNA repositories must be configured with either a repository source factory or a repository source.
sourceInUse = All sessions must end before a new repository source can be set.
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -29,7 +29,7 @@
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
-import javax.jcr.Value;
+import org.jboss.dna.spi.DnaLexicon;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -50,7 +50,7 @@
public void before() {
MockitoAnnotations.initMocks(this);
properties = new HashSet<Property>();
- node = new AbstractJcrNode(session, properties) {
+ node = new AbstractJcrNode(session) {
public String getName() {
return null;
@@ -60,11 +60,12 @@
return null;
}
};
+ node.setProperties(properties);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoSession() throws Exception {
- new AbstractJcrNode(null, properties) {
+ new AbstractJcrNode(null) {
public String getName() {
return null;
@@ -84,10 +85,8 @@
@Test
public void shouldProvideUuid() throws Exception {
Property property = Mockito.mock(Property.class);
- stub(property.getName()).toReturn("jcr:uuid");
- Value value = Mockito.mock(Value.class);
- stub(value.getString()).toReturn("uuid");
- stub(property.getValue()).toReturn(value);
+ stub(property.getName()).toReturn(DnaLexicon.UUID.getString());
+ stub(property.getString()).toReturn("uuid");
properties.add(property);
assertThat(node.getUUID(), is("uuid"));
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -23,9 +23,17 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.io.InputStream;
+import java.util.Calendar;
+import javax.jcr.Node;
import javax.jcr.Session;
+import javax.jcr.Value;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -36,56 +44,152 @@
private AbstractJcrProperty prop;
@Mock
- private Session session;
+ private Node node;
+ @Mock
+ private ExecutionContext executionContext;
+ @Mock
+ private Name name;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
- prop = new AbstractJcrProperty(session, "name") {
-
- public boolean getBoolean() {
- return false;
- }
- };
+ prop = new MockAbstractJcrProperty(node, executionContext, name);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoSession() throws Exception {
- new AbstractJcrProperty(null, "name") {
-
- public boolean getBoolean() {
- return false;
- }
- };
+ new MockAbstractJcrProperty(null, executionContext, name);
}
@Test( expected = AssertionError.class )
- public void shouldNotAllowNoName() throws Exception {
- new AbstractJcrProperty(session, null) {
-
- public boolean getBoolean() {
- return false;
- }
- };
+ public void shouldNotAllowNoExecutionContext() throws Exception {
+ new MockAbstractJcrProperty(node, null, name);
}
@Test( expected = AssertionError.class )
- public void shouldNotAllowEmptyName() throws Exception {
- new AbstractJcrProperty(session, "") {
-
- public boolean getBoolean() {
- return false;
- }
- };
+ public void shouldNotAllowNoName() throws Exception {
+ new MockAbstractJcrProperty(node, executionContext, null);
}
@Test
public void shouldProvideSession() throws Exception {
+ Session session = Mockito.mock(Session.class);
+ stub(node.getSession()).toReturn(session);
assertThat(prop.getSession(), is(session));
}
@Test
+ public void shouldProvideExecutionContext() throws Exception {
+ assertThat(prop.getExecutionContext(), is(executionContext));
+ }
+
+ @Test
+ public void shouldProvideNode() throws Exception {
+ assertThat(prop.getNode(), is(node));
+ }
+
+ @Test
public void shouldProvideName() throws Exception {
+ stub(name.getString()).toReturn("name");
assertThat(prop.getName(), is("name"));
}
+
+ private class MockAbstractJcrProperty extends AbstractJcrProperty {
+
+ MockAbstractJcrProperty( Node node,
+ ExecutionContext executionContext,
+ Name name ) {
+ super(node, executionContext, name);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getBoolean()
+ */
+ public boolean getBoolean() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDate()
+ */
+ public Calendar getDate() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDouble()
+ */
+ public double getDouble() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLength()
+ */
+ public long getLength() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLengths()
+ */
+ public long[] getLengths() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLong()
+ */
+ public long getLong() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getStream()
+ */
+ public InputStream getStream() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getString()
+ */
+ public String getString() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getType()
+ */
+ public int getType() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValue()
+ */
+ public Value getValue() {
+ return null;
+ }
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -49,7 +49,8 @@
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
properties = new HashSet<Property>();
- node = new JcrNode(session, properties);
+ node = new JcrNode(session);
+ node.setProperties(properties);
}
@Test
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -21,50 +21,121 @@
*/
package org.jboss.dna.jcr;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author jverhaeg
*/
public class JcrPropertyTest {
- //
- // private AbstractJcrProperty prop;
- // @Mock
- // private Session session;
- //
- // @Before
- // public void before() {
- // MockitoAnnotations.initMocks(this);
- // prop = new AbstractJcrProperty(session, "name") {};
- // }
- //
- // @Test( expected = AssertionError.class )
- // public void shouldNotAllowNoSession() throws Exception {
- // new AbstractJcrProperty(null, "name") {};
- // }
- //
- // @Test( expected = AssertionError.class )
- // public void shouldNotAllowNoName() throws Exception {
- // new AbstractJcrProperty(session, null) {};
- // }
- //
- // @Test( expected = AssertionError.class )
- // public void shouldNotAllowEmptyName() throws Exception {
- // new AbstractJcrProperty(session, "") {};
- // }
- //
- // @Test
- // public void shouldProvideSession() throws Exception {
- // assertThat(prop.getSession(), is(session));
- // }
- //
- // @Test
- // public void shouldProvideName() throws Exception {
- // assertThat(prop.getName(), is("name"));
- // }
+ @Mock
+ private Node node;
+ private ExecutionContext executionContext = new BasicExecutionContext();
+ @Mock
+ Name name;
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoValue() {
+ new JcrProperty(node, executionContext, name, null);
+ }
+
@Test
- public void should() {
+ public void shouldProvideBoolean() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, true);
+ assertThat(prop.getBoolean(), is(true));
+ }
+ @Test
+ public void shouldProvideDate() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ Property prop = new JcrProperty(node, executionContext, name, cal);
+ assertThat(prop.getDate(), is(cal));
+ prop = new JcrProperty(node, executionContext, name, cal.getTime());
+ assertThat(prop.getDate(), is(cal));
}
+
+ @Test
+ public void shouldProvideDouble() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, 1.0);
+ assertThat(prop.getDouble(), is(1.0));
+ prop = new JcrProperty(node, executionContext, name, 1.0F);
+ assertThat(prop.getDouble(), is(1.0));
+ }
+
+ @Test
+ public void shouldProvideLength() throws Exception {
+ assertThat(new JcrProperty(node, executionContext, name, "value").getLength(), is(5L));
+ Object obj = new Object();
+ assertThat(new JcrProperty(node, executionContext, name, obj).getLength(), is((long)obj.toString().length()));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLengths() throws Exception {
+ new JcrProperty(node, executionContext, name, "value").getLengths();
+ }
+
+ @Test
+ public void shouldProvideLong() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, 1);
+ assertThat(prop.getLong(), is(1L));
+ prop = new JcrProperty(node, executionContext, name, 1L);
+ assertThat(prop.getLong(), is(1L));
+ }
+
+ @Test
+ public void shouldProvideStream() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, "value");
+ InputStream stream = prop.getStream();
+ assertThat(stream, notNullValue());
+ stream.close();
+ }
+
+ @Test
+ public void shouldProvideString() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, "value");
+ assertThat(prop.getString(), is("value"));
+ }
+
+ @Test
+ public void shouldProvideUuid() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ Property prop = new JcrProperty(node, executionContext, name, uuid);
+ assertThat(prop.getString(), is(uuid.toString()));
+ }
+
+ @Test
+ public void shouldProvideType() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, UUID.randomUUID());
+ assertThat(prop.getType(), is(PropertyType.STRING));
+ }
+
+ @Test
+ public void shouldProvideValue() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, true);
+ Value val = prop.getValue();
+ assertThat(val, notNullValue());
+ assertThat(val.getBoolean(), is(true));
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -48,7 +48,8 @@
public void before() {
MockitoAnnotations.initMocks(this);
properties = new HashSet<Property>();
- root = new JcrRootNode(session, properties);
+ root = new JcrRootNode(session);
+ root.setProperties(properties);
}
@Test
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -22,19 +22,32 @@
package org.jboss.dna.jcr;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.stub;
+import java.lang.ref.WeakReference;
import java.security.Principal;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.Session;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
-import org.jboss.dna.jcr.GraphTools.NodeContent;
-import org.jboss.dna.spi.graph.PathFactory;
-import org.jboss.dna.spi.graph.ValueFactories;
-import org.jboss.dna.spi.graph.impl.BasicPath;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.SimpleRepository;
+import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -45,42 +58,87 @@
*/
public class JcrSessionTest {
- private JcrSession session;
+ private static final String WORKSPACE_NAME = JcrI18n.defaultWorkspaceName.text();
+
+ private static ExecutionContext executionContext;
+ private static SimpleRepository simpleRepository;
+ private static RepositoryConnectionFactory connectionFactory;
+ private static RepositoryConnection connection;
+ private static Repository repository;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ ExecutionContextFactory factory = TestUtil.getExecutionContextFactory();
+ executionContext = factory.create();
+ simpleRepository = SimpleRepository.get(WORKSPACE_NAME);
+ simpleRepository.setProperty(executionContext, "/a/b", "booleanProperty", true);
+ simpleRepository.setProperty(executionContext, "/a/b/c", "stringProperty", "value");
+ connectionFactory = TestUtil.createJackRabbitConnectionFactory(simpleRepository, executionContext);
+ repository = new JcrRepository(factory, connectionFactory);
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SimpleRepository.shutdownAll();
+ }
+
+ private Session session;
@Mock
- private JcrRepository repository;
- @Mock
- private JcrExecutionContext executionContext;
- @Mock
- private GraphTools tools;
- @Mock
- private LoginContext loginContext;
+ private Map<String, WeakReference<Node>> uuid2NodeMap;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- stub(executionContext.getLoginContext()).toReturn(loginContext);
- stub(executionContext.getGraphTools()).toReturn(tools);
- session = new JcrSession(repository, executionContext, JcrI18n.defaultWorkspaceName.text());
+ session = repository.login();
}
+ @After
+ public void after() throws Exception {
+ if (session.isLive()) {
+ session.logout();
+ }
+ }
+
@Test( expected = AssertionError.class )
public void shouldNotAllowNoRepository() throws Exception {
- new JcrSession(null, executionContext, JcrI18n.defaultWorkspaceName.text());
+ new JcrSession(null, executionContext, WORKSPACE_NAME, connection, uuid2NodeMap);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoExecutionContext() throws Exception {
- new JcrSession(repository, null, JcrI18n.defaultWorkspaceName.text());
+ new JcrSession(repository, null, WORKSPACE_NAME, connection, uuid2NodeMap);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoWorkspaceName() throws Exception {
- new JcrSession(repository, executionContext, null);
+ new JcrSession(repository, executionContext, null, connection, uuid2NodeMap);
}
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoConnection() throws Exception {
+ new JcrSession(repository, executionContext, WORKSPACE_NAME, null, uuid2NodeMap);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoUuid2NodeMap() throws Exception {
+ new JcrSession(repository, executionContext, WORKSPACE_NAME, connection, null);
+ }
+
@Test
+ public void shouldProvideNoAttributes() throws Exception {
+ assertThat(session.getAttribute(null), nullValue());
+ }
+
+ @Test
+ public void shouldProvideEmptyAttributeNames() throws Exception {
+ String[] names = session.getAttributeNames();
+ assertThat(names, notNullValue());
+ assertThat(names.length, is(0));
+ }
+
+ @Test
public void shouldProvideAccessToRepository() throws Exception {
- assertThat((JcrRepository)session.getRepository(), is(repository));
+ assertThat(session.getRepository(), is(repository));
}
@Test
@@ -110,19 +168,40 @@
Principal principal = Mockito.mock(Principal.class);
stub(principal.getName()).toReturn("name");
Subject subject = new Subject(false, Collections.singleton(principal), Collections.EMPTY_SET, Collections.EMPTY_SET);
+ ExecutionContext executionContext = Mockito.mock(ExecutionContext.class);
stub(executionContext.getSubject()).toReturn(subject);
- assertThat(session.getUserID(), is("name"));
+ stub(executionContext.getLoginContext()).toReturn(Mockito.mock(LoginContext.class));
+ Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME, Mockito.mock(RepositoryConnection.class),
+ uuid2NodeMap);
+ try {
+ assertThat(session.getUserID(), is("name"));
+ } finally {
+ session.logout();
+ }
}
@Test
public void shouldProvideRootNode() throws Exception {
- ValueFactories valueFactories = Mockito.mock(ValueFactories.class);
- PathFactory pathFactory = Mockito.mock(PathFactory.class);
- stub(pathFactory.createRootPath()).toReturn(BasicPath.ROOT);
- stub(valueFactories.getPathFactory()).toReturn(pathFactory);
- stub(executionContext.getValueFactories()).toReturn(valueFactories);
- NodeContent content = tools.new NodeContent();
- stub(tools.getNodeContent(BasicPath.ROOT)).toReturn(content);
- assertThat(session.getRootNode(), notNullValue());
+ Map<String, WeakReference<Node>> uuid2NodeMap = new HashMap<String, WeakReference<Node>>();
+ Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME,
+ connectionFactory.createConnection(WORKSPACE_NAME), uuid2NodeMap);
+ assertThat(uuid2NodeMap.isEmpty(), is(true));
+ Node root = session.getRootNode();
+ assertThat(root, notNullValue());
+ String uuid = root.getUUID();
+ assertThat(uuid, notNullValue());
+ WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+ assertThat(ref, notNullValue());
+ assertThat(ref.get(), is(root));
}
+
+ @Test
+ public void shouldProvideItemsByPath() throws Exception {
+ Item item = session.getItem("/a");
+ assertThat(item, instanceOf(Node.class));
+ item = session.getItem("/a/b");
+ assertThat(item, instanceOf(Node.class));
+ item = session.getItem("/a/b/booleanProperty");
+ assertThat(item, instanceOf(Property.class));
+ }
}
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -0,0 +1,311 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import javax.jcr.PropertyType;
+import javax.jcr.ValueFormatException;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.impl.StandardValueFactories;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrValueTest {
+
+ private ValueFactories factories;
+ private JcrValue<Boolean> value;
+
+ @Before
+ public void before() {
+ factories = new StandardValueFactories(Mockito.mock(NamespaceRegistry.class));
+ value = new JcrValue<Boolean>(factories, PropertyType.BOOLEAN, true);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoValueFactories() throws Exception {
+ new JcrValue<Object>(null, PropertyType.BINARY, true);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowInvalidType() throws Exception {
+ new JcrValue<Object>(factories, 0, true);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoValue() throws Exception {
+ new JcrValue<Object>(factories, PropertyType.BINARY, null);
+ }
+
+ @Test
+ public void shouldProvideType() throws Exception {
+ assertThat(value.getType(), is(PropertyType.BOOLEAN));
+ }
+
+ @Test( expected = IllegalStateException.class )
+ public void shouldNotAllowConsumingInputStreamAfterConsumingNonInputStream() throws Exception {
+ value.getBoolean();
+ value.getStream();
+ }
+
+ @Test( expected = IllegalStateException.class )
+ public void shouldNotAllowConsumingNonInputStreamAfterConsumingInputStream() throws Exception {
+ value.getBoolean();
+ value.getStream();
+ }
+
+ @Test
+ public void shouldProvideBooleanForBoolean() throws Exception {
+ assertThat(value.getBoolean(), is(true));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideDateForBoolean() throws Exception {
+ value.getDate();
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideDoubleForBoolean() throws Exception {
+ value.getDouble();
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLongForBoolean() throws Exception {
+ value.getLong();
+ }
+
+ @Test
+ public void shouldProvideStreamForBoolean() throws Exception {
+ testProvidesStream(value);
+ }
+
+ @Test
+ public void shouldProvideStringForBoolean() throws Exception {
+ assertThat(value.getString(), is("true"));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideBooleanForDate() throws Exception {
+ new JcrValue<Date>(factories, PropertyType.DATE, new Date()).getBoolean();
+ }
+
+ @Test
+ public void shouldProvideDateForDate() throws Exception {
+ Date date = new Date();
+ assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date).getDate().getTime(), is(date));
+ }
+
+ @Test
+ public void shouldProvideDoubleForDate() throws Exception {
+ Date date = new Date();
+ assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date).getDouble(), is((double)date.getTime()));
+ }
+
+ @Test
+ public void shouldProvideLongForDate() throws Exception {
+ Date date = new Date();
+ assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date).getLong(), is(date.getTime()));
+ }
+
+ @Test
+ public void shouldProvideStreamForDate() throws Exception {
+ testProvidesStream(new JcrValue<Date>(factories, PropertyType.DATE, new Date()));
+ }
+
+ @Test
+ public void shouldProvideStringForDate() throws Exception {
+ Calendar date = Calendar.getInstance();
+ date.set(2008, 7, 18, 12, 0, 0);
+ date.set(Calendar.MILLISECOND, 0);
+ String expectedValue = "2008-08-18T12:00:00.000";
+ assertThat(new JcrValue<Calendar>(factories, PropertyType.DATE, date).getString().substring(0, expectedValue.length()),
+ is(expectedValue));
+ assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date.getTime()).getString().substring(0,
+ expectedValue.length()),
+ is(expectedValue));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideBooleanForDouble() throws Exception {
+ new JcrValue<Double>(factories, PropertyType.DOUBLE, 0.0).getBoolean();
+ }
+
+ @Test
+ public void shouldProvideDateForDouble() throws Exception {
+ Calendar expectedValue = Calendar.getInstance();
+ expectedValue.setTime(new Date(0L));
+ assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 0.0).getDate(), is(expectedValue));
+ }
+
+ @Test
+ public void shouldProvideDoubleForDouble() throws Exception {
+ assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.2).getDouble(), is(1.2));
+ }
+
+ @Test
+ public void shouldProvideLongForDouble() throws Exception {
+ assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.0).getLong(), is(1L));
+ assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, Double.MAX_VALUE).getLong(), is(Long.MAX_VALUE));
+ }
+
+ @Test
+ public void shouldProvideStreamForDouble() throws Exception {
+ testProvidesStream(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.0));
+ }
+
+ @Test
+ public void shouldProvideStringForDouble() throws Exception {
+ assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.0).getString(), is("1.0"));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideBooleanForLong() throws Exception {
+ new JcrValue<Long>(factories, PropertyType.LONG, 0L).getBoolean();
+ }
+
+ @Test
+ public void shouldProvideDateForLong() throws Exception {
+ Calendar expectedValue = Calendar.getInstance();
+ expectedValue.setTime(new Date(0L));
+ assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 0L).getDate(), is(expectedValue));
+ }
+
+ @Test
+ public void shouldProvideDoubleForLong() throws Exception {
+ assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 1L).getDouble(), is(1.0));
+ }
+
+ @Test
+ public void shouldProvideLongForLong() throws Exception {
+ assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 1L).getLong(), is(1L));
+ }
+
+ @Test
+ public void shouldProvideStreamForLong() throws Exception {
+ testProvidesStream(new JcrValue<Long>(factories, PropertyType.LONG, 1L));
+ }
+
+ @Test
+ public void shouldProvideStringForLong() throws Exception {
+ assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 1L).getString(), is("1"));
+ }
+
+ @Test
+ public void shouldProvideBooleanForString() throws Exception {
+ assertThat(new JcrValue<String>(factories, PropertyType.STRING, "true").getBoolean(), is(true));
+ assertThat(new JcrValue<String>(factories, PropertyType.STRING, "yes").getBoolean(), is(false));
+ }
+
+ @Test
+ public void shouldProvideDateForString() throws Exception {
+ assertThat(new JcrValue<String>(factories, PropertyType.STRING, "2008").getDate(), notNullValue());
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideDateForInvalidString() throws Exception {
+ new JcrValue<String>(factories, PropertyType.STRING, "true").getDate();
+ }
+
+ @Test
+ public void shouldProvideDoubleForString() throws Exception {
+ assertThat(new JcrValue<String>(factories, PropertyType.STRING, "1").getDouble(), is(1.0));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideDoubleForInvalidString() throws Exception {
+ new JcrValue<String>(factories, PropertyType.STRING, "true").getDouble();
+ }
+
+ @Test
+ public void shouldProvideLongForString() throws Exception {
+ assertThat(new JcrValue<String>(factories, PropertyType.STRING, "1").getLong(), is(1L));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLongForInvalidString() throws Exception {
+ new JcrValue<String>(factories, PropertyType.STRING, "true").getLong();
+ }
+
+ @Test
+ public void shouldProvideStreamForString() throws Exception {
+ testProvidesStream(new JcrValue<String>(factories, PropertyType.STRING, "true"));
+ }
+
+ @Test
+ public void shouldProvideStringForString() throws Exception {
+ assertThat(new JcrValue<String>(factories, PropertyType.STRING, "true").getString(), is("true"));
+ }
+
+ @Test
+ public void shouldProvideBooleanForUuid() throws Exception {
+ assertThat(new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getBoolean(), is(false));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideDateForUuid() throws Exception {
+ new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getDate();
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideDoubleForUuid() throws Exception {
+ new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getDouble();
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLongForUuid() throws Exception {
+ new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getLong();
+ }
+
+ @Test
+ public void shouldProvideStreamForUuid() throws Exception {
+ testProvidesStream(new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()));
+ }
+
+ @Test
+ public void shouldProvideStringForUuid() throws Exception {
+ String expectedValue = "40d373f7-75ad-4d84-900e-c72ebd98abb9";
+ assertThat(new JcrValue<UUID>(factories, PropertyType.STRING, UUID.fromString(expectedValue)).getString(),
+ is(expectedValue));
+ }
+
+ @Test
+ public void shouldProvideLength() throws Exception {
+ assertThat(new JcrValue<String>(factories, PropertyType.STRING, "test").getLength(), is(4L));
+ assertThat(new JcrValue<Object>(factories, PropertyType.BINARY, "test").getLength(), is(4L));
+ }
+
+ private void testProvidesStream( JcrValue<?> value ) throws Exception {
+ InputStream stream = value.getStream();
+ assertThat(stream, notNullValue());
+ stream.close();
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java 2008-08-20 15:19:52 UTC (rev 452)
@@ -0,0 +1,746 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.security.AccessControlContext;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.SimpleRepository;
+import org.jboss.dna.spi.connector.SimpleRepositorySource;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.mockito.Mockito;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+public class TestUtil {
+
+ public static RepositoryConnectionFactory createJackRabbitConnectionFactory( SimpleRepository repository,
+ ExecutionContext context ) {
+ repository.setProperty(context, "/", "jcr:primaryType", "nt:unstructured");
+ // repository.setProperty(context, "/dna:system/dna:jcr", "jcr:primaryType", "nt:unstructured");
+ // repository.setProperty(context, "/dna:system/dna:jcr/jcr:versionStorage", "jcr:primaryType", "rep:versionStorage");
+ // repository.setProperty(context, "/dna:system/dna:jcr/jcr:nodeTypes", "jcr:primaryType", "rep:nodeTypes");
+ createNodeType(repository, context, "rep:nodeTypes", false, false);
+ createChildDefinition(repository, context, "rep:nodeTypes", false, "nt:nodeType", false, "ABORT", true, false);
+ createNodeType(repository, context, "mix:versionable", false, true);
+ createPropertyDefinition(repository,
+ context,
+ "mix:versionable",
+ 1,
+ false,
+ false,
+ true,
+ "jcr:mergeFailed",
+ "ABORT",
+ true,
+ "REFERENCE");
+ createPropertyDefinition(repository,
+ context,
+ "mix:versionable",
+ 2,
+ false,
+ true,
+ true,
+ "jcr:predecessors",
+ "COPY",
+ true,
+ "REFERENCE");
+ createPropertyDefinition(repository,
+ context,
+ "mix:versionable",
+ 3,
+ true,
+ true,
+ false,
+ "jcr:isCheckedOut",
+ "IGNORE",
+ true,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "mix:versionable",
+ 4,
+ false,
+ true,
+ false,
+ "jcr:baseVersion",
+ "IGNORE",
+ true,
+ "REFERENCE");
+ createPropertyDefinition(repository,
+ context,
+ "mix:versionable",
+ 5,
+ false,
+ true,
+ false,
+ "jcr:versionHistory",
+ "COPY",
+ true,
+ "REFERENCE");
+ createNodeType(repository, context, "nt:file", false, false);
+ createProperty(repository, context, "nt:file", "jcr:primaryItemName", "jcr:content");
+ createChildDefinition(repository, context, "nt:file", false, true, "jcr:content", "COPY", false, false);
+ createNodeType(repository, context, "nt:hierarchyNode", false, false);
+ createPropertyDefinition(repository,
+ context,
+ "nt:hierarchyNode",
+ true,
+ false,
+ false,
+ "jcr:created",
+ "INITIALIZE",
+ true,
+ "DATE");
+ createNodeType(repository, context, "nt:versionedChild", false, false);
+ createPropertyDefinition(repository,
+ context,
+ "nt:versionedChild",
+ true,
+ true,
+ false,
+ "jcr:childVersionHistory",
+ "ABORT",
+ true,
+ "REFERENCE");
+ createNodeType(repository, context, "nt:version", false, false);
+ createPropertyDefinition(repository,
+ context,
+ "nt:version",
+ 1,
+ false,
+ false,
+ true,
+ "jcr:successors",
+ "ABORT",
+ true,
+ "REFERENCE");
+ createPropertyDefinition(repository,
+ context,
+ "nt:version",
+ 2,
+ false,
+ false,
+ true,
+ "jcr:predecessors",
+ "ABORT",
+ true,
+ "REFERENCE");
+ createPropertyDefinition(repository, context, "nt:version", 3, true, true, false, "jcr:created", "ABORT", true, "DATE");
+ createChildDefinition(repository, context, "nt:version", false, false, "jcr:frozenNode", "ABORT", true, false);
+ /*
+ <nt:versionLabels jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:versionLabels">
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="REFERENCE"/>
+ <nt:folder jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:folder">
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:onParentVersion="VERSION" jcr:protected="false" jcr:sameNameSiblings="false"/>
+ */
+ createNodeType(repository, context, "nt:nodeType", false, false);
+ createPropertyDefinition(repository,
+ context,
+ "nt:nodeType",
+ 1,
+ false,
+ false,
+ false,
+ "jcr:primaryItemName",
+ "COPY",
+ false,
+ "NAME");
+ createPropertyDefinition(repository,
+ context,
+ "nt:nodeType",
+ 2,
+ false,
+ true,
+ false,
+ "jcr:hasOrderableChildNodes",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:nodeType",
+ 3,
+ false,
+ true,
+ false,
+ "jcr:isMixin",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:nodeType",
+ 4,
+ false,
+ false,
+ true,
+ "jcr:supertypes",
+ "COPY",
+ false,
+ "NAME");
+ createPropertyDefinition(repository,
+ context,
+ "nt:nodeType",
+ 5,
+ false,
+ true,
+ false,
+ "jcr:nodeTypeName",
+ "COPY",
+ false,
+ "NAME");
+ createChildDefinition(repository,
+ context,
+ "nt:nodeType",
+ 1,
+ false,
+ "nt:childNodeDefinition",
+ false,
+ "jcr:childNodeDefinition",
+ "VERSION",
+ false,
+ true);
+ createChildDefinition(repository,
+ context,
+ "nt:nodeType",
+ 2,
+ false,
+ "nt:propertyDefinition",
+ false,
+ "jcr:propertyDefinition",
+ "VERSION",
+ false,
+ true);
+ createNodeType(repository, context, "nt:propertyDefinition", false, false);
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 1,
+ false,
+ true,
+ false,
+ "jcr:multiple",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 2,
+ false,
+ false,
+ true,
+ "jcr:defaultValues",
+ "COPY",
+ false,
+ "UNDEFINED");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 3,
+ false,
+ false,
+ true,
+ "jcr:valueConstraints",
+ "COPY",
+ false,
+ "STRING");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 4,
+ false,
+ true,
+ false,
+ "jcr:requiredType",
+ "COPY",
+ false,
+ "STRING");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 5,
+ false,
+ true,
+ false,
+ "jcr:protected",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 6,
+ false,
+ true,
+ false,
+ "jcr:onParentVersion",
+ "COPY",
+ false,
+ "STRING");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 7,
+ false,
+ true,
+ false,
+ "jcr:mandatory",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 8,
+ false,
+ true,
+ false,
+ "jcr:autoCreated",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:propertyDefinition",
+ 9,
+ false,
+ false,
+ false,
+ "jcr:name",
+ "COPY",
+ false,
+ "NAME");
+ /*
+ <rep:versionStorage jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="rep:versionStorage">
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="rep:versionStorage" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="true"/>
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="nt:versionHistory" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="true"/>
+ */
+ createNodeType(repository, context, "nt:base", false, false);
+ createPropertyDefinition(repository, context, "nt:base", false, false, true, "jcr:mixinTypes", "COMPUTE", true, "NAME");
+ createPropertyDefinition(repository, context, "nt:base", true, true, false, "jcr:primaryType", "COMPUTE", true, "NAME");
+ /*
+ <nt:resource jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:resource" jcr:primaryItemName="jcr:data">
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:lastModified" jcr:onParentVersion="IGNORE" jcr:protected="false" jcr:requiredType="DATE"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:data" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="BINARY"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:mimeType" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:encoding" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+ */
+ createNodeType(repository, context, "nt:childNodeDefinition", false, false);
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 1,
+ false,
+ true,
+ false,
+ "jcr:sameNameSiblings",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 2,
+ false,
+ false,
+ false,
+ "jcr:defaultPrimaryType",
+ "COPY",
+ false,
+ "NAME");
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 3,
+ false,
+ true,
+ true,
+ "jcr:requiredPrimaryTypes",
+ "COPY",
+ false,
+ "NAME");
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 4,
+ false,
+ true,
+ false,
+ "jcr:protected",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 5,
+ false,
+ true,
+ false,
+ "jcr:onParentVersion",
+ "COPY",
+ false,
+ "STRING");
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 6,
+ false,
+ true,
+ false,
+ "jcr:mandatory",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 7,
+ false,
+ true,
+ false,
+ "jcr:autoCreated",
+ "COPY",
+ false,
+ "BOOLEAN");
+ createPropertyDefinition(repository,
+ context,
+ "nt:childNodeDefinition",
+ 8,
+ false,
+ false,
+ false,
+ "jcr:name",
+ "COPY",
+ false,
+ "NAME");
+ createNodeType(repository, context, "mix:referenceable", false, true);
+ createPropertyDefinition(repository,
+ context,
+ "mix:referenceable",
+ true,
+ true,
+ false,
+ "jcr:uuid",
+ "INITIALIZE",
+ true,
+ "STRING");
+ createNodeType(repository, context, "nt:unstructured", true, false);
+ createPropertyDefinition(repository, context, "nt:unstructured", false, false, false, "COPY", false, "UNDEFINED");
+ createPropertyDefinition(repository, context, "nt:unstructured", false, false, true, "COPY", false, "UNDEFINED");
+ createChildDefinition(repository, context, "nt:unstructured", false, "nt:unstructured", false, "VERSION", false, true);
+ /*
+ <nt:versionHistory jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:versionHistory">
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:versionableUuid" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="STRING"/>
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="nt:version" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="true" jcr:defaultPrimaryType="nt:versionLabels" jcr:mandatory="true" jcr:name="jcr:versionLabels" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="true" jcr:defaultPrimaryType="nt:version" jcr:mandatory="true" jcr:name="jcr:rootVersion" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+ <mix:lockable jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="true" jcr:nodeTypeName="mix:lockable">
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:lockIsDeep" jcr:onParentVersion="IGNORE" jcr:protected="true" jcr:requiredType="BOOLEAN"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:lockOwner" jcr:onParentVersion="IGNORE" jcr:protected="true" jcr:requiredType="STRING"/>
+ <nt:frozenNode jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="true" jcr:isMixin="false" jcr:nodeTypeName="nt:frozenNode">
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="true" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="UNDEFINED"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="UNDEFINED"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:frozenUuid" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="STRING"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="true" jcr:name="jcr:frozenMixinTypes" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="NAME"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:frozenPrimaryType" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="NAME"/>
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="true"/>
+ <rep:system jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="true" jcr:isMixin="false" jcr:nodeTypeName="rep:system">
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="nt:unstructured" jcr:mandatory="false" jcr:onParentVersion="IGNORE" jcr:protected="false" jcr:sameNameSiblings="true"/>
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="rep:nodeTypes" jcr:mandatory="true" jcr:name="jcr:nodeTypes" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+ <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="rep:versionStorage" jcr:mandatory="true" jcr:name="jcr:versionStorage" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+ */
+ createNodeType(repository, context, "rep:root", true, false);
+ createChildDefinition(repository, context, "rep:root", false, true, "jcr:system", false, false);
+ /*
+ <nt:query jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:query">
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:language" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:statement" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+ </nt:query>
+ <nt:linkedFile jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:linkedFile" jcr:primaryItemName="jcr:content">
+ <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:content" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="REFERENCE"/>
+ </nt:linkedFile>
+ */
+ final SimpleRepositorySource source = new SimpleRepositorySource();
+ source.setRepositoryName(repository.getRepositoryName());
+ source.setName(repository.getRepositoryName());
+ return new RepositoryConnectionFactory() {
+
+ public RepositoryConnection createConnection( String sourceName ) {
+ return source.getConnection();
+ }
+ };
+ }
+
+ public static ExecutionContextFactory getExecutionContextFactory() {
+ final ExecutionContext context = new BasicExecutionContext(Mockito.mock(LoginContext.class));
+ NamespaceRegistry registry = context.getNamespaceRegistry();
+ registry.register("dna", "http://www.jboss.org/dna/1.0");
+ registry.register("fn", "http://www.w3.org/2005/xpath-functions");
+ registry.register("fn_old", "http://www.w3.org/2004/10/xpath-functions");
+ 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");
+ registry.register("rep", "internal");
+ registry.register("sv", "http://www.jcp.org/jcr/sv/1.0");
+ registry.register("xs", "http://www.w3.org/2001/XMLSchema");
+ return new ExecutionContextFactory() {
+
+ public ExecutionContext create() {
+ return context;
+ }
+
+ public ExecutionContext create( AccessControlContext accessControlContext ) {
+ return context;
+ }
+
+ public ExecutionContext create( LoginContext loginContext ) {
+ return context;
+ }
+
+ public ExecutionContext create( String name ) {
+ return context;
+ }
+
+ public ExecutionContext create( String name,
+ CallbackHandler callbackHandler ) {
+ return context;
+ }
+
+ public ExecutionContext create( String name,
+ Subject subject ) {
+ return context;
+ }
+
+ public ExecutionContext create( String name,
+ Subject subject,
+ CallbackHandler callbackHandler ) {
+ return context;
+ }
+ };
+ }
+
+ private static void createChildDefinition( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ Boolean autoCreated,
+ Boolean mandatory,
+ String onParentVersion,
+ Boolean isProtected,
+ Boolean sameNameSiblings ) {
+ createChildDefinition(repository,
+ context,
+ node,
+ 0,
+ autoCreated,
+ null,
+ mandatory,
+ null,
+ onParentVersion,
+ isProtected,
+ sameNameSiblings);
+ }
+
+ private static void createChildDefinition( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ Boolean autoCreated,
+ Boolean mandatory,
+ String name,
+ String onParentVersion,
+ Boolean isProtected,
+ Boolean sameNameSiblings ) {
+ createChildDefinition(repository,
+ context,
+ node,
+ 0,
+ autoCreated,
+ null,
+ mandatory,
+ name,
+ onParentVersion,
+ isProtected,
+ sameNameSiblings);
+ }
+
+ private static void createChildDefinition( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ Boolean autoCreated,
+ String defaultPrimaryType,
+ Boolean mandatory,
+ String onParentVersion,
+ Boolean isProtected,
+ Boolean sameNameSiblings ) {
+ createChildDefinition(repository,
+ context,
+ node,
+ 0,
+ autoCreated,
+ defaultPrimaryType,
+ mandatory,
+ null,
+ onParentVersion,
+ isProtected,
+ sameNameSiblings);
+ }
+
+ private static void createChildDefinition( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ int index,
+ Boolean autoCreated,
+ String defaultPrimaryType,
+ Boolean mandatory,
+ String name,
+ String onParentVersion,
+ Boolean isProtected,
+ Boolean sameNameSiblings ) {
+ String defNode = node + "/jcr:childNodeDefinition";
+ if (index > 0) {
+ defNode += '[' + index + ']';
+ }
+ createProperty(repository, context, defNode, "jcr:primaryType", "nt:childNodeDefinition");
+ createProperty(repository, context, defNode, "jcr:autoCreated", autoCreated.toString());
+ if (defaultPrimaryType != null) {
+ createProperty(repository, context, defNode, "jcr:defaultPrimaryType", defaultPrimaryType);
+ }
+ createProperty(repository, context, defNode, "jcr:mandatory", mandatory.toString());
+ if (name != null) {
+ createProperty(repository, context, defNode, "jcr:name", name);
+ }
+ createProperty(repository, context, defNode, "jcr:onParentVersion", onParentVersion);
+ createProperty(repository, context, defNode, "jcr:protected", isProtected.toString());
+ createProperty(repository, context, defNode, "jcr:sameNameSiblings", sameNameSiblings.toString());
+ }
+
+ //
+ // private static void createChildDefinitionProperty( SimpleRepository repository,
+ // ExecutionContext context,
+ // String node,
+ // String property,
+ // String value ) {
+ // createProperty(repository, context, node + "/jcr:childNodeDefinition", property, value);
+ // }
+
+ private static void createNodeType( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ Boolean hasOrderableChildNodes,
+ Boolean isMixin ) {
+ createProperty(repository, context, node, "jcr:primaryType", "nt:nodeType");
+ createProperty(repository, context, node, "jcr:hasOrderableChildNodes", hasOrderableChildNodes.toString());
+ createProperty(repository, context, node, "jcr:isMixin", isMixin.toString());
+ createProperty(repository, context, node, "jcr:nodeTypeName", node);
+ }
+
+ private static void createProperty( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ String property,
+ String value ) {
+ repository.setProperty(context, "/dna:system/dna:jcr/" + node, property, value);
+ }
+
+ private static void createPropertyDefinition( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ Boolean autoCreated,
+ Boolean mandatory,
+ Boolean multiple,
+ String onParentVersion,
+ Boolean isProtected,
+ String requiredType ) {
+ createPropertyDefinition(repository,
+ context,
+ node,
+ 0,
+ autoCreated,
+ mandatory,
+ multiple,
+ null,
+ onParentVersion,
+ isProtected,
+ requiredType);
+ }
+
+ private static void createPropertyDefinition( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ Boolean autoCreated,
+ Boolean mandatory,
+ Boolean multiple,
+ String name,
+ String onParentVersion,
+ Boolean isProtected,
+ String requiredType ) {
+ createPropertyDefinition(repository,
+ context,
+ node,
+ 0,
+ autoCreated,
+ mandatory,
+ multiple,
+ name,
+ onParentVersion,
+ isProtected,
+ requiredType);
+ }
+
+ private static void createPropertyDefinition( SimpleRepository repository,
+ ExecutionContext context,
+ String node,
+ int index,
+ Boolean autoCreated,
+ Boolean mandatory,
+ Boolean multiple,
+ String name,
+ String onParentVersion,
+ Boolean isProtected,
+ String requiredType ) {
+ String defNode = node + "/nt:propertyDefinition";
+ if (index > 0) {
+ defNode += '[' + index + ']';
+ }
+ createProperty(repository, context, defNode, "jcr:primaryType", "nt:propertyDefinition");
+ createProperty(repository, context, defNode, "jcr:autoCreated", autoCreated.toString());
+ createProperty(repository, context, defNode, "jcr:mandatory", mandatory.toString());
+ createProperty(repository, context, defNode, "jcr:multiple", multiple.toString());
+ if (name != null) {
+ createProperty(repository, context, defNode, "jcr:name", name);
+ }
+ createProperty(repository, context, defNode, "jcr:onParentVersion", onParentVersion);
+ createProperty(repository, context, defNode, "jcr:protected", isProtected.toString());
+ createProperty(repository, context, defNode, "jcr:requiredType", requiredType);
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 9 months
DNA SVN: r451 - in trunk/dna-spi/src: test/java/org/jboss/dna/spi/connector and 1 other directories.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-20 11:11:57 -0400 (Wed, 20 Aug 2008)
New Revision: 451
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
Log:
DNA-197: Changed BasicPath to return null for root path's ancestor and updated SimpleRepository to account for a path having a null parent.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-19 21:24:05 UTC (rev 450)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-20 15:11:57 UTC (rev 451)
@@ -83,7 +83,7 @@
* {@inheritDoc}
*/
public Path getAncestor() {
- if (this.isRoot()) return this;
+ if (this.isRoot()) return null;
if (this.segments.size() == 1) return ROOT;
return subpath(0, this.segments.size() - 1);
}
@@ -93,8 +93,8 @@
*/
public Path getAncestor( int degree ) {
ArgCheck.isNonNegative(degree, "degree");
- if (this.isRoot()) return this;
if (degree == 0) return this;
+ if (this.isRoot()) return null;
int endIndex = this.segments.size() - degree;
if (endIndex < 0) {
String msg = SpiI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree));
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-19 21:24:05 UTC (rev 450)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-20 15:11:57 UTC (rev 451)
@@ -132,7 +132,9 @@
NameFactory nameFactory = context.getValueFactories().getNameFactory();
PropertyFactory propertyFactory = context.getPropertyFactory();
Path pathObj = pathFactory.create(path);
- create(context, pathObj.getAncestor().getString(context.getNamespaceRegistry()));
+ if (!pathObj.isRoot()) {
+ create(context, pathObj.getAncestor().getString(context.getNamespaceRegistry()));
+ }
Property property = propertyFactory.create(nameFactory.create(propertyName), values);
Map<Name, Property> properties = new HashMap<Name, Property>();
Map<Name, Property> existingProperties = data.putIfAbsent(pathObj, properties);
@@ -152,12 +154,11 @@
String path ) {
PathFactory pathFactory = context.getValueFactories().getPathFactory();
Path pathObj = pathFactory.create(path);
- Path ancestorPath = pathObj.getAncestor();
+ Path ancestorPath = pathObj;
while (!ancestorPath.isRoot()) {
data.putIfAbsent(ancestorPath, new HashMap<Name, Property>());
ancestorPath = ancestorPath.getAncestor();
}
- data.putIfAbsent(pathObj, new HashMap<Name, Property>());
Name uuidName = context.getValueFactories().getNameFactory().create(this.getUuidPropertyName());
UUID uuid = context.getValueFactories().getUuidFactory().create();
Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-19 21:24:05 UTC (rev 450)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-20 15:11:57 UTC (rev 451)
@@ -25,6 +25,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.Reference;
@@ -41,6 +42,7 @@
import org.jboss.dna.spi.graph.commands.GraphCommand;
import org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor;
import org.jboss.dna.spi.graph.commands.executor.CommandExecutor;
+import org.jboss.dna.spi.graph.impl.BasicSingleValueProperty;
/**
* A {@link RepositorySource} for a {@link SimpleRepository simple repository}.
@@ -321,7 +323,7 @@
// Iterate through all of the properties, looking for any paths that are children of the path ...
List<Path.Segment> childSegments = new LinkedList<Path.Segment>();
for (Path path : data.keySet()) {
- if (path.getAncestor().equals(targetPath)) {
+ if (!path.isRoot() && path.getAncestor().equals(targetPath)) {
childSegments.add(path.getLastSegment());
}
}
@@ -330,7 +332,8 @@
for (Path.Segment childSegment : childSegments) {
Map<Name, Property> properties = repository.getData().get(targetPath);
Property uuidProperty = properties.get(uuidPropertyName);
- command.addChild(childSegment, uuidProperty);
+ command.addChild(childSegment,
+ uuidProperty == null ? new BasicSingleValueProperty(uuidPropertyName, UUID.randomUUID()) : uuidProperty);
}
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-19 21:24:05 UTC (rev 450)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-20 15:11:57 UTC (rev 451)
@@ -224,8 +224,8 @@
}
@Test
- public void shouldReturnRootForAncestorOfRoot() {
- assertThat(BasicPath.ROOT.getAncestor(), is(ROOT));
+ public void shouldReturnNoAncestorForRoot() {
+ assertThat(BasicPath.ROOT.getAncestor(), nullValue());
}
@Test
15 years, 9 months
DNA SVN: r450 - in trunk/dna-spi/src: main/java/org/jboss/dna/spi/graph/impl and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-19 17:24:05 -0400 (Tue, 19 Aug 2008)
New Revision: 450
Added:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java
Log:
DNA-96 - ValueFormatException should be replaced by existing JDK IllegalArgumentException and UnsupportedOperationException in ValueFactories
http://jira.jboss.com/jira/browse/DNA-96
Changed to rely upon a ValueFormatException for all conversions, and the IoException only on conversions that take (or might take) a Binary, InputStream, or Reader. Also added methods to the ValueFactory that create from a DateTime and from a Binary (not sure why these were never added).
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -63,10 +63,10 @@
*
* @param value the string from which the value is to be created
* @return the value, or null if the supplied string is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a string could not be performed
* @see #create(String, TextDecoder)
*/
- T create( String value ) throws IoException;
+ T create( String value ) throws ValueFormatException;
/**
* Create a value from a string, using the supplied decoder.
@@ -74,148 +74,169 @@
* @param value the string from which the value is to be created
* @param decoder the decoder that should be used; if null, the {@link #DEFAULT_DECODER default decoder} is used
* @return the value, or null if the supplied string is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a string could not be performed
* @see #create(String)
*/
T create( String value,
- TextDecoder decoder ) throws IoException;
+ TextDecoder decoder ) throws ValueFormatException;
/**
* Create a value from an integer.
*
* @param value the integer from which the value is to be created
* @return the value; never null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an integer could not be performed
*/
- T create( int value ) throws IoException;
+ T create( int value ) throws ValueFormatException;
/**
* Create a long from a string.
*
* @param value the string from which the long is to be created
* @return the value; never null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a long could not be performed
*/
- T create( long value ) throws IoException;
+ T create( long value ) throws ValueFormatException;
/**
* Create a boolean from a string.
*
* @param value the boolean from which the value is to be created
* @return the value; never null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a boolean could not be performed
*/
- T create( boolean value ) throws IoException;
+ T create( boolean value ) throws ValueFormatException;
/**
* Create a value from a float.
*
* @param value the float from which the value is to be created
* @return the value; never null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a float could not be performed
*/
- T create( float value ) throws IoException;
+ T create( float value ) throws ValueFormatException;
/**
* Create a value from a double.
*
* @param value the double from which the value is to be created
* @return the value; never null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a double could not be performed
*/
- T create( double value ) throws IoException;
+ T create( double value ) throws ValueFormatException;
/**
* Create a value from a decimal.
*
* @param value the decimal from which the value is to be created
* @return the value, or null if the supplied decimal is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a decimal could not be performed
*/
- T create( BigDecimal value ) throws IoException;
+ T create( BigDecimal value ) throws ValueFormatException;
/**
* Create a value from a Calendar instance.
*
* @param value the Calendar instance from which the value is to be created
* @return the value, or null if the supplied Calendar is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a Calendar could not be performed
*/
- T create( Calendar value ) throws IoException;
+ T create( Calendar value ) throws ValueFormatException;
/**
* Create a value from a date.
*
* @param value the date from which the value is to be created
* @return the value, or null if the supplied date is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a Date could not be performed
*/
- T create( Date value ) throws IoException;
+ T create( Date value ) throws ValueFormatException;
/**
+ * Create a value from a date-time instant.
+ *
+ * @param value the date-time instant from which the value is to be created
+ * @return the value, or null if the supplied date is null
+ * @throws ValueFormatException if the conversion from a Date could not be performed
+ */
+ T create( DateTime value ) throws ValueFormatException;
+
+ /**
* Create a value from a name.
*
* @param value the name from which the value is to be created
* @return the value, or null if the supplied name is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a name could not be performed
*/
- T create( Name value ) throws IoException;
+ T create( Name value ) throws ValueFormatException;
/**
* Create a value from a path.
*
* @param value the path from which the value is to be created
* @return the value, or null if the supplied path is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a path could not be performed
*/
- T create( Path value ) throws IoException;
+ T create( Path value ) throws ValueFormatException;
/**
* Create a value from a reference.
*
* @param value the reference from which the value is to be created
* @return the value, or null if the supplied reference is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a reference could not be performed
*/
- T create( Reference value ) throws IoException;
+ T create( Reference value ) throws ValueFormatException;
/**
* Create a value from a URI.
*
* @param value the URI from which the value is to be created
* @return the value, or null if the supplied URI is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a URI could not be performed
*/
- T create( URI value ) throws IoException;
+ T create( URI value ) throws ValueFormatException;
/**
* Create a value from a UUID.
*
* @param value the UUID from which the value is to be created
* @return the value, or null if the supplied URI is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a UUID could not be performed
*/
- T create( UUID value ) throws IoException;
+ T create( UUID value ) throws ValueFormatException;
/**
* Create a value from the binary content given by the supplied array.
*
* @param value the content to be used to create the value
* @return the value, or null if the supplied stream is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a byte array could not be performed
*/
- T create( byte[] value ) throws IoException;
+ T create( byte[] value ) throws ValueFormatException;
/**
* Create a value from the binary content given by the supplied stream.
*
+ * @param value the binary object to be used to create the value
+ * @return the value, or null if the supplied stream is null
+ * @throws ValueFormatException if the conversion from the binary object could not be performed
+ * @throws IoException If an unexpected problem occurs while accessing the supplied binary value (such as an
+ * {@link IOException}).
+ */
+ T create( Binary value ) throws ValueFormatException, IoException;
+
+ /**
+ * Create a value from the binary content given by the supplied stream.
+ *
* @param stream the stream containing the content to be used to create the value
* @param approximateLength the approximate length of the content (in bytes)
* @return the value, or null if the supplied stream is null
- * @throws IoException If an unexpected problem occurs during the conversion (such as an {@link IOException}).
+ * @throws ValueFormatException if the conversion from an input stream could not be performed
+ * @throws IoException If an unexpected problem occurs while accessing the supplied stream (such as an {@link IOException}).
*/
T create( InputStream stream,
- int approximateLength ) throws IoException;
+ long approximateLength ) throws ValueFormatException, IoException;
/**
* Create a value from a the binary content given by the supplied reader.
@@ -223,31 +244,34 @@
* @param reader the reader containing the content to be used to create the value
* @param approximateLength the approximate length of the content (in bytes)
* @return the value, or null if the supplied string is null
- * @throws IoException If an unexpected problem occurs during the conversion (such as an {@link IOException}).
+ * @throws ValueFormatException if the conversion from a reader could not be performed
+ * @throws IoException If an unexpected problem occurs while accessing the supplied reader (such as an {@link IOException}).
*/
T create( Reader reader,
- int approximateLength ) throws IoException;
+ long approximateLength ) throws ValueFormatException, IoException;
/**
* Create a value from the specified information by determining which other <code>create</code> method applies and delegating
* to that method. Note that this method only will call <code>create</code> methods that take a single parameter; so this
- * excludes {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ * excludes {@link #create(InputStream, long)}, {@link #create(Reader, long)} and {@link #create(String, TextDecoder)}.
*
* @param value the value
* @return the new value, or null if the supplied parameter is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an object could not be performed
+ * @throws IoException If an unexpected problem occurs while accessing the supplied binary value (such as an
+ * {@link IOException}).
*/
- T create( Object value ) throws IoException;
+ T create( Object value ) throws ValueFormatException, IoException;
/**
* Create an array of values from an array of string values, using no decoding.
*
* @param values the values
* @return the values, or null if the supplied string is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a string array could not be performed
* @see #create(String[], TextDecoder)
*/
- T[] create( String[] values ) throws IoException;
+ T[] create( String[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of strings, using the supplied decoder.
@@ -255,161 +279,183 @@
* @param values the string values from which the values are to be created
* @param decoder the decoder that should be used; if null, the {@link #DEFAULT_DECODER default decoder} is used
* @return the value, or null if the supplied string is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from a string array could not be performed
* @see #create(String)
*/
T[] create( String[] values,
- TextDecoder decoder ) throws IoException;
+ TextDecoder decoder ) throws ValueFormatException;
/**
* Create an array of values from an array of integers.
*
* @param values the integers from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an integer array could not be performed
*/
- T[] create( int[] values ) throws IoException;
+ T[] create( int[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of longs.
*
* @param values the longs from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of longs could not be performed
*/
- T[] create( long[] values ) throws IoException;
+ T[] create( long[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of booleans.
*
* @param values the booleans from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of booleans could not be performed
*/
- T[] create( boolean[] values ) throws IoException;
+ T[] create( boolean[] values ) throws ValueFormatException;
/**
- * Create an array of values from an array of booleans.
+ * Create an array of values from an array of floats.
*
* @param values the floats from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of floats could not be performed
*/
- T[] create( float[] values ) throws IoException;
+ T[] create( float[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of doubles.
*
* @param values the doubles from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of doubles could not be performed
*/
- T[] create( double[] values ) throws IoException;
+ T[] create( double[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of decimal values.
*
* @param values the decimals from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of decimal values could not be performed
*/
- T[] create( BigDecimal[] values ) throws IoException;
+ T[] create( BigDecimal[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of Calendar instances.
*
* @param values the Calendar instances from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of calendar instances could not be performed
*/
- T[] create( Calendar[] values ) throws IoException;
+ T[] create( Calendar[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of dates.
*
* @param values the dates from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of date values could not be performed
*/
- T[] create( Date[] values ) throws IoException;
+ T[] create( Date[] values ) throws ValueFormatException;
/**
+ * Create an array of values from an array of {@link DateTime} instants.
+ *
+ * @param values the instants from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws ValueFormatException if the conversion from an array of date values could not be performed
+ */
+ T[] create( DateTime[] values ) throws ValueFormatException;
+
+ /**
* Create an array of values from an array of names.
*
* @param values the names from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of names could not be performed
*/
- T[] create( Name[] values ) throws IoException;
+ T[] create( Name[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of paths.
*
* @param values the paths from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of paths could not be performed
*/
- T[] create( Path[] values ) throws IoException;
+ T[] create( Path[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of references.
*
* @param values the references from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of references could not be performed
*/
- T[] create( Reference[] values ) throws IoException;
+ T[] create( Reference[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of URIs.
*
* @param values the URIs from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of URIs could not be performed
*/
- T[] create( URI[] values ) throws IoException;
+ T[] create( URI[] values ) throws ValueFormatException;
/**
* Create an array of values from an array of UUIDs.
*
* @param values the UUIDs from which the values are to be created
* @return the values, or null if the supplied array is null
- * @throws IoException If an unexpected problem occurs during the conversion.
+ * @throws ValueFormatException if the conversion from an array of UUIDs could not be performed
*/
- T[] create( UUID[] values ) throws IoException;
+ T[] create( UUID[] values ) throws ValueFormatException;
/**
* Create an array of values from the array of binary content.
*
* @param values the array of content to be used to create the values
* @return the value, or null if the supplied array is null
+ * @throws ValueFormatException if the conversion from an array of byte arrays could not be performed
+ */
+ T[] create( byte[][] values ) throws ValueFormatException;
+
+ /**
+ * Create an array of values from the array of binary objects.
+ *
+ * @param values the values
+ * @return the new value, or null if the supplied parameter is null
+ * @throws ValueFormatException if the conversion from an array of objects could not be performed
* @throws IoException If an unexpected problem occurs during the conversion.
*/
- T[] create( byte[][] values ) throws IoException;
+ T[] create( Binary[] values ) throws ValueFormatException, IoException;
/**
* Create an array of values from the specified information by determining which other <code>create</code> method applies for
- * each object and then delegating to that method. Note that this method will not consider {@link #create(InputStream, int)},
- * {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ * each object and then delegating to that method. Note that this method will not consider {@link #create(InputStream, long)},
+ * {@link #create(Reader, long)} and {@link #create(String, TextDecoder)}.
*
* @param values the values
* @return the new value, or null if the supplied parameter is null
+ * @throws ValueFormatException if the conversion from an array of objects could not be performed
* @throws IoException If an unexpected problem occurs during the conversion.
*/
- T[] create( Object[] values ) throws IoException;
+ T[] create( Object[] values ) throws ValueFormatException, IoException;
/**
* Create an iterator over the values (of an unknown type). The factory converts any values as required. Note that this method
- * will not consider {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ * will not consider {@link #create(InputStream, long)}, {@link #create(Reader, long)} and
+ * {@link #create(String, TextDecoder)}.
* <p>
* This is useful to use when iterating over the {@link Property#getValues() values} of a {@link Property}.
* </p>
*
* @param values the values
* @return the iterator of type <code>T</code> over the values, or null if the supplied parameter is null
+ * @throws ValueFormatException if the conversion from an iterator of objects could not be performed
* @throws IoException If an unexpected problem occurs during the conversion.
* @see Property#getValues()
*/
- Iterator<T> create( Iterator<?> values ) throws IoException;
+ Iterator<T> create( Iterator<?> values ) throws ValueFormatException, IoException;
}
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph;
+
+/**
+ * @author Randall Hauch
+ */
+public class ValueFormatException extends RuntimeException {
+
+ /**
+ */
+ private static final long serialVersionUID = 1L;
+
+ private final Object value;
+ private final PropertyType targetType;
+
+ /**
+ * @param value the value that was not able to be converted
+ * @param targetType the {@link PropertyType} to which the value was being converted
+ */
+ public ValueFormatException( Object value,
+ PropertyType targetType ) {
+ this.value = value;
+ this.targetType = targetType;
+ }
+
+ /**
+ * @param value the value that was not able to be converted
+ * @param targetType the {@link PropertyType} to which the value was being converted
+ * @param message the message
+ */
+ public ValueFormatException( Object value,
+ PropertyType targetType,
+ String message ) {
+ super(message);
+ this.value = value;
+ this.targetType = targetType;
+ }
+
+ /**
+ * @param value the value that was not able to be converted
+ * @param targetType the {@link PropertyType} to which the value was being converted
+ * @param cause the cause of the exception
+ */
+ public ValueFormatException( Object value,
+ PropertyType targetType,
+ Throwable cause ) {
+ super(cause);
+ this.value = value;
+ this.targetType = targetType;
+ }
+
+ /**
+ * @param value the value that was not able to be converted
+ * @param targetType the {@link PropertyType} to which the value was being converted
+ * @param message the message
+ * @param cause the cause of the exception
+ */
+ public ValueFormatException( Object value,
+ PropertyType targetType,
+ String message,
+ Throwable cause ) {
+ super(message, cause);
+ this.value = value;
+ this.targetType = targetType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return super.toString();
+ }
+
+ /**
+ * Get the {@link PropertyType} to which the {@link #getValue() value} was being converted.
+ *
+ * @return the target type
+ */
+ public PropertyType getTargetType() {
+ return targetType;
+ }
+
+ /**
+ * Get the original value that was being converted.
+ *
+ * @return the value
+ */
+ public Object getValue() {
+ return value;
+ }
+}
Property changes on: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,12 +32,15 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* Abstract {@link ValueFactory}.
@@ -188,7 +191,22 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime[])
*/
+ public T[] create( DateTime[] values ) throws ValueFormatException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public T[] create( double[] values ) {
if (values == null) return null;
final int length = values.length;
@@ -335,7 +353,7 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID[])
*/
- public T[] create( UUID[] values ) throws IoException {
+ public T[] create( UUID[] values ) {
if (values == null) return null;
final int length = values.length;
T[] result = createEmptyArray(length);
@@ -345,6 +363,21 @@
return result;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary[])
+ */
+ public T[] create( Binary[] values ) throws ValueFormatException, IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
protected static class ConvertingIterator<ValueType> implements Iterator<ValueType> {
private final Iterator<?> delegate;
private final ValueFactory<ValueType> factory;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,12 +32,15 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#BOOLEAN} values.
@@ -74,18 +77,18 @@
* {@inheritDoc}
*/
public Boolean create( int value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Integer.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Integer.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( long value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Long.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Long.class.getSimpleName(),
+ value));
}
/**
@@ -99,81 +102,94 @@
* {@inheritDoc}
*/
public Boolean create( float value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Float.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Float.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( double value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Double.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Double.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( BigDecimal value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- BigDecimal.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ BigDecimal.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( Calendar value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Calendar.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Calendar.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( Date value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Boolean create( DateTime value ) throws ValueFormatException {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ DateTime.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Boolean create( Name value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Name.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( Path value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Path.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Boolean create( URI value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- URI.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ URI.class.getSimpleName(),
+ value));
}
/**
@@ -181,10 +197,10 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public Boolean create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ public Boolean create( UUID value ) {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -197,9 +213,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Boolean create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Boolean create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First create a string and then create the boolean from the string value ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -208,7 +234,7 @@
* {@inheritDoc}
*/
public Boolean create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First create a string and then create the boolean from the string value ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,12 +32,15 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#DECIMAL} values.
@@ -61,9 +64,10 @@
try {
return new BigDecimal(value.trim());
} catch (NumberFormatException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- BigDecimal.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ BigDecimal.class.getSimpleName(),
+ value), err);
}
}
@@ -94,9 +98,9 @@
* {@inheritDoc}
*/
public BigDecimal create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Boolean.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Boolean.class.getSimpleName(),
+ value));
}
/**
@@ -138,38 +142,49 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public BigDecimal create( DateTime value ) throws ValueFormatException {
+ if (value == null) return null;
+ return create(value.getMilliseconds());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public BigDecimal create( Name value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Name.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public BigDecimal create( Path value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Path.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public BigDecimal create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public BigDecimal create( URI value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- URI.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ URI.class.getSimpleName(),
+ value));
}
/**
@@ -178,9 +193,9 @@
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
public BigDecimal create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -193,9 +208,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public BigDecimal create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public BigDecimal create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -204,7 +229,7 @@
* {@inheritDoc}
*/
public BigDecimal create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,12 +32,15 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#DOUBLE} values.
@@ -61,9 +64,10 @@
try {
return Double.valueOf(value.trim());
} catch (NumberFormatException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- Double.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ Double.class.getSimpleName(),
+ value), err);
}
}
@@ -94,9 +98,9 @@
* {@inheritDoc}
*/
public Double create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Double.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Double.class.getSimpleName(),
+ value));
}
/**
@@ -120,9 +124,10 @@
if (value == null) return null;
double result = value.doubleValue();
if (result == Double.NEGATIVE_INFINITY || result == Double.POSITIVE_INFINITY) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(BigDecimal.class.getSimpleName(),
- Double.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(BigDecimal.class.getSimpleName(),
+ Double.class.getSimpleName(),
+ value));
}
return result;
}
@@ -145,38 +150,49 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Double create( DateTime value ) throws ValueFormatException {
+ if (value == null) return null;
+ return create(value.getMilliseconds());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Double create( Name value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Name.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Double create( Path value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Path.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Double create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Double create( URI value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- URI.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ URI.class.getSimpleName(),
+ value));
}
/**
@@ -184,10 +200,10 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public Double create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ public Double create( UUID value ) {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -200,9 +216,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Double create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Double create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -211,7 +237,7 @@
* {@inheritDoc}
*/
public Double create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,12 +36,14 @@
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* Teh standard {@link ValueFactory} for {@link PropertyType#BINARY} values.
@@ -67,9 +69,10 @@
try {
return create(value.getBytes(CHAR_SET_NAME));
} catch (UnsupportedEncodingException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- Binary.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ Binary.class.getSimpleName(),
+ value), err);
}
}
@@ -148,7 +151,17 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Binary create( DateTime value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Binary create( Name value ) {
// Convert the value to a string, then to a binary ...
return create(this.getStringValueFactory().create(value));
@@ -183,7 +196,7 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public Binary create( UUID value ) throws IoException {
+ public Binary create( UUID value ) {
// Convert the value to a string, then to a binary ...
return create(this.getStringValueFactory().create(value));
}
@@ -197,9 +210,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Binary create( Binary value ) throws ValueFormatException, IoException {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Binary create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
if (stream == null) return null;
try {
byte[] value = IoUtil.readBytes(stream);
@@ -215,7 +237,7 @@
* {@inheritDoc}
*/
public Binary create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
if (reader == null) return null;
// Convert the value to a string, then to a binary ...
try {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,6 +32,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.DateTimeFactory;
import org.jboss.dna.spi.graph.IoException;
@@ -40,6 +41,7 @@
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.joda.time.DateTimeZone;
/**
@@ -64,9 +66,10 @@
try {
return new JodaDateTime(value.trim());
} catch (IllegalArgumentException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- DateTime.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ DateTime.class.getSimpleName(),
+ value), err);
}
}
@@ -97,9 +100,9 @@
* {@inheritDoc}
*/
public DateTime create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
@@ -142,38 +145,48 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public DateTime create( DateTime value ) throws ValueFormatException {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public DateTime create( Name value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Name.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public DateTime create( Path value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Path.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public DateTime create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public DateTime create( URI value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- URI.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ URI.class.getSimpleName(),
+ value));
}
/**
@@ -181,10 +194,10 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public DateTime create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ public DateTime create( UUID value ) {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -197,9 +210,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public DateTime create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public DateTime create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -208,7 +231,7 @@
* {@inheritDoc}
*/
public DateTime create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,12 +32,15 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#LONG} values.
@@ -61,9 +64,10 @@
try {
return Long.valueOf(value.trim());
} catch (NumberFormatException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- Long.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ Long.class.getSimpleName(),
+ value), err);
}
}
@@ -94,9 +98,9 @@
* {@inheritDoc}
*/
public Long create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Long.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Long.class.getSimpleName(),
+ value));
}
/**
@@ -139,38 +143,49 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Long create( DateTime value ) throws ValueFormatException {
+ if (value == null) return null;
+ return value.getMilliseconds();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Long create( Name value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Name.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Long create( Path value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Path.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Long create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Long create( URI value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- URI.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ URI.class.getSimpleName(),
+ value));
}
/**
@@ -179,9 +194,9 @@
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
public Long create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -194,9 +209,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Long create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Long create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -205,7 +230,7 @@
* {@inheritDoc}
*/
public Long create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -35,6 +35,8 @@
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
@@ -44,6 +46,7 @@
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#NAME} values.
@@ -114,13 +117,14 @@
return new BasicName(namespaceUri, localName);
}
} catch (NamespaceException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- Name.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ Name.class.getSimpleName(),
+ value), err);
}
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- Name.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
@@ -148,77 +152,89 @@
* {@inheritDoc}
*/
public Name create( int value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Integer.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( long value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Long.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Boolean.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( float value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Float.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( double value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Double.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( BigDecimal value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ BigDecimal.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( Calendar value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Calendar.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( Date value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Name create( DateTime value ) throws ValueFormatException {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ DateTime.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Name create( Name value ) {
return value;
}
@@ -232,18 +248,19 @@
// A relative name of length 1 is converted to a name
return value.getSegment(0).getName();
}
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(Path.class.getSimpleName(),
- Name.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.errorConvertingType.text(Path.class.getSimpleName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Name create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
@@ -259,9 +276,9 @@
if (asciiString.indexOf('/') == -1) {
return create(asciiString);
}
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(URI.class.getSimpleName(),
- Path.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.errorConvertingType.text(URI.class.getSimpleName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
@@ -270,9 +287,9 @@
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
public Name create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -285,9 +302,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Name create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Name create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -296,7 +323,7 @@
* {@inheritDoc}
*/
public Name create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -33,12 +33,14 @@
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#OBJECT} values.
@@ -139,7 +141,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Object create( DateTime value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Object create( Name value ) {
return value;
}
@@ -203,9 +214,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Object create( Binary value ) throws ValueFormatException, IoException {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Object create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) {
return getBinaryValueFactory().create(stream, approximateLength);
}
@@ -213,7 +233,7 @@
* {@inheritDoc}
*/
public Object create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) {
return getBinaryValueFactory().create(reader, approximateLength);
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -37,6 +37,8 @@
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -44,6 +46,7 @@
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.jboss.dna.spi.graph.Path.Segment;
/**
@@ -144,7 +147,7 @@
List<Segment> segments = new ArrayList<Segment>();
String[] pathSegments = DELIMITER_PATTERN.split(trimmedValue);
if (pathSegments.length == 0) {
- throw new IllegalArgumentException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.validPathMayNotContainEmptySegment.text(value));
}
if (decoder == null) decoder = getDecoder();
assert pathSegments.length != 0;
@@ -153,7 +156,7 @@
assert segment != null;
segment = segment.trim();
if (segment.length() == 0) {
- throw new IllegalArgumentException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.validPathMayNotContainEmptySegment.text(value));
}
// Create the name and add a segment with it ...
segments.add(createSegment(segment, decoder));
@@ -167,82 +170,98 @@
* {@inheritDoc}
*/
public Path create( int value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Integer.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Path create( long value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Long.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Path create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Boolean.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Path create( float value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Float.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Path create( double value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Double.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Path create( BigDecimal value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ BigDecimal.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Path create( Calendar value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Calendar.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Path create( Date value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Path create( DateTime value ) throws ValueFormatException {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ DateTime.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Path create( Name value ) {
if (value == null) return null;
- List<Path.Segment> segments = new ArrayList<Path.Segment>(1);
- segments.add(new BasicPathSegment(value));
- return new BasicPath(segments, true);
+ try {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>(1);
+ segments.add(new BasicPathSegment(value));
+ return new BasicPath(segments, true);
+ } catch (IllegalArgumentException e) {
+ throw new ValueFormatException(value, getPropertyType(), e);
+ }
}
/**
@@ -519,7 +538,8 @@
return new BasicPathSegment(this.nameValueFactory.create(segmentName.substring(0, startBracketNdx), decoder),
Integer.parseInt(ndx));
} catch (NumberFormatException err) {
- throw new IllegalArgumentException(SpiI18n.invalidIndexInSegmentName.text(ndx, segmentName));
+ throw new ValueFormatException(segmentName, getPropertyType(), SpiI18n.invalidIndexInSegmentName.text(ndx,
+ segmentName));
}
}
@@ -538,9 +558,10 @@
* {@inheritDoc}
*/
public Path create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
@@ -556,9 +577,9 @@
if (asciiString.indexOf('/') == -1) {
return create(asciiString);
}
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(URI.class.getSimpleName(),
- Path.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.errorConvertingType.text(URI.class.getSimpleName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
@@ -566,10 +587,10 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public Path create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ public Path create( UUID value ) {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -582,9 +603,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Path create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Path create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -593,7 +624,7 @@
* {@inheritDoc}
*/
public Path create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,13 +36,17 @@
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.IoUtil;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#STRING} values.
@@ -155,7 +159,17 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public String create( DateTime value ) throws ValueFormatException {
+ if (value == null) return null;
+ return value.getString(); // ISO representation
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String create( Name value ) {
if (value == null) return null;
return value.getString(getEncoder());
@@ -203,26 +217,52 @@
try {
return new String(value, "UTF-8");
} catch (UnsupportedEncodingException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(byte[].class.getSimpleName(),
- String.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(byte[].class.getSimpleName(),
+ String.class.getSimpleName(),
+ value), err);
}
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public String create( Binary value ) throws ValueFormatException, IoException {
+ if (value == null) return null;
+ try {
+ value.acquire();
+ InputStream stream = value.getStream();
+ try {
+ return create(stream, value.getSize());
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ Logger.getLogger(getClass()).debug(e, "Error closing the stream while converting from Binary to String");
+ }
+ }
+ } finally {
+ value.release();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
if (stream == null) return null;
byte[] value = null;
try {
value = IoUtil.readBytes(stream);
return new String(value, "UTF-8");
} catch (UnsupportedEncodingException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(InputStream.class.getSimpleName(),
- String.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(InputStream.class.getSimpleName(),
+ String.class.getSimpleName(),
+ value), err);
} catch (IOException err) {
throw new IoException(
SpiI18n.errorConvertingIo.text(InputStream.class.getSimpleName(), String.class.getSimpleName()),
@@ -234,7 +274,7 @@
* {@inheritDoc}
*/
public String create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
if (reader == null) return null;
try {
return IoUtil.read(reader);
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -34,6 +34,8 @@
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
@@ -41,6 +43,7 @@
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#URI} values.
@@ -69,9 +72,10 @@
try {
return new URI(value);
} catch (URISyntaxException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- URI.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ URI.class.getSimpleName(),
+ value), err);
}
}
@@ -88,77 +92,89 @@
* {@inheritDoc}
*/
public URI create( int value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Integer.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public URI create( long value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Long.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public URI create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Boolean.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public URI create( float value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Float.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public URI create( double value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Double.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public URI create( BigDecimal value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ BigDecimal.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public URI create( Calendar value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Calendar.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public URI create( Date value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public URI create( DateTime value ) throws ValueFormatException {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ DateTime.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public URI create( Name value ) {
if (value == null) return null;
return create("./" + value.getString(this.namespaceRegistry));
@@ -179,9 +195,10 @@
* {@inheritDoc}
*/
public URI create( Reference value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
@@ -189,10 +206,10 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public URI create( UUID value ) throws IoException {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- UUID.class.getSimpleName(),
- value));
+ public URI create( UUID value ) {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
}
/**
@@ -212,9 +229,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public URI create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public URI create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -223,7 +250,7 @@
* {@inheritDoc}
*/
public URI create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,12 +32,15 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#REFERENCE} values.
@@ -62,9 +65,10 @@
UUID uuid = UUID.fromString(value);
return new UuidReference(uuid);
} catch (IllegalArgumentException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- Reference.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ Reference.class.getSimpleName(),
+ value), err);
}
}
@@ -81,90 +85,102 @@
* {@inheritDoc}
*/
public Reference create( int value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Integer.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( long value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Long.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Boolean.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( float value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Float.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( double value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Double.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( BigDecimal value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(),
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ BigDecimal.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( Calendar value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Calendar.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( Date value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public Reference create( DateTime value ) throws ValueFormatException {
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ DateTime.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Reference create( Name value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public Reference create( Path value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
@@ -179,7 +195,8 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public Reference create( UUID value ) throws IoException {
+ public Reference create( UUID value ) {
+ if (value == null) return null;
return new UuidReference(value);
}
@@ -187,9 +204,9 @@
* {@inheritDoc}
*/
public Reference create( URI value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, getPropertyType(), SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
@@ -202,9 +219,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public Reference create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Reference create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -213,7 +240,7 @@
* {@inheritDoc}
*/
public Reference create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -32,6 +32,8 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -39,6 +41,7 @@
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.UuidFactory;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#URI} values.
@@ -72,9 +75,10 @@
try {
return UUID.fromString(value);
} catch (IllegalArgumentException err) {
- throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
- URI.class.getSimpleName(),
- value), err);
+ throw new ValueFormatException(value, PropertyType.UUID,
+ SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ URI.class.getSimpleName(),
+ value), err);
}
}
@@ -91,90 +95,102 @@
* {@inheritDoc}
*/
public UUID create( int value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Integer.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( long value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Long.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( boolean value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Boolean.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( float value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Float.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( double value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Double.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( BigDecimal value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID,
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ BigDecimal.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( Calendar value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Calendar.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( Date value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Date.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.DateTime)
*/
+ public UUID create( DateTime value ) throws ValueFormatException {
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ DateTime.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public UUID create( Name value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Name.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( Path value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Path.class.getSimpleName(),
+ value));
}
/**
@@ -185,18 +201,19 @@
UuidReference ref = (UuidReference)value;
return ref.getUuid();
}
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID,
+ SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
}
/**
* {@inheritDoc}
*/
public UUID create( URI value ) {
- throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
- Reference.class.getSimpleName(),
- value));
+ throw new ValueFormatException(value, PropertyType.UUID, SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ URI.class.getSimpleName(),
+ value));
}
/**
@@ -204,7 +221,7 @@
*
* @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
- public UUID create( UUID value ) throws IoException {
+ public UUID create( UUID value ) {
return value;
}
@@ -218,9 +235,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(org.jboss.dna.spi.graph.Binary)
*/
+ public UUID create( Binary value ) throws ValueFormatException, IoException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public UUID create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(stream, approximateLength));
}
@@ -229,7 +256,7 @@
* {@inheritDoc}
*/
public UUID create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) throws IoException {
// First attempt to create a string from the value, then a double from the string ...
return create(getStringValueFactory().create(reader, approximateLength));
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,12 +36,15 @@
import java.util.UUID;
import org.jboss.dna.common.text.NoOpEncoder;
import org.jboss.dna.common.text.TextDecoder;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -100,6 +103,10 @@
return null;
}
+ public String create( DateTime value ) throws ValueFormatException {
+ return null;
+ }
+
public String create( Name value ) {
return null;
}
@@ -124,13 +131,17 @@
return null;
}
+ public String create( Binary value ) throws ValueFormatException, IoException {
+ return null;
+ }
+
public String create( InputStream stream,
- int approximateLength ) {
+ long approximateLength ) {
return null;
}
public String create( Reader reader,
- int approximateLength ) {
+ long approximateLength ) {
return null;
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,6 +36,7 @@
import org.jboss.dna.spi.graph.InvalidPathException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -179,12 +180,12 @@
assertThat(pathFactory.create("/").isRoot(), is(true));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotConstructPathWithSuccessiveDelimiters() {
pathFactory.create("///a/b///c//d//");
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotConstructPathWithOnlyDelimiters() {
pathFactory.create("///");
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -35,6 +35,7 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -86,57 +87,57 @@
assertThat(factory.create(" 1 "), is(false));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromIntegerValue() {
factory.create(1);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromLongValue() {
factory.create(1l);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromFloatValue() {
factory.create(1.0f);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromDoubleValue() {
factory.create(1.0d);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromBigDecimal() {
factory.create(1.0d);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromDate() {
factory.create(new Date());
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromCalendar() {
factory.create(Calendar.getInstance());
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromName() {
factory.create(mock(Name.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromPath() {
factory.create(mock(Path.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromReference() {
factory.create(mock(Reference.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateBooleanFromUri() throws Exception {
factory.create(new URI("http://www.jboss.org"));
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,6 +36,7 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -57,7 +58,7 @@
factory = new DecimalValueFactory(Path.URL_DECODER, stringFactory);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromBooleanValue() {
factory.create(true);
}
@@ -114,22 +115,22 @@
assertThat(factory.create(value), is(BigDecimal.valueOf(value.getTimeInMillis())));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromName() {
factory.create(mock(Name.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromPath() {
factory.create(mock(Path.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromReference() {
factory.create(mock(Reference.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromUri() throws Exception {
factory.create(new URI("http://www.jboss.org"));
}
@@ -155,18 +156,18 @@
assertThat(factory.create(new StringReader("100.000101")), is(BigDecimal.valueOf(100.000101d)));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanDecimal() throws Exception {
factory.create("something".getBytes("UTF-8"));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanDecimal()
throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDecimalFromReaderContainingStringWithContentsOtherThanDecimal() {
factory.create(new StringReader("something"));
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,6 +36,7 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -57,7 +58,7 @@
factory = new DoubleValueFactory(Path.URL_DECODER, stringFactory);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromBooleanValue() {
factory.create(true);
}
@@ -114,22 +115,22 @@
assertThat(factory.create(value), is(Double.valueOf(value.getTimeInMillis())));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromName() {
factory.create(mock(Name.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromPath() {
factory.create(mock(Path.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromReference() {
factory.create(mock(Reference.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromUri() throws Exception {
factory.create(new URI("http://www.jboss.org"));
}
@@ -158,17 +159,17 @@
assertThat(factory.create(new StringReader("1003044")), is(1003044.d));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanDouble() throws Exception {
factory.create("something".getBytes("UTF-8"));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanDouble() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromReaderContainingStringWithContentsOtherThanDouble() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,6 +36,7 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -66,7 +67,7 @@
factory = new JodaDateTimeValueFactory(Path.URL_DECODER, stringFactory);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromBoolean() {
factory.create(true);
}
@@ -83,7 +84,7 @@
assertThat(factory.create(" " + LAST_YEAR.getString() + " "), is(LAST_YEAR));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromStringThatIsNotInTheStandardFormat() {
factory.create("something");
}
@@ -126,22 +127,22 @@
assertThat(factory.create(value), is((DateTime)new JodaDateTime(value)));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromName() {
factory.create(mock(Name.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromPath() {
factory.create(mock(Path.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromReference() {
factory.create(mock(Reference.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromUri() throws Exception {
factory.create(new URI("http://www.jboss.org"));
}
@@ -164,19 +165,19 @@
assertThat(factory.create(new StringReader(LAST_YEAR.getString())), is(LAST_YEAR));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromByteArrayContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate()
throws Exception {
factory.create("something".getBytes("UTF-8"));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromInputStreamContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate()
throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDateFromReaderContainingStringWithContentThatIsNotWellFormedDate() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,6 +36,7 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -57,7 +58,7 @@
factory = new LongValueFactory(Path.URL_DECODER, stringFactory);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromBooleanValue() {
factory.create(true);
}
@@ -116,22 +117,22 @@
assertThat(factory.create(value), is(Long.valueOf(value.getTimeInMillis())));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateLongFromName() {
factory.create(mock(Name.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateLongFromPath() {
factory.create(mock(Path.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateLongFromReference() {
factory.create(mock(Reference.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateLongFromUri() throws Exception {
factory.create(new URI("http://www.jboss.org"));
}
@@ -160,17 +161,17 @@
assertThat(factory.create(new StringReader("1003044")), is(1003044l));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateLongFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanLong() throws Exception {
factory.create("something".getBytes("UTF-8"));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateLongFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanLong() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateLongFromReaderContainingStringWithContentsOtherThanLong() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java 2008-08-19 19:34:42 UTC (rev 449)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java 2008-08-19 21:24:05 UTC (rev 450)
@@ -36,6 +36,7 @@
import java.util.UUID;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.junit.Before;
import org.junit.Test;
@@ -59,7 +60,7 @@
uuid = UUID.randomUUID();
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateDoubleFromBooleanValue() {
factory.create(true);
}
@@ -84,42 +85,42 @@
assertThat(factory.create(" " + uuid.toString() + " "), is(uuid));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromIntegerValue() {
factory.create(1);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromLongValue() {
factory.create(1L);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromDoubleValue() {
factory.create(1.0d);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromFloatValue() {
factory.create(1.0f);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromBooleanValue() {
factory.create(true);
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromCalendarValue() {
factory.create(Calendar.getInstance());
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromName() {
factory.create(mock(Name.class));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromPath() {
factory.create(mock(Path.class));
}
@@ -130,7 +131,7 @@
assertThat(factory.create(ref), is(uuid));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromUri() throws Exception {
factory.create(new URI("http://www.jboss.org"));
}
@@ -150,17 +151,17 @@
assertThat(factory.create(new StringReader(uuid.toString())), is(uuid));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuidFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanUuid() throws Exception {
factory.create("something".getBytes("UTF-8"));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuuidFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanUuuid() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ValueFormatException.class )
public void shouldNotCreateUuuidFromReaderContainingStringWithContentsOtherThanUuuid() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
15 years, 9 months
DNA SVN: r449 - in trunk/extensions/dna-connector-federation/src: main/java/org/jboss/dna/connector/federation/merge and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-19 15:34:42 -0400 (Tue, 19 Aug 2008)
New Revision: 449
Added:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Added more unit tests for the OneContributionMergeStrategy class.
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-19 19:34:20 UTC (rev 448)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-19 19:34:42 UTC (rev 449)
@@ -381,6 +381,7 @@
// If there are no contributions from any source ...
boolean foundNonEmptyContribution = false;
for (Contribution contribution : contributions) {
+ assert contribution != null;
if (!contribution.isEmpty()) {
foundNonEmptyContribution = true;
break;
@@ -398,6 +399,8 @@
// Merge the results into a single set of results ...
FederatedNode mergedNode = new FederatedNode(path, UUID.randomUUID());
ExecutionContext context = getExecutionContext();
+ assert contributions.size() > 0;
+ assert context != null;
mergingStrategy.merge(mergedNode, contributions, context);
if (mergedNode.getCachePolicy() == null) {
mergedNode.setCachePolicy(defaultCachePolicy);
@@ -522,138 +525,6 @@
}
}
- // /**
- // * Load the node at the supplied path, returning the information. This method always obtains the information from the
- // sources
- // * and does not use or update the cache.
- // *
- // * @param path the path of the node that is to be loaded
- // * @return the federated node containing information loaded from the sources, or null if none of the sources had a
- // * contribution
- // * @throws InterruptedException
- // * @throws RepositorySourceException
- // */
- // protected FederatedNode loadFromSources( Path path ) throws RepositorySourceException, InterruptedException {
- // // At this point, there is no merge plan, so read information from the sources ...
- // ExecutionContext context = getExecutionContext();
- // PathFactory pathFactory = context.getValueFactories().getPathFactory();
- // DateTimeFactory timeFactory = context.getValueFactories().getDateFactory();
- // List<Contribution> contributions = new LinkedList<Contribution>();
- // boolean foundContribution = false;
- // for (Projection projection : this.sourceProjections) {
- // final String source = projection.getSourceName();
- // final RepositoryConnection sourceConnection = getConnection(projection);
- // if (sourceConnection == null) continue; // No source exists by this name
- // try {
- // // Get the cached information ...
- // CachePolicy cachePolicy = sourceConnection.getDefaultCachePolicy();
- // if (cachePolicy == null) cachePolicy = this.defaultCachePolicy;
- // DateTime expirationTime = null;
- // if (cachePolicy != null) {
- // expirationTime = getCurrentTimeInUtc().plus(cachePolicy.getTimeToLive(), TimeUnit.MILLISECONDS);
- // }
- // // Get the paths-in-source where we should fetch node contributions ...
- // Set<Path> pathsInSource = projection.getPathsInSource(path, pathFactory);
- // if (pathsInSource.isEmpty()) {
- // // The source has no contributions, but see whether the project exists BELOW this path.
- // // We do this by getting the top-level repository paths of the projection, and then
- // // use those to figure out the children of the nodes.
- // Contribution contribution = null;
- // Set<Path> topLevelPaths = projection.getTopLevelPathsInRepository(pathFactory);
- // switch (topLevelPaths.size()) {
- // case 0:
- // break;
- // case 1: {
- // Path topLevelPath = topLevelPaths.iterator().next();
- // if (path.isAncestorOf(topLevelPath)) {
- // assert topLevelPath.size() > path.size();
- // Path.Segment child = topLevelPath.getSegment(path.size());
- // contribution = Contribution.create(source, path, expirationTime, null, child);
- // foundContribution = true;
- // }
- // break;
- // }
- // default: {
- // Set<Path.Segment> children = new HashSet<Path.Segment>();
- // for (Path topLevelPath : topLevelPaths) {
- // if (path.isAncestorOf(topLevelPath)) {
- // assert topLevelPath.size() > path.size();
- // Path.Segment child = topLevelPath.getSegment(path.size());
- // children.add(child);
- // }
- // }
- // if (children.size() > 0) {
- // contribution = Contribution.create(source, path, expirationTime, null, children);
- // foundContribution = true;
- // }
- // }
- // }
- // if (contribution == null) contribution = Contribution.create(source, expirationTime);
- // contributions.add(contribution);
- // } else {
- // // There is at least one (real) contribution ...
- //
- // // Get the contributions ...
- // final int numPaths = pathsInSource.size();
- // if (numPaths == 1) {
- // Path pathInSource = pathsInSource.iterator().next();
- // BasicGetNodeCommand fromSource = new BasicGetNodeCommand(pathInSource);
- // sourceConnection.execute(getExecutionContext(), fromSource);
- // if (!fromSource.hasError()) {
- // Collection<Property> properties = fromSource.getProperties();
- // Collection<Segment> children = fromSource.getChildren();
- // DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
- // fromSource.getCachePolicy().getTimeToLive());
- // Contribution contribution = Contribution.create(source, pathInSource, expTime, properties, children);
- // if (!contribution.isEmpty()) foundContribution = true;
- // contributions.add(contribution);
- // }
- // } else {
- // BasicGetNodeCommand[] fromSourceCommands = new BasicGetNodeCommand[numPaths];
- // int i = 0;
- // for (Path pathInSource : pathsInSource) {
- // fromSourceCommands[i++] = new BasicGetNodeCommand(pathInSource);
- // }
- // sourceConnection.execute(context, fromSourceCommands);
- // for (BasicGetNodeCommand fromSource : fromSourceCommands) {
- // if (fromSource.hasError()) continue;
- // Collection<Property> properties = fromSource.getProperties();
- // Collection<Segment> children = fromSource.getChildren();
- // DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
- // fromSource.getCachePolicy().getTimeToLive());
- // Contribution contribution = Contribution.create(source,
- // fromSource.getPath(),
- // expTime,
- // properties,
- // children);
- // if (!contribution.isEmpty()) foundContribution = true;
- // contributions.add(contribution);
- // }
- // }
- // }
- // } finally {
- // sourceConnection.close();
- // }
- // }
- // // If there are no contributions from any source ...
- // if (!foundContribution) return null;
- // if (logger.isTraceEnabled()) {
- // logger.trace("Loaded {0} from sources, resulting in these contributions:", path);
- // int i = 0;
- // for (Contribution contribution : contributions) {
- // logger.trace(" {0} {1}", ++i, contribution);
- // }
- // }
- //
- // // Merge the results into a single set of results ...
- // FederatedNode mergedNode = new FederatedNode(path, UUID.randomUUID());
- // mergingStrategy.merge(mergedNode, contributions, context);
- // if (mergedNode.getCachePolicy() == null) {
- // mergedNode.setCachePolicy(defaultCachePolicy);
- // }
- // return mergedNode;
- // }
- //
protected MergePlan getMergePlan( BasicGetNodeCommand command ) {
Property mergePlanProperty = command.getPropertiesByName().get(mergePlanPropertyName);
if (mergePlanProperty == null || mergePlanProperty.isEmpty()) {
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java 2008-08-19 19:34:20 UTC (rev 448)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java 2008-08-19 19:34:42 UTC (rev 449)
@@ -38,7 +38,7 @@
private static final long serialVersionUID = 1L;
- private final UUID uuid;
+ private UUID uuid;
private MergePlan mergePlan;
private NodeConflictBehavior nodeConflictBehavior = DEFAULT_CONFLICT_BEHAVIOR;
@@ -65,6 +65,13 @@
}
/**
+ * @param uuid Sets uuid to the specified value.
+ */
+ public void setUuid( UUID uuid ) {
+ this.uuid = uuid;
+ }
+
+ /**
* Get the merge plan for this federated node
*
* @return the merge plan, or null if there is no merge plan
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java 2008-08-19 19:34:20 UTC (rev 448)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java 2008-08-19 19:34:42 UTC (rev 449)
@@ -34,7 +34,7 @@
* Merge the contributions into a single
*
* @param federatedNode the federated node into which the contributions are to be merged; never null
- * @param contributions the contributions to the node; never null
+ * @param contributions the contributions to the node; never null, never empty, and never containing nulls
* @param context the context in which this operation is to be performed; never null
*/
public void merge( FederatedNode federatedNode,
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-08-19 19:34:20 UTC (rev 448)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-08-19 19:34:42 UTC (rev 449)
@@ -24,10 +24,13 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.UuidFactory;
import org.jboss.dna.spi.graph.Path.Segment;
/**
@@ -37,6 +40,9 @@
/**
* {@inheritDoc}
+ * <p>
+ * This method only uses the one and only one non-null {@link Contribution} in the <code>contributions</code>.
+ * </p>
*
* @see org.jboss.dna.connector.federation.merge.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
* java.util.List, org.jboss.dna.spi.ExecutionContext)
@@ -46,8 +52,9 @@
ExecutionContext context ) {
assert federatedNode != null;
assert contributions != null;
- assert contributions.size() == 1;
+ assert contributions.size() > 0;
Contribution contribution = contributions.get(0);
+ assert contribution != null;
// Copy the children ...
List<Segment> children = federatedNode.getChildren();
children.clear();
@@ -59,11 +66,26 @@
// Copy the properties ...
Map<Name, Property> properties = federatedNode.getPropertiesByName();
properties.clear();
+ UUID uuid = null;
+ UuidFactory uuidFactory = null;
Iterator<Property> propertyIterator = contribution.getProperties();
while (propertyIterator.hasNext()) {
Property property = propertyIterator.next();
properties.put(property.getName(), property);
+ if (uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
+ if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
+ try {
+ uuid = uuidFactory.create(property.getValues().next());
+ } catch (IoException e) {
+ // Ignore conversion exceptions
+ }
+ }
}
+ // If we found a single "uuid" property whose value is a valid UUID ..
+ if (uuid != null) {
+ // then set the UUID on the federated node ...
+ federatedNode.setUuid(uuid);
+ }
// Assign the merge plan ...
MergePlan mergePlan = MergePlan.create(contributions);
federatedNode.setMergePlan(mergePlan);
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java 2008-08-19 19:34:42 UTC (rev 449)
@@ -0,0 +1,207 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.federation.merge;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class OneContributionMergeStrategyTest {
+
+ private OneContributionMergeStrategy strategy;
+ private List<Contribution> contributions;
+ private ExecutionContext context;
+ private FederatedNode node;
+ private Map<Name, Property> properties;
+ private List<Path.Segment> children;
+ @Mock
+ private Contribution contribution;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ Path path = mock(Path.class);
+ node = new FederatedNode(path, UUID.randomUUID());
+ strategy = new OneContributionMergeStrategy();
+ contributions = new LinkedList<Contribution>();
+ contributions.add(contribution);
+ context = new BasicExecutionContext();
+ context.getNamespaceRegistry().register("dna", "http://www.jboss.org/dna/something");
+ context.getNamespaceRegistry().register("jcr", "http://www.jcr.org");
+ stub(contribution.getSourceName()).toReturn("source name");
+ children = new LinkedList<Path.Segment>();
+ for (int i = 0; i != 10; ++i) {
+ children.add(context.getValueFactories().getPathFactory().createSegment("a" + i));
+ }
+ properties = new HashMap<Name, Property>();
+ for (int i = 0; i != 10; ++i) {
+ Name propertyName = context.getValueFactories().getNameFactory().create("property" + i);
+ properties.put(propertyName, context.getPropertyFactory().create(propertyName, "value"));
+ }
+ }
+
+ @Test
+ public void shouldMegeTheChildrenFromTheFirstContribution() {
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), is(children));
+ }
+
+ @Test
+ public void shouldMegeThePropertiesFromTheFirstContribution() {
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ assertThat(node.getPropertiesByName(), is(properties));
+ }
+
+ @Test
+ public void shouldCreateMergePlanInTheFederatedNode() {
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ MergePlan mergePlan = node.getMergePlan();
+ assertThat(mergePlan.getContributionFrom(contribution.getSourceName()), is(sameInstance(contribution)));
+ assertThat(mergePlan.getContributionCount(), is(1));
+ }
+
+ @Test
+ public void shouldSetTheUuidOnTheNodeIfThereIsASingleValuedPropertyNamedUuidWithValueThatConvertsToUuidInstance() {
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ UUID uuid = UUID.randomUUID();
+ Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+
+ // Test the "jcr:uuid" property ...
+ uuidName = context.getValueFactories().getNameFactory().create("jcr:uuid");
+ uuid = UUID.randomUUID();
+ uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+
+ // Test the "uuid" property ...
+ uuidName = context.getValueFactories().getNameFactory().create("uuid");
+ uuid = UUID.randomUUID();
+ uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+
+ // Test the "uuid" property whose value is a String ...
+ uuidName = context.getValueFactories().getNameFactory().create("uuid");
+ uuid = UUID.randomUUID();
+ uuidProperty = context.getPropertyFactory().create(uuidName, uuid.toString());
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+ }
+
+ @Test
+ public void shouldNotSetTheUuidOnTheNodeIfThereIsNoPropertyNamedUuid() {
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ UUID uuid = UUID.randomUUID();
+ Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+ }
+
+ @Test
+ public void shouldNotSetTheUuidOnTheNodeIfThereIsAMultiValuedPropertyNamedUuid() {
+ final UUID originalUuid = node.getUuid();
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ Property uuidProperty = context.getPropertyFactory().create(uuidName,
+ UUID.randomUUID(),
+ UUID.randomUUID(),
+ UUID.randomUUID());
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(originalUuid));
+ }
+
+ @Ignore
+ @Test
+ public void shouldNotSetTheUuidOnTheNodeIfThereIsASingleValuedPropertyNamedUuidWithValueThatDoesNotConvertToUuidInstance() {
+ final UUID originalUuid = node.getUuid();
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ Property uuidProperty = context.getPropertyFactory().create(uuidName, 3.33d);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(originalUuid));
+ }
+
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 9 months