DNA SVN: r219 - in branches/federation: connectors and 16 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-02 12:45:45 -0400 (Mon, 02 Jun 2008)
New Revision: 219
Added:
branches/federation/connectors/
branches/federation/connectors/dna-connector-jbosscache/
branches/federation/connectors/dna-connector-jbosscache/.classpath
branches/federation/connectors/dna-connector-jbosscache/.project
branches/federation/connectors/dna-connector-jbosscache/pom.xml
branches/federation/connectors/dna-connector-jbosscache/src/
branches/federation/connectors/dna-connector-jbosscache/src/main/
branches/federation/connectors/dna-connector-jbosscache/src/main/java/
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java
branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
branches/federation/connectors/dna-connector-jbosscache/src/main/resources/
branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/
branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/
branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/
branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/
branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/
branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties
branches/federation/connectors/dna-connector-jbosscache/src/test/
branches/federation/connectors/dna-connector-jbosscache/src/test/java/
branches/federation/connectors/dna-connector-jbosscache/src/test/resources/
Modified:
branches/federation/pom.xml
Log:
Added JBoss Cache connector project
Property changes on: branches/federation/connectors/dna-connector-jbosscache
___________________________________________________________________
Name: svn:ignore
+ target
Added: branches/federation/connectors/dna-connector-jbosscache/.classpath
===================================================================
--- branches/federation/connectors/dna-connector-jbosscache/.classpath (rev 0)
+++ branches/federation/connectors/dna-connector-jbosscache/.classpath 2008-06-02 16:45:45 UTC (rev 219)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: branches/federation/connectors/dna-connector-jbosscache/.project
===================================================================
--- branches/federation/connectors/dna-connector-jbosscache/.project (rev 0)
+++ branches/federation/connectors/dna-connector-jbosscache/.project 2008-06-02 16:45:45 UTC (rev 219)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>dna-connector-jbosscache</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: branches/federation/connectors/dna-connector-jbosscache/pom.xml
===================================================================
--- branches/federation/connectors/dna-connector-jbosscache/pom.xml (rev 0)
+++ branches/federation/connectors/dna-connector-jbosscache/pom.xml 2008-06-02 16:45:45 UTC (rev 219)
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+ <!-- The groupId and version values are inherited from parent -->
+ <artifactId>dna-connector-jbosscache</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss DNA Connector to JBoss Cache</name>
+ <description>JBoss DNA Connector that accesses an in-process JBoss Cache instance.</description>
+ <url>http://labs.jboss.org/dna</url>
+
+ <properties>
+ <dna-version>0.2-SNAPSHOT</dna-version>
+ </properties>
+ <!--
+ Define the dependencies. Note that all version and scopes default to those
+ defined in the dependencyManagement section of the parent pom.
+ -->
+ <dependencies>
+ <!--
+ Common
+ -->
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ <version>${dna-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-spi</artifactId>
+ <version>${dna-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <!--
+ JBoss Cache
+ -->
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>2.2.0.CR1</version>
+ </dependency>
+ <!--
+ Testing (note the scope)
+ -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </dependency>
+ <!--
+ Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
+ -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ <!--
+ Java Concurrency in Practice annotations
+ -->
+ <dependency>
+ <groupId>net.jcip</groupId>
+ <artifactId>jcip-annotations</artifactId>
+ </dependency>
+ </dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
\ No newline at end of file
Added: branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java (rev 0)
+++ branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-06-02 16:45:45 UTC (rev 219)
@@ -0,0 +1,323 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.jbosscache;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import javax.transaction.xa.XAResource;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.commands.ActsOnPath;
+import org.jboss.dna.spi.graph.commands.CopyBranchCommand;
+import org.jboss.dna.spi.graph.commands.CopyNodeCommand;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.DeleteBranchCommand;
+import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
+import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.MoveBranchCommand;
+import org.jboss.dna.spi.graph.commands.SetPropertiesCommand;
+import org.jboss.dna.spi.graph.connection.ExecutionEnvironment;
+import org.jboss.dna.spi.graph.connection.RepositoryConnection;
+import org.jboss.dna.spi.graph.connection.RepositorySourceException;
+import org.jboss.dna.spi.graph.connection.RepositorySourceListener;
+
+/**
+ * @author Randall Hauch
+ */
+public class JBossCacheConnection implements RepositoryConnection {
+
+ protected static final RepositorySourceListener NO_OP_LISTENER = new RepositorySourceListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void notify( String sourceName, Object... events ) {
+ // do nothing
+ }
+ };
+
+ private boolean initializedUuidPropertyName = false;
+ private Name uuidPropertyName;
+ private final JBossCacheSource source;
+ private final Cache<Name, Object> cache;
+ private RepositorySourceListener listener = NO_OP_LISTENER;
+
+ /**
+ *
+ */
+ /* package */JBossCacheConnection( JBossCacheSource source, Cache<Name, Object> cache ) {
+ assert source != null;
+ assert cache != null;
+ this.source = source;
+ this.cache = cache;
+ }
+
+ /**
+ * @return uuidPropertyName
+ */
+ public Name getUuidPropertyName() {
+ return this.uuidPropertyName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getSourceName() {
+ return source.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public XAResource getXAResource() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean ping( long time, TimeUnit unit ) {
+ this.cache.getRoot();
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setListener( RepositorySourceListener listener ) {
+ this.listener = listener != null ? listener : NO_OP_LISTENER;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() {
+ // do nothing
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute( ExecutionEnvironment env, GraphCommand... commands ) throws RepositorySourceException {
+ // Set up the workspace ...
+
+ // Now execute the commands ...
+ for (GraphCommand command : commands) {
+ // This node reference is available for any command that extends ActsOnPath ...
+ Node<Name, Object> node = null;
+
+ // First, process the commands that create a new node ...
+ if (command instanceof CreateNodeCommand) {
+ CreateNodeCommand theCommand = (CreateNodeCommand)command;
+ Path path = theCommand.getPath();
+ Path parent = path.getAncestor();
+ Fqn<Segment> childFqn = getFullyQualifiedName(path.getLastSegment());
+ // Look up the parent node, which must exist ...
+ Node<Name, Object> parentNode = getNode(env, parent);
+ node = parentNode.addChild(childFqn);
+ // Add the UUID property (if required), which may be overwritten by a supplied property ...
+ Name uuidPropertyName = getUuidProperty(env);
+ if (uuidPropertyName != null) {
+ node.put(uuidPropertyName, generateUuid());
+ }
+ // Now add the properties to the supplied node ...
+ for (Property property : theCommand.getProperties()) {
+ if (property.size() == 0) continue;
+ Name propName = property.getName();
+ Object value = null;
+ if (property.size() == 1) {
+ value = property.iterator().next();
+ } else {
+ value = property.getValuesAsArray();
+ }
+ node.put(propName, value);
+ }
+ assert node != null;
+ }
+
+ // Otherwise, check whether the command is applies to a path; all the remaining commands
+ // that do so expect the node to exist ...
+ else if (command instanceof ActsOnPath) {
+ ActsOnPath theCommand = (ActsOnPath)command;
+ Path path = theCommand.getPath();
+ // Look up the node with the supplied path ...
+ node = getNode(env, path);
+ assert node != null;
+ }
+
+ if (command instanceof GetChildrenCommand) {
+ GetChildrenCommand theCommand = (GetChildrenCommand)command;
+ assert command instanceof ActsOnPath;
+ assert node != null;
+ // Get the names of the children ...
+ List<Segment> childSegments = new ArrayList<Segment>();
+ for (Node<Name, Object> child : node.getChildren()) {
+ childSegments.add((Segment)child.getFqn().getLastElement());
+ }
+ theCommand.setChildren(childSegments);
+
+ }
+ if (command instanceof GetPropertiesCommand) {
+ GetPropertiesCommand theCommand = (GetPropertiesCommand)command;
+ assert command instanceof ActsOnPath;
+ assert node != null;
+ Map<Name, Object> dataMap = node.getData();
+ for (Map.Entry<Name, Object> data : dataMap.entrySet()) {
+ Name propertyName = data.getKey();
+ Object values = data.getValue();
+ theCommand.setProperty(propertyName, values);
+ }
+ }
+ if (command instanceof SetPropertiesCommand) {
+ SetPropertiesCommand theCommand = (SetPropertiesCommand)command;
+ assert command instanceof ActsOnPath;
+ assert node != null;
+ // Now set (or remove) the properties to the supplied node ...
+ for (Property property : theCommand.getProperties()) {
+ Name propName = property.getName();
+ if (property.size() == 0) {
+ node.remove(propName);
+ continue;
+ }
+ Object value = null;
+ if (property.size() == 1) {
+ value = property.iterator().next();
+ } else {
+ value = property.getValuesAsArray();
+ }
+ node.put(propName, value);
+ }
+ }
+ if (command instanceof DeleteBranchCommand) {
+ assert command instanceof ActsOnPath;
+ assert node != null;
+ node.getParent().removeChild(node.getFqn().getLastElement());
+ }
+ if (command instanceof CopyNodeCommand) {
+ CopyNodeCommand theCommand = (CopyNodeCommand)command;
+ boolean recursive = command instanceof CopyBranchCommand;
+ // Look up the new parent, which must exist ...
+ Path newPath = theCommand.getNewPath();
+ Node<Name, Object> newParent = getNode(env, newPath.getAncestor());
+ copyNode(node, newParent, recursive, null);
+ }
+ if (command instanceof MoveBranchCommand) {
+ MoveBranchCommand theCommand = (MoveBranchCommand)command;
+ assert command instanceof ActsOnPath;
+ assert node != null;
+ boolean recursive = true;
+ Name uuidProperty = getUuidProperty(env);
+ // Look up the new parent, which must exist ...
+ Path newPath = theCommand.getNewPath();
+ Node<Name, Object> newParent = getNode(env, newPath.getAncestor());
+ copyNode(node, newParent, recursive, uuidProperty);
+ // Now delete the old node ...
+ Node<Name, Object> oldParent = node.getParent();
+ boolean removed = oldParent.removeChild(node.getFqn().getLastElement());
+ assert removed;
+ }
+ }
+ }
+
+ /**
+ * @return listener
+ */
+ protected RepositorySourceListener getListener() {
+ return this.listener;
+ }
+
+ /**
+ * Utility method to calculate (if required) and obtain the name that should be used to store the UUID values for each node.
+ * This method may be called without regard to synchronization, since it should return the same value if it happens to be
+ * called concurrently while not yet initialized.
+ *
+ * @param env the environment
+ * @return the name, or null if the UUID should not be stored
+ */
+ protected Name getUuidProperty( ExecutionEnvironment env ) {
+ if (!initializedUuidPropertyName) {
+ this.uuidPropertyName = this.source.getUuidPropertyName(env.getValueFactories().getNameFactory());
+ initializedUuidPropertyName = true;
+ }
+ return this.uuidPropertyName;
+ }
+
+ protected Fqn<Path.Segment> getFullyQualifiedName( Path path ) {
+ return Fqn.fromList(path.getSegmentsList());
+ }
+
+ /**
+ * Get a relative fully-qualified name that consists only of the supplied segment.
+ *
+ * @param pathSegment the segment from which the fully qualified name is to be created
+ * @return the relative fully-qualified name
+ */
+ protected Fqn<Path.Segment> getFullyQualifiedName( Path.Segment pathSegment ) {
+ return Fqn.fromElements(pathSegment);
+ }
+
+ protected Node<Name, Object> getNode( ExecutionEnvironment env, Path path ) {
+ // Look up the node with the supplied path ...
+ Fqn<Segment> fqn = getFullyQualifiedName(path);
+ Node<Name, Object> node = cache.getNode(fqn);
+ if (node == null) {
+ String nodePath = path.getString(env.getNamespaceRegistry());
+ throw new RepositorySourceException(getSourceName(), JBossCacheConnectorI18n.nodeDoesNotExist.text(nodePath));
+ }
+ return node;
+
+ }
+
+ protected UUID generateUuid() {
+ return UUID.randomUUID();
+ }
+
+ protected int copyNode( Node<Name, Object> original, Node<Name, Object> newParent, boolean recursive, Name uuidProperty ) {
+ // Get or create the new node ...
+ Segment name = (Segment)original.getFqn().getLastElement();
+ Node<Name, Object> copy = newParent.addChild(getFullyQualifiedName(name));
+ // Copy the properties ...
+ copy.clearData();
+ copy.putAll(original.getData());
+ if (uuidProperty != null) {
+ // Generate a new UUID for the new node ...
+ copy.put(uuidProperty, generateUuid());
+ }
+ int numNodesCopied = 1;
+ if (recursive) {
+ // Loop over each child and call this method ...
+ for (Node<Name, Object> child : original.getChildren()) {
+ numNodesCopied += copyNode(child, copy, true, uuidProperty);
+ }
+ }
+ return numNodesCopied;
+ }
+}
Added: branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java
===================================================================
--- branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java (rev 0)
+++ branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java 2008-06-02 16:45:45 UTC (rev 219)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.jbosscache;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * @author Randall Hauch
+ */
+public final class JBossCacheConnectorI18n {
+
+ public static I18n connectorName;
+ public static I18n nodeDoesNotExist;
+
+ static {
+ try {
+ I18n.initialize(JBossCacheConnectorI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set<Locale> getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(JBossCacheConnectorI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems() {
+ return I18n.getLocalizationProblems(JBossCacheConnectorI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(JBossCacheConnectorI18n.class, locale);
+ }
+}
Added: branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java (rev 0)
+++ branches/federation/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-06-02 16:45:45 UTC (rev 219)
@@ -0,0 +1,316 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.jbosscache;
+
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+import net.jcip.annotations.GuardedBy;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.connection.RepositoryConnection;
+import org.jboss.dna.spi.graph.connection.RepositorySource;
+import org.jboss.dna.spi.graph.connection.RepositorySourceException;
+
+/**
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class JBossCacheSource implements RepositorySource, ObjectFactory {
+
+ public static final String DEFAULT_UUID_PROPERTY_NAMESPACE = "http://www.jboss.org/dna/connector/jbosscache";
+ public static final String DEFAULT_UUID_PROPERTY_NAME = "uuid";
+
+ private static final ConcurrentMap<String, JBossCacheSource> sources = new ConcurrentHashMap<String, JBossCacheSource>();
+ private static final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
+
+ /**
+ * Get the names of the in-memory repository sources that are currently registered
+ *
+ * @return the unmodifiable set of names
+ */
+ public static Set<String> getSourceNames() {
+ Lock lock = sourcesLock.readLock();
+ try {
+ lock.lock();
+ return Collections.unmodifiableSet(sources.keySet());
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * Get the source with the supplied name.
+ *
+ * @param name the name
+ * @return the source, or null if there is no source with the supplied name
+ */
+ public static JBossCacheSource getSource( String name ) {
+ Lock lock = sourcesLock.readLock();
+ try {
+ lock.lock();
+ return sources.get(name);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ @GuardedBy( "sourcesLock" )
+ private String name;
+ @GuardedBy( "this" )
+ private String jndiName;
+ private final AtomicInteger retryLimit = new AtomicInteger(0);
+ private UUID rootNodeUuid = UUID.randomUUID();
+ private CachePolicy defaultCachePolicy;
+ private String cacheConfigurationName;
+ private String uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
+ private String uuidPropertyNamespaceUri = DEFAULT_UUID_PROPERTY_NAMESPACE;
+ private transient Cache<Name, Object> cache;
+
+ /**
+ * Create a repository source instance.
+ */
+ public JBossCacheSource() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CachePolicy getDefaultCachePolicy() {
+ return defaultCachePolicy;
+ }
+
+ /**
+ * @param defaultCachePolicy Sets defaultCachePolicy to the specified value.
+ */
+ public void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
+ this.defaultCachePolicy = defaultCachePolicy;
+ }
+
+ /**
+ * @return rootNodeUuid
+ */
+ public UUID getRootNodeUuid() {
+ return this.rootNodeUuid;
+ }
+
+ /**
+ * @param rootNodeUuid Sets rootNodeUuid to the specified value.
+ */
+ public void setRootNodeUuid( UUID rootNodeUuid ) {
+ this.rootNodeUuid = rootNodeUuid != null ? rootNodeUuid : UUID.randomUUID();
+ }
+
+ /**
+ * @return uuidPropertyName
+ */
+ public String getUuidPropertyName() {
+ return this.uuidPropertyName;
+ }
+
+ /**
+ * @param uuidPropertyName Sets uuidPropertyName to the specified value.
+ */
+ public synchronized void setUuidPropertyName( String uuidPropertyName ) {
+ this.uuidPropertyName = uuidPropertyName != null ? uuidPropertyName.trim() : DEFAULT_UUID_PROPERTY_NAME;
+ }
+
+ /**
+ * @return uuidPropertyNamespaceUri
+ */
+ public String getUuidPropertyNamespaceUri() {
+ return this.uuidPropertyNamespaceUri;
+ }
+
+ /**
+ * @param uuidPropertyNamespaceUri Sets uuidPropertyNamespaceUri to the specified value.
+ */
+ public synchronized void setUuidPropertyNamespaceUri( String uuidPropertyNamespaceUri ) {
+ this.uuidPropertyNamespaceUri = uuidPropertyNamespaceUri != null ? uuidPropertyNamespaceUri.trim() : DEFAULT_UUID_PROPERTY_NAMESPACE;
+ }
+
+ /**
+ * If you use this to set a JNDI name, this source will be bound to that name using the default {@link InitialContext}. You
+ * can also do this manually if you have additional requirements.
+ *
+ * @param name the JNDI name
+ * @throws NamingException if there is a problem registering this object
+ * @see #getJndiName()
+ */
+ public void setJndiName( String name ) throws NamingException {
+ setJndiName(name, null);
+ }
+
+ /**
+ * Register this source in JNDI under the supplied name using the supplied context. to set a JNDI name, this source will be
+ * bound to that name using the default {@link InitialContext}. You can also do this manually if you have additional
+ * requirements.
+ *
+ * @param name the JNDI name, or null if this object is to no longer be registered
+ * @param context the JNDI context, or null if the {@link InitialContext} should be used
+ * @throws NamingException if there is a problem registering this object
+ * @see #getJndiName()
+ */
+ public synchronized void setJndiName( String name, Context context ) throws NamingException {
+ ArgCheck.isNotNull(name, "name");
+ if (context == null) context = new InitialContext();
+
+ // First register in JNDI under the new name ...
+ if (name != null) {
+ context.bind(name, this);
+ }
+ // Second, unregister from JNDI if there is already a name ...
+ if (jndiName != null && !jndiName.equals(name)) {
+ context.unbind(jndiName);
+ }
+ // Record the new name ...
+ this.jndiName = name;
+ }
+
+ /**
+ * Gets the JNDI name this source is bound to. Only valid if you used setJNDIName to bind it.
+ *
+ * @return the JNDI name, or null if it is not bound in JNDI
+ * @see #setJndiName(String)
+ */
+ public synchronized String getJndiName() {
+ return jndiName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ Lock lock = sourcesLock.readLock();
+ try {
+ lock.lock();
+ return this.name;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * @param name Sets name to the specified value.
+ * @return true if the name was changed, or false if an existing instance already exists with that name
+ */
+ public boolean setName( String name ) {
+ Lock lock = sourcesLock.writeLock();
+ try {
+ lock.lock();
+ // Determine if this name is allowed ...
+ if (sources.containsKey(name)) return false;
+
+ // Remove this object under its current name
+ if (this.name != null) {
+ sources.remove(this.name);
+ }
+ // Register this object under the new name
+ this.name = name;
+ sources.put(this.name, this);
+ return true;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getRetryLimit() {
+ return retryLimit.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setRetryLimit( int limit ) {
+ retryLimit.set(limit);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized RepositoryConnection getConnection() throws RepositorySourceException {
+ if (this.cache == null) {
+ CacheFactory<Name, Object> factory = new DefaultCacheFactory<Name, Object>();
+ cache = factory.createCache(cacheConfigurationName);
+ }
+ return new JBossCacheConnection(this, this.cache);
+ }
+
+ /**
+ * Utility method to obtain a consistent {@link Name} for the property that should store the UUID value on each node. This
+ * method is properly coded so that it is threadsafe.
+ *
+ * @param factory the name factory; may not be null
+ * @return the property name, or null if UUIDs are not to be maintained
+ */
+ /* package */synchronized Name getUuidPropertyName( NameFactory factory ) {
+ if (this.uuidPropertyName.length() == 0 && this.uuidPropertyNamespaceUri.length() == 0) return null;
+ return factory.create(this.uuidPropertyNamespaceUri, this.uuidPropertyName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference getReference() {
+ String className = getClass().getName();
+ String factoryClassName = className;
+ return new Reference(className, new StringRefAddr("DnaConnectorJBossCacheSource", getName()), factoryClassName, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getObjectInstance( Object obj, javax.naming.Name name, Context nameCtx, Hashtable<?, ?> environment ) throws Exception {
+ if (obj instanceof Reference) {
+ Reference ref = (Reference)obj;
+ if (ref.getClassName().equals(getClass().getName())) {
+ RefAddr addr = ref.get("DnaConnectorJBossCacheSource");
+ return JBossCacheSource.getSource((String)addr.getContent());
+ }
+ }
+ return null;
+ }
+
+}
Added: branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties
===================================================================
--- branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties (rev 0)
+++ branches/federation/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties 2008-06-02 16:45:45 UTC (rev 219)
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+connectorName = In-Memory Connector
+nodeDoesNotExist = Could not find an existing node at {0}
\ No newline at end of file
Modified: branches/federation/pom.xml
===================================================================
--- branches/federation/pom.xml 2008-06-02 16:34:47 UTC (rev 218)
+++ branches/federation/pom.xml 2008-06-02 16:45:45 UTC (rev 219)
@@ -61,7 +61,8 @@
<module>dna-maven-classloader</module>
<module>sequencers/dna-sequencer-images</module>
<module>sequencers/dna-sequencer-mp3</module>
- <module>dna-integration-tests</module>
+ <module>connectors/dna-connector-jbosscache</module>
+ <module>dna-integration-tests</module>
</modules>
<properties>
15 years, 11 months
DNA SVN: r218 - in branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph: commands and 3 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-06-02 12:34:47 -0400 (Mon, 02 Jun 2008)
New Revision: 218
Added:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
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/PropertyType.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/GetPropertiesCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
Log:
DNA-68: Create connector API
http://jira.jboss.org/jira/browse/DNA-68
Added basic property implementation. Refactored the commands and added basic implementations. Also included several other changes to enhance readability of the code that uses.
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-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -23,13 +23,13 @@
import java.math.BigDecimal;
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). Note that this property is immutable, meaning that the property
* values may not be changed through this interface.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -37,52 +37,62 @@
/**
* Get the name of the property.
+ *
* @return the property name; never null
*/
Name getName();
/**
* Get the name of the property's definition.
+ *
* @return the property definition's name; never null
*/
Name getDefinitionName();
/**
- * Determine whether the property is defined to allow multiple values.
+ * Get the number of actual values in this property. If the property allows {@link #isMultiple() multiple values}, then this
+ * method may return a value greater than 1. If the property only allows a {@link #isSingle() single value}, then this method
+ * will return either 0 or 1. This method may return 0 regardless of whether the property allows a
+ * {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
+ *
+ * @return the number of actual values in this property; always non-negative
+ */
+ int size();
+
+ /**
+ * Determine whether the property currently has multiple values.
+ *
* @return true if the property has multiple values, or false otherwise.
* @see #isSingle()
+ * @see #isEmpty()
*/
boolean isMultiple();
/**
- * Determine whether the property is defined to allow a single value. This is a convenience method that is equivalent to
- * calling <code>!isMultiple()</code>.
- * @return true if the property has multiple values, or false otherwise.
+ * Determine whether the property currently has a single value.
+ *
+ * @return true if the property has a single value, or false otherwise.
* @see #isMultiple()
+ * @see #isEmpty()
*/
boolean isSingle();
/**
- * Get the number of actual values in this property. If the property allows {@link #isMultiple() multiple values}, then this
- * method may return a value greater than 1. If the property only allows a {@link #isSingle() single value}, then this method
- * will return either 0 or 1. This method may return 0 regardless of whether the property allows a
- * {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
- * @return the number of actual values in this property; always non-negative
- */
- int size();
-
- /**
* Determine whether this property has no actual values. This method may return <code>true</code> regardless of whether the
* property allows a {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
* <p>
* This method is a convenience method that is equivalent to <code>size() == 0</code>.
* </p>
- * @return the number of actual values in this property; always non-negative
+ *
+ * @return true if this property has no values, or false otherwise
+ * @see #isMultiple()
+ * @see #isSingle()
*/
boolean isEmpty();
/**
* Get the type for this property.
+ *
* @return the property's type, which is never null
*/
PropertyType getPropertyType();
@@ -96,12 +106,30 @@
* <p>
* The resulting iterator is immutable, and all property values are immutable.
* </p>
+ *
* @return an iterator over the values; never null
* @see Iterable#iterator()
+ * @see #getValuesAsArray()
*/
Iterator<?> getValues();
/**
+ * Obtain the property's values as an array of objects in their natural form, as defined by {@link #getPropertyType()}.
+ * <p>
+ * A valid array is return if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}, or a
+ * null value is returned if the property is {@link #isEmpty() empty}.
+ * </p>
+ * <p>
+ * The resulting array is a copy, guaranteeing immutability for the property.
+ * </p>
+ *
+ * @return the array of values
+ * @see Iterable#iterator()
+ * @see #getValues()
+ */
+ Object[] getValuesAsArray();
+
+ /**
* Obtain the property's values in their natural form, converting the values to the supplied {@link PropertyType} if it is
* different than this property's {@link #getPropertyType() property type}. Note that it is not always possible to convert
* between PropertyTypes.
@@ -111,6 +139,7 @@
* <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
@@ -126,6 +155,7 @@
* <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();
@@ -139,6 +169,7 @@
* <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();
@@ -152,6 +183,7 @@
* <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();
@@ -165,6 +197,7 @@
* <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();
@@ -179,12 +212,13 @@
* <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();
/**
- * Obtain the property's values as {@link Calendar dates}, converting the values if the
+ * Obtain the property's values as {@link DateTime dates}, converting the values if the
* {@link #getPropertyType() property type} is not {@link PropertyType#DATE}. Note that it is not always possible to convert
* to a {@link PropertyType#DATE date} value.
* <p>
@@ -193,9 +227,10 @@
* <p>
* The resulting iterator is immutable, and all property values are immutable.
* </p>
- * @return an iterator over the Calendar values; never null
+ *
+ * @return an iterator over the DateTime values; never null
*/
- Iterator<Calendar> getDateValues();
+ Iterator<DateTime> getDateValues();
/**
* Obtain the property's values as booleans, converting the values if the {@link #getPropertyType() property type} is not
@@ -207,6 +242,7 @@
* <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();
@@ -221,6 +257,7 @@
* <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();
@@ -235,6 +272,7 @@
* <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();
@@ -249,6 +287,7 @@
* <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();
@@ -262,6 +301,7 @@
* <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();
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -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;
+
+import java.util.Iterator;
+
+/**
+ * @author Randall Hauch
+ */
+public interface PropertyFactory {
+
+ Property create( Name name, PropertyType type, Name definitionName, Object... values );
+
+ Property create( Name name, PropertyType type, Name definitionName, Iterable<?> values );
+
+ Property create( Name name, PropertyType type, Name definitionName, Iterator<?> values );
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -24,6 +24,7 @@
import java.math.BigDecimal;
import java.net.URI;
import java.util.Comparator;
+import java.util.Iterator;
import net.jcip.annotations.Immutable;
import org.jboss.dna.spi.SpiI18n;
@@ -68,17 +69,32 @@
return this.comparator;
}
- public boolean isInstance( Object value ) {
+ public boolean isTypeFor( Object value ) {
return this.valueClass.isInstance(value);
}
+ public boolean isTypeForEach( Iterable<?> values ) {
+ for (Object value : values) {
+ if (!this.valueClass.isInstance(value)) return false;
+ }
+ return true;
+ }
+
+ public boolean isTypeForEach( Iterator<?> values ) {
+ while (values.hasNext()) {
+ Object value = values.next();
+ if (!this.valueClass.isInstance(value)) return false;
+ }
+ return true;
+ }
+
public static PropertyType discoverType( Object value ) {
if (value == null) {
throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyTypeForNullValue.text());
}
for (PropertyType type : PropertyType.values()) {
if (type == OBJECT) continue;
- if (type.isInstance(value)) return type;
+ if (type.isTypeFor(value)) return type;
}
return OBJECT;
}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * Command that copies a branch from one path to another. In other words, this is a deep version of {@link CopyNodeCommand}.
+ *
+ * @author Randall Hauch
+ */
+public interface CopyBranchCommand extends CopyNodeCommand {
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * Command that makes a copy of a single node at another location.
+ *
+ * @author Randall Hauch
+ */
+public interface CopyNodeCommand extends GraphCommand, ActsOnPath, ActsAsUpdate {
+
+ /**
+ * Get the new path to which the copy is to be made.
+ *
+ * @return the new path; never null
+ */
+ Path getNewPath();
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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/graph/commands/GetChildrenCommand.java 2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -24,9 +24,11 @@
import java.util.Iterator;
import org.jboss.dna.spi.cache.Cacheable;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
/**
* A command to get the children of a single node given its path.
+ *
* @author Randall Hauch
*/
public interface GetChildrenCommand extends GraphCommand, ActsOnPath, Cacheable {
@@ -41,9 +43,10 @@
* The caller may supply a custom iterator implementation, which will be called on this same connection within the same
* transaction when the node data is processed and consumed.
* </p>
+ *
* @param namesOfChildren the iterator over the names of children; may be null if there are no children
*/
- void setChildren( Iterator<Name> namesOfChildren );
+ void setChildren( Iterator<Path.Segment> namesOfChildren );
/**
* Set the children of this node using an iterator of names. Any existing child references already set on this command will be
@@ -55,9 +58,10 @@
* The caller may supply a custom iterator implementation, which will be called on this same connection within the same
* transaction when the node data is processed and consumed.
* </p>
+ *
* @param namesOfChildren the iterable names of children; may be null if there are no children
*/
- void setChildren( Iterable<Name> namesOfChildren );
+ void setChildren( Iterable<Path.Segment> namesOfChildren );
/**
* Set the children of this node using the array of names. Any existing child references already set on this command will be
@@ -65,13 +69,16 @@
* <p>
* The indexes of the same-name siblings will be determined by the order in which they appear in the iterator.
* </p>
+ *
* @param namesOfChildren the names of children; may be null if there are no children
*/
- void setChildren( Name... namesOfChildren );
+ void setChildren( Path.Segment... namesOfChildren );
/**
* Set the child of this node using the supplied name. Any existing child references already set on this command will be
- * replaced by those supplied to this method.
+ * replaced by those supplied to this method. Note that a {@link Path.Segment segment} is not required in this case because
+ * there is only one child and (by definition) no index.
+ *
* @param nameOfChild
*/
void setChild( Name nameOfChild );
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/graph/commands/GetPropertiesCommand.java 2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -21,36 +21,48 @@
*/
package org.jboss.dna.spi.graph.commands;
+import java.util.Iterator;
import org.jboss.dna.spi.cache.Cacheable;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Property;
/**
* A command to obtain from the source the properties for a single node given its path.
+ *
* @author Randall Hauch
*/
public interface GetPropertiesCommand extends GraphCommand, ActsOnPath, Cacheable {
/**
- * Set the properties. Any existing property values, if previously set, will be overwritten. If there are no property vlaues
- * or if all of the property values are null, the property will be removed.
- * @param properties the properties
+ * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
+ * no property vlaues or if all of the property values are null, the property will be removed.
+ * <p>
+ * The implementation should be capable of accepting an array, {@link Iterator}, or {@link Iterable} as a sole single
+ * parameter, and properly extracting the values. This is so that callers that have an {@link Object} reference to an array,
+ * Iterator, or Iterable don't need to type check and cast in order to call {@link #setProperty(Name, Iterable...) the}
+ * {@link #setProperty(Name, Iterator...) appropriate} method.
+ * </p>
+ *
+ * @param propertyName the name of the property
+ * @param values the property values
*/
- void setProperties( Iterable<Property> properties );
+ void setProperty( Name propertyName, Object... values );
/**
- * Set the values for the property. Any existing property values, if previously set, will be overwritten. If there are no
- * property vlaues or if all of the property values are null, the property will be removed.
- * @param property the property
+ * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
+ * no property vlaues or if all of the property values are null, the property will be removed.
+ *
+ * @param propertyName the name of the property
+ * @param values the iterable property values
*/
- void setProperty( Property property );
+ void setProperty( Name propertyName, Iterable<?> values );
/**
* Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
* no property vlaues or if all of the property values are null, the property will be removed.
+ *
* @param propertyName the name of the property
- * @param values the property values
+ * @param values the iterator over the property values
*/
- void setProperty( Name propertyName, Object... values );
+ void setProperty( Name propertyName, Iterator<?> values );
}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,40 @@
+/*
+ * 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.impl;
+
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.CopyBranchCommand;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicCopyBranchCommand extends BasicCopyNodeCommand implements CopyBranchCommand {
+
+ /**
+ * @param oldPath
+ * @param newPath
+ */
+ public BasicCopyBranchCommand( Path oldPath, Path newPath ) {
+ super(oldPath, newPath);
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,63 @@
+/*
+ * 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.impl;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.CopyNodeCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicCopyNodeCommand extends BasicGraphCommand implements CopyNodeCommand {
+
+ private final Path oldPath;
+ private final Path newPath;
+
+ /**
+ * @param oldPath the path to the original; may not be null
+ * @param newPath the path to the copy; may not be null
+ */
+ public BasicCopyNodeCommand( Path oldPath, Path newPath ) {
+ super();
+ assert oldPath != null;
+ assert newPath != null;
+ this.oldPath = oldPath;
+ this.newPath = newPath;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return oldPath;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getNewPath() {
+ return newPath;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,96 @@
+/*
+ * 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.impl;
+
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicCreateNodeCommand extends BasicGraphCommand implements CreateNodeCommand {
+
+ private final Path path;
+ private final List<Property> properties;
+ private CachePolicy cachePolicy;
+ private long timeLoaded;
+
+ /**
+ * @param path the path to the node; may not be null
+ * @param properties the properties of the node; may not be null
+ */
+ public BasicCreateNodeCommand( Path path, List<Property> properties ) {
+ super();
+ assert path != null;
+ assert properties != null;
+ this.properties = properties;
+ this.path = path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterable<Property> getProperties() {
+ return properties;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CachePolicy getCachePolicy() {
+ return cachePolicy;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTimeLoaded() {
+ return timeLoaded;
+ }
+
+ /**
+ * @param timeLoaded Sets timeLoaded to the specified value.
+ */
+ public void setTimeLoaded( long timeLoaded ) {
+ this.timeLoaded = timeLoaded;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setCachePolicy( CachePolicy cachePolicy ) {
+ this.cachePolicy = cachePolicy;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,52 @@
+/*
+ * 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.impl;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.DeleteBranchCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicDeleteBranchCommand extends BasicGraphCommand implements DeleteBranchCommand {
+
+ private final Path path;
+
+ /**
+ * @param path the path to the node; may not be null
+ */
+ public BasicDeleteBranchCommand( Path path ) {
+ super();
+ assert path != null;
+ this.path = path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return path;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,131 @@
+/*
+ * 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.impl;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicGetChildrenCommand extends BasicGraphCommand implements GetChildrenCommand {
+
+ private List<Segment> children;
+ private final Path path;
+ private CachePolicy cachePolicy;
+ private long timeLoaded;
+
+ /**
+ * @param path the path to the node; may not be null
+ */
+ public BasicGetChildrenCommand( Path path ) {
+ super();
+ assert path != null;
+ this.path = path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChild( Name nameOfChild ) {
+ children = createChildrenList(nameOfChild);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChildren( Iterator<Segment> namesOfChildren ) {
+ children = createChildrenList(namesOfChildren);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChildren( Iterable<Segment> namesOfChildren ) {
+ children = createChildrenList(namesOfChildren);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChildren( Segment... namesOfChildren ) {
+ children = createChildrenList(namesOfChildren);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setNoChildren() {
+ children = Collections.emptyList();
+ }
+
+ /**
+ * @return children
+ */
+ public List<Segment> getChildren() {
+ return this.children;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CachePolicy getCachePolicy() {
+ return cachePolicy;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTimeLoaded() {
+ return timeLoaded;
+ }
+
+ /**
+ * @param timeLoaded Sets timeLoaded to the specified value.
+ */
+ public void setTimeLoaded( long timeLoaded ) {
+ this.timeLoaded = timeLoaded;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setCachePolicy( CachePolicy cachePolicy ) {
+ this.cachePolicy = cachePolicy;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,111 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.commands.GetNodeCommand;
+import org.jboss.dna.spi.graph.impl.BasicPathSegment;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicGetNodeCommand extends BasicGetPropertiesCommand implements GetNodeCommand {
+
+ private List<Segment> children;
+
+ /**
+ * @param path
+ */
+ public BasicGetNodeCommand( Path path ) {
+ super(path);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChild( Name nameOfChild ) {
+ if (nameOfChild == null) {
+ children = Collections.emptyList();
+ } else {
+ children = Collections.singletonList((Segment)new BasicPathSegment(nameOfChild));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChildren( Iterator<Segment> namesOfChildren ) {
+ if (namesOfChildren == null) {
+ children = Collections.emptyList();
+ } else {
+ children = new ArrayList<Segment>();
+ while (namesOfChildren.hasNext()) {
+ children.add(namesOfChildren.next());
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChildren( Iterable<Segment> namesOfChildren ) {
+ if (namesOfChildren == null) {
+ children = Collections.emptyList();
+ } else {
+ children = new ArrayList<Segment>();
+ for (Segment childSegment : namesOfChildren) {
+ children.add(childSegment);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setChildren( Segment... namesOfChildren ) {
+ if (namesOfChildren == null || namesOfChildren.length == 0) {
+ children = Collections.emptyList();
+ } else {
+ children = new ArrayList<Segment>();
+ for (Segment childSegment : namesOfChildren) {
+ children.add(childSegment);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setNoChildren() {
+ children = Collections.emptyList();
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,119 @@
+/*
+ * 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.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicGetPropertiesCommand extends BasicGraphCommand implements GetPropertiesCommand {
+
+ private final Map<Name, List<Object>> propertyValues = new HashMap<Name, List<Object>>();
+ private final Path path;
+ private CachePolicy cachePolicy;
+ private long timeLoaded;
+
+ /**
+ * @param path the path to the node; may not be null
+ */
+ public BasicGetPropertiesCommand( Path path ) {
+ super();
+ assert path != null;
+ this.path = path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Name propertyName, Object... values ) {
+ setProperty(propertyValues, propertyName, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Name propertyName, Iterable<?> values ) {
+ setProperty(propertyValues, propertyName, values);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setProperty( Name propertyName, Iterator<?> values ) {
+ setProperty(propertyValues, propertyName, values);
+ }
+
+ /**
+ * Get the property values that were added to the command
+ *
+ * @return the map of property name to values
+ */
+ public Map<Name, List<Object>> getPropertyValues() {
+ return this.propertyValues;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CachePolicy getCachePolicy() {
+ return cachePolicy;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTimeLoaded() {
+ return timeLoaded;
+ }
+
+ /**
+ * @param timeLoaded Sets timeLoaded to the specified value.
+ */
+ public void setTimeLoaded( long timeLoaded ) {
+ this.timeLoaded = timeLoaded;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setCachePolicy( CachePolicy cachePolicy ) {
+ this.cachePolicy = cachePolicy;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,163 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.impl.BasicPathSegment;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public abstract class BasicGraphCommand implements GraphCommand {
+
+ private boolean cancelled = false;
+
+ /**
+ *
+ */
+ public BasicGraphCommand() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ /**
+ * @param cancelled Sets cancelled to the specified value.
+ */
+ public void setCancelled( boolean cancelled ) {
+ this.cancelled = cancelled;
+ }
+
+ // ----------------------------------------------------------------------------------------------------------------
+ // Utility methods used by concrete command implementations
+ // ----------------------------------------------------------------------------------------------------------------
+
+ protected List<Segment> createChildrenList( Name nameOfChild ) {
+ if (nameOfChild == null) {
+ return Collections.emptyList();
+ }
+ return Collections.singletonList((Segment)new BasicPathSegment(nameOfChild));
+ }
+
+ protected List<Segment> createChildrenList( Iterator<Segment> namesOfChildren ) {
+ if (namesOfChildren == null) {
+ return Collections.emptyList();
+ }
+ List<Segment> children = new ArrayList<Segment>();
+ while (namesOfChildren.hasNext()) {
+ children.add(namesOfChildren.next());
+ }
+ return children;
+ }
+
+ protected List<Segment> createChildrenList( Iterable<Segment> namesOfChildren ) {
+ if (namesOfChildren == null) {
+ return Collections.emptyList();
+ }
+ List<Segment> children = new ArrayList<Segment>();
+ for (Segment childSegment : namesOfChildren) {
+ children.add(childSegment);
+ }
+ return children;
+ }
+
+ protected static List<Segment> createChildrenList( Segment... namesOfChildren ) {
+ if (namesOfChildren == null || namesOfChildren.length == 0) {
+ return Collections.emptyList();
+ }
+ List<Segment> children = new ArrayList<Segment>();
+ for (Segment childSegment : namesOfChildren) {
+ children.add(childSegment);
+ }
+ return children;
+ }
+
+ protected static void setProperty( Map<Name, List<Object>> propertyValues, Name propertyName, Object... values ) {
+ if (values == null || values.length == 0) {
+ propertyValues.remove(propertyName);
+ } else {
+ List<Object> valuesList = null;
+ if (values.length == 1) {
+ Object value = values[0];
+ if (value instanceof Collection<?>) {
+ setProperty(propertyValues, propertyName, ((Collection<?>)value).iterator());
+ return;
+ } else if (value instanceof Iterable<?>) {
+ setProperty(propertyValues, propertyName, (Iterable<?>)value);
+ return;
+ } else if (value instanceof Iterator<?>) {
+ setProperty(propertyValues, propertyName, (Iterator<?>)value);
+ return;
+ }
+ // Otherwise, single object is just a normal value ...
+ valuesList = Collections.singletonList(value);
+ } else {
+ assert values.length > 1;
+ valuesList = new ArrayList<Object>(values.length);
+ for (Object arrayValue : values) {
+ valuesList.add(arrayValue);
+ }
+ }
+ propertyValues.put(propertyName, valuesList);
+ }
+ }
+
+ protected static void setProperty( Map<Name, List<Object>> propertyValues, Name propertyName, Iterable<?> values ) {
+ if (values == null) {
+ propertyValues.remove(propertyName);
+ } else {
+ List<Object> valuesList = new ArrayList<Object>();
+ for (Object value : values) {
+ valuesList.add(value);
+ }
+ propertyValues.put(propertyName, valuesList);
+ }
+ }
+
+ protected static void setProperty( Map<Name, List<Object>> propertyValues, Name propertyName, Iterator<?> values ) {
+ if (values == null) {
+ propertyValues.remove(propertyName);
+ } else {
+ List<Object> valuesList = new ArrayList<Object>();
+ while (values.hasNext()) {
+ Object value = values.next();
+ valuesList.add(value);
+ }
+ propertyValues.put(propertyName, valuesList);
+ }
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,63 @@
+/*
+ * 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.impl;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.MoveBranchCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicMoveBranchCommand extends BasicGraphCommand implements MoveBranchCommand {
+
+ private final Path oldPath;
+ private final Path newPath;
+
+ /**
+ * @param oldPath the path to the original; may not be null
+ * @param newPath the path to the new location; may not be null
+ */
+ public BasicMoveBranchCommand( Path oldPath, Path newPath ) {
+ super();
+ assert oldPath != null;
+ assert newPath != null;
+ this.oldPath = oldPath;
+ this.newPath = newPath;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return oldPath;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getNewPath() {
+ return newPath;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,96 @@
+/*
+ * 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.impl;
+
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.SetPropertiesCommand;
+
+/**
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class BasicSetPropertiesCommand extends BasicGraphCommand implements SetPropertiesCommand {
+
+ private final Path path;
+ private final List<Property> properties;
+ private CachePolicy cachePolicy;
+ private long timeLoaded;
+
+ /**
+ * @param path the path to the node; may not be null
+ * @param properties the properties of the node; may not be null
+ */
+ public BasicSetPropertiesCommand( Path path, List<Property> properties ) {
+ super();
+ assert path != null;
+ assert properties != null;
+ this.properties = properties;
+ this.path = path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterable<Property> getProperties() {
+ return properties;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CachePolicy getCachePolicy() {
+ return cachePolicy;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTimeLoaded() {
+ return timeLoaded;
+ }
+
+ /**
+ * @param timeLoaded Sets timeLoaded to the specified value.
+ */
+ public void setTimeLoaded( long timeLoaded ) {
+ this.timeLoaded = timeLoaded;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setCachePolicy( CachePolicy cachePolicy ) {
+ this.cachePolicy = cachePolicy;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: 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 2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -23,6 +23,7 @@
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.PropertyFactory;
import org.jboss.dna.spi.graph.ValueFactories;
/**
@@ -32,20 +33,30 @@
/**
* 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();
+ /**
+ * Get the factory for creating {@link Property} objects.
+ *
+ * @return the property factory; never null
+ */
+ PropertyFactory getPropertyFactory();
+
}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,110 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.NoSuchElementException;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public class BasicEmptyProperty extends BasicProperty {
+
+ /**
+ * @param name
+ * @param type
+ * @param definitionName
+ * @param valueFactories
+ */
+ public BasicEmptyProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories ) {
+ super(name, type, definitionName, valueFactories);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEmpty() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMultiple() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSingle() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int size() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Object> iterator() {
+ return new EmptyIterator<Object>();
+ }
+
+ protected class EmptyIterator<T> implements Iterator<T> {
+
+ protected EmptyIterator() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNext() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T next() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,120 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.List;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public class BasicMultiValueProperty extends BasicProperty {
+
+ private final List<Object> values;
+
+ /**
+ * @param name
+ * @param type
+ * @param definitionName
+ * @param valueFactories
+ * @param values
+ */
+ public BasicMultiValueProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories, List<Object> values ) {
+ super(name, type, definitionName, valueFactories);
+ this.values = values;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEmpty() {
+ assert values.isEmpty() == false;
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMultiple() {
+ assert values.size() > 1;
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSingle() {
+ assert values.size() == 1;
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int size() {
+ return values.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Object> iterator() {
+ return new ReadOnlyIterator(values.iterator());
+ }
+
+ protected class ReadOnlyIterator implements Iterator<Object> {
+
+ private final Iterator<Object> values;
+
+ protected ReadOnlyIterator( Iterator<Object> values ) {
+ assert values != null;
+ this.values = values;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNext() {
+ return values.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object next() {
+ return values.next();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,293 @@
+/*
+ * 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 java.math.BigDecimal;
+import java.net.URI;
+import java.util.Iterator;
+import net.jcip.annotations.Immutable;
+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.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public abstract class BasicProperty implements Property {
+
+ private final Name name;
+ private final Name definitionName;
+ private final PropertyType type;
+ private final ValueFactories factories;
+
+ /**
+ * @param name
+ * @param type
+ * @param definitionName
+ * @param valueFactories
+ */
+ public BasicProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories ) {
+ this.name = name;
+ this.type = type;
+ this.definitionName = definitionName;
+ this.factories = valueFactories;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name getName() {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name getDefinitionName() {
+ return definitionName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PropertyType getPropertyType() {
+ return type;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Binary> getBinaryValues() {
+ return new ValueIterator<Binary>(factories.getBinaryFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Boolean> getBooleanValues() {
+ return new ValueIterator<Boolean>(factories.getBooleanFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<DateTime> getDateValues() {
+ return new ValueIterator<DateTime>(factories.getDateFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<BigDecimal> getDecimalValues() {
+ return new ValueIterator<BigDecimal>(factories.getDecimalFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Double> getDoubleValues() {
+ return new ValueIterator<Double>(factories.getDoubleFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Long> getLongValues() {
+ return new ValueIterator<Long>(factories.getLongFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Name> getNameValues() {
+ return new ValueIterator<Name>(factories.getNameFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Path> getPathValues() {
+ return new ValueIterator<Path>(factories.getPathFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Reference> getReferenceValues() {
+ return new ValueIterator<Reference>(factories.getReferenceFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<String> getStringValues() {
+ return new ValueIterator<String>(factories.getStringFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<URI> getUriValues() {
+ return new ValueIterator<URI>(factories.getUriFactory(), iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<?> getValues() {
+ return iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<?> getValues( PropertyType type ) {
+ switch (type) {
+ case BINARY:
+ return getBinaryValues();
+ case BOOLEAN:
+ return getBooleanValues();
+ case DATE:
+ return getDateValues();
+ case DECIMAL:
+ return getDecimalValues();
+ case DOUBLE:
+ return getDoubleValues();
+ case LONG:
+ return getLongValues();
+ case NAME:
+ return getNameValues();
+ case OBJECT:
+ return getValues();
+ case PATH:
+ return getPathValues();
+ case REFERENCE:
+ return getReferenceValues();
+ case STRING:
+ return getStringValues();
+ case URI:
+ return getUriValues();
+ }
+ return getValues(); // should never get here ...
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object[] getValuesAsArray() {
+ if (size() == 0) return null;
+ Object[] results = new Object[size()];
+ Iterator<?> iter = iterator();
+ int index = 0;
+ while (iter.hasNext()) {
+ Object value = iter.next();
+ results[index++] = value;
+ }
+ return results;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Property o ) {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Property) {
+ Property that = (Property)obj;
+ if (!this.getName().equals(that.getName())) return false;
+ if (this.getPropertyType() != that.getPropertyType()) return false;
+ if (this.size() != that.size()) return false;
+ Iterator<?> thisIter = iterator();
+ Iterator<?> thatIter = that.iterator();
+ while (thisIter.hasNext()) { // && thatIter.hasNext()
+ Object thisValue = thisIter.next();
+ Object thatValue = thatIter.next();
+ if (thisValue == null) {
+ if (thatValue != null) return false;
+ // else both are null
+ } else {
+ if (!thisValue.equals(thatValue)) return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ protected class ValueIterator<T> implements Iterator<T> {
+
+ private final ValueFactory<T> factory;
+ private final Iterator<Object> values;
+
+ protected ValueIterator( ValueFactory<T> factory, Iterator<Object> values ) {
+ assert factory != null;
+ assert values != null;
+ this.factory = factory;
+ this.values = values;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNext() {
+ return values.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T next() {
+ return factory.create(values.next());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,135 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.PropertyFactory;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicPropertyFactory implements PropertyFactory {
+
+ private final ValueFactories factories;
+
+ /**
+ * @param valueFactories the value factories
+ * @throws IllegalArgumentException if the reference to the value factories is null
+ */
+ public BasicPropertyFactory( ValueFactories valueFactories ) {
+ ArgCheck.isNotNull(valueFactories, "value factories");
+ this.factories = valueFactories;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Property create( Name name, PropertyType type, Name definitionName, Object... values ) {
+ ArgCheck.isNotNull(name, "name");
+ ArgCheck.isNotNull(type, "type");
+ if (values == null || values.length == 0) {
+ return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ }
+ final int len = values.length;
+ final ValueFactory<?> factory = factories.getValueFactory(type);
+ if (values.length == 1) {
+ Object value = values[0];
+ // Check whether the sole value was a collection ...
+ if (value instanceof Collection) {
+ // The single value is a collection, so create property with the collection's contents ...
+ return create(name, type, definitionName, (Collection<?>)value);
+ }
+ value = factory.create(values[0]);
+ return new BasicSingleValueProperty(name, type, definitionName, this.factories, value);
+ }
+ List<Object> valueList = new ArrayList<Object>(len);
+ for (int i = 0; i != len; ++i) {
+ Object value = factory.create(values[i]);
+ valueList.add(value);
+ }
+ return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings( "unchecked" )
+ public Property create( Name name, PropertyType type, Name definitionName, Iterable<?> values ) {
+ ArgCheck.isNotNull(name, "name");
+ ArgCheck.isNotNull(type, "type");
+ List<Object> valueList = null;
+ if (values instanceof Collection) {
+ Collection<Object> originalValues = (Collection<Object>)values;
+ if (originalValues.isEmpty()) {
+ return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ }
+ valueList = new ArrayList<Object>(originalValues.size());
+ } else {
+ // We don't know the size
+ valueList = new ArrayList<Object>();
+ }
+ // Copy the values, ensuring that the values are the correct type ...
+ final ValueFactory<?> factory = factories.getValueFactory(type);
+ for (Object value : values) {
+ valueList.add(factory.create(value));
+ }
+ if (valueList.isEmpty()) { // may not have been a collection earlier
+ return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ }
+ if (valueList.size() == 1) {
+ return new BasicSingleValueProperty(name, type, definitionName, this.factories, valueList.get(0));
+ }
+ return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Property create( Name name, PropertyType type, Name definitionName, Iterator<?> values ) {
+ ArgCheck.isNotNull(name, "name");
+ ArgCheck.isNotNull(type, "type");
+ final List<Object> valueList = new ArrayList<Object>();
+ final ValueFactory<?> factory = factories.getValueFactory(type);
+ while (values.hasNext()) {
+ Object value = values.next();
+ value = factory.create(value);
+ valueList.add(value);
+ }
+ if (valueList.isEmpty()) {
+ return new BasicEmptyProperty(name, type, definitionName, this.factories);
+ }
+ if (valueList.size() == 1) {
+ return new BasicSingleValueProperty(name, type, definitionName, this.factories, valueList.get(0));
+ }
+ return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java 2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,120 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.NoSuchElementException;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public class BasicSingleValueProperty extends BasicProperty {
+
+ protected final Object value;
+
+ /**
+ * @param name
+ * @param type
+ * @param definitionName
+ * @param valueFactories
+ * @param value
+ */
+ public BasicSingleValueProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories, Object value ) {
+ super(name, type, definitionName, valueFactories);
+ this.value = value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMultiple() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSingle() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int size() {
+ return 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Object> iterator() {
+ return new ValueIterator();
+ }
+
+ protected class ValueIterator implements Iterator<Object> {
+
+ private boolean done = false;
+
+ protected ValueIterator() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNext() {
+ return !done;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object next() {
+ if (!done) {
+ done = true;
+ return BasicSingleValueProperty.this.value;
+ }
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 11 months