DNA SVN: r206 - in branches/federation/dna-spi/src/main/java/org/jboss/dna/spi: graph and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-28 13:18:41 -0400 (Wed, 28 May 2008)
New Revision: 206
Added:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GraphCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnection.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceListener.java
Removed:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/RepositoryCommand.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnPath.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/DeleteBranchCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/MoveBranchCommand.java
Log:
DNA-68: Create connector API
http://jira.jboss.org/jira/browse/DNA-68
Renamed the connector and command packages since they all fall under the "graph SPI".
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java 2008-05-28 15:48:30 UTC (rev 205)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -1,80 +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.spi.connector;
-
-import java.util.concurrent.TimeUnit;
-import javax.transaction.xa.XAResource;
-import org.jboss.dna.spi.connector.commands.RepositoryCommand;
-
-/**
- * A connection to a repository source.
- * <p>
- * These connections need not support concurrent operations by multiple threads, since the federation engine never uses them this
- * way.
- * </p>
- * @author Randall Hauch
- */
-public interface RepositoryConnection {
-
- /**
- * Get the name for this repository source. This value should be the same as that {@link RepositorySource#getName() returned}
- * by the same {@link RepositorySource} that created this connection.
- * @return the identifier; never null or empty
- */
- String getSourceName();
-
- /**
- * Return the transactional resource associated with this connection. The transaction manager will use this resource to manage
- * the participation of this connection in a distributed transaction.
- * @return the XA resource, or null if this connection is not aware of distributed transactions
- */
- XAResource getXAResource();
-
- /**
- * Ping the underlying system to determine if the connection is still valid and alive.
- * @param time the length of time to wait before timing out
- * @param unit the time unit to use; may not be null
- * @return true if this connection is still valid and can still be used, or false otherwise
- * @throws InterruptedException if the thread has been interrupted during the operation
- */
- boolean ping( long time, TimeUnit unit ) throws InterruptedException;
-
- /**
- * Set the listener that is to receive notifications to changes to content within this source.
- * @param listener the new listener, or null if no component is interested in the change notifications
- */
- void setListener( RepositorySourceListener listener );
-
- /**
- * Execute the supplied commands against this repository source.
- * @param env the environment in which the commands are being executed; never null
- * @param commands the commands to be executed; never null
- * @throws RepositorySourceException if there is a problem loading the node data
- */
- void execute( RepositorySourceEnvironment env, RepositoryCommand... commands ) throws RepositorySourceException;
-
- /**
- * Close this connection to signal that it is no longer needed and that any accumulated resources are to be released.
- * @throws InterruptedException if the thread has been interrupted while the close was in progress
- */
- void close() throws InterruptedException;
-}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java 2008-05-28 15:48:30 UTC (rev 205)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -1,37 +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.spi.connector;
-
-/**
- * @author Randall Hauch
- */
-public interface RepositoryConnectionFactory {
-
- /**
- * Get a connection from this factory.
- * @return a connection
- * @throws RepositorySourceException if there is a problem obtaining a connection
- * @throws InterruptedException if the thread is interrupted while attempting to get a connection
- * @throws IllegalStateException if the factory is not in a state to create or return connections
- */
- RepositoryConnection getConnection() throws RepositorySourceException, InterruptedException;
-}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java 2008-05-28 15:48:30 UTC (rev 205)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -1,74 +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.spi.connector;
-
-import java.io.Serializable;
-import javax.naming.Referenceable;
-import org.jboss.dna.spi.cache.CachePolicy;
-
-/**
- * A repository source is a description of a resource that can be used to access or store repository information. This class
- * serves as a factory for {@link RepositoryConnection} instances and provides some basic configuration information.
- * <p>
- * Typically this interface is implemented by classes that provide standard-style getters and setters for the various properties
- * necessary for proper configuration via reflection or introspection. This interface expects nor defines any such properties,
- * leaving that entirely to the implementation classes.
- * </p>
- * <p>
- * Objects that implement this <code>RepositorySource</code> interface are typically registered with a naming service such as
- * Java Naming and Directory Interface<sup><font size=-3>TM</font></sup> (JNDI). This interface extends both
- * {@link Referenceable} and {@link Serializable} so that such objects can be stored in any JNDI naming context and enable proper
- * system recovery,
- * </p>
- * @author Randall Hauch
- */
-public interface RepositorySource extends RepositoryConnectionFactory, Referenceable, Serializable {
-
- /**
- * Get the name for this repository source.
- * @return the name; never null or empty
- */
- String getName();
-
- /**
- * Get the maximum number of retries that may be performed on a given operation when using
- * {@link #getConnection() connections} created by this source. This value does not constitute a minimum number of retries; in
- * fact, the connection user is not required to retry any operations.
- * @return the maximum number of allowable retries, or 0 if the source has no limit
- */
- int getRetryLimit();
-
- /**
- * Set the maximum number of retries that may be performed on a given operation when using
- * {@link #getConnection() connections} created by this source. This value does not constitute a minimum number of retries; in
- * fact, the connection user is not required to retry any operations.
- * @param limit the maximum number of allowable retries, or 0 if the source has no limit
- */
- void setRetryLimit( int limit );
-
- /**
- * Get the default cache policy for this source. If none is provided, a global cache policy will be used.
- * @return the default cache policy
- */
- CachePolicy getDefaultCachePolicy();
-
-}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java 2008-05-28 15:48:30 UTC (rev 205)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -1,53 +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.spi.connector;
-
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.Property;
-import org.jboss.dna.spi.graph.ValueFactories;
-
-/**
- * @author Randall Hauch
- */
-public interface RepositorySourceEnvironment {
-
- /**
- * Get the factories that should be used to create values for {@link Property properties}.
- * @return the property value factory; never null
- */
- ValueFactories getValueFactories();
-
- /**
- * Get the factory that should be used to create {@link Name names}.
- * @return the name factory; never null
- */
- NameFactory getNameFactory();
-
- /**
- * Get the {@link RepositorySource} instance that this environment represents. This instance will be the same instance that
- * created the {@link RepositoryConnection} for which this environment was created and is being used.
- * @return the repository source; never null
- */
- RepositorySource getRepositorySource();
-
-}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java 2008-05-28 15:48:30 UTC (rev 205)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -1,73 +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.spi.connector;
-
-/**
- * @author Randall Hauch
- */
-public class RepositorySourceException extends RuntimeException {
-
- private final String sourceName;
-
- /**
- * @param sourceName the identifier of the source from which this exception eminates
- */
- public RepositorySourceException( String sourceName ) {
- this.sourceName = sourceName;
- }
-
- /**
- * @param sourceName the identifier of the source from which this exception eminates
- * @param message
- */
- public RepositorySourceException( String sourceName, String message ) {
- super(message);
- this.sourceName = sourceName;
- }
-
- /**
- * @param sourceName the identifier of the source from which this exception eminates
- * @param cause
- */
- public RepositorySourceException( String sourceName, Throwable cause ) {
- super(cause);
- this.sourceName = sourceName;
- }
-
- /**
- * @param sourceName the identifier of the source from which this exception eminates
- * @param message
- * @param cause
- */
- public RepositorySourceException( String sourceName, String message, Throwable cause ) {
- super(message, cause);
- this.sourceName = sourceName;
- }
-
- /**
- * @return sourceName
- */
- public String getSourceName() {
- return this.sourceName;
- }
-
-}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java 2008-05-28 15:48:30 UTC (rev 205)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -1,30 +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.spi.connector;
-
-/**
- * @author Randall Hauch
- */
-public interface RepositorySourceListener {
-
- void notify( String sourceName, Object... events );
-}
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands (from rev 204, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands)
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnPath.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnPath.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnPath.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,7 +19,7 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
import org.jboss.dna.spi.graph.Path;
@@ -28,7 +28,7 @@
* recipient to obtain the path that the command applies to.
* @author Randall Hauch
*/
-public interface ActsOnPath extends RepositoryCommand {
+public interface ActsOnPath extends GraphCommand {
/**
* Get the path to which this command applies.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnProperties.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,7 +19,7 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
import org.jboss.dna.spi.cache.Cacheable;
import org.jboss.dna.spi.graph.Name;
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/CreateNodeCommand.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,7 +19,7 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
import java.util.Iterator;
import org.jboss.dna.spi.cache.Cacheable;
@@ -30,7 +30,7 @@
* A command to get the children of a single node given its path.
* @author Randall Hauch
*/
-public interface CreateNodeCommand extends RepositoryCommand, ActsOnPath, Cacheable, ActsOnProperties {
+public interface CreateNodeCommand extends GraphCommand, ActsOnPath, Cacheable, ActsOnProperties {
/**
* Get the names of the children for this new node. The recipient of the command should {@link Iterator#remove() remove} any
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/DeleteBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/DeleteBranchCommand.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/DeleteBranchCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,11 +19,11 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
/**
* Command that deletes a branch given by a specified path.
* @author Randall Hauch
*/
-public interface DeleteBranchCommand extends RepositoryCommand, ActsOnPath {
+public interface DeleteBranchCommand extends GraphCommand, ActsOnPath {
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,7 +19,7 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
import java.util.Iterator;
import org.jboss.dna.spi.cache.Cacheable;
@@ -29,7 +29,7 @@
* A command to get the children of a single node given its path.
* @author Randall Hauch
*/
-public interface GetChildrenCommand extends RepositoryCommand, ActsOnPath, Cacheable {
+public interface GetChildrenCommand extends GraphCommand, ActsOnPath, Cacheable {
/**
* Set the children of this node using an iterator of names. Any existing child references already set on this command will be
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetNodeCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,7 +19,7 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
/**
* A command to get the properties and children for a single node given its path.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,7 +19,7 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
import org.jboss.dna.spi.cache.Cacheable;
@@ -27,6 +27,6 @@
* A command to obtain from the source the properties for a single node given its path.
* @author Randall Hauch
*/
-public interface GetPropertiesCommand extends RepositoryCommand, ActsOnPath, Cacheable, ActsOnProperties {
+public interface GetPropertiesCommand extends GraphCommand, ActsOnPath, Cacheable, ActsOnProperties {
}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GraphCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GraphCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GraphCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -0,0 +1,36 @@
+/*
+ * 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.commands;
+
+/**
+ * The base interface for all repository commands
+ * @author Randall Hauch
+ */
+public interface GraphCommand {
+
+ /**
+ * Return whether this command has been cancelled.
+ * @return true if this command has been cancelled, or false otherwise.
+ */
+ boolean isCancelled();
+
+}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/MoveBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/MoveBranchCommand.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/MoveBranchCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -19,7 +19,7 @@
* 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.connector.commands;
+package org.jboss.dna.spi.graph.commands;
import org.jboss.dna.spi.graph.Path;
@@ -27,7 +27,7 @@
* Command that moves a branch from one path to another.
* @author Randall Hauch
*/
-public interface MoveBranchCommand extends RepositoryCommand, ActsOnPath {
+public interface MoveBranchCommand extends GraphCommand, ActsOnPath {
/**
* Get the new path to which the branch is to be moved.
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/RepositoryCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/RepositoryCommand.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/RepositoryCommand.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -1,36 +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.spi.connector.commands;
-
-/**
- * The base interface for all repository commands
- * @author Randall Hauch
- */
-public interface RepositoryCommand {
-
- /**
- * Return whether this command has been cancelled.
- * @return true if this command has been cancelled, or false otherwise.
- */
- boolean isCancelled();
-
-}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -0,0 +1,51 @@
+/*
+ * 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.connection;
+
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author Randall Hauch
+ */
+public interface ExecutionEnvironment {
+
+ /**
+ * Get the factories that should be used to create values for {@link Property properties}.
+ * @return the property value factory; never null
+ */
+ ValueFactories getValueFactories();
+
+ /**
+ * Get the namespace registry for this environment.
+ * @return the namespace registry; never null
+ */
+ NamespaceRegistry getNamespaceRegistry();
+
+ /**
+ * Return the repository source against which this environment applies.
+ * @return the repository source; never null
+ */
+ RepositorySource getRepositorySource();
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnection.java (from rev 204, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnection.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnection.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -0,0 +1,80 @@
+/*
+ * 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.connection;
+
+import java.util.concurrent.TimeUnit;
+import javax.transaction.xa.XAResource;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+
+/**
+ * A connection to a repository source.
+ * <p>
+ * These connections need not support concurrent operations by multiple threads, since the federation engine never uses them this
+ * way.
+ * </p>
+ * @author Randall Hauch
+ */
+public interface RepositoryConnection {
+
+ /**
+ * Get the name for this repository source. This value should be the same as that {@link RepositorySource#getName() returned}
+ * by the same {@link RepositorySource} that created this connection.
+ * @return the identifier; never null or empty
+ */
+ String getSourceName();
+
+ /**
+ * Return the transactional resource associated with this connection. The transaction manager will use this resource to manage
+ * the participation of this connection in a distributed transaction.
+ * @return the XA resource, or null if this connection is not aware of distributed transactions
+ */
+ XAResource getXAResource();
+
+ /**
+ * Ping the underlying system to determine if the connection is still valid and alive.
+ * @param time the length of time to wait before timing out
+ * @param unit the time unit to use; may not be null
+ * @return true if this connection is still valid and can still be used, or false otherwise
+ * @throws InterruptedException if the thread has been interrupted during the operation
+ */
+ boolean ping( long time, TimeUnit unit ) throws InterruptedException;
+
+ /**
+ * Set the listener that is to receive notifications to changes to content within this source.
+ * @param listener the new listener, or null if no component is interested in the change notifications
+ */
+ void setListener( RepositorySourceListener listener );
+
+ /**
+ * Execute the supplied commands against this repository source.
+ * @param env the environment in which the commands are being executed; never null
+ * @param commands the commands to be executed; never null
+ * @throws RepositorySourceException if there is a problem loading the node data
+ */
+ void execute( ExecutionEnvironment env, GraphCommand... commands ) throws RepositorySourceException;
+
+ /**
+ * Close this connection to signal that it is no longer needed and that any accumulated resources are to be released.
+ * @throws InterruptedException if the thread has been interrupted while the close was in progress
+ */
+ void close() throws InterruptedException;
+}
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactory.java (from rev 204, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactory.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -0,0 +1,37 @@
+/*
+ * 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.connection;
+
+/**
+ * @author Randall Hauch
+ */
+public interface RepositoryConnectionFactory {
+
+ /**
+ * Get a connection from this factory.
+ * @return a connection
+ * @throws RepositorySourceException if there is a problem obtaining a connection
+ * @throws InterruptedException if the thread is interrupted while attempting to get a connection
+ * @throws IllegalStateException if the factory is not in a state to create or return connections
+ */
+ RepositoryConnection getConnection() throws RepositorySourceException, InterruptedException;
+}
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java (from rev 204, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -0,0 +1,74 @@
+/*
+ * 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.connection;
+
+import java.io.Serializable;
+import javax.naming.Referenceable;
+import org.jboss.dna.spi.cache.CachePolicy;
+
+/**
+ * A repository source is a description of a resource that can be used to access or store repository information. This class
+ * serves as a factory for {@link RepositoryConnection} instances and provides some basic configuration information.
+ * <p>
+ * Typically this interface is implemented by classes that provide standard-style getters and setters for the various properties
+ * necessary for proper configuration via reflection or introspection. This interface expects nor defines any such properties,
+ * leaving that entirely to the implementation classes.
+ * </p>
+ * <p>
+ * Objects that implement this <code>RepositorySource</code> interface are typically registered with a naming service such as
+ * Java Naming and Directory Interface<sup><font size=-3>TM</font></sup> (JNDI). This interface extends both
+ * {@link Referenceable} and {@link Serializable} so that such objects can be stored in any JNDI naming context and enable proper
+ * system recovery,
+ * </p>
+ * @author Randall Hauch
+ */
+public interface RepositorySource extends RepositoryConnectionFactory, Referenceable, Serializable {
+
+ /**
+ * Get the name for this repository source.
+ * @return the name; never null or empty
+ */
+ String getName();
+
+ /**
+ * Get the maximum number of retries that may be performed on a given operation when using
+ * {@link #getConnection() connections} created by this source. This value does not constitute a minimum number of retries; in
+ * fact, the connection user is not required to retry any operations.
+ * @return the maximum number of allowable retries, or 0 if the source has no limit
+ */
+ int getRetryLimit();
+
+ /**
+ * Set the maximum number of retries that may be performed on a given operation when using
+ * {@link #getConnection() connections} created by this source. This value does not constitute a minimum number of retries; in
+ * fact, the connection user is not required to retry any operations.
+ * @param limit the maximum number of allowable retries, or 0 if the source has no limit
+ */
+ void setRetryLimit( int limit );
+
+ /**
+ * Get the default cache policy for this source. If none is provided, a global cache policy will be used.
+ * @return the default cache policy
+ */
+ CachePolicy getDefaultCachePolicy();
+
+}
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java (from rev 204, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -0,0 +1,73 @@
+/*
+ * 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.connection;
+
+/**
+ * @author Randall Hauch
+ */
+public class RepositorySourceException extends RuntimeException {
+
+ private final String sourceName;
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ */
+ public RepositorySourceException( String sourceName ) {
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ * @param message
+ */
+ public RepositorySourceException( String sourceName, String message ) {
+ super(message);
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ * @param cause
+ */
+ public RepositorySourceException( String sourceName, Throwable cause ) {
+ super(cause);
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ * @param message
+ * @param cause
+ */
+ public RepositorySourceException( String sourceName, String message, Throwable cause ) {
+ super(message, cause);
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @return sourceName
+ */
+ public String getSourceName() {
+ return this.sourceName;
+ }
+
+}
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceListener.java (from rev 204, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceListener.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceListener.java 2008-05-28 17:18:41 UTC (rev 206)
@@ -0,0 +1,30 @@
+/*
+ * 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.connection;
+
+/**
+ * @author Randall Hauch
+ */
+public interface RepositorySourceListener {
+
+ void notify( String sourceName, Object... events );
+}
15 years, 11 months
DNA SVN: r205 - branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-28 11:48:30 -0400 (Wed, 28 May 2008)
New Revision: 205
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
Log:
Merged changes from trunk@204 to federation branch: svn merge https://svn.jboss.org/repos/dna/branches/federation@204 https://svn.jboss.org/repos/dna/trunk@204
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-28 15:48:30 UTC (rev 205)
@@ -37,7 +37,24 @@
public interface DateTime extends Comparable<DateTime>, Serializable {
/**
- * Get the ISO-8601 representation of this instance in time.
+ * Get the ISO-8601 representation of this instance in time. The month-based ISO-8601 representation is the most common format
+ * of ISO8601, and is the format used in the XML standards for passing dates and times:
+ *
+ * <pre>
+ * yyyy-mm-ddTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit year;</li>
+ * <li>two digit month, where 01 is Janurary and 12 is December;</li>
+ * <li>two digit day of month, from 01 to 31;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
* @return the string representation; never null
*/
String getString();
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java 2008-05-28 15:48:30 UTC (rev 205)
@@ -22,6 +22,80 @@
package org.jboss.dna.spi.graph;
/**
+ * A factory for creating {@link DateTime date-time instants}. This interface extends the {@link ValueFactory} generic interface
+ * and adds specific methods for creating instants for the current time (and time zone) as well as various combinations of
+ * individual field values.
+ * <h2>ISO-8601</h2>
+ * <p>
+ * The factory creates date-time instants from strings that are in the standard ISO-8601 format. There are three supported styles:
+ * month-based, day-of-year-based, and week-based.
+ * </p>
+ * <h3>Month-Based</h3>
+ * <p>
+ * The month-based representation is the most common format of ISO8601, and is the format used in the XML standards for passing
+ * dates and times:
+ *
+ * <pre>
+ * yyyy-mm-ddTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit year;</li>
+ * <li>two digit month, where 01 is Janurary and 12 is December;</li>
+ * <li>two digit day of month, from 01 to 31;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
+ * </p>
+ * <h3>Day of Year Based</h3>
+ * <p>
+ * This format of ISO-8601 uses a single field to represent the day of the year:
+ *
+ * <pre>
+ * yyyy-dddTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit year</li>
+ * <li>three digit day of year, from 001 to 366;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
+ * </p>
+ * <h3>Week Based</h3>
+ * <p>
+ * This format of ISO-8601 uses a single field to represent the day of the year:
+ *
+ * <pre>
+ * yyyy-Www-dTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit weekyear (see below)</li>
+ * <li>two digit week of year, from 01 to 53;</li>
+ * <li>one digit day of week, from 1 to 7 where 1 is Monday and 7 is Sunday;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
+ * </p>
+ * <p>
+ * From <a href="http://joda-time.sourceforge.net/cal_iso.html">Joda-Time</a>: Weeks are always complete, and the first week of a
+ * year is the one that includes the first Thursday of the year. This definition can mean that the first week of a year starts in
+ * the previous year, and the last week finishes in the next year. The weekyear field is defined to refer to the year that owns
+ * the week, which may differ from the actual year.
+ * </p>
* @author Randall Hauch
*/
public interface DateTimeFactory extends ValueFactory<DateTime> {
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-28 15:45:27 UTC (rev 204)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-28 15:48:30 UTC (rev 205)
@@ -22,7 +22,8 @@
package org.jboss.dna.spi.graph;
/**
- * A factory for creating {@link Path paths}.
+ * A factory for creating {@link Path paths}. This interface extends the {@link ValueFactory} generic interface and adds specific
+ * methods for creating paths (and relative paths) from a series of names, segments, or combinations.
* @author Randall Hauch
*/
public interface PathFactory extends ValueFactory<Path> {
15 years, 11 months
DNA SVN: r204 - trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-28 11:45:27 -0400 (Wed, 28 May 2008)
New Revision: 204
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added JavaDoc.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-28 02:46:17 UTC (rev 203)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-28 15:45:27 UTC (rev 204)
@@ -37,7 +37,24 @@
public interface DateTime extends Comparable<DateTime>, Serializable {
/**
- * Get the ISO-8601 representation of this instance in time.
+ * Get the ISO-8601 representation of this instance in time. The month-based ISO-8601 representation is the most common format
+ * of ISO8601, and is the format used in the XML standards for passing dates and times:
+ *
+ * <pre>
+ * yyyy-mm-ddTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit year;</li>
+ * <li>two digit month, where 01 is Janurary and 12 is December;</li>
+ * <li>two digit day of month, from 01 to 31;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
* @return the string representation; never null
*/
String getString();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java 2008-05-28 02:46:17 UTC (rev 203)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java 2008-05-28 15:45:27 UTC (rev 204)
@@ -22,6 +22,80 @@
package org.jboss.dna.spi.graph;
/**
+ * A factory for creating {@link DateTime date-time instants}. This interface extends the {@link ValueFactory} generic interface
+ * and adds specific methods for creating instants for the current time (and time zone) as well as various combinations of
+ * individual field values.
+ * <h2>ISO-8601</h2>
+ * <p>
+ * The factory creates date-time instants from strings that are in the standard ISO-8601 format. There are three supported styles:
+ * month-based, day-of-year-based, and week-based.
+ * </p>
+ * <h3>Month-Based</h3>
+ * <p>
+ * The month-based representation is the most common format of ISO8601, and is the format used in the XML standards for passing
+ * dates and times:
+ *
+ * <pre>
+ * yyyy-mm-ddTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit year;</li>
+ * <li>two digit month, where 01 is Janurary and 12 is December;</li>
+ * <li>two digit day of month, from 01 to 31;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
+ * </p>
+ * <h3>Day of Year Based</h3>
+ * <p>
+ * This format of ISO-8601 uses a single field to represent the day of the year:
+ *
+ * <pre>
+ * yyyy-dddTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit year</li>
+ * <li>three digit day of year, from 001 to 366;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
+ * </p>
+ * <h3>Week Based</h3>
+ * <p>
+ * This format of ISO-8601 uses a single field to represent the day of the year:
+ *
+ * <pre>
+ * yyyy-Www-dTHH:MM:SS.SSSZ
+ * </pre>
+ *
+ * The fields are separated by dashes and consist of:
+ * <ul>
+ * <li>four digit weekyear (see below)</li>
+ * <li>two digit week of year, from 01 to 53;</li>
+ * <li>one digit day of week, from 1 to 7 where 1 is Monday and 7 is Sunday;</li>
+ * <li>two digit hour, from 00 to 23;</li>
+ * <li>two digit minute, from 00 to 59;</li>
+ * <li>two digit second, from 00 to 59;</li>
+ * <li>three decimal places for milliseconds, if required;</li>
+ * <li>time zone offset of the form <code>�HH:mm</code> (or '0' if UTC)</li>
+ * </ul>
+ * </p>
+ * <p>
+ * From <a href="http://joda-time.sourceforge.net/cal_iso.html">Joda-Time</a>: Weeks are always complete, and the first week of a
+ * year is the one that includes the first Thursday of the year. This definition can mean that the first week of a year starts in
+ * the previous year, and the last week finishes in the next year. The weekyear field is defined to refer to the year that owns
+ * the week, which may differ from the actual year.
+ * </p>
* @author Randall Hauch
*/
public interface DateTimeFactory extends ValueFactory<DateTime> {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-28 02:46:17 UTC (rev 203)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-28 15:45:27 UTC (rev 204)
@@ -22,7 +22,8 @@
package org.jboss.dna.spi.graph;
/**
- * A factory for creating {@link Path paths}.
+ * A factory for creating {@link Path paths}. This interface extends the {@link ValueFactory} generic interface and adds specific
+ * methods for creating paths (and relative paths) from a series of names, segments, or combinations.
* @author Randall Hauch
*/
public interface PathFactory extends ValueFactory<Path> {
15 years, 11 months
DNA SVN: r203 - in branches/federation: dna-repository/src/test/java/org/jboss/dna/repository/sequencers and 4 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-27 22:46:17 -0400 (Tue, 27 May 2008)
New Revision: 203
Modified:
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
branches/federation/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
branches/federation/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
Log:
Merged changes from turnk to federation branch
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java 2008-05-27 21:50:04 UTC (rev 202)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java 2008-05-28 02:46:17 UTC (rev 203)
@@ -32,8 +32,10 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.ValueFactories;
import org.jboss.dna.spi.sequencers.SequencerOutput;
/**
@@ -48,37 +50,45 @@
private static final String JCR_NAME_PROPERTY_NAME = "jcr:name";
private final Map<Path, List<PropertyValue>> data;
- private boolean valuesSorted = true;
- private final PathFactory pathFactory;
+ private transient boolean valuesSorted = true;
+ private final ValueFactories factories;
+ private final Name jcrName;
- public SequencerOutputMap( PathFactory pathFactory ) {
- ArgCheck.isNotNull(pathFactory, "pathFactory");
+ public SequencerOutputMap( ValueFactories factories ) {
+ ArgCheck.isNotNull(factories, "factories");
this.data = new HashMap<Path, List<PropertyValue>>();
- this.pathFactory = pathFactory;
+ this.factories = factories;
+ this.jcrName = this.factories.getNameFactory().create(JCR_NAME_PROPERTY_NAME);
}
/**
* {@inheritDoc}
*/
- public void setProperty( String nodePath, String property, Object... values ) {
- property = property.trim();
- if (JCR_NAME_PROPERTY_NAME.equals(property)) return; // ignore the "jcr:name" property
- nodePath = nodePath.trim();
- if (nodePath.endsWith("/")) nodePath = nodePath.replaceFirst("/+$", "");
+ public ValueFactories getFactories() {
+ return this.factories;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Path nodePath, Name propertyName, Object... values ) {
+ ArgCheck.isNotNull(nodePath, "nodePath");
+ ArgCheck.isNotNull(propertyName, "property");
+ // Ignore the "jcr:name" property, as that's handled by the path ...
+ if (this.jcrName.equals(propertyName)) return;
+
// Find or create the entry for this node ...
- Path path = pathFactory.create(nodePath);
- List<PropertyValue> properties = this.data.get(path);
+ List<PropertyValue> properties = this.data.get(nodePath);
if (properties == null) {
if (values == null || values.length == 0) return; // do nothing
properties = new ArrayList<PropertyValue>();
- this.data.put(path, properties);
+ this.data.put(nodePath, properties);
}
if (values == null || values.length == 0) {
- properties.remove(new PropertyValue(property, null));
+ properties.remove(new PropertyValue(propertyName, null));
} else {
Object propValue = values.length == 1 ? values[0] : values;
- PropertyValue value = new PropertyValue(property, propValue);
+ PropertyValue value = new PropertyValue(propertyName, propValue);
properties.add(value);
valuesSorted = false;
}
@@ -87,18 +97,30 @@
/**
* {@inheritDoc}
*/
- public void setReference( String nodePath, String property, String... paths ) {
- if (paths == null || paths.length == 0) {
- setProperty(nodePath, property, (Object[])null);
- } else if (paths.length == 1) {
- setProperty(nodePath, property, pathFactory.create(paths[0]));
- } else {
- Path[] pathsArray = new Path[paths.length];
- for (int i = 0; i != paths.length; ++i) {
- pathsArray[i] = pathFactory.create(paths[i]);
+ public void setProperty( String nodePath, String property, Object... values ) {
+ ArgCheck.isNotEmpty(nodePath, "nodePath");
+ ArgCheck.isNotEmpty(property, "property");
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name propertyName = this.factories.getNameFactory().create(property);
+ setProperty(path, propertyName, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setReference( String nodePath, String propertyName, String... paths ) {
+ PathFactory pathFactory = this.factories.getPathFactory();
+ Path path = pathFactory.create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ Object[] values = null;
+ if (paths != null && paths.length != 0) {
+ values = new Path[paths.length];
+ for (int i = 0, len = paths.length; i != len; ++i) {
+ String pathValue = paths[i];
+ values[i] = pathFactory.create(pathValue);
}
- setProperty(nodePath, property, (Object[])pathsArray);
}
+ setProperty(path, name, values);
}
/**
@@ -167,10 +189,10 @@
@Immutable
public class PropertyValue implements Comparable<PropertyValue> {
- private final String name;
+ private final Name name;
private final Object value;
- protected PropertyValue( String propertyName, Object value ) {
+ protected PropertyValue( Name propertyName, Object value ) {
this.name = propertyName;
this.value = value;
}
@@ -179,7 +201,7 @@
* Get the property name.
* @return the property name; never null
*/
- public String getName() {
+ public Name getName() {
return this.name;
}
@@ -241,7 +263,7 @@
public class Entry {
private final Path path;
- private final String primaryType;
+ private final Name primaryType;
private final List<PropertyValue> properties;
protected Entry( Path path, List<PropertyValue> properties ) {
@@ -251,7 +273,7 @@
this.properties = properties;
if (this.properties.size() > 0 && this.properties.get(0).getName().equals("jcr:primaryType")) {
PropertyValue primaryTypeProperty = this.properties.remove(0);
- this.primaryType = primaryTypeProperty.getValue().toString();
+ this.primaryType = getFactories().getNameFactory().create(primaryTypeProperty.getValue());
} else {
this.primaryType = null;
}
@@ -268,7 +290,7 @@
* Get the primary type specified for this node, or null if the type was not specified
* @return the primary type, or null
*/
- public String getPrimaryTypeValue() {
+ public Name getPrimaryTypeValue() {
return this.primaryType;
}
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-27 21:50:04 UTC (rev 202)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-28 02:46:17 UTC (rev 203)
@@ -22,7 +22,9 @@
package org.jboss.dna.repository.sequencers;
import java.io.InputStream;
+import java.math.BigDecimal;
import java.util.Calendar;
+import java.util.Date;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
@@ -35,6 +37,9 @@
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.ExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
@@ -90,7 +95,7 @@
progressMonitor.worked(10);
// Get the binary property with the image content, and build the image metadata from the image ...
- SequencerOutputMap output = new SequencerOutputMap(context.getValueFactories().getPathFactory());
+ SequencerOutputMap output = new SequencerOutputMap(context.getValueFactories());
InputStream stream = null;
Throwable firstError = null;
ProgressMonitor sequencingMonitor = progressMonitor.createSubtask(50);
@@ -169,7 +174,7 @@
// prefix and name)
for (SequencerOutputMap.Entry entry : output) {
Path targetNodePath = entry.getPath();
- String primaryType = entry.getPrimaryTypeValue();
+ Name primaryType = entry.getPrimaryTypeValue();
// Resolve this path relative to the output node path, handling any parent or self references ...
Path absolutePath = targetNodePath.isAbsolute() ? targetNodePath : outputNodePath.resolve(targetNodePath);
@@ -190,7 +195,7 @@
}
// We only have the primary type for the final one ...
if (i == (max - 1) && primaryType != null) {
- targetNode = targetNode.addNode(qualifiedName, primaryType);
+ targetNode = targetNode.addNode(qualifiedName, primaryType.getString(namespaceRegistry, Path.NO_OP_ENCODER));
} else {
targetNode = targetNode.addNode(qualifiedName);
}
@@ -201,13 +206,15 @@
// Set all of the properties on this
for (SequencerOutputMap.PropertyValue property : entry.getPropertyValues()) {
- String propertyName = property.getName();
+ String propertyName = property.getName().getString(namespaceRegistry, Path.NO_OP_ENCODER);
Object value = property.getValue();
Logger.getLogger(this.getClass()).trace("Writing property {0}/{1}={2}", targetNode.getPath(), propertyName, value);
if (value instanceof Boolean) {
targetNode.setProperty(propertyName, ((Boolean)value).booleanValue());
} else if (value instanceof String) {
targetNode.setProperty(propertyName, (String)value);
+ } else if (value instanceof String[]) {
+ targetNode.setProperty(propertyName, (String[])value);
} else if (value instanceof Integer) {
targetNode.setProperty(propertyName, ((Integer)value).intValue());
} else if (value instanceof Short) {
@@ -218,8 +225,27 @@
targetNode.setProperty(propertyName, ((Float)value).floatValue());
} else if (value instanceof Double) {
targetNode.setProperty(propertyName, ((Double)value).doubleValue());
+ } else if (value instanceof Binary) {
+ Binary binaryValue = (Binary)value;
+ try {
+ binaryValue.acquire();
+ targetNode.setProperty(propertyName, binaryValue.getStream());
+ } finally {
+ binaryValue.release();
+ }
+ } else if (value instanceof BigDecimal) {
+ targetNode.setProperty(propertyName, ((BigDecimal)value).doubleValue());
+ } else if (value instanceof DateTime) {
+ targetNode.setProperty(propertyName, ((DateTime)value).toCalendar());
+ } else if (value instanceof Date) {
+ DateTime instant = context.getValueFactories().getDateFactory().create((Date)value);
+ targetNode.setProperty(propertyName, instant.toCalendar());
} else if (value instanceof Calendar) {
targetNode.setProperty(propertyName, (Calendar)value);
+ } else if (value instanceof Name) {
+ Name nameValue = (Name)value;
+ String stringValue = nameValue.getString(namespaceRegistry);
+ targetNode.setProperty(propertyName, stringValue);
} else if (value instanceof Path) {
// Find the path to reference node ...
Path pathToReferencedNode = (Path)value;
Modified: branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
===================================================================
--- branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-05-27 21:50:04 UTC (rev 202)
+++ branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-05-28 02:46:17 UTC (rev 203)
@@ -39,16 +39,14 @@
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.RecordingProgressMonitor;
import org.jboss.dna.repository.observation.NodeChange;
-import org.jboss.dna.repository.sequencers.SequencerConfig;
-import org.jboss.dna.repository.sequencers.SequencerException;
-import org.jboss.dna.repository.sequencers.SequencerOutputMap;
-import org.jboss.dna.repository.sequencers.StreamSequencerAdapter;
import org.jboss.dna.repository.util.ExecutionContext;
+import org.jboss.dna.repository.util.JcrNamespaceRegistry;
import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.RepositoryNodePath;
import org.jboss.dna.repository.util.SessionFactory;
import org.jboss.dna.repository.util.SimpleExecutionContext;
-import org.jboss.dna.spi.graph.impl.BasicNamespaceRegistry;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
import org.junit.After;
@@ -82,8 +80,9 @@
return createTestSession();
}
};
- this.context = new SimpleExecutionContext(sessionFactory, new BasicNamespaceRegistry(), null);
- this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories().getPathFactory());
+ NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory, "doesn't matter");
+ this.context = new SimpleExecutionContext(sessionFactory, registry, null);
+ this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories());
this.progressMonitor = new RecordingProgressMonitor(StreamSequencerAdapterTest.class.getName());
final SequencerOutputMap finalOutput = sequencerOutput;
this.streamSequencer = new StreamSequencer() {
@@ -94,7 +93,7 @@
*/
public void sequence( InputStream stream, SequencerOutput output, ProgressMonitor progressMonitor ) {
for (SequencerOutputMap.Entry entry : finalOutput) {
- String nodePath = entry.getPath().getString();
+ Path nodePath = entry.getPath();
for (SequencerOutputMap.PropertyValue property : entry.getPropertyValues()) {
output.setProperty(nodePath, property.getName(), property.getValue());
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-05-27 21:50:04 UTC (rev 202)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-05-28 02:46:17 UTC (rev 203)
@@ -21,48 +21,62 @@
*/
package org.jboss.dna.spi.sequencers;
-import java.io.InputStream;
-import java.util.Calendar;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* Interface for sequencers to use to generate their output.
- *
* @author Randall Hauch
*/
public interface SequencerOutput {
- /**
- * Set the supplied property on the supplied node.
- * <p>
- * The allowable values are any of the following:
- * <ul>
- * <li>primitives (which will be autoboxed)</li>
- * <li>{@link String} instances</li>
- * <li>{@link String} arrays</li>
- * <li>byte arrays</li>
- * <li>{@link InputStream} instances</li>
- * <li>{@link Calendar} instances</li>
- * <li></li>
- * </ul>
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param property the name of the property to be set
- * @param values the value(s) for the property; may be empty if any existing property is to be removed
- */
- void setProperty( String nodePath,
- String property,
- Object... values );
+ /**
+ * Get the factories that can be used to create {@link Path paths} and other property values.
+ * @return the collection of factories; never null
+ */
+ ValueFactories getFactories();
- /**
- * Set the supplied reference on the supplied node.
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param property the name of the property to be set
- * @param paths the paths to the referenced property, which may be absolute paths or relative to the sequencer output node;
- * may be empty if any existing property is to be removed
- */
- void setReference( String nodePath,
- String property,
- String... paths );
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
+ * </p>
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property is to be removed
+ */
+ void setProperty( String nodePath, String propertyName, Object... values );
+
+ /**
+ * Set the supplied reference on the supplied node.
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
+ * </p>
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param paths the paths to the referenced property, which may be absolute paths or relative to the sequencer output node;
+ * may be empty if any existing property is to be removed
+ */
+ void setReference( String nodePath, String propertyName, String... paths );
+
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property is to be removed
+ */
+ void setProperty( Path nodePath, Name propertyName, Object... values );
}
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-05-27 21:50:04 UTC (rev 202)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-05-28 02:46:17 UTC (rev 203)
@@ -24,6 +24,11 @@
import java.util.HashMap;
import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* @author Randall Hauch
@@ -31,22 +36,30 @@
@NotThreadSafe
public class MockSequencerOutput implements SequencerOutput {
- private final Map<String, Object[]> properties;
- private final Map<String, String[]> references;
+ private final Map<Path, Object[]> properties;
+ private final ValueFactories factories;
/**
- *
+ * @param factories the factories to be used to create output property values
*/
- public MockSequencerOutput() {
- this.properties = new HashMap<String, Object[]>();
- this.references = new HashMap<String, String[]>();
+ public MockSequencerOutput( ValueFactories factories ) {
+ ArgCheck.isNotNull(factories, "factories");
+ this.properties = new HashMap<Path, Object[]>();
+ this.factories = factories;
}
/**
* {@inheritDoc}
*/
- public void setProperty( String nodePath, String property, Object... values ) {
- String key = getKey(nodePath, property);
+ public ValueFactories getFactories() {
+ return this.factories;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Path nodePath, Name propertyName, Object... values ) {
+ Path key = getKey(nodePath, propertyName);
if (values == null || values.length == 0) {
this.properties.remove(key);
} else {
@@ -57,45 +70,52 @@
/**
* {@inheritDoc}
*/
- public void setReference( String nodePath, String property, String... paths ) {
- String key = getKey(nodePath, property);
- if (paths == null || paths.length == 0) {
- this.references.remove(key);
- } else {
- this.references.put(key, paths);
+ public void setProperty( String nodePath, String propertyName, Object... values ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ setProperty(path, name, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setReference( String nodePath, String propertyName, String... paths ) {
+ PathFactory pathFactory = this.factories.getPathFactory();
+ Path path = pathFactory.create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ Object[] values = null;
+ if (paths != null && paths.length != 0) {
+ values = new Path[paths.length];
+ for (int i = 0, len = paths.length; i != len; ++i) {
+ String pathValue = paths[i];
+ values[i] = pathFactory.create(pathValue);
+ }
}
+ setProperty(path, name, values);
}
public Object[] getPropertyValues( String nodePath, String property ) {
- String key = getKey(nodePath, property);
+ Path key = getKey(nodePath, property);
return this.properties.get(key);
}
- public String[] getReferenceValues( String nodePath, String property ) {
- String key = getKey(nodePath, property);
- return this.references.get(key);
- }
-
public boolean hasProperty( String nodePath, String property ) {
- String key = nodePath + "@" + property;
+ Path key = getKey(nodePath, property);
return this.properties.containsKey(key);
}
- public boolean hasReference( String nodePath, String property ) {
- String key = nodePath + "@" + property;
- return this.references.containsKey(key);
- }
-
public boolean hasProperties() {
return this.properties.size() > 0;
}
- public boolean hasReferences() {
- return this.references.size() > 0;
+ protected Path getKey( String nodePath, String propertyName ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ return getKey(path, name);
}
- protected String getKey( String nodePath, String property ) {
- return nodePath + "@" + property;
+ protected Path getKey( Path nodePath, Name propertyName ) {
+ return this.factories.getPathFactory().create(nodePath, propertyName);
}
}
Modified: branches/federation/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
===================================================================
--- branches/federation/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-05-27 21:50:04 UTC (rev 202)
+++ branches/federation/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-05-28 02:46:17 UTC (rev 203)
@@ -23,6 +23,9 @@
import java.io.InputStream;
import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -99,21 +102,25 @@
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
+ NameFactory nameFactory = output.getFactories().getNameFactory();
+ PathFactory pathFactory = output.getFactories().getPathFactory();
+ Path metadataNode = pathFactory.create(METADATA_NODE);
+
// Place the image metadata into the output map ...
- output.setProperty(METADATA_NODE, IMAGE_PRIMARY_TYPE, "image:metadata");
- // output.psetProperty(METADATA_NODE, IMAGE_MIXINS, "");
- output.setProperty(METADATA_NODE, IMAGE_MIME_TYPE, metadata.getMimeType());
- // output.setProperty(METADATA_NODE, IMAGE_ENCODING, "");
- output.setProperty(METADATA_NODE, IMAGE_FORMAT_NAME, metadata.getFormatName());
- output.setProperty(METADATA_NODE, IMAGE_WIDTH, metadata.getWidth());
- output.setProperty(METADATA_NODE, IMAGE_HEIGHT, metadata.getHeight());
- output.setProperty(METADATA_NODE, IMAGE_BITS_PER_PIXEL, metadata.getBitsPerPixel());
- output.setProperty(METADATA_NODE, IMAGE_PROGRESSIVE, metadata.isProgressive());
- output.setProperty(METADATA_NODE, IMAGE_NUMBER_OF_IMAGES, metadata.getNumberOfImages());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_WIDTH_DPI, metadata.getPhysicalWidthDpi());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_HEIGHT_DPI, metadata.getPhysicalHeightDpi());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_WIDTH_INCHES, metadata.getPhysicalWidthInch());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_HEIGHT_INCHES, metadata.getPhysicalHeightInch());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PRIMARY_TYPE), "image:metadata");
+ // output.psetProperty(metadataNode, nameFactory.create(IMAGE_MIXINS), "");
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_MIME_TYPE), metadata.getMimeType());
+ // output.setProperty(metadataNode, nameFactory.create(IMAGE_ENCODING), "");
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_FORMAT_NAME), metadata.getFormatName());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_WIDTH), metadata.getWidth());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_HEIGHT), metadata.getHeight());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_BITS_PER_PIXEL), metadata.getBitsPerPixel());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PROGRESSIVE), metadata.isProgressive());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_NUMBER_OF_IMAGES), metadata.getNumberOfImages());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_WIDTH_DPI), metadata.getPhysicalWidthDpi());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_HEIGHT_DPI), metadata.getPhysicalHeightDpi());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_WIDTH_INCHES), metadata.getPhysicalWidthInch());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_HEIGHT_INCHES), metadata.getPhysicalHeightInch());
}
progressMonitor.done();
Modified: branches/federation/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
--- branches/federation/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-05-27 21:50:04 UTC (rev 202)
+++ branches/federation/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-05-28 02:46:17 UTC (rev 203)
@@ -30,6 +30,9 @@
import java.net.URL;
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.impl.BasicNamespaceRegistry;
+import org.jboss.dna.spi.graph.impl.StandardValueFactories;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
import org.junit.After;
import org.junit.Before;
@@ -52,7 +55,12 @@
@Before
public void beforeEach() throws Exception {
this.sequencer = new ImageMetadataSequencer();
- this.output = new MockSequencerOutput();
+ NamespaceRegistry registry = new BasicNamespaceRegistry();
+ registry.register("image", "http://jboss.org/dna/images/1.0");
+ registry.register("jcr", "http://www.jcp.org/jcr/1.0");
+ registry.register("nt", "http://www.jcp.org/jcr/nt/1.0");
+ registry.register("mix", "http://www.jcp.org/jcr/mix/1.0");
+ this.output = new MockSequencerOutput(new StandardValueFactories(registry));
this.progress = new SimpleProgressMonitor("Test activity");
this.cautionGif = this.getClass().getClassLoader().getResource("caution.gif");
this.cautionJpg = this.getClass().getClassLoader().getResource("caution.jpg");
@@ -90,7 +98,6 @@
assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {72}));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])).doubleValue(), is(closeTo(0.666667d, 0.0001d)));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])).doubleValue(), is(closeTo(0.666667d, 0.0001d)));
- assertThat(output.hasReferences(), is(false));
}
@Test
@@ -112,7 +119,6 @@
assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {-1}));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])), is(-1f));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])), is(-1f));
- assertThat(output.hasReferences(), is(false));
}
@Test
@@ -133,7 +139,6 @@
assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {-1}));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])), is(-1f));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])), is(-1f));
- assertThat(output.hasReferences(), is(false));
}
@Test
@@ -144,7 +149,6 @@
assertThat(content, is(notNullValue()));
sequencer.sequence(content, output, progress);
assertThat(output.hasProperties(), is(false));
- assertThat(output.hasReferences(), is(false));
}
}
15 years, 11 months
DNA SVN: r202 - trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-27 17:50:04 -0400 (Tue, 27 May 2008)
New Revision: 202
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
Log:
DNA-77: SequencerOutput setProperty and setReference method signatures need to be changed
http://jira.jboss.org/jira/browse/DNA-77
Minor change to correctly convert SPI graph property values to JCR property values.
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-27 21:31:52 UTC (rev 201)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-27 21:50:04 UTC (rev 202)
@@ -22,7 +22,9 @@
package org.jboss.dna.repository.sequencers;
import java.io.InputStream;
+import java.math.BigDecimal;
import java.util.Calendar;
+import java.util.Date;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
@@ -35,6 +37,8 @@
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.ExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
@@ -209,6 +213,8 @@
targetNode.setProperty(propertyName, ((Boolean)value).booleanValue());
} else if (value instanceof String) {
targetNode.setProperty(propertyName, (String)value);
+ } else if (value instanceof String[]) {
+ targetNode.setProperty(propertyName, (String[])value);
} else if (value instanceof Integer) {
targetNode.setProperty(propertyName, ((Integer)value).intValue());
} else if (value instanceof Short) {
@@ -219,8 +225,27 @@
targetNode.setProperty(propertyName, ((Float)value).floatValue());
} else if (value instanceof Double) {
targetNode.setProperty(propertyName, ((Double)value).doubleValue());
+ } else if (value instanceof Binary) {
+ Binary binaryValue = (Binary)value;
+ try {
+ binaryValue.acquire();
+ targetNode.setProperty(propertyName, binaryValue.getStream());
+ } finally {
+ binaryValue.release();
+ }
+ } else if (value instanceof BigDecimal) {
+ targetNode.setProperty(propertyName, ((BigDecimal)value).doubleValue());
+ } else if (value instanceof DateTime) {
+ targetNode.setProperty(propertyName, ((DateTime)value).toCalendar());
+ } else if (value instanceof Date) {
+ DateTime instant = context.getValueFactories().getDateFactory().create((Date)value);
+ targetNode.setProperty(propertyName, instant.toCalendar());
} else if (value instanceof Calendar) {
targetNode.setProperty(propertyName, (Calendar)value);
+ } else if (value instanceof Name) {
+ Name nameValue = (Name)value;
+ String stringValue = nameValue.getString(namespaceRegistry);
+ targetNode.setProperty(propertyName, stringValue);
} else if (value instanceof Path) {
// Find the path to reference node ...
Path pathToReferencedNode = (Path)value;
15 years, 11 months
DNA SVN: r201 - in trunk: dna-repository/src/test/java/org/jboss/dna/repository/sequencers and 4 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-27 17:31:52 -0400 (Tue, 27 May 2008)
New Revision: 201
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
Log:
DNA-77: SequencerOutput setProperty and setReference method signatures need to be changed
http://jira.jboss.org/jira/browse/DNA-77
Added two methods to the SequencerOutput interface: a method to obtain the org.jboss.dna.spi.graph.ValueFactories instance that can be used to create paths, names, and other value objects (like binary objects, date-time instants, strings, doubles, etc.); and a method to set the property values using a Path object for the node path, and a Name object for the property name. The Path, Name, DateTime, Reference, Binary, ValueFactory, and ValueFactories interfaces are all part of the SPI, and will be used by the federation engine, connectors, and (now) sequencers. The existing SequencerOutput methods (that take string paths and names) simply create the Path and Name objects and then delegate to the new method.
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java 2008-05-27 19:54:50 UTC (rev 200)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java 2008-05-27 21:31:52 UTC (rev 201)
@@ -32,8 +32,10 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.ValueFactories;
import org.jboss.dna.spi.sequencers.SequencerOutput;
/**
@@ -48,37 +50,45 @@
private static final String JCR_NAME_PROPERTY_NAME = "jcr:name";
private final Map<Path, List<PropertyValue>> data;
- private boolean valuesSorted = true;
- private final PathFactory pathFactory;
+ private transient boolean valuesSorted = true;
+ private final ValueFactories factories;
+ private final Name jcrName;
- public SequencerOutputMap( PathFactory pathFactory ) {
- ArgCheck.isNotNull(pathFactory, "pathFactory");
+ public SequencerOutputMap( ValueFactories factories ) {
+ ArgCheck.isNotNull(factories, "factories");
this.data = new HashMap<Path, List<PropertyValue>>();
- this.pathFactory = pathFactory;
+ this.factories = factories;
+ this.jcrName = this.factories.getNameFactory().create(JCR_NAME_PROPERTY_NAME);
}
/**
* {@inheritDoc}
*/
- public void setProperty( String nodePath, String property, Object... values ) {
- property = property.trim();
- if (JCR_NAME_PROPERTY_NAME.equals(property)) return; // ignore the "jcr:name" property
- nodePath = nodePath.trim();
- if (nodePath.endsWith("/")) nodePath = nodePath.replaceFirst("/+$", "");
+ public ValueFactories getFactories() {
+ return this.factories;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Path nodePath, Name propertyName, Object... values ) {
+ ArgCheck.isNotNull(nodePath, "nodePath");
+ ArgCheck.isNotNull(propertyName, "property");
+ // Ignore the "jcr:name" property, as that's handled by the path ...
+ if (this.jcrName.equals(propertyName)) return;
+
// Find or create the entry for this node ...
- Path path = pathFactory.create(nodePath);
- List<PropertyValue> properties = this.data.get(path);
+ List<PropertyValue> properties = this.data.get(nodePath);
if (properties == null) {
if (values == null || values.length == 0) return; // do nothing
properties = new ArrayList<PropertyValue>();
- this.data.put(path, properties);
+ this.data.put(nodePath, properties);
}
if (values == null || values.length == 0) {
- properties.remove(new PropertyValue(property, null));
+ properties.remove(new PropertyValue(propertyName, null));
} else {
Object propValue = values.length == 1 ? values[0] : values;
- PropertyValue value = new PropertyValue(property, propValue);
+ PropertyValue value = new PropertyValue(propertyName, propValue);
properties.add(value);
valuesSorted = false;
}
@@ -87,18 +97,30 @@
/**
* {@inheritDoc}
*/
- public void setReference( String nodePath, String property, String... paths ) {
- if (paths == null || paths.length == 0) {
- setProperty(nodePath, property, (Object[])null);
- } else if (paths.length == 1) {
- setProperty(nodePath, property, pathFactory.create(paths[0]));
- } else {
- Path[] pathsArray = new Path[paths.length];
- for (int i = 0; i != paths.length; ++i) {
- pathsArray[i] = pathFactory.create(paths[i]);
+ public void setProperty( String nodePath, String property, Object... values ) {
+ ArgCheck.isNotEmpty(nodePath, "nodePath");
+ ArgCheck.isNotEmpty(property, "property");
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name propertyName = this.factories.getNameFactory().create(property);
+ setProperty(path, propertyName, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setReference( String nodePath, String propertyName, String... paths ) {
+ PathFactory pathFactory = this.factories.getPathFactory();
+ Path path = pathFactory.create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ Object[] values = null;
+ if (paths != null && paths.length != 0) {
+ values = new Path[paths.length];
+ for (int i = 0, len = paths.length; i != len; ++i) {
+ String pathValue = paths[i];
+ values[i] = pathFactory.create(pathValue);
}
- setProperty(nodePath, property, (Object[])pathsArray);
}
+ setProperty(path, name, values);
}
/**
@@ -167,10 +189,10 @@
@Immutable
public class PropertyValue implements Comparable<PropertyValue> {
- private final String name;
+ private final Name name;
private final Object value;
- protected PropertyValue( String propertyName, Object value ) {
+ protected PropertyValue( Name propertyName, Object value ) {
this.name = propertyName;
this.value = value;
}
@@ -179,7 +201,7 @@
* Get the property name.
* @return the property name; never null
*/
- public String getName() {
+ public Name getName() {
return this.name;
}
@@ -241,7 +263,7 @@
public class Entry {
private final Path path;
- private final String primaryType;
+ private final Name primaryType;
private final List<PropertyValue> properties;
protected Entry( Path path, List<PropertyValue> properties ) {
@@ -251,7 +273,7 @@
this.properties = properties;
if (this.properties.size() > 0 && this.properties.get(0).getName().equals("jcr:primaryType")) {
PropertyValue primaryTypeProperty = this.properties.remove(0);
- this.primaryType = primaryTypeProperty.getValue().toString();
+ this.primaryType = getFactories().getNameFactory().create(primaryTypeProperty.getValue());
} else {
this.primaryType = null;
}
@@ -268,7 +290,7 @@
* Get the primary type specified for this node, or null if the type was not specified
* @return the primary type, or null
*/
- public String getPrimaryTypeValue() {
+ public Name getPrimaryTypeValue() {
return this.primaryType;
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-27 19:54:50 UTC (rev 200)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-27 21:31:52 UTC (rev 201)
@@ -35,6 +35,7 @@
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.ExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
+import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
@@ -90,7 +91,7 @@
progressMonitor.worked(10);
// Get the binary property with the image content, and build the image metadata from the image ...
- SequencerOutputMap output = new SequencerOutputMap(context.getValueFactories().getPathFactory());
+ SequencerOutputMap output = new SequencerOutputMap(context.getValueFactories());
InputStream stream = null;
Throwable firstError = null;
ProgressMonitor sequencingMonitor = progressMonitor.createSubtask(50);
@@ -169,7 +170,7 @@
// prefix and name)
for (SequencerOutputMap.Entry entry : output) {
Path targetNodePath = entry.getPath();
- String primaryType = entry.getPrimaryTypeValue();
+ Name primaryType = entry.getPrimaryTypeValue();
// Resolve this path relative to the output node path, handling any parent or self references ...
Path absolutePath = targetNodePath.isAbsolute() ? targetNodePath : outputNodePath.resolve(targetNodePath);
@@ -190,7 +191,7 @@
}
// We only have the primary type for the final one ...
if (i == (max - 1) && primaryType != null) {
- targetNode = targetNode.addNode(qualifiedName, primaryType);
+ targetNode = targetNode.addNode(qualifiedName, primaryType.getString(namespaceRegistry, Path.NO_OP_ENCODER));
} else {
targetNode = targetNode.addNode(qualifiedName);
}
@@ -201,7 +202,7 @@
// Set all of the properties on this
for (SequencerOutputMap.PropertyValue property : entry.getPropertyValues()) {
- String propertyName = property.getName();
+ String propertyName = property.getName().getString(namespaceRegistry, Path.NO_OP_ENCODER);
Object value = property.getValue();
Logger.getLogger(this.getClass()).trace("Writing property {0}/{1}={2}", targetNode.getPath(), propertyName, value);
if (value instanceof Boolean) {
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-05-27 19:54:50 UTC (rev 200)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-05-27 21:31:52 UTC (rev 201)
@@ -39,16 +39,14 @@
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.RecordingProgressMonitor;
import org.jboss.dna.repository.observation.NodeChange;
-import org.jboss.dna.repository.sequencers.SequencerConfig;
-import org.jboss.dna.repository.sequencers.SequencerException;
-import org.jboss.dna.repository.sequencers.SequencerOutputMap;
-import org.jboss.dna.repository.sequencers.StreamSequencerAdapter;
import org.jboss.dna.repository.util.ExecutionContext;
+import org.jboss.dna.repository.util.JcrNamespaceRegistry;
import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.RepositoryNodePath;
import org.jboss.dna.repository.util.SessionFactory;
import org.jboss.dna.repository.util.SimpleExecutionContext;
-import org.jboss.dna.spi.graph.impl.BasicNamespaceRegistry;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
import org.junit.After;
@@ -82,8 +80,9 @@
return createTestSession();
}
};
- this.context = new SimpleExecutionContext(sessionFactory, new BasicNamespaceRegistry(), null);
- this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories().getPathFactory());
+ NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory, "doesn't matter");
+ this.context = new SimpleExecutionContext(sessionFactory, registry, null);
+ this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories());
this.progressMonitor = new RecordingProgressMonitor(StreamSequencerAdapterTest.class.getName());
final SequencerOutputMap finalOutput = sequencerOutput;
this.streamSequencer = new StreamSequencer() {
@@ -94,7 +93,7 @@
*/
public void sequence( InputStream stream, SequencerOutput output, ProgressMonitor progressMonitor ) {
for (SequencerOutputMap.Entry entry : finalOutput) {
- String nodePath = entry.getPath().getString();
+ Path nodePath = entry.getPath();
for (SequencerOutputMap.PropertyValue property : entry.getPropertyValues()) {
output.setProperty(nodePath, property.getName(), property.getValue());
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-05-27 19:54:50 UTC (rev 200)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/sequencers/SequencerOutput.java 2008-05-27 21:31:52 UTC (rev 201)
@@ -21,48 +21,62 @@
*/
package org.jboss.dna.spi.sequencers;
-import java.io.InputStream;
-import java.util.Calendar;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* Interface for sequencers to use to generate their output.
- *
* @author Randall Hauch
*/
public interface SequencerOutput {
- /**
- * Set the supplied property on the supplied node.
- * <p>
- * The allowable values are any of the following:
- * <ul>
- * <li>primitives (which will be autoboxed)</li>
- * <li>{@link String} instances</li>
- * <li>{@link String} arrays</li>
- * <li>byte arrays</li>
- * <li>{@link InputStream} instances</li>
- * <li>{@link Calendar} instances</li>
- * <li></li>
- * </ul>
- * </p>
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param property the name of the property to be set
- * @param values the value(s) for the property; may be empty if any existing property is to be removed
- */
- void setProperty( String nodePath,
- String property,
- Object... values );
+ /**
+ * Get the factories that can be used to create {@link Path paths} and other property values.
+ * @return the collection of factories; never null
+ */
+ ValueFactories getFactories();
- /**
- * Set the supplied reference on the supplied node.
- *
- * @param nodePath the path to the node containing the property; may not be null
- * @param property the name of the property to be set
- * @param paths the paths to the referenced property, which may be absolute paths or relative to the sequencer output node;
- * may be empty if any existing property is to be removed
- */
- void setReference( String nodePath,
- String property,
- String... paths );
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
+ * </p>
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property is to be removed
+ */
+ void setProperty( String nodePath, String propertyName, Object... values );
+
+ /**
+ * Set the supplied reference on the supplied node.
+ * <p>
+ * This method is provided as a convenience, but it identical to creating a {@link Path} and {@link Name} using the
+ * {@link #getFactories() factories} and calling {@link #setProperty(Path, Name, Object...)}.
+ * </p>
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param paths the paths to the referenced property, which may be absolute paths or relative to the sequencer output node;
+ * may be empty if any existing property is to be removed
+ */
+ void setReference( String nodePath, String propertyName, String... paths );
+
+ /**
+ * Set the supplied property on the supplied node.
+ * <p>
+ * The {@link #getFactories() value factories} should be used to create paths, names, and values. These factories can be used
+ * to create new values or convert values from one property type to another. (Note that each of the factories have methods
+ * that create values from all of the property types.)
+ * </p>
+ * @param nodePath the path to the node containing the property; may not be null
+ * @param propertyName the name of the property to be set
+ * @param values the value(s) for the property; may be empty if any existing property is to be removed
+ */
+ void setProperty( Path nodePath, Name propertyName, Object... values );
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-05-27 19:54:50 UTC (rev 200)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java 2008-05-27 21:31:52 UTC (rev 201)
@@ -24,6 +24,11 @@
import java.util.HashMap;
import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* @author Randall Hauch
@@ -31,22 +36,30 @@
@NotThreadSafe
public class MockSequencerOutput implements SequencerOutput {
- private final Map<String, Object[]> properties;
- private final Map<String, String[]> references;
+ private final Map<Path, Object[]> properties;
+ private final ValueFactories factories;
/**
- *
+ * @param factories the factories to be used to create output property values
*/
- public MockSequencerOutput() {
- this.properties = new HashMap<String, Object[]>();
- this.references = new HashMap<String, String[]>();
+ public MockSequencerOutput( ValueFactories factories ) {
+ ArgCheck.isNotNull(factories, "factories");
+ this.properties = new HashMap<Path, Object[]>();
+ this.factories = factories;
}
/**
* {@inheritDoc}
*/
- public void setProperty( String nodePath, String property, Object... values ) {
- String key = getKey(nodePath, property);
+ public ValueFactories getFactories() {
+ return this.factories;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Path nodePath, Name propertyName, Object... values ) {
+ Path key = getKey(nodePath, propertyName);
if (values == null || values.length == 0) {
this.properties.remove(key);
} else {
@@ -57,45 +70,52 @@
/**
* {@inheritDoc}
*/
- public void setReference( String nodePath, String property, String... paths ) {
- String key = getKey(nodePath, property);
- if (paths == null || paths.length == 0) {
- this.references.remove(key);
- } else {
- this.references.put(key, paths);
+ public void setProperty( String nodePath, String propertyName, Object... values ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ setProperty(path, name, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setReference( String nodePath, String propertyName, String... paths ) {
+ PathFactory pathFactory = this.factories.getPathFactory();
+ Path path = pathFactory.create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ Object[] values = null;
+ if (paths != null && paths.length != 0) {
+ values = new Path[paths.length];
+ for (int i = 0, len = paths.length; i != len; ++i) {
+ String pathValue = paths[i];
+ values[i] = pathFactory.create(pathValue);
+ }
}
+ setProperty(path, name, values);
}
public Object[] getPropertyValues( String nodePath, String property ) {
- String key = getKey(nodePath, property);
+ Path key = getKey(nodePath, property);
return this.properties.get(key);
}
- public String[] getReferenceValues( String nodePath, String property ) {
- String key = getKey(nodePath, property);
- return this.references.get(key);
- }
-
public boolean hasProperty( String nodePath, String property ) {
- String key = nodePath + "@" + property;
+ Path key = getKey(nodePath, property);
return this.properties.containsKey(key);
}
- public boolean hasReference( String nodePath, String property ) {
- String key = nodePath + "@" + property;
- return this.references.containsKey(key);
- }
-
public boolean hasProperties() {
return this.properties.size() > 0;
}
- public boolean hasReferences() {
- return this.references.size() > 0;
+ protected Path getKey( String nodePath, String propertyName ) {
+ Path path = this.factories.getPathFactory().create(nodePath);
+ Name name = this.factories.getNameFactory().create(propertyName);
+ return getKey(path, name);
}
- protected String getKey( String nodePath, String property ) {
- return nodePath + "@" + property;
+ protected Path getKey( Path nodePath, Name propertyName ) {
+ return this.factories.getPathFactory().create(nodePath, propertyName);
}
}
Modified: trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-05-27 19:54:50 UTC (rev 200)
+++ trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-05-27 21:31:52 UTC (rev 201)
@@ -23,6 +23,9 @@
import java.io.InputStream;
import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
@@ -99,21 +102,25 @@
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
+ NameFactory nameFactory = output.getFactories().getNameFactory();
+ PathFactory pathFactory = output.getFactories().getPathFactory();
+ Path metadataNode = pathFactory.create(METADATA_NODE);
+
// Place the image metadata into the output map ...
- output.setProperty(METADATA_NODE, IMAGE_PRIMARY_TYPE, "image:metadata");
- // output.psetProperty(METADATA_NODE, IMAGE_MIXINS, "");
- output.setProperty(METADATA_NODE, IMAGE_MIME_TYPE, metadata.getMimeType());
- // output.setProperty(METADATA_NODE, IMAGE_ENCODING, "");
- output.setProperty(METADATA_NODE, IMAGE_FORMAT_NAME, metadata.getFormatName());
- output.setProperty(METADATA_NODE, IMAGE_WIDTH, metadata.getWidth());
- output.setProperty(METADATA_NODE, IMAGE_HEIGHT, metadata.getHeight());
- output.setProperty(METADATA_NODE, IMAGE_BITS_PER_PIXEL, metadata.getBitsPerPixel());
- output.setProperty(METADATA_NODE, IMAGE_PROGRESSIVE, metadata.isProgressive());
- output.setProperty(METADATA_NODE, IMAGE_NUMBER_OF_IMAGES, metadata.getNumberOfImages());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_WIDTH_DPI, metadata.getPhysicalWidthDpi());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_HEIGHT_DPI, metadata.getPhysicalHeightDpi());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_WIDTH_INCHES, metadata.getPhysicalWidthInch());
- output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_HEIGHT_INCHES, metadata.getPhysicalHeightInch());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PRIMARY_TYPE), "image:metadata");
+ // output.psetProperty(metadataNode, nameFactory.create(IMAGE_MIXINS), "");
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_MIME_TYPE), metadata.getMimeType());
+ // output.setProperty(metadataNode, nameFactory.create(IMAGE_ENCODING), "");
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_FORMAT_NAME), metadata.getFormatName());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_WIDTH), metadata.getWidth());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_HEIGHT), metadata.getHeight());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_BITS_PER_PIXEL), metadata.getBitsPerPixel());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PROGRESSIVE), metadata.isProgressive());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_NUMBER_OF_IMAGES), metadata.getNumberOfImages());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_WIDTH_DPI), metadata.getPhysicalWidthDpi());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_HEIGHT_DPI), metadata.getPhysicalHeightDpi());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_WIDTH_INCHES), metadata.getPhysicalWidthInch());
+ output.setProperty(metadataNode, nameFactory.create(IMAGE_PHYSICAL_HEIGHT_INCHES), metadata.getPhysicalHeightInch());
}
progressMonitor.done();
Modified: trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-05-27 19:54:50 UTC (rev 200)
+++ trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-05-27 21:31:52 UTC (rev 201)
@@ -30,6 +30,9 @@
import java.net.URL;
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.impl.BasicNamespaceRegistry;
+import org.jboss.dna.spi.graph.impl.StandardValueFactories;
import org.jboss.dna.spi.sequencers.MockSequencerOutput;
import org.junit.After;
import org.junit.Before;
@@ -52,7 +55,12 @@
@Before
public void beforeEach() throws Exception {
this.sequencer = new ImageMetadataSequencer();
- this.output = new MockSequencerOutput();
+ NamespaceRegistry registry = new BasicNamespaceRegistry();
+ registry.register("image", "http://jboss.org/dna/images/1.0");
+ registry.register("jcr", "http://www.jcp.org/jcr/1.0");
+ registry.register("nt", "http://www.jcp.org/jcr/nt/1.0");
+ registry.register("mix", "http://www.jcp.org/jcr/mix/1.0");
+ this.output = new MockSequencerOutput(new StandardValueFactories(registry));
this.progress = new SimpleProgressMonitor("Test activity");
this.cautionGif = this.getClass().getClassLoader().getResource("caution.gif");
this.cautionJpg = this.getClass().getClassLoader().getResource("caution.jpg");
@@ -90,7 +98,6 @@
assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {72}));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])).doubleValue(), is(closeTo(0.666667d, 0.0001d)));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])).doubleValue(), is(closeTo(0.666667d, 0.0001d)));
- assertThat(output.hasReferences(), is(false));
}
@Test
@@ -112,7 +119,6 @@
assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {-1}));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])), is(-1f));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])), is(-1f));
- assertThat(output.hasReferences(), is(false));
}
@Test
@@ -133,7 +139,6 @@
assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {-1}));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])), is(-1f));
assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])), is(-1f));
- assertThat(output.hasReferences(), is(false));
}
@Test
@@ -144,7 +149,6 @@
assertThat(content, is(notNullValue()));
sequencer.sequence(content, output, progress);
assertThat(output.hasProperties(), is(false));
- assertThat(output.hasReferences(), is(false));
}
}
15 years, 11 months
DNA SVN: r199 - in branches/federation: dna-spi/src/main/java/org/jboss/dna/spi/graph and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-27 15:24:32 -0400 (Tue, 27 May 2008)
New Revision: 199
Added:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java
Modified:
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added and refined documentation. Added more unit tests. Added modification methods to the NamespaceRegistry interface.
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -21,6 +21,9 @@
*/
package org.jboss.dna.repository.util;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.jboss.dna.common.util.ArgCheck;
@@ -79,7 +82,7 @@
/**
* {@inheritDoc}
*/
- public String getPrefixForNamespaceUri( String namespaceUri ) {
+ public String getPrefixForNamespaceUri( String namespaceUri, boolean generateIfMissing ) {
Session session = null;
try {
session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
@@ -113,4 +116,47 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ public String register( String prefix, String namespaceUri ) {
+ String previousNamespaceUriForPrefix = null;
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ previousNamespaceUriForPrefix = session.getNamespacePrefix(namespaceUri);
+ javax.jcr.NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
+ registry.registerNamespace(prefix, namespaceUri);
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ return previousNamespaceUriForPrefix;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getRegisteredNamespaceUris() {
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ javax.jcr.NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
+ Set<String> result = new HashSet<String>();
+ for (String uri : registry.getURIs()) {
+ result.add(uri);
+ }
+ return Collections.unmodifiableSet(result);
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -23,13 +23,13 @@
import java.io.InputStream;
import java.io.Serializable;
-import net.jcip.annotations.ThreadSafe;
+import net.jcip.annotations.Immutable;
/**
- * Value holder for binary data.
+ * Value holder for binary data. Binary instances are not mutable.
* @author Randall Hauch
*/
-@ThreadSafe
+@Immutable
public interface Binary extends Comparable<Binary>, Serializable {
/**
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.util.Locale;
+import net.jcip.annotations.Immutable;
/**
* An immutable date-time class that represents an instance in time. This class is designed to hide the horrible implementations
@@ -32,6 +33,7 @@
* classes.
* @author Randall Hauch
*/
+@Immutable
public interface DateTime extends Comparable<DateTime>, Serializable {
/**
@@ -164,4 +166,31 @@
* @return the milliseconds
*/
int getMillisOfSecond();
+
+ /**
+ * Get the number of hours that this time zone is offset from UTC.
+ * @return the number of hours
+ */
+ int getTimeZoneOffsetHours();
+
+ /**
+ * Get the identifier of the time zone in which this instant is defined
+ * @return the time zone identifier; never null
+ */
+ String getTimeZoneId();
+
+ /**
+ * Convert this time to the same instant in the UTC time zone.
+ * @return this instant in time in the specified time zone
+ */
+ DateTime toUtcTimeZone();
+
+ /**
+ * Convert this time to the time zone given by the supplied identifier.
+ * @param timeZoneId the time zone identifier
+ * @return the instant in the specified time zone
+ * @throws IllegalArgumentException if the time zone identifier is null or is invalid
+ */
+ DateTime toTimeZone( String timeZoneId );
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -21,9 +21,14 @@
*/
package org.jboss.dna.spi.graph;
+import java.util.Set;
+import net.jcip.annotations.ThreadSafe;
+
/**
+ * Registry of namespaces, which are used to provide isolated and independent domains for {@link Name names}.
* @author Randall Hauch
*/
+@ThreadSafe
public interface NamespaceRegistry {
/**
@@ -41,21 +46,38 @@
String getNamespaceForPrefix( String prefix );
/**
- * Return the prefix used for the supplied namespace URI. In effect, every URI should have a corresponding prefix, even if
- * that prefix is automatically generated. Therefore,
- * @param namespaceUri
+ * Return the prefix used for the supplied namespace URI.
+ * @param namespaceUri the namespace URI
+ * @param generateIfMissing true if the namespace URI has not already been registered and the method should auto-register the
+ * namespace with a generated prefix, or false if the method should never auto-register the namespace
* @return the prefix currently being used for the namespace; never null but possibly empty for the default namespace
* @throws IllegalArgumentException if the namespace URI is null
+ * @see #isRegisteredNamespaceUri(String)
*/
- String getPrefixForNamespaceUri( String namespaceUri );
+ String getPrefixForNamespaceUri( String namespaceUri, boolean generateIfMissing );
/**
- * Return whether there is a registered prefix for the supplied namespace URI. Those namespace URIs that have not been
- * registered may result in {@link #getPrefixForNamespaceUri(String) automatically generated prefixes}.
+ * Return whether there is a registered prefix for the supplied namespace URI.
* @param namespaceUri the namespace URI
* @return true if the supplied namespace has been registered with a prefix, or false otherwise
* @throws IllegalArgumentException if the namespace URI is null
*/
boolean isRegisteredNamespaceUri( String namespaceUri );
+ /**
+ * Register a new namespace using the supplied prefix, returning the namespace URI previously registered under that prefix.
+ * @param prefix the prefix for the namespace, or null if a namesapce prefix should be generated automatically
+ * @param namespaceUri the namespace URI
+ * @return the namespace URI that was previously registered with the supplied prefix, or null if the prefix was not previously
+ * bound to a namespace URI
+ * @throws IllegalArgumentException if the namespace URI is null
+ */
+ String register( String prefix, String namespaceUri );
+
+ /**
+ * Obtain the set of namespaces that are registered.
+ * @return the set of
+ */
+ Set<String> getRegisteredNamespaceUris();
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -195,6 +195,370 @@
}
/**
+ * Singleton instance of the name referencing a self, provided as a convenience.
+ */
+ public static final Name SELF_NAME = new Name() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLocalName() {
+ return SELF;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceUri() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return encoder.encode(SELF);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return getString(namespaceRegistry, DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ return encoder.encode(SELF);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Name that ) {
+ if (this == that) return 0;
+ int diff = this.getLocalName().compareTo(that.getLocalName());
+ if (diff != 0) return diff;
+ return this.getNamespaceUri().compareTo(that.getNamespaceUri());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Name) {
+ Name that = (Name)obj;
+ if (!this.getLocalName().equals(that.getLocalName())) return false;
+ return this.getNamespaceUri().equals(that.getNamespaceUri());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return SELF;
+ }
+
+ };
+
+ /**
+ * Singleton instance of the name referencing a parent, provided as a convenience.
+ */
+ public static final Name PARENT_NAME = new Name() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLocalName() {
+ return PARENT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceUri() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return encoder.encode(PARENT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return getString(namespaceRegistry, DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ return encoder.encode(PARENT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Name that ) {
+ if (this == that) return 0;
+ int diff = this.getLocalName().compareTo(that.getLocalName());
+ if (diff != 0) return diff;
+ return this.getNamespaceUri().compareTo(that.getNamespaceUri());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Name) {
+ Name that = (Name)obj;
+ if (!this.getLocalName().equals(that.getLocalName())) return false;
+ return this.getNamespaceUri().equals(that.getNamespaceUri());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return PARENT;
+ }
+
+ };
+
+ /**
+ * Singleton instance of the path segment referencing a parent, provided as a convenience.
+ */
+ public static final Path.Segment SELF_SEGMENT = new Path.Segment() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getIndex() {
+ return NO_INDEX;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name getName() {
+ return SELF_NAME;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return SELF_NAME.getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return SELF_NAME.getString(encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return SELF_NAME.getString(namespaceRegistry);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ return SELF_NAME.getString(namespaceRegistry, encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasIndex() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isParentReference() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSelfReference() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Segment that ) {
+ if (this == that) return 0;
+ int diff = this.getName().compareTo(that.getName());
+ if (diff != 0) return diff;
+ return this.getIndex() - that.getIndex();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Segment) {
+ Segment that = (Segment)obj;
+ if (!this.getName().equals(that.getName())) return false;
+ return this.hasIndex() == that.hasIndex();
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return SELF_NAME.toString();
+ }
+ };
+
+ /**
+ * Singleton instance of the path segment referencing a parent, provided as a convenience.
+ */
+ public static final Path.Segment PARENT_SEGMENT = new Path.Segment() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getIndex() {
+ return NO_INDEX;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name getName() {
+ return PARENT_NAME;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return PARENT_NAME.getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return PARENT_NAME.getString(encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return PARENT_NAME.getString(namespaceRegistry);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ return PARENT_NAME.getString(namespaceRegistry, encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasIndex() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isParentReference() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSelfReference() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Segment that ) {
+ if (this == that) return 0;
+ int diff = this.getName().compareTo(that.getName());
+ if (diff != 0) return diff;
+ return this.getIndex() - that.getIndex();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Segment) {
+ Segment that = (Segment)obj;
+ if (!this.getName().equals(that.getName())) return false;
+ return this.hasIndex() == that.hasIndex();
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return PARENT_NAME.toString();
+ }
+ };
+
+ /**
* Return the number of segments in this path.
* @return the number of path segments
*/
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -25,11 +25,14 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Iterator;
+import net.jcip.annotations.Immutable;
/**
- * Representation of a property consisting of a name and value(s).
+ * Representation of a property consisting of a name and value(s). Note that this property is immutable, meaning that the property
+ * values may not be changed through this interface.
* @author Randall Hauch
*/
+@Immutable
public interface Property extends Iterable<Object>, Comparable<Property> {
/**
@@ -90,6 +93,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the values; never null
* @see Iterable#iterator()
*/
@@ -102,6 +108,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @param type the property type defining the form of the values to be returned; if null, the
* {@link #getPropertyType() property's type} is used
* @return an iterator over the values; never null
@@ -114,6 +123,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the String values; never null
*/
Iterator<String> getStringValues();
@@ -124,6 +136,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the {@link Binary} values; never null
*/
Iterator<Binary> getBinaryValues();
@@ -134,6 +149,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the long values; never null
*/
Iterator<Long> getLongValues();
@@ -144,6 +162,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the double values; never null
*/
Iterator<Double> getDoubleValues();
@@ -155,6 +176,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the decimal values; never null
*/
Iterator<BigDecimal> getDecimalValues();
@@ -166,6 +190,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Calendar values; never null
*/
Iterator<Calendar> getDateValues();
@@ -177,6 +204,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Boolean values; never null
*/
Iterator<Boolean> getBooleanValues();
@@ -188,6 +218,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Name values; never null
*/
Iterator<Name> getNameValues();
@@ -199,6 +232,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Path values; never null
*/
Iterator<Path> getPathValues();
@@ -210,6 +246,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Reference values; never null
*/
Iterator<Reference> getReferenceValues();
@@ -220,6 +259,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the URI values; never null
*/
Iterator<URI> getUriValues();
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -22,11 +22,14 @@
package org.jboss.dna.spi.graph;
import java.io.Serializable;
+import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
/**
+ * A representation of a reference to another node. Node references may not necessarily resolve to an existing node.
* @author Randall Hauch
*/
+@Immutable
public interface Reference extends Comparable<Reference>, Serializable {
/**
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -84,7 +84,7 @@
*/
public String getString( NamespaceRegistry namespaceRegistry ) {
ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
- String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri, true);
if (prefix != null) {
return prefix + ":" + this.localName;
}
@@ -96,8 +96,8 @@
*/
public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
- String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
- if (prefix != null) {
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri, true);
+ if (prefix != null && prefix.length() != 0) {
return encoder.encode(prefix) + ":" + encoder.encode(this.localName);
}
return this.localName;
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -21,11 +21,16 @@
*/
package org.jboss.dna.spi.graph.impl;
+import java.text.DecimalFormat;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.NamespaceRegistry;
@@ -36,17 +41,58 @@
@ThreadSafe
public class BasicNamespaceRegistry implements NamespaceRegistry {
+ public static final String DEFAULT_NAMESPACE_URI = "";
+ public static final String DEFAULT_PREFIX_TEMPLATE = "ns##000";
+ public static final String DEFAULT_PREFIX_NUMBER_FORMAT = "##000";
+
private final ReadWriteLock registryLock = new ReentrantReadWriteLock();
private final Map<String, String> namespacesByPrefix = new HashMap<String, String>();
private final Map<String, String> prefixesByNamespace = new HashMap<String, String>();
+ private String generatedPrefixTemplate = DEFAULT_PREFIX_TEMPLATE;
+ private int nextGeneratedPrefixNumber = 1;
/**
*
*/
public BasicNamespaceRegistry() {
+ this(DEFAULT_NAMESPACE_URI);
}
/**
+ * @param defaultNamespaceUri the namespace URI to use for the default prefix
+ */
+ public BasicNamespaceRegistry( final String defaultNamespaceUri ) {
+ register("", defaultNamespaceUri);
+ }
+
+ /**
+ * @return prefixTemplate
+ */
+ public String getGeneratedPrefixTemplate() {
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ return this.generatedPrefixTemplate;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * @param prefixTemplate Sets prefixTemplate to the specified value.
+ */
+ public void setGeneratedPrefixTemplate( String prefixTemplate ) {
+ if (prefixTemplate == null) prefixTemplate = DEFAULT_PREFIX_TEMPLATE;
+ Lock lock = this.registryLock.writeLock();
+ try {
+ lock.lock();
+ this.generatedPrefixTemplate = prefixTemplate;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
public String getNamespaceForPrefix( String prefix ) {
@@ -63,15 +109,34 @@
/**
* {@inheritDoc}
*/
- public String getPrefixForNamespaceUri( String namespaceUri ) {
+ public String getPrefixForNamespaceUri( String namespaceUri, boolean generateIfMissing ) {
ArgCheck.isNotNull(namespaceUri, "namespaceUri");
+ String prefix = null;
Lock lock = this.registryLock.readLock();
try {
lock.lock();
- return this.prefixesByNamespace.get(namespaceUri);
+ prefix = this.prefixesByNamespace.get(namespaceUri);
} finally {
lock.unlock();
}
+ if (prefix == null && generateIfMissing) {
+ // Get a write lock ...
+ lock = this.registryLock.writeLock();
+ try {
+ lock.lock();
+ // Since we got a new lock, we need to check again ...
+ prefix = this.prefixesByNamespace.get(namespaceUri);
+ if (prefix == null) {
+ // Now we can genereate a prefix and register it ...
+ prefix = this.generatePrefix();
+ this.register(prefix, namespaceUri);
+ }
+ return prefix;
+ } finally {
+ lock.unlock();
+ }
+ }
+ return prefix;
}
/**
@@ -101,15 +166,18 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public String register( String prefix, String namespaceUri ) {
- ArgCheck.isNotNull(prefix, "prefix");
- ArgCheck.isNotEmpty(namespaceUri, "namespaceUri");
+ ArgCheck.isNotNull(namespaceUri, "namespaceUri");
String previousNamespaceForPrefix = null;
- prefix = prefix.trim();
namespaceUri = namespaceUri.trim();
Lock lock = this.registryLock.writeLock();
try {
lock.lock();
+ if (prefix == null) prefix = generatePrefix();
+ prefix = prefix.trim();
previousNamespaceForPrefix = this.namespacesByPrefix.put(prefix, namespaceUri);
String previousPrefix = this.prefixesByNamespace.put(namespaceUri, prefix);
if (previousPrefix != null) {
@@ -121,4 +189,25 @@
return previousNamespaceForPrefix;
}
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getRegisteredNamespaceUris() {
+ Set<String> result = new HashSet<String>();
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ result.addAll(this.prefixesByNamespace.keySet());
+ } finally {
+ lock.unlock();
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ @GuardedBy( "registryLock" )
+ protected String generatePrefix() {
+ DecimalFormat formatter = new DecimalFormat(this.generatedPrefixTemplate);
+ return formatter.format(nextGeneratedPrefixNumber++);
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -48,7 +48,7 @@
public static final Path ROOT = new BasicPath(EMPTY_SEGMENTS, true);
- protected static final Path SELF_PATH = new BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
+ protected static final Path SELF_PATH = new BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
private final List<Segment> segments;
private final boolean absolute;
@@ -362,14 +362,14 @@
int numberOfParentReferences = startingPath.size() - lengthOfCommonAncestor;
List<Segment> relativeSegments = new ArrayList<Segment>();
for (int i = 0; i != numberOfParentReferences; ++i) {
- relativeSegments.add(BasicPathSegment.PARENT_SEGMENT);
+ relativeSegments.add(Path.PARENT_SEGMENT);
}
// Add the segments of this path from the common ancestor ...
for (int i = lengthOfCommonAncestor; i < this.size(); ++i) {
relativeSegments.add(this.segments.get(i));
}
if (relativeSegments.isEmpty()) {
- relativeSegments.add(BasicPathSegment.SELF_SEGMENT);
+ relativeSegments.add(Path.SELF_SEGMENT);
}
return new BasicPath(relativeSegments, false);
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -35,9 +35,6 @@
@Immutable
public class BasicPathSegment implements Path.Segment {
- public static final Path.Segment SELF_SEGMENT = new BasicPathSegment(new BasicName("", Path.SELF));
- public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(new BasicName("", Path.PARENT));
-
private final Name name;
private final int index;
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -26,6 +26,7 @@
import java.util.GregorianCalendar;
import java.util.Locale;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.ArgCheck;
import org.joda.time.Chronology;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -37,13 +38,23 @@
@Immutable
public class JodaDateTime implements org.jboss.dna.spi.graph.DateTime {
+ private static final int MILLIS_IN_HOUR = 1000 * 60 * 60;
+
private final DateTime instance;
private transient String formattedString;
+ public JodaDateTime() {
+ this.instance = new DateTime();
+ }
+
public JodaDateTime( String iso8601 ) {
this.instance = new DateTime(iso8601);
}
+ public JodaDateTime( String iso8601, String timeZoneId ) {
+ this.instance = new DateTime(iso8601, DateTimeZone.forID(timeZoneId));
+ }
+
public JodaDateTime( long milliseconds ) {
this.instance = new DateTime(milliseconds);
}
@@ -215,6 +226,21 @@
/**
* {@inheritDoc}
*/
+ public int getTimeZoneOffsetHours() {
+ // return this.instance.getZone().toTimeZone().getRawOffset() / MILLIS_IN_HOUR;
+ return this.instance.getZone().getOffset(this.instance.getMillis()) / MILLIS_IN_HOUR;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getTimeZoneId() {
+ return this.instance.getZone().getID();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Calendar toCalendar() {
return toCalendar(null);
}
@@ -279,4 +305,21 @@
return getString();
}
+ /**
+ * {@inheritDoc}
+ */
+ public org.jboss.dna.spi.graph.DateTime toUtcTimeZone() {
+ DateTime jodaTime = this.instance.withZone(DateTimeZone.forID("UTC"));
+ return new JodaDateTime(jodaTime);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public org.jboss.dna.spi.graph.DateTime toTimeZone( String timeZoneId ) {
+ ArgCheck.isNotNull(timeZoneId, "time zone identifier");
+ DateTime jodaTime = this.instance.withZone(DateTimeZone.forID(timeZoneId));
+ return new JodaDateTime(jodaTime);
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -186,7 +186,7 @@
* {@inheritDoc}
*/
public DateTime create() {
- return null;
+ return new JodaDateTime();
}
/**
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -97,16 +97,13 @@
String prefix = matcher.group(2);
String localName = matcher.group(3);
// Decode the parts ...
- prefix = decoder.decode(prefix);
+ prefix = prefix == null ? "" : decoder.decode(prefix);
localName = decoder.decode(localName);
// Look for a namespace match ...
- String namespaceUri = "";
- if (prefix != null) {
- namespaceUri = this.namespaceRegistry.getNamespaceForPrefix(prefix);
- // Fail if no namespace is found ...
- if (namespaceUri == null) {
- throw new NamespaceException(SpiI18n.noNamespaceRegisteredForPrefix.text(prefix));
- }
+ String namespaceUri = this.namespaceRegistry.getNamespaceForPrefix(prefix);
+ // Fail if no namespace is found ...
+ if (namespaceUri == null) {
+ throw new NamespaceException(SpiI18n.noNamespaceRegisteredForPrefix.text(prefix));
}
return new BasicName(namespaceUri, localName);
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -334,6 +334,8 @@
*/
public Segment createSegment( Name segmentName ) {
ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF_NAME.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT_NAME.equals(segmentName)) return Path.PARENT_SEGMENT;
return new BasicPathSegment(segmentName);
}
@@ -342,6 +344,8 @@
*/
public Segment createSegment( Name segmentName, int index ) {
ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF_NAME.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT_NAME.equals(segmentName)) return Path.PARENT_SEGMENT;
return new BasicPathSegment(segmentName, index);
}
@@ -350,6 +354,8 @@
*/
public Segment createSegment( String segmentName ) {
ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT.equals(segmentName)) return Path.PARENT_SEGMENT;
return new BasicPathSegment(this.nameValueFactory.create(segmentName));
}
@@ -358,6 +364,8 @@
*/
public Segment createSegment( String segmentName, int index ) {
ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT.equals(segmentName)) return Path.PARENT_SEGMENT;
return new BasicPathSegment(this.nameValueFactory.create(segmentName), index);
}
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -22,6 +22,7 @@
package org.jboss.dna.spi.graph.impl;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import org.junit.Before;
@@ -42,7 +43,7 @@
@Before
public void setUp() throws Exception {
namespaceRegistry = new BasicNamespaceRegistry();
- validNamespaceUri1 = "http://www.jboss.org/dna";
+ validNamespaceUri1 = "http://www.jboss.org/dna/2";
validNamespaceUri2 = "http://acme.com/something";
validNamespaceUri3 = "http://www.redhat.com";
validPrefix1 = "dna";
@@ -73,36 +74,47 @@
@Test
public void shouldReturnNullForPrefixIfNamespaceUriIsNotRegistered() {
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3), is(nullValue()));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, false), is(nullValue()));
// now register some namespaces ...
namespaceRegistry.register(validPrefix1, validNamespaceUri1);
namespaceRegistry.register(validPrefix2, validNamespaceUri2);
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3), is(nullValue()));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, false), is(nullValue()));
}
@Test
+ public void shouldGeneratePrefixIfNamespaceUriIsNotRegistered() {
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, false), is(nullValue()));
+ // Now get the generated prefix ...
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, true), is("ns001"));
+ // Change the template ...
+ namespaceRegistry.setGeneratedPrefixTemplate("xyz0000abc");
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2, true), is("xyz0002abc"));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2, true), is("xyz0002abc"));
+ // Change the template again ...
+ namespaceRegistry.setGeneratedPrefixTemplate("xyz####abc");
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1, true), is("xyz3abc"));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1, true), is("xyz3abc"));
+ }
+
+ @Test
public void shouldReturnPrefixForNamespaceUriThatIsRegistered() {
namespaceRegistry.register(validPrefix1, validNamespaceUri1);
namespaceRegistry.register(validPrefix2, validNamespaceUri2);
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1), is(validPrefix1));
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2), is(validPrefix2));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1, false), is(validPrefix1));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2, false), is(validPrefix2));
}
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowNullNamespaceUriParameterWhenGettingPrefix() {
- namespaceRegistry.getPrefixForNamespaceUri(null);
+ namespaceRegistry.getPrefixForNamespaceUri(null, false);
}
@Test
- public void shouldReturnNullDefaultNamespaceUriWhenNoNamespacesAreRegistered() {
- assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(nullValue()));
- }
-
- @Test
- public void shouldReturnNullDefaultNamespaceUriWhenThereAreNamespacesRegisteredButNoneRegisteredWithZeroLengthPrefix() {
+ public void shouldAlwaysHaveDefaultNamespaceRegistered() {
+ assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(notNullValue()));
namespaceRegistry.register(validPrefix1, validNamespaceUri1);
namespaceRegistry.register(validPrefix2, validNamespaceUri2);
- assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(nullValue()));
+ assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(notNullValue()));
}
@Test
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -133,13 +133,13 @@
@Test
public void shouldConsiderSegmentCreatedWithSelfReferenceToBeEqualToStaticSingleton() {
segment = factory.createSegment(Path.SELF);
- assertThat(segment.equals(BasicPathSegment.SELF_SEGMENT), is(true));
+ assertThat(segment.equals(Path.SELF_SEGMENT), is(true));
}
@Test
public void shouldConsiderSegmentCreatedWithParentReferenceToBeEqualToStaticSingleton() {
segment = factory.createSegment(Path.PARENT);
- assertThat(segment.equals(BasicPathSegment.PARENT_SEGMENT), is(true));
+ assertThat(segment.equals(Path.PARENT_SEGMENT), is(true));
}
}
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -95,7 +95,7 @@
@Test
public void shouldCreateAbsolutePathWithParentSegment() {
- validSegmentsList.add(BasicPathSegment.PARENT_SEGMENT);
+ validSegmentsList.add(Path.PARENT_SEGMENT);
path = new BasicPath(validSegmentsList, true);
assertThat(path.isAbsolute(), is(true));
assertThat(path.isNormalized(), is(false));
@@ -105,7 +105,7 @@
@Test
public void shouldCreateRelativePathWithParentSegment() {
- validSegmentsList.add(BasicPathSegment.PARENT_SEGMENT);
+ validSegmentsList.add(Path.PARENT_SEGMENT);
path = new BasicPath(validSegmentsList, false);
assertThat(path.isAbsolute(), is(false));
assertThat(path.isNormalized(), is(false));
@@ -115,7 +115,7 @@
@Test
public void shouldCreateAbsolutePathWithSelfSegment() {
- validSegmentsList.add(BasicPathSegment.SELF_SEGMENT);
+ validSegmentsList.add(Path.SELF_SEGMENT);
path = new BasicPath(validSegmentsList, true);
assertThat(path.isAbsolute(), is(true));
assertThat(path.isNormalized(), is(false));
@@ -125,7 +125,7 @@
@Test
public void shouldCreateRelativePathWithSelfSegment() {
- validSegmentsList.add(BasicPathSegment.SELF_SEGMENT);
+ validSegmentsList.add(Path.SELF_SEGMENT);
path = new BasicPath(validSegmentsList, false);
assertThat(path.isAbsolute(), is(false));
assertThat(path.isNormalized(), is(false));
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -0,0 +1,82 @@
+/*
+ * 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.impl;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.text.StringStartsWith.startsWith;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class JodaDateTimeTest {
+
+ private JodaDateTime instant;
+ private String iso8601instance;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ iso8601instance = "2008-05-10T13:22:04.678";
+ }
+
+ @Test
+ public void shouldConstructWithIso8601FormattedStringWithoutZone() {
+ instant = new JodaDateTime(iso8601instance, "UTC");
+ assertThat(instant.getString(), startsWith(iso8601instance));
+ assertThat(instant.getYearOfCentury(), is(8));
+ assertThat(instant.getYear(), is(2008));
+ assertThat(instant.getMonthOfYear(), is(5));
+ assertThat(instant.getDayOfMonth(), is(10));
+ assertThat(instant.getDayOfWeek(), is(6));
+ assertThat(instant.getHourOfDay(), is(13));
+ assertThat(instant.getMinuteOfHour(), is(22));
+ assertThat(instant.getSecondOfMinute(), is(04));
+ assertThat(instant.getMillisOfSecond(), is(678));
+ assertThat(instant.getTimeZoneId(), is("UTC"));
+ assertThat(instant.getTimeZoneOffsetHours(), is(0));
+ }
+
+ @Test
+ public void shouldConstructWithIso8601FormattedString() {
+ iso8601instance = "2008-05-10T13:22:04.678-04:00";
+ instant = new JodaDateTime(iso8601instance);
+ instant = (JodaDateTime)instant.toTimeZone("UTC");
+ assertThat(instant.getString(), is("2008-05-10T17:22:04.678Z"));
+ assertThat(instant.getYearOfCentury(), is(8));
+ assertThat(instant.getYear(), is(2008));
+ assertThat(instant.getMonthOfYear(), is(5));
+ assertThat(instant.getDayOfMonth(), is(10));
+ assertThat(instant.getDayOfWeek(), is(6));
+ assertThat(instant.getHourOfDay(), is(17));
+ assertThat(instant.getMinuteOfHour(), is(22));
+ assertThat(instant.getSecondOfMinute(), is(04));
+ assertThat(instant.getMillisOfSecond(), is(678));
+ assertThat(instant.getTimeZoneId(), is("UTC"));
+ assertThat(instant.getTimeZoneOffsetHours(), is(0));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-05-24 17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-05-27 19:24:32 UTC (rev 199)
@@ -53,6 +53,13 @@
}
@Test
+ public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormatWithoutPrefix() {
+ name = factory.create("a");
+ assertThat(name.getLocalName(), is("a"));
+ assertThat(name.getNamespaceUri(), is(this.registry.getNamespaceForPrefix("")));
+ }
+
+ @Test
public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormat() {
name = factory.create("dna:something");
assertThat(name.getLocalName(), is("something"));
15 years, 11 months
DNA SVN: r198 - in branches/federation/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-05-24 13:08:43 -0400 (Sat, 24 May 2008)
New Revision: 198
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Changed from Externalizable to Serializable so that the graph objects can be truly immutable. This will eliminate concurrency issues and safety issues.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,8 +21,8 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
import java.io.InputStream;
+import java.io.Serializable;
import net.jcip.annotations.ThreadSafe;
/**
@@ -30,7 +30,7 @@
* @author Randall Hauch
*/
@ThreadSafe
-public interface Binary extends Comparable<Binary>, Externalizable {
+public interface Binary extends Comparable<Binary>, Serializable {
/**
* Get the length of this binary data.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import java.util.Locale;
/**
@@ -32,7 +32,7 @@
* classes.
* @author Randall Hauch
*/
-public interface DateTime extends Comparable<DateTime>, Externalizable {
+public interface DateTime extends Comparable<DateTime>, Serializable {
/**
* Get the ISO-8601 representation of this instance in time.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
@@ -30,7 +30,7 @@
* @author Randall Hauch
*/
@Immutable
-public interface Name extends Comparable<Name>, Externalizable {
+public interface Name extends Comparable<Name>, Serializable {
/**
* Get the local name part of this qualified name.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import net.jcip.annotations.Immutable;
@@ -67,7 +67,7 @@
* @author Randall Hauch
*/
@Immutable
-public interface Path extends Comparable<Path>, Iterable<Path.Segment>, Externalizable {
+public interface Path extends Comparable<Path>, Iterable<Path.Segment>, Serializable {
/**
* The text encoder that does nothing.
@@ -121,7 +121,7 @@
* @author Randall Hauch
*/
@Immutable
- public static interface Segment extends Cloneable, Comparable<Segment>, Externalizable {
+ public static interface Segment extends Cloneable, Comparable<Segment>, Serializable {
/**
* Get the name component of this segment.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,13 +21,13 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import org.jboss.dna.common.text.TextEncoder;
/**
* @author Randall Hauch
*/
-public interface Reference extends Comparable<Reference>, Externalizable {
+public interface Reference extends Comparable<Reference>, Serializable {
/**
* Get the string form of the Reference. The {@link Path#DEFAULT_ENCODER default encoder} is used to encode characters in the
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
@@ -39,14 +36,10 @@
@Immutable
public class BasicName implements Name {
- private String namespaceUri;
- private String localName;
- private transient int hc;
+ private final String namespaceUri;
+ private final String localName;
+ private final int hc;
- public BasicName() {
- this("", "");
- }
-
public BasicName( String namespaceUri, String localName ) {
this.namespaceUri = namespaceUri != null ? namespaceUri.trim() : "";
this.localName = localName != null ? localName.trim() : "";
@@ -151,21 +144,4 @@
return "{" + this.namespaceUri + "}" + this.localName;
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- this.namespaceUri = in.readUTF();
- this.localName = in.readUTF();
- this.hc = HashCode.compute(this.namespaceUri, this.localName);
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeUTF(this.namespaceUri);
- out.writeUTF(this.localName);
- }
-
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -53,9 +50,9 @@
protected static final Path SELF_PATH = new BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
- private List<Segment> segments;
- private boolean absolute;
- private transient boolean normalized;
+ private final List<Segment> segments;
+ private final boolean absolute;
+ private final boolean normalized;
private transient String path;
/**
@@ -497,31 +494,4 @@
return getString(Path.URL_ENCODER);
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
- int numSegments = in.readInt();
- this.segments = new ArrayList<Segment>(numSegments);
- for (int i = 0; i != numSegments; ++i) {
- BasicPathSegment segment = new BasicPathSegment();
- segment.readExternal(in);
- this.segments.add(segment);
- }
- this.absolute = in.readBoolean();
- this.normalized = isNormalized(this.segments);
- this.path = null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeInt(this.segments.size());
- for (Segment segment : this.segments) {
- segment.writeExternal(out);
- }
- out.writeBoolean(this.absolute);
- }
-
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
@@ -42,13 +39,8 @@
public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(new BasicName("", Path.PARENT));
private final Name name;
- private int index;
+ private final int index;
- public BasicPathSegment() {
- this.name = new BasicName();
- this.index = Path.NO_INDEX;
- }
-
/**
* @param name the segment name
* @throws IllegalArgumentException if the name is null or if the index is invalid
@@ -186,20 +178,4 @@
return encodedName;
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
- this.name.readExternal(in);
- this.index = in.readInt();
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- this.name.writeExternal(out);
- out.writeInt(this.index);
- }
-
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -22,10 +22,7 @@
package org.jboss.dna.spi.graph.impl;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
@@ -40,12 +37,8 @@
protected static final byte[] EMPTY_CONTENT = new byte[0];
- private byte[] bytes;
+ private final byte[] bytes;
- public InMemoryBinary() {
- this.bytes = EMPTY_CONTENT;
- }
-
public InMemoryBinary( byte[] bytes ) {
ArgCheck.isNotNull(bytes, "bytes");
this.bytes = bytes;
@@ -110,23 +103,6 @@
/**
* {@inheritDoc}
*/
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- int length = in.readInt();
- this.bytes = new byte[length];
- in.read(this.bytes);
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeInt(this.bytes.length);
- out.write(this.bytes);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -40,7 +37,7 @@
@Immutable
public class JodaDateTime implements org.jboss.dna.spi.graph.DateTime {
- private DateTime instance;
+ private final DateTime instance;
private transient String formattedString;
public JodaDateTime( String iso8601 ) {
@@ -282,18 +279,4 @@
return getString();
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- this.instance = new DateTime(in.readUTF());
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeUTF(this.getString());
- }
-
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
@@ -98,21 +95,4 @@
return this.uuid.toString();
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- long lsb = in.readLong();
- long msb = in.readLong();
- this.uuid = new UUID(msb, lsb);
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeLong(this.uuid.getLeastSignificantBits());
- out.writeLong(this.uuid.getMostSignificantBits());
- }
-
}
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java 2008-05-24 16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java 2008-05-24 17:08:43 UTC (rev 198)
@@ -25,12 +25,8 @@
import static org.jboss.dna.spi.graph.impl.BinaryContains.hasContent;
import static org.jboss.dna.spi.graph.impl.BinaryContains.hasNoContent;
import static org.junit.Assert.assertThat;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.graph.Binary;
import org.junit.Before;
@@ -113,22 +109,4 @@
assertThat(another, hasContent(shorterContent));
}
- @Test
- public void shouldBeRecoverableFromExternalizedForm() throws Exception {
- ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
- ObjectOutputStream output = new ObjectOutputStream(contentStream);
- // Write the binary object ...
- binary.writeExternal(output);
- output.close();
- // Now read the object back in ...
- ByteArrayInputStream contentInputStream = new ByteArrayInputStream(contentStream.toByteArray());
- ObjectInputStream input = new ObjectInputStream(contentInputStream);
- InMemoryBinary recovered = new InMemoryBinary();
- recovered.readExternal(input);
- input.close();
- // Compare ...
- assertThat(recovered, is(binary));
- assertThat(recovered, hasContent(binary));
- }
-
}
15 years, 11 months
DNA SVN: r197 - in branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph: impl and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-24 12:54:26 -0400 (Sat, 24 May 2008)
New Revision: 197
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Correctly implemented the externalizable methods, and provided no-arg constructors. Note that all Externalizable.readObject(...) methods are synchronized to ensure that they properly reconstitute the object in the face of multiple concurrent calls.
Unfortunately, using Externalizable makes these classes technically not immutable, since anybody may call "readObject" to change the instance. That may warrant changing back to Serializable.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Serializable;
+import java.io.Externalizable;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
@@ -30,7 +30,7 @@
* @author Randall Hauch
*/
@Immutable
-public interface Name extends Comparable<Name>, Serializable {
+public interface Name extends Comparable<Name>, Externalizable {
/**
* Get the local name part of this qualified name.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Serializable;
+import java.io.Externalizable;
import java.util.Iterator;
import java.util.List;
import net.jcip.annotations.Immutable;
@@ -67,7 +67,7 @@
* @author Randall Hauch
*/
@Immutable
-public interface Path extends Comparable<Path>, Iterable<Path.Segment>, Serializable {
+public interface Path extends Comparable<Path>, Iterable<Path.Segment>, Externalizable {
/**
* The text encoder that does nothing.
@@ -121,7 +121,7 @@
* @author Randall Hauch
*/
@Immutable
- public static interface Segment extends Cloneable, Comparable<Segment>, Serializable {
+ public static interface Segment extends Cloneable, Comparable<Segment>, Externalizable {
/**
* Get the name component of this segment.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -21,6 +21,9 @@
*/
package org.jboss.dna.spi.graph.impl;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
@@ -36,10 +39,14 @@
@Immutable
public class BasicName implements Name {
- private final String namespaceUri;
- private final String localName;
- private final int hc;
+ private String namespaceUri;
+ private String localName;
+ private transient int hc;
+ public BasicName() {
+ this("", "");
+ }
+
public BasicName( String namespaceUri, String localName ) {
this.namespaceUri = namespaceUri != null ? namespaceUri.trim() : "";
this.localName = localName != null ? localName.trim() : "";
@@ -144,4 +151,21 @@
return "{" + this.namespaceUri + "}" + this.localName;
}
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void readExternal( ObjectInput in ) throws IOException {
+ this.namespaceUri = in.readUTF();
+ this.localName = in.readUTF();
+ this.hc = HashCode.compute(this.namespaceUri, this.localName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ out.writeUTF(this.namespaceUri);
+ out.writeUTF(this.localName);
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -21,6 +21,9 @@
*/
package org.jboss.dna.spi.graph.impl;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -50,9 +53,9 @@
protected static final Path SELF_PATH = new BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
- private final List<Segment> segments;
- private final boolean absolute;
- private final boolean normalized;
+ private List<Segment> segments;
+ private boolean absolute;
+ private transient boolean normalized;
private transient String path;
/**
@@ -494,4 +497,31 @@
return getString(Path.URL_ENCODER);
}
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ int numSegments = in.readInt();
+ this.segments = new ArrayList<Segment>(numSegments);
+ for (int i = 0; i != numSegments; ++i) {
+ BasicPathSegment segment = new BasicPathSegment();
+ segment.readExternal(in);
+ this.segments.add(segment);
+ }
+ this.absolute = in.readBoolean();
+ this.normalized = isNormalized(this.segments);
+ this.path = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ out.writeInt(this.segments.size());
+ for (Segment segment : this.segments) {
+ segment.writeExternal(out);
+ }
+ out.writeBoolean(this.absolute);
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -21,6 +21,9 @@
*/
package org.jboss.dna.spi.graph.impl;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
@@ -39,8 +42,13 @@
public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(new BasicName("", Path.PARENT));
private final Name name;
- private final int index;
+ private int index;
+ public BasicPathSegment() {
+ this.name = new BasicName();
+ this.index = Path.NO_INDEX;
+ }
+
/**
* @param name the segment name
* @throws IllegalArgumentException if the name is null or if the index is invalid
@@ -178,4 +186,20 @@
return encodedName;
}
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ this.name.readExternal(in);
+ this.index = in.readInt();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ this.name.writeExternal(out);
+ out.writeInt(this.index);
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -110,7 +110,7 @@
/**
* {@inheritDoc}
*/
- public void readExternal( ObjectInput in ) throws IOException {
+ public synchronized void readExternal( ObjectInput in ) throws IOException {
int length = in.readInt();
this.bytes = new byte[length];
in.read(this.bytes);
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -285,7 +285,7 @@
/**
* {@inheritDoc}
*/
- public void readExternal( ObjectInput in ) throws IOException {
+ public synchronized void readExternal( ObjectInput in ) throws IOException {
this.instance = new DateTime(in.readUTF());
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-24 16:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-24 16:54:26 UTC (rev 197)
@@ -101,7 +101,7 @@
/**
* {@inheritDoc}
*/
- public void readExternal( ObjectInput in ) throws IOException {
+ public synchronized void readExternal( ObjectInput in ) throws IOException {
long lsb = in.readLong();
long msb = in.readLong();
this.uuid = new UUID(msb, lsb);
15 years, 11 months
DNA SVN: r196 - branches/federation/dna-common/src/main/java/org/jboss/dna/common/util.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-24 12:51:54 -0400 (Sat, 24 May 2008)
New Revision: 196
Modified:
branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
Log:
Removed unused import.
Modified: branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
===================================================================
--- branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java 2008-05-24 16:36:24 UTC (rev 195)
+++ branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java 2008-05-24 16:51:54 UTC (rev 196)
@@ -26,12 +26,11 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.jboss.dna.common.CommonI18n;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.CommonI18n;
/**
* Utilities for working with dates.
15 years, 11 months