DNA SVN: r859 - in trunk: docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer and 4 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-27 21:50:54 -0400 (Mon, 27 Apr 2009)
New Revision: 859
Removed:
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/SequencerConfig.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
trunk/extensions/dna-sequencer-java/pom.xml
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
Log:
DNA-384 Trouble compiling Java sequencer using Eclipse JDT and its dependencies
Adjusted the Eclipse JDT dependency fragments, removing some of its dependencies that remain unused in the "dna-sequencer-java" project.
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/SequencerConfig.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/SequencerConfig.java 2009-04-27 18:58:29 UTC (rev 858)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencer/SequencerConfig.java 2009-04-28 01:50:54 UTC (rev 859)
@@ -39,11 +39,30 @@
private final Set<SequencerPathExpression> pathExpressions;
- public SequencerConfig( String name, String description, Map<String, Object> properties, String classname, String[] classpath, String... pathExpressions ) {
+ public SequencerConfig( String name,
+ String description,
+ String classname,
+ String[] classpath,
+ String... pathExpressions ) {
+ this(name, description, System.currentTimeMillis(), null, classname, classpath, pathExpressions);
+ }
+
+ public SequencerConfig( String name,
+ String description,
+ Map<String, Object> properties,
+ String classname,
+ String[] classpath,
+ String... pathExpressions ) {
this(name, description, System.currentTimeMillis(), properties, classname, classpath, pathExpressions);
}
- public SequencerConfig( String name, String description, long timestamp, Map<String, Object> properties, String classname, String[] classpath, String... pathExpressions ) {
+ public SequencerConfig( String name,
+ String description,
+ long timestamp,
+ Map<String, Object> properties,
+ String classname,
+ String[] classpath,
+ String... pathExpressions ) {
super(name, description, timestamp, properties, classname, classpath);
this.pathExpressions = buildPathExpressionSet(pathExpressions);
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-04-27 18:58:29 UTC (rev 858)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencer/SequencingClient.java 2009-04-28 01:50:54 UTC (rev 859)
@@ -168,7 +168,8 @@
try {
// Register the node types (only valid the first time) ...
- JackrabbitNodeTypeManager mgr = (JackrabbitNodeTypeManager)this.keepAliveSession.getWorkspace().getNodeTypeManager();
+ JackrabbitNodeTypeManager mgr = (JackrabbitNodeTypeManager)this.keepAliveSession.getWorkspace()
+ .getNodeTypeManager();
mgr.registerNodeTypes(cndFile.openStream(), JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
} catch (RepositoryException e) {
if (!e.getMessage().contains("already exists")) throw e;
@@ -287,9 +288,11 @@
this.sequencingService.getAdministrator().shutdown();
this.sequencingService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);
- // Shut down the observation service ...
- this.observationService.getAdministrator().shutdown();
- this.observationService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);
+ if (this.observationService != null) {
+ // Shut down the observation service ...
+ this.observationService.getAdministrator().shutdown();
+ this.observationService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);
+ }
}
/**
@@ -396,7 +399,8 @@
// import informations
javaElements = new ArrayList<Properties>();
try {
- for (NodeIterator singleImportIterator = javaCompilationUnit.getNode("java:import/java:importDeclaration/java:singleImport").getNodes(); singleImportIterator.hasNext();) {
+ for (NodeIterator singleImportIterator = javaCompilationUnit.getNode("java:import/java:importDeclaration/java:singleImport")
+ .getNodes(); singleImportIterator.hasNext();) {
Node javasingleTypeImportDeclarationNode = singleImportIterator.nextNode();
javaElements.add(extractJavaInfo(javasingleTypeImportDeclarationNode));
}
@@ -407,7 +411,8 @@
javaElements = new ArrayList<Properties>();
try {
- for (NodeIterator javaImportOnDemandIterator = javaCompilationUnit.getNode("java:import/java:importDeclaration/java:importOnDemand").getNodes(); javaImportOnDemandIterator.hasNext();) {
+ for (NodeIterator javaImportOnDemandIterator = javaCompilationUnit.getNode("java:import/java:importDeclaration/java:importOnDemand")
+ .getNodes(); javaImportOnDemandIterator.hasNext();) {
Node javaImportOnDemandtDeclarationNode = javaImportOnDemandIterator.nextNode();
javaElements.add(extractJavaInfo(javaImportOnDemandtDeclarationNode));
}
@@ -424,7 +429,8 @@
// field member informations
javaElements = new ArrayList<Properties>();
- for (NodeIterator javaFieldTypeIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:field/java:fieldType").getNodes(); javaFieldTypeIterator.hasNext();) {
+ for (NodeIterator javaFieldTypeIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:field/java:fieldType")
+ .getNodes(); javaFieldTypeIterator.hasNext();) {
Node rootFieldTypeNode = javaFieldTypeIterator.nextNode();
if (rootFieldTypeNode.hasNode("java:primitiveType")) {
Node javaPrimitiveTypeNode = rootFieldTypeNode.getNode("java:primitiveType");
@@ -449,7 +455,8 @@
// constructor informations
javaElements = new ArrayList<Properties>();
- for (NodeIterator javaConstructorIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:constructor").getNodes(); javaConstructorIterator.hasNext();) {
+ for (NodeIterator javaConstructorIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:constructor")
+ .getNodes(); javaConstructorIterator.hasNext();) {
Node javaConstructor = javaConstructorIterator.nextNode();
javaElements.add(extractJavaInfo(javaConstructor));
}
@@ -457,7 +464,8 @@
// method informations
javaElements = new ArrayList<Properties>();
- for (NodeIterator javaMethodIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:method").getNodes(); javaMethodIterator.hasNext();) {
+ for (NodeIterator javaMethodIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:method")
+ .getNodes(); javaMethodIterator.hasNext();) {
Node javaMethod = javaMethodIterator.nextNode();
javaElements.add(extractJavaInfo(javaMethod));
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-04-27 18:58:29 UTC (rev 858)
+++ trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencer/SequencingClientTest.java 2009-04-28 01:50:54 UTC (rev 859)
@@ -31,7 +31,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import org.jboss.dna.common.util.FileUtil;
-import org.jboss.example.dna.sequencer.SequencingClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -65,9 +64,15 @@
@After
public void afterEach() throws Exception {
- client.shutdownDnaServices();
- client.shutdownRepository();
- FileUtil.delete("target/repositoryData");
+ try {
+ client.shutdownDnaServices();
+ } finally {
+ try {
+ client.shutdownRepository();
+ } finally {
+ FileUtil.delete("target/repositoryData");
+ }
+ }
}
@Test
Modified: trunk/extensions/dna-sequencer-java/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-java/pom.xml 2009-04-27 18:58:29 UTC (rev 858)
+++ trunk/extensions/dna-sequencer-java/pom.xml 2009-04-28 01:50:54 UTC (rev 859)
@@ -87,49 +87,49 @@
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
</dependency>
- <dependency>
- <groupId>org.eclipse.jdt</groupId>
- <artifactId>core</artifactId>
- <version>3.2.3.v_686_R32x</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.core</groupId>
- <artifactId>runtime</artifactId>
- <version>3.3.100-v20070530</version>
- <!-- Exclude this problem library -->
- <exclusions>
- <exclusion>
- <groupId>org.eclipse.equinox</groupId>
- <artifactId>app</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.eclipse.core</groupId>
- <artifactId>resources</artifactId>
- <version>3.3.0-v20070604</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.4</version>
- </dependency>
<!--
- Apache Jackrabbit (JCR Implementation)
+ Eclipse Java Development Tools (JDT) parser and its (many) required libraries
-->
- <dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-core</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>core</artifactId>
+ <version>3.4.2.v_883_R34x</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>resources</artifactId>
+ <version>[3.2.0,4.0.0)</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.eclipse.core.runtime.compatibility</groupId>
+ <artifactId>auth</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>app</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ <version>[3.2.0,4.0.0)</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>runtime</artifactId>
+ <version>[3.2.0,4.0.0)</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.eclipse.core.runtime.compatibility</groupId>
+ <artifactId>auth</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>app</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<reporting>
<plugins>
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2009-04-27 18:58:29 UTC (rev 858)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2009-04-28 01:50:54 UTC (rev 859)
@@ -26,7 +26,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import org.apache.commons.lang.StringUtils;
import org.jboss.dna.graph.property.NameFactory;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
@@ -200,7 +199,8 @@
// sequence package declaration of a unit.
PackageMetadata packageMetadata = javaMetadata.getPackageMetadata();
if (packageMetadata != null) {
- if (StringUtils.isNotEmpty(packageMetadata.getName())) {
+ String packageName = packageMetadata.getName();
+ if (packageName != null && packageName.length() != 0) {
Path javaPackageDeclarationChildNode = pathFactory.create(JAVA_COMPILATION_UNIT_NODE + SLASH
+ JAVA_PACKAGE_CHILD_NODE + SLASH
16 years, 8 months
DNA SVN: r858 - in trunk: dna-jcr/src/test/resources and 3 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-27 14:58:29 -0400 (Mon, 27 Apr 2009)
New Revision: 858
Added:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
Removed:
trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
trunk/dna-jcr-tck/src/test/resources/repositoryStubImpl.properties
Modified:
trunk/dna-jcr-tck/pom.xml
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java
trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
Log:
DNA-383 dna-jcr-tck Project Keeps Getting Out Of Sync With dna-jcr Project
Applied the patch, which removes the redundant files in dna-jcr-tck and fixes the POM.
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-04-27 18:58:29 UTC (rev 858)
@@ -0,0 +1,328 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.File;
+import java.net.URI;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import javax.jcr.Credentials;
+import javax.jcr.PropertyType;
+import org.apache.jackrabbit.test.RepositoryStub;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.JcrMixLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.graph.io.GraphImporter;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.jcr.JcrRepository.Options;
+
+/**
+ * Concrete implementation of {@link RepositoryStub} based on DNA-specific configuration.
+ */
+public class InMemoryRepositoryStub extends RepositoryStub {
+ private JcrRepository repository;
+ protected InMemoryRepositorySource source;
+ protected AccessControlContext accessControlContext = AccessController.getContext();
+
+ private Credentials superUserCredentials = new Credentials() {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public AccessControlContext getAccessControlContext() {
+ return accessControlContext;
+ }
+ };
+
+ private Credentials readWriteCredentials = new Credentials() {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public AccessControlContext getAccessControlContext() {
+ return accessControlContext;
+ }
+ };
+
+ private Credentials readOnlyCredentials = new Credentials() {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public AccessControlContext getAccessControlContext() {
+ return accessControlContext;
+ }
+ };
+
+ protected ExecutionContext executionContext = new ExecutionContext();
+
+ protected RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() {
+ public RepositoryConnection createConnection( String sourceName ) {
+ return source.getConnection();
+ }
+ };
+
+ public InMemoryRepositoryStub( Properties env ) {
+ super(env);
+
+ // Create the in-memory (DNA) repository
+ source = new InMemoryRepositorySource();
+
+ // Various calls will fail if you do not set a non-null name for the source
+ source.setName("TestRepositorySource");
+
+ // Make sure the path to the namespaces exists ...
+ Graph graph = Graph.create(source.getName(), connectionFactory, executionContext);
+ graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces");
+
+ // Wrap a connection to the in-memory (DNA) repository in a (JCR) repository
+ Map<Options, String> options = Collections.singletonMap(Options.PROJECT_NODE_TYPES, "false");
+
+ repository = new JcrRepository(executionContext.create(accessControlContext), connectionFactory, source.getName(), null,
+ options);
+ RepositoryNodeTypeManager nodeTypes = repository.getRepositoryTypeManager();
+
+ // Set up some sample nodes in the graph to match the expected test configuration
+ try {
+ nodeTypes.registerNodeTypes(new TckTestNodeTypeSource(executionContext, nodeTypes));
+
+ executionContext.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI);
+
+ Path destinationPath = executionContext.getValueFactories().getPathFactory().create("/");
+ GraphImporter importer = new GraphImporter(graph);
+
+ URI xmlContent = new File("src/test/resources/repositoryForTckTests.xml").toURI();
+ Graph.Batch batch = importer.importXml(xmlContent, Location.create(destinationPath));
+ batch.execute();
+
+ } catch (Exception ex) {
+ // The TCK tries to quash this exception. Print it out to be more obvious.
+ ex.printStackTrace();
+ throw new IllegalStateException("Repository initialization failed.", ex);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.jackrabbit.test.RepositoryStub#getSuperuserCredentials()
+ */
+ @Override
+ public Credentials getSuperuserCredentials() {
+ return superUserCredentials;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.jackrabbit.test.RepositoryStub#getReadOnlyCredentials()
+ */
+ @Override
+ public Credentials getReadOnlyCredentials() {
+ return readOnlyCredentials;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.jackrabbit.test.RepositoryStub#getReadOnlyCredentials()
+ */
+ @Override
+ public Credentials getReadWriteCredentials() {
+ return readWriteCredentials;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.jackrabbit.test.RepositoryStub#getRepository()
+ */
+ @Override
+ public JcrRepository getRepository() {
+ return repository;
+ }
+
+ class TckTestNodeTypeSource extends AbstractJcrNodeTypeSource {
+ /** The list of node types. */
+ private final List<JcrNodeType> nodeTypes;
+
+ TckTestNodeTypeSource( ExecutionContext context,
+ RepositoryNodeTypeManager nodeTypeManager ) {
+ super(null);
+
+ nodeTypes = new ArrayList<JcrNodeType>();
+
+ JcrNodeType base = nodeTypeManager.getNodeType(JcrNtLexicon.BASE);
+
+ if (base == null) {
+ String baseTypeName = JcrNtLexicon.BASE.getString(context.getNamespaceRegistry());
+ String namespaceTypeName = TestLexicon.NO_SAME_NAME_SIBS.getString(context.getNamespaceRegistry());
+ throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+ }
+
+ JcrNodeType referenceable = nodeTypeManager.getNodeType(JcrMixLexicon.REFERENCEABLE);
+
+ if (referenceable == null) {
+ String baseTypeName = JcrMixLexicon.REFERENCEABLE.getString(context.getNamespaceRegistry());
+ String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry());
+ throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+ }
+
+ JcrNodeType unstructured = nodeTypeManager.getNodeType(JcrNtLexicon.UNSTRUCTURED);
+
+ if (unstructured == null) {
+ String baseTypeName = JcrNtLexicon.UNSTRUCTURED.getString(context.getNamespaceRegistry());
+ String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry());
+ throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+ }
+
+ // Stubbing in child node and property definitions for now
+ JcrNodeType noSameNameSibs = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.NO_SAME_NAME_SIBS,
+ Arrays.asList(new JcrNodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ context,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.VERSION.getJcrValue(),
+ false,
+ false,
+ false,
+ false,
+ JcrNtLexicon.UNSTRUCTURED,
+ new JcrNodeType[] {base}),}),
+ NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType referenceableUnstructured = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.REFERENCEABLE_UNSTRUCTURED,
+ Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
+ NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, NO_PROPERTIES,
+ NOT_MIXIN, ORDERABLE_CHILD_NODES);
+
+ JcrNodeType nodeWithMandatoryProperty = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.NODE_WITH_MANDATORY_PROPERTY,
+ Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ context,
+ null,
+ TestLexicon.MANDATORY_STRING,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false,
+ true,
+ false,
+ NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED,
+ NO_CONSTRAINTS,
+ false)}),
+ NOT_MIXIN, ORDERABLE_CHILD_NODES);
+ JcrNodeType nodeWithMandatoryChild = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.NODE_WITH_MANDATORY_CHILD,
+ Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ context,
+ null,
+ TestLexicon.MANDATORY_CHILD,
+ OnParentVersionBehavior.VERSION.getJcrValue(),
+ false,
+ true,
+ false,
+ false,
+ JcrNtLexicon.UNSTRUCTURED,
+ new JcrNodeType[] {base}),}),
+ NO_PROPERTIES, NOT_MIXIN, ORDERABLE_CHILD_NODES);
+
+ JcrNodeType unorderableUnstructured = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.UNORDERABLE_UNSTRUCTURED,
+ Arrays.asList(new JcrNodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ context,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.VERSION.getJcrValue(),
+ false,
+ false,
+ false,
+ true,
+ TestLexicon.UNORDERABLE_UNSTRUCTURED,
+ new JcrNodeType[] {base}),}),
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(
+ context,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false,
+ NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+ context,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false,
+ NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED,
+ NO_CONSTRAINTS, true),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {referenceableUnstructured, noSameNameSibs,
+ nodeWithMandatoryProperty, nodeWithMandatoryChild, unorderableUnstructured,}));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrNodeTypeSource#getNodeTypes()
+ */
+ @Override
+ public Collection<JcrNodeType> getDeclaredNodeTypes() {
+ return nodeTypes;
+ }
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-27 18:45:16 UTC (rev 857)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-27 18:58:29 UTC (rev 858)
@@ -23,23 +23,9 @@
*/
package org.jboss.dna.jcr;
-import java.io.File;
-import java.net.URI;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import javax.jcr.Credentials;
-import javax.jcr.PropertyType;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.jackrabbit.test.JCRTestSuite;
-import org.apache.jackrabbit.test.RepositoryStub;
import org.apache.jackrabbit.test.api.AddNodeTest;
import org.apache.jackrabbit.test.api.DocumentViewImportTest;
import org.apache.jackrabbit.test.api.NamespaceRegistryTest;
@@ -83,18 +69,8 @@
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesTest;
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesVersionableTest;
import org.apache.jackrabbit.test.api.WorkspaceCopyVersionableTest;
+import org.apache.jackrabbit.test.api.WorkspaceMoveReferenceableTest;
import org.apache.jackrabbit.test.api.WorkspaceMoveVersionableTest;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.Graph;
-import org.jboss.dna.graph.JcrMixLexicon;
-import org.jboss.dna.graph.JcrNtLexicon;
-import org.jboss.dna.graph.Location;
-import org.jboss.dna.graph.connector.RepositoryConnection;
-import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
-import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
-import org.jboss.dna.graph.io.GraphImporter;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.jcr.JcrRepository.Options;
/**
* Test suite to wrap Apache Jackrabbit JCR technology compatibility kit (TCK) unit tests. Note that technically these are not the
@@ -244,7 +220,7 @@
// addTestSuite(WorkspaceCopySameNameSibsTest.class);
// addTestSuite(WorkspaceCopyTest.class);
addTestSuite(WorkspaceCopyVersionableTest.class);
- // addTestSuite(WorkspaceMoveReferenceableTest.class);
+ addTestSuite(WorkspaceMoveReferenceableTest.class);
// addTestSuite(WorkspaceMoveSameNameSibsTest.class);
// addTestSuite(WorkspaceMoveTest.class);
addTestSuite(WorkspaceMoveVersionableTest.class);
@@ -275,249 +251,4 @@
addTest(org.apache.jackrabbit.test.api.util.TestAll.suite());
}
}
-
- /**
- * Concrete implementation of {@link RepositoryStub} based on DNA-specific configuration.
- */
- public static class InMemoryRepositoryStub extends RepositoryStub {
- private JcrRepository repository;
- protected InMemoryRepositorySource source;
- protected AccessControlContext accessControlContext = AccessController.getContext();
-
- private Credentials superUserCredentials = new Credentials() {
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings( "unused" )
- public AccessControlContext getAccessControlContext() {
- return accessControlContext;
- }
- };
-
- private Credentials readWriteCredentials = new Credentials() {
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings( "unused" )
- public AccessControlContext getAccessControlContext() {
- return accessControlContext;
- }
- };
-
- private Credentials readOnlyCredentials = new Credentials() {
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings( "unused" )
- public AccessControlContext getAccessControlContext() {
- return accessControlContext;
- }
- };
-
- protected ExecutionContext executionContext = new ExecutionContext();
-
- protected RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() {
- public RepositoryConnection createConnection( String sourceName ) {
- return source.getConnection();
- }
- };
-
- public InMemoryRepositoryStub( Properties env ) {
- super(env);
-
- // Create the in-memory (DNA) repository
- source = new InMemoryRepositorySource();
-
- // Various calls will fail if you do not set a non-null name for the source
- source.setName("TestRepositorySource");
-
- // Make sure the path to the namespaces exists ...
- Graph graph = Graph.create(source.getName(), connectionFactory, executionContext);
- graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces");
-
- // Wrap a connection to the in-memory (DNA) repository in a (JCR) repository
- Map<Options, String> options = Collections.singletonMap(Options.PROJECT_NODE_TYPES, "false");
-
- repository = new JcrRepository(executionContext.create(accessControlContext), connectionFactory, source.getName(),
- null, options);
- RepositoryNodeTypeManager nodeTypes = repository.getRepositoryTypeManager();
-
- // Set up some sample nodes in the graph to match the expected test configuration
- try {
- nodeTypes.registerNodeTypes(new TckTestNodeTypeSource(executionContext, nodeTypes));
-
- executionContext.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI);
-
- Path destinationPath = executionContext.getValueFactories().getPathFactory().create("/");
- GraphImporter importer = new GraphImporter(graph);
-
- URI xmlContent = new File("src/test/resources/repositoryForTckTests.xml").toURI();
- Graph.Batch batch = importer.importXml(xmlContent, Location.create(destinationPath));
- batch.execute();
-
- } catch (Exception ex) {
- // The TCK tries to quash this exception. Print it out to be more obvious.
- ex.printStackTrace();
- throw new IllegalStateException("Repository initialization failed.", ex);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.jackrabbit.test.RepositoryStub#getSuperuserCredentials()
- */
- @Override
- public Credentials getSuperuserCredentials() {
- return superUserCredentials;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.jackrabbit.test.RepositoryStub#getReadOnlyCredentials()
- */
- @Override
- public Credentials getReadOnlyCredentials() {
- return readOnlyCredentials;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.jackrabbit.test.RepositoryStub#getReadOnlyCredentials()
- */
- @Override
- public Credentials getReadWriteCredentials() {
- return readWriteCredentials;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.jackrabbit.test.RepositoryStub#getRepository()
- */
- @Override
- public JcrRepository getRepository() {
- return repository;
- }
-
- }
-
- static class TckTestNodeTypeSource extends AbstractJcrNodeTypeSource {
- /** The list of node types. */
- private final List<JcrNodeType> nodeTypes;
-
- TckTestNodeTypeSource( ExecutionContext context,
- RepositoryNodeTypeManager nodeTypeManager ) {
- super(null);
-
- nodeTypes = new ArrayList<JcrNodeType>();
-
- JcrNodeType base = nodeTypeManager.getNodeType(JcrNtLexicon.BASE);
-
- if (base == null) {
- String baseTypeName = JcrNtLexicon.BASE.getString(context.getNamespaceRegistry());
- String namespaceTypeName = TestLexicon.NO_SAME_NAME_SIBS.getString(context.getNamespaceRegistry());
- throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
- }
-
- JcrNodeType referenceable = nodeTypeManager.getNodeType(JcrMixLexicon.REFERENCEABLE);
-
- if (referenceable == null) {
- String baseTypeName = JcrMixLexicon.REFERENCEABLE.getString(context.getNamespaceRegistry());
- String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry());
- throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
- }
-
- JcrNodeType unstructured = nodeTypeManager.getNodeType(JcrNtLexicon.UNSTRUCTURED);
-
- if (unstructured == null) {
- String baseTypeName = JcrNtLexicon.UNSTRUCTURED.getString(context.getNamespaceRegistry());
- String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry());
- throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
- }
-
- // Stubbing in child node and property definitions for now
- JcrNodeType noSameNameSibs = new JcrNodeType(
- context,
- NO_NODE_TYPE_MANAGER,
- TestLexicon.NO_SAME_NAME_SIBS,
- Arrays.asList(new JcrNodeType[] {base}),
- NO_PRIMARY_ITEM_NAME,
- Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
- context,
- null,
- ALL_NODES,
- OnParentVersionBehavior.VERSION.getJcrValue(),
- false,
- false,
- false,
- false,
- JcrNtLexicon.UNSTRUCTURED,
- new JcrNodeType[] {base}),}),
- NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES);
-
- JcrNodeType referenceableUnstructured = new JcrNodeType(
- context,
- NO_NODE_TYPE_MANAGER,
- TestLexicon.REFERENCEABLE_UNSTRUCTURED,
- Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
- NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, NO_PROPERTIES,
- NOT_MIXIN, ORDERABLE_CHILD_NODES);
-
- JcrNodeType nodeWithMandatoryProperty = new JcrNodeType(
- context,
- NO_NODE_TYPE_MANAGER,
- TestLexicon.NODE_WITH_MANDATORY_PROPERTY,
- Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
- NO_PRIMARY_ITEM_NAME,
- NO_CHILD_NODES,
- Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
- context,
- null,
- TestLexicon.MANDATORY_STRING,
- OnParentVersionBehavior.COPY.getJcrValue(),
- false,
- true,
- false,
- NO_DEFAULT_VALUES,
- PropertyType.UNDEFINED,
- NO_CONSTRAINTS,
- false)}),
- NOT_MIXIN, ORDERABLE_CHILD_NODES);
-
- JcrNodeType nodeWithMandatoryChild = new JcrNodeType(
- context,
- NO_NODE_TYPE_MANAGER,
- TestLexicon.NODE_WITH_MANDATORY_CHILD,
- Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
- NO_PRIMARY_ITEM_NAME,
- Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
- context,
- null,
- TestLexicon.MANDATORY_CHILD,
- OnParentVersionBehavior.VERSION.getJcrValue(),
- false,
- true,
- false,
- false,
- JcrNtLexicon.UNSTRUCTURED,
- new JcrNodeType[] {base}),}),
- NO_PROPERTIES, NOT_MIXIN, ORDERABLE_CHILD_NODES);
-
- nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {referenceableUnstructured, noSameNameSibs,
- nodeWithMandatoryProperty, nodeWithMandatoryChild,}));
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.JcrNodeTypeSource#getNodeTypes()
- */
- @Override
- public Collection<JcrNodeType> getDeclaredNodeTypes() {
- return nodeTypes;
- }
-
- }
-
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java 2009-04-27 18:45:16 UTC (rev 857)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java 2009-04-27 18:58:29 UTC (rev 858)
@@ -28,7 +28,6 @@
/**
* Namespace and names for DNA testing.
- *
*/
public class TestLexicon {
@@ -55,4 +54,5 @@
public static final Name NODE_WITH_MANDATORY_PROPERTY = new BasicName(Namespace.URI, "nodeWithMandatoryProperty");
public static final Name NODE_WITH_MANDATORY_CHILD = new BasicName(Namespace.URI, "nodeWithMandatoryChild");
+ public static final Name UNORDERABLE_UNSTRUCTURED = new BasicName(Namespace.URI, "unorderableUnstructured");
}
Modified: trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-04-27 18:45:16 UTC (rev 857)
+++ trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-04-27 18:58:29 UTC (rev 858)
@@ -1,4 +1,4 @@
-javax.jcr.tck.repository_stub_impl=org.jboss.dna.jcr.JcrTckTest$InMemoryRepositoryStub
+javax.jcr.tck.repository_stub_impl=org.jboss.dna.jcr.InMemoryRepositoryStub
javax.jcr.tck.testroot=/testroot
javax.jcr.tck.nodename1=node1
javax.jcr.tck.nodename2=node2
@@ -41,3 +41,5 @@
javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype2=dnatest\:nodeWithMandatoryChild
javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodename3=dnatest\:mandatoryChild
javax.jcr.tck.NodeTest.testSaveContstraintViolationException.nodetype2=dnatest\:nodeWithMandatoryProperty
+javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupportedRepositoryOperationException.nodetype2=dnatest\:unorderableUnstructured
+javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupportedRepositoryOperationException.nodetype3=dnatest\:unorderableUnstructured
\ No newline at end of file
Modified: trunk/dna-jcr-tck/pom.xml
===================================================================
--- trunk/dna-jcr-tck/pom.xml 2009-04-27 18:45:16 UTC (rev 857)
+++ trunk/dna-jcr-tck/pom.xml 2009-04-27 18:58:29 UTC (rev 858)
@@ -49,6 +49,13 @@
<artifactId>dna-jcr</artifactId>
<version>${pom.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-jcr</artifactId>
+ <version>${pom.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<!--
Testing (note the scope)
-->
Deleted: trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
===================================================================
--- trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-04-27 18:45:16 UTC (rev 857)
+++ trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-04-27 18:58:29 UTC (rev 858)
@@ -1,155 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you 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.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import java.io.File;
-import java.net.URI;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Properties;
-import javax.jcr.Credentials;
-import javax.jcr.Repository;
-import org.apache.jackrabbit.test.RepositoryStub;
-import org.jboss.dna.graph.DnaLexicon;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.Graph;
-import org.jboss.dna.graph.JcrNtLexicon;
-import org.jboss.dna.graph.Location;
-import org.jboss.dna.graph.connector.RepositoryConnection;
-import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
-import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
-import org.jboss.dna.graph.io.GraphImporter;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.jcr.JcrRepository.Options;
-
-/**
- * Class with TCK repository stub. This class does not contain any tests.
- */
-public class InMemoryRepositoryStub extends RepositoryStub {
- private Repository repository;
- protected RepositoryConnection connection;
- protected AccessControlContext accessControlContext = AccessController.getContext();
-
- private Credentials credentials = new Credentials() {
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings( "unused" )
- public AccessControlContext getAccessControlContext() {
- return accessControlContext;
- }
- };
-
- protected ExecutionContext executionContext = new ExecutionContext() {
-
- @Override
- public ExecutionContext create( AccessControlContext accessControlContext ) {
- return executionContext;
- }
- };
-
- protected RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() {
- public RepositoryConnection createConnection( String sourceName ) {
- return connection;
- }
- };
-
- public InMemoryRepositoryStub( Properties env ) {
- super(env);
-
- // Create the in-memory (DNA) repository
- InMemoryRepositorySource source = new InMemoryRepositorySource();
-
- // Various calls will fail if you do not set a non-null name for the source
- source.setName("TestRepositorySource");
-
- // Wrap a connection to the in-memory (DNA) repository in a (JCR) repository
- Map<Options, String> options = Collections.singletonMap(Options.PROJECT_NODE_TYPES, "true");
- connection = source.getConnection();
- repository = new JcrRepository(executionContext.create(accessControlContext), connectionFactory, source.getName(), null,
- options);
-
- // Make sure the path to the namespaces exists ...
- Graph graph = Graph.create(source.getName(), connectionFactory, executionContext);
- graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces");
-
- // Set up some sample nodes in the graph to match the expected test configuration
- try {
-
- // TODO: Should there be an easier way to define these since they will be needed for all JCR repositories?
- executionContext.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX, JcrLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register(JcrNtLexicon.Namespace.PREFIX, JcrNtLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register(JcrSvLexicon.Namespace.PREFIX, JcrSvLexicon.Namespace.URI);
-
- Path destinationPath = executionContext.getValueFactories().getPathFactory().create("/");
- GraphImporter importer = new GraphImporter(graph);
-
- URI xmlContent = new File("src/test/resources/repositoryForTckTests.xml").toURI();
- Graph.Batch batch = importer.importXml(xmlContent, Location.create(destinationPath));
- batch.execute();
-
- } catch (Exception ex) {
- // The TCK tries to quash this exception. Print it out to be more obvious.
- ex.printStackTrace();
- throw new IllegalStateException("Repository initialization failed.", ex);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.jackrabbit.test.RepositoryStub#getSuperuserCredentials()
- */
- @Override
- public Credentials getSuperuserCredentials() {
- // TODO: Why must we override this method? The default TCK implementation just returns a particular instance of
- // SimpleCredentials.
- return credentials;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.jackrabbit.test.RepositoryStub#getReadOnlyCredentials()
- */
- @Override
- public Credentials getReadOnlyCredentials() {
- // TODO: Why must we override this method? The default TCK implementation just returns a particular instance of
- // SimpleCredentials.
- return credentials;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.jackrabbit.test.RepositoryStub#getRepository()
- */
- @Override
- public Repository getRepository() {
- return repository;
- }
-
-}
Deleted: trunk/dna-jcr-tck/src/test/resources/repositoryStubImpl.properties
===================================================================
--- trunk/dna-jcr-tck/src/test/resources/repositoryStubImpl.properties 2009-04-27 18:45:16 UTC (rev 857)
+++ trunk/dna-jcr-tck/src/test/resources/repositoryStubImpl.properties 2009-04-27 18:58:29 UTC (rev 858)
@@ -1,9 +0,0 @@
-javax.jcr.tck.repository_stub_impl=org.jboss.dna.jcr.InMemoryRepositoryStub
-javax.jcr.tck.testroot=/testroot
-javax.jcr.tck.nodename1=node1
-javax.jcr.tck.nodename2=node2
-javax.jcr.tck.nodename3=node3
-javax.jcr.tck.nodename4=node4
-javax.jcr.tck.propertyname1=prop1
-javax.jcr.tck.propertyname2=prop2
-javax.jcr.tck.workspacename=
16 years, 8 months
DNA SVN: r857 - in trunk/dna-jcr/src: main/java/org/jboss/dna/jcr/cache and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-27 14:45:16 -0400 (Mon, 27 Apr 2009)
New Revision: 857
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaIntLexicon.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/SessionCacheTest.java
Log:
DNA-374 Multiplicity of some properties may change when saved and reloaded from the graph
Added a patch that fixes this issue by maintaining a hidden property to store the names of the properties that use multi-valued definitions but that have only one value. This property is persisted as required, but is also cleaned up if it is empty or no longer needed.
The patch also moves the "dna:nodeDefinition" and this new property into a new "dnaint" namespace. This allows some of the code to just check the namespace to know whether properties should be hidden from the JCR view.
Committed the patch, which also added in a number of commented-out TCK unit tests.
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaIntLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaIntLexicon.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaIntLexicon.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -0,0 +1,41 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you 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.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.basic.BasicName;
+
+/**
+ * A lexicon of internal and implementation-specific information
+ */
+public class DnaIntLexicon {
+
+ public static class Namespace {
+ public static final String URI = "http://www.jboss.org/dna/internal/1.0";
+ public static final String PREFIX = "dnaint";
+ }
+
+ public static final Name NODE_DEFINITON = new BasicName(Namespace.URI, "nodeDefinition");
+ public static final Name MULTI_VALUED_PROPERTIES = new BasicName(Namespace.URI, "multiValuedProperties");
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaIntLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-04-23 21:51:50 UTC (rev 856)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -31,9 +31,8 @@
*/
public class DnaLexicon extends org.jboss.dna.repository.DnaLexicon {
- public static final Name DEFINED = new BasicName(Namespace.URI, "defined");
+ public static final Name BASE = new BasicName(Namespace.URI, "base");
public static final Name NAMESPACE = new BasicName(Namespace.URI, "namespace");
- public static final Name NODE_DEFINITON = new BasicName(Namespace.URI, "nodeDefinition");
public static final Name NODE_TYPES = new BasicName(Namespace.URI, "nodeTypes");
public static final Name ROOT = new BasicName(Namespace.URI, "root");
public static final Name SYSTEM = new BasicName(Namespace.URI, "system");
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-04-23 21:51:50 UTC (rev 856)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -65,25 +65,17 @@
// Value trueValue = new JcrValue(context.getValueFactories(), null, PropertyType.BOOLEAN, Boolean.TRUE);
Value ntBaseValue = new JcrValue(context.getValueFactories(), null, PropertyType.NAME, JcrNtLexicon.BASE);
- JcrNodeType defined = new JcrNodeType(
- context,
- NO_NODE_TYPE_MANAGER,
- DnaLexicon.DEFINED,
- NO_SUPERTYPES,
- DnaLexicon.NODE_DEFINITON,
- NO_CHILD_NODES,
- Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
- context,
- null,
- DnaLexicon.NODE_DEFINITON,
- OnParentVersionBehavior.INITIALIZE.getJcrValue(),
- false,
- false,
- true,
- NO_DEFAULT_VALUES,
- PropertyType.STRING,
- NO_CONSTRAINTS,
- false),}),
+ JcrNodeType defined = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, DnaLexicon.BASE, NO_SUPERTYPES,
+ DnaIntLexicon.NODE_DEFINITON, NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(context, null, DnaIntLexicon.NODE_DEFINITON,
+ OnParentVersionBehavior.INITIALIZE.getJcrValue(),
+ false, false, true, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(context, null, DnaIntLexicon.MULTI_VALUED_PROPERTIES,
+ OnParentVersionBehavior.INITIALIZE.getJcrValue(),
+ false, false, true, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS, true),}),
IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
// Stubbing in child node and property definitions for now
JcrNodeType base = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrNtLexicon.BASE,
@@ -636,7 +628,7 @@
// Disabling version-related types until DNA supports versioning, as per section 4.11 of the 1.0.1 specification
nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {defined, base, unstructured, childNodeDefinition, file, folder,
frozenNode, hierarchyNode, linkedFile, nodeType, propertyDefinition, query, resource, nodeType /*, version, versionHistory,
- versionLabels, versionedChild */}));
+ versionLabels, versionedChild */}));
JcrNodeType lockable = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrMixLexicon.LOCKABLE, NO_SUPERTYPES,
NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-04-23 21:51:50 UTC (rev 856)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -71,7 +71,7 @@
static final String XML_SCHEMA_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema";
static final String XML_SCHEMA_INSTANCE_NAMESPACE_PREFIX = "xsi";
static final String XML_SCHEMA_INSTANCE_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance";
-
+
static final Set<String> STANDARD_BUILT_IN_PREFIXES;
static final Set<String> STANDARD_BUILT_IN_URIS;
static final Map<String, String> STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX;
@@ -90,6 +90,7 @@
namespaces.put(XML_SCHEMA_NAMESPACE_PREFIX, XML_SCHEMA_NAMESPACE_URI);
namespaces.put(XML_SCHEMA_INSTANCE_NAMESPACE_PREFIX, XML_SCHEMA_INSTANCE_NAMESPACE_URI);
namespaces.put(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
+ namespaces.put(DnaIntLexicon.Namespace.PREFIX, DnaIntLexicon.Namespace.URI);
// Set up the reverse map for the standard namespaces ...
Map<String, String> prefixes = new HashMap<String, String>();
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-23 21:51:50 UTC (rev 856)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -53,6 +53,7 @@
import javax.jcr.nodetype.PropertyDefinition;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.Location;
@@ -128,6 +129,8 @@
*/
private static final boolean INCLUDE_PROPERTIES_NOT_ALLOWED_BY_NODE_TYPE_OR_MIXINS = true;
+ private static final Set<Name> EMPTY_NAMES = Collections.emptySet();
+
private final JcrSession session;
private final String workspaceName;
protected final ExecutionContext context;
@@ -391,6 +394,7 @@
mixinTypeNames,
property.property(),
property.getType(),
+ property.property().isSingle(),
false);
if (definition == null) {
throw new ConstraintViolationException(JcrI18n.noDefinition.text("property",
@@ -748,7 +752,8 @@
PropertyInfo info = findPropertyInfo(propertyId); // throws PathNotFoundException if node not there
if (info == null) return null; // no such property on this node
- if (DnaLexicon.NODE_DEFINITON.equals(info.getPropertyName())) return null;
+ // Skip all internal properties ...
+ if (info.getPropertyName().getNamespaceUri().equals(DnaIntLexicon.Namespace.URI)) return null;
// Now create the appropriate JCR Property object ...
return createAndCacheJcrPropertyFor(info);
@@ -760,7 +765,7 @@
Set<Name> propertyNames = info.getPropertyNames();
Collection<AbstractJcrProperty> result = new ArrayList<AbstractJcrProperty>(propertyNames.size());
for (Name propertyName : propertyNames) {
- if (!DnaLexicon.NODE_DEFINITON.equals(propertyName)) {
+ if (!propertyName.getNamespaceUri().equals(DnaIntLexicon.Namespace.URI)) {
result.add(findJcrProperty(new PropertyId(nodeUuid, propertyName)));
}
}
@@ -1080,8 +1085,7 @@
assert name != null;
assert values != null;
- // TODO: Re-add following line!
- // checkCardinalityOfExistingProperty(name, true);
+ checkCardinalityOfExistingProperty(name, true);
int len = values.length;
Value[] newValues = null;
@@ -1171,8 +1175,8 @@
}
}
// Create the DNA property ...
- int type = newValues.length != 0 ? newValues[0].getType() : definition.getRequiredType();
- Object[] objValues = new Object[newValues.length];
+ int type = numValues != 0 ? newValues[0].getType() : definition.getRequiredType();
+ Object[] objValues = new Object[numValues];
int propertyType = definition.getRequiredType();
if (propertyType == PropertyType.UNDEFINED || propertyType == type) {
// Can use the values as is ...
@@ -1198,6 +1202,23 @@
// Finally update the cached information and record the change ...
node.setProperty(newProperty, factories());
operations.set(dnaProp).on(currentLocation);
+
+ // If there is a single value, we need to record that this property is actually a multi-valued property definition ...
+ if (numValues == 1) {
+ if (node.setSingleMultiProperty(name)) {
+ Set<Name> names = node.getSingleMultiPropertyNames();
+ // Added this property name to the set, so record the change ...
+ PropertyInfo singleMulti = createSingleMultiplePropertyInfo(node.getUuid(),
+ node.getPrimaryTypeName(),
+ node.getMixinTypeNames(),
+ names);
+ node.setProperty(singleMulti, factories());
+ operations.set(singleMulti.getProperty()).on(currentLocation);
+ }
+ } else {
+ removeSingleMultiProperty(node, name);
+ }
+
return newProperty.getPropertyId();
}
@@ -1208,13 +1229,35 @@
* @return true if there was a property with the supplied name, or false if no such property existed
*/
public boolean removeProperty( Name name ) {
- if (node.removeProperty(name) != null) {
+ PropertyInfo info = node.removeProperty(name);
+ if (info != null) {
operations.remove(name).on(currentLocation);
+ // Is this named in the single-multi property names? ...
+ removeSingleMultiProperty(node, name);
return true;
}
return false;
}
+ private void removeSingleMultiProperty( ChangedNodeInfo node,
+ Name propertyName ) {
+ if (node.removeSingleMultiProperty(propertyName)) {
+ Set<Name> names = node.getSingleMultiPropertyNames();
+ if (names == null || names.isEmpty()) {
+ node.removeProperty(DnaIntLexicon.MULTI_VALUED_PROPERTIES);
+ operations.remove(DnaIntLexicon.MULTI_VALUED_PROPERTIES).on(currentLocation);
+ } else {
+ // Added this property name to the set, so record the change ...
+ PropertyInfo singleMulti = createSingleMultiplePropertyInfo(node.getUuid(),
+ node.getPrimaryTypeName(),
+ node.getMixinTypeNames(),
+ names);
+ node.setProperty(singleMulti, factories());
+ operations.set(singleMulti.getProperty()).on(currentLocation);
+ }
+ }
+ }
+
/**
* Move the child specified by the supplied UUID to be a child of this node, appending the child to the end of the current
* list of children. This method automatically disconnects the node from its current parent.
@@ -1255,7 +1298,7 @@
try {
JcrValue value = new JcrValue(factories(), SessionCache.this, PropertyType.STRING, definition.getId()
.getString());
- setProperty(DnaLexicon.NODE_DEFINITON, value);
+ setProperty(DnaIntLexicon.NODE_DEFINITON, value);
} catch (ConstraintViolationException e) {
// We can't set this property on the node (according to the node definition).
// But we still want the node info to have the correct node definition.
@@ -1264,7 +1307,7 @@
node.setDefinitionId(definition.getId());
// And remove the property from the info ...
- newChildEditor.removeProperty(DnaLexicon.NODE_DEFINITON);
+ newChildEditor.removeProperty(DnaIntLexicon.NODE_DEFINITON);
}
}
@@ -1428,7 +1471,7 @@
// Create the properties ...
Map<Name, PropertyInfo> properties = new HashMap<Name, PropertyInfo>();
Property primaryTypeProp = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, primaryTypeName);
- Property nodeDefinitionProp = propertyFactory.create(DnaLexicon.NODE_DEFINITON, definition.getId().getString());
+ Property nodeDefinitionProp = propertyFactory.create(DnaIntLexicon.NODE_DEFINITON, definition.getId().getString());
// Now add the "jcr:uuid" property if and only if referenceable ...
if (primaryType.isNodeType(JcrMixLexicon.REFERENCEABLE)) {
@@ -1457,6 +1500,7 @@
node.getMixinTypeNames(),
primaryTypeProp,
PropertyType.NAME,
+ true,
false);
PropertyDefinitionId primaryTypeDefinitionId = primaryTypeDefn.getId();
PropertyInfo primaryTypeInfo = new PropertyInfo(new PropertyId(desiredUuid, primaryTypeProp.getName()),
@@ -1469,6 +1513,7 @@
node.getMixinTypeNames(),
nodeDefinitionProp,
PropertyType.STRING,
+ false,
false);
if (nodeDefnDefn != null) {
PropertyDefinitionId nodeDefnDefinitionId = nodeDefnDefn.getId();
@@ -1538,6 +1583,8 @@
* to include in the search
* @param dnaProperty the new property that is to be set on this node
* @param propertyType the property type; must be a valid {@link PropertyType} value
+ * @param isSingle true if the property definition should be single-valued, or false if the property definition should allow
+ * multiple values
* @param skipProtected true if this operation is being done from within the public JCR node and property API, or false if
* this operation is being done from within internal implementations
* @return the property definition that allows setting this property, or null if there is no such definition
@@ -1546,6 +1593,7 @@
List<Name> mixinTypeNamesOfParent,
Property dnaProperty,
int propertyType,
+ boolean isSingle,
boolean skipProtected ) {
JcrPropertyDefinition definition = null;
if (propertyType == PropertyType.UNDEFINED) {
@@ -1553,7 +1601,7 @@
}
// If single-valued ...
- if (dnaProperty.isSingle()) {
+ if (isSingle) {
// Create a value for the DNA property value ...
Object value = dnaProperty.getFirstValue();
Value jcrValue = new JcrValue(factories(), SessionCache.this, propertyType, value);
@@ -2047,7 +2095,7 @@
// Look for a node definition stored on the node ...
JcrNodeDefinition definition = null;
- org.jboss.dna.graph.property.Property nodeDefnProperty = graphProperties.get(DnaLexicon.NODE_DEFINITON);
+ org.jboss.dna.graph.property.Property nodeDefnProperty = graphProperties.get(DnaIntLexicon.NODE_DEFINITON);
if (nodeDefnProperty != null && !nodeDefnProperty.isEmpty()) {
String nodeDefinitionString = stringFactory.create(nodeDefnProperty.getFirstValue());
NodeDefinitionId id = NodeDefinitionId.fromString(nodeDefinitionString, nameFactory);
@@ -2089,7 +2137,7 @@
if (primaryType.isNodeType(JcrMixLexicon.REFERENCEABLE)) referenceable = true;
// The process the mixin types ...
- org.jboss.dna.graph.property.Property mixinTypesProperty = graphProperties.get(JcrLexicon.MIXIN_TYPES);
+ Property mixinTypesProperty = graphProperties.get(JcrLexicon.MIXIN_TYPES);
List<Name> mixinTypeNames = null;
if (mixinTypesProperty != null && !mixinTypesProperty.isEmpty()) {
for (Object mixinTypeValue : mixinTypesProperty) {
@@ -2102,17 +2150,31 @@
}
}
+ // Create the set of multi-valued property names ...
+ Set<Name> multiValuedPropertyNames = EMPTY_NAMES;
+ Set<Name> newSingleMultiPropertyNames = null;
+ Property multiValuedPropNamesProp = graphProperties.get(DnaIntLexicon.MULTI_VALUED_PROPERTIES);
+ if (multiValuedPropNamesProp != null && !multiValuedPropNamesProp.isEmpty()) {
+ multiValuedPropertyNames = getSingleMultiPropertyNames(multiValuedPropNamesProp, location.getPath(), uuid);
+ }
+
// Now create the JCR property object wrappers around the other properties ...
Map<Name, PropertyInfo> props = new HashMap<Name, PropertyInfo>();
- for (org.jboss.dna.graph.property.Property dnaProp : graphProperties.values()) {
+ for (Property dnaProp : graphProperties.values()) {
Name name = dnaProp.getName();
+ // Is this is single-valued property?
+ boolean isSingle = dnaProp.isSingle();
+ // Make sure that this isn't a multi-valued property with one value ...
+ if (isSingle && multiValuedPropertyNames.contains(name)) isSingle = false;
+
// Figure out the JCR property type for this property ...
int propertyType = PropertyTypeUtil.jcrPropertyTypeFor(dnaProp);
PropertyDefinition propertyDefinition = findBestPropertyDefintion(primaryTypeName,
mixinTypeNames,
dnaProp,
propertyType,
+ isSingle,
false);
// If there still is no property type defined ...
@@ -2138,6 +2200,12 @@
continue;
}
+ // Update the list of single-valued multi-property names ...
+ if (isMultiple && isSingle) {
+ if (newSingleMultiPropertyNames == null) newSingleMultiPropertyNames = new HashSet<Name>();
+ newSingleMultiPropertyNames.add(name);
+ }
+
// Figure out the property type ...
int definitionType = propertyDefinition.getRequiredType();
if (definitionType != PropertyType.UNDEFINED) {
@@ -2173,6 +2241,15 @@
// Make sure the "dna:uuid" property did not get in there ...
props.remove(DnaLexicon.UUID);
+ // Make sure the single-valued multi-property names are stored as a property ...
+ if (newSingleMultiPropertyNames != null) {
+ PropertyInfo info = createSingleMultiplePropertyInfo(uuid,
+ primaryTypeName,
+ mixinTypeNames,
+ newSingleMultiPropertyNames);
+ props.put(info.getPropertyName(), info);
+ }
+
// Create the node information ...
UUID parentUuid = parentInfo != null ? parentInfo.getUuid() : null;
List<Location> locations = graphNode.getChildren();
@@ -2181,6 +2258,69 @@
return new ImmutableNodeInfo(location, primaryTypeName, mixinTypeNames, definition.getId(), parentUuid, children, props);
}
+ protected final PropertyInfo createSingleMultiplePropertyInfo( UUID uuid,
+ Name primaryTypeName,
+ List<Name> mixinTypeNames,
+ Set<Name> newSingleMultiPropertyNames ) {
+ int number = newSingleMultiPropertyNames.size();
+ String[] names = new String[number];
+ JcrValue[] values = new JcrValue[number];
+ if (number == 1) {
+ String str = newSingleMultiPropertyNames.iterator().next().getString(namespaces);
+ names[0] = str;
+ values[0] = new JcrValue(factories(), this, PropertyType.STRING, str);
+ } else {
+ int index = 0;
+ for (Name name : newSingleMultiPropertyNames) {
+ String str = name.getString(namespaces);
+ names[index] = str;
+ values[index] = new JcrValue(factories(), this, PropertyType.STRING, str);
+ ++index;
+ }
+ }
+ PropertyDefinition propertyDefinition = nodeTypes().findPropertyDefinition(primaryTypeName,
+ mixinTypeNames,
+ DnaIntLexicon.MULTI_VALUED_PROPERTIES,
+ values,
+ false);
+ Property dnaProp = propertyFactory.create(DnaIntLexicon.MULTI_VALUED_PROPERTIES, newSingleMultiPropertyNames.iterator()
+ .next());
+ PropertyId propId = new PropertyId(uuid, dnaProp.getName());
+ JcrPropertyDefinition defn = (JcrPropertyDefinition)propertyDefinition;
+ return new PropertyInfo(propId, defn.getId(), PropertyType.STRING, dnaProp, defn.isMultiple(), true, false);
+ }
+
+ protected final Set<Name> getSingleMultiPropertyNames( Property dnaProperty,
+ Path knownPath,
+ UUID knownUuid ) {
+ Set<Name> multiValuedPropertyNames = new HashSet<Name>();
+ for (Object value : dnaProperty) {
+ try {
+ multiValuedPropertyNames.add(nameFactory.create(value));
+ } catch (ValueFormatException e) {
+ String msg = "{0} value \"{1}\" on {2} in \"{3}\" workspace is not a valid name and is being ignored";
+ String path = null;
+ if (knownPath != null) {
+ path = knownPath.getString(namespaces);
+ } else {
+ assert knownUuid != null;
+ try {
+ path = getPathFor(knownUuid).getString(namespaces);
+ } catch (RepositoryException err) {
+ path = knownUuid.toString();
+ }
+ }
+ Logger.getLogger(getClass()).trace(e,
+ msg,
+ DnaIntLexicon.MULTI_VALUED_PROPERTIES.getString(namespaces),
+ value,
+ path,
+ workspaceName());
+ }
+ }
+ return multiValuedPropertyNames;
+ }
+
/**
* This method finds the {@link NodeInfo} for the node with the supplied UUID and marks it as being deleted, and does the same
* for all decendants (e.g., children, grandchildren, great-grandchildren, etc.) that have been cached or changed.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java 2009-04-23 21:51:50 UTC (rev 856)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.property.Name;
@@ -40,7 +41,7 @@
import org.jboss.dna.graph.property.ValueFactories;
import org.jboss.dna.graph.property.ValueFactory;
import org.jboss.dna.graph.property.Path.Segment;
-import org.jboss.dna.jcr.DnaLexicon;
+import org.jboss.dna.jcr.DnaIntLexicon;
import org.jboss.dna.jcr.NodeDefinitionId;
/**
@@ -49,6 +50,7 @@
* Each instance maintains a reference to the original (usually immutable) NodeInfo representation that was probably read from the
* repository.
*/
+@NotThreadSafe
public class ChangedNodeInfo implements NodeInfo {
protected static final PropertyInfo DELETED_PROPERTY = null;
@@ -88,6 +90,8 @@
private List<UUID> peers;
+ private Set<Name> singleMultiPropertyNames;
+
/**
* Create an immutable NodeInfo instance.
*
@@ -127,6 +131,19 @@
peers.add(peerUuid);
}
+ public boolean setSingleMultiProperty( Name name ) {
+ if (singleMultiPropertyNames == null) singleMultiPropertyNames = new HashSet<Name>();
+ return singleMultiPropertyNames.add(name);
+ }
+
+ public boolean removeSingleMultiProperty( Name name ) {
+ return singleMultiPropertyNames == null ? false : singleMultiPropertyNames.remove(name);
+ }
+
+ public Set<Name> getSingleMultiPropertyNames() {
+ return singleMultiPropertyNames;
+ }
+
/**
* Return the original node information. May be null if this is a new node.
*
@@ -213,8 +230,8 @@
/**
* Set the identifier of the node definition for this node. This should normally be changed by
- * {@link #setProperty(PropertyInfo, ValueFactories) setting} the {@link DnaLexicon#NODE_DEFINITON} property. However, since
- * that property is not always allowed, this method provides a way to set it locally (without requiring a property).
+ * {@link #setProperty(PropertyInfo, ValueFactories) setting} the {@link DnaIntLexicon#NODE_DEFINITON} property. However,
+ * since that property is not always allowed, this method provides a way to set it locally (without requiring a property).
*
* @param definitionId the new property definition identifier; may not be null
* @see #setProperty(PropertyInfo, ValueFactories)
@@ -404,7 +421,7 @@
for (Object value : newProperty.getProperty()) {
changedMixinTypeNames.add(nameFactory.create(value));
}
- } else if (name.equals(DnaLexicon.NODE_DEFINITON)) {
+ } else if (name.equals(DnaIntLexicon.NODE_DEFINITON)) {
ValueFactory<String> stringFactory = factories.getStringFactory();
String value = stringFactory.create(newProperty.getProperty().getFirstValue());
changedDefinitionId = NodeDefinitionId.fromString(value, factories.getNameFactory());
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-23 21:51:50 UTC (rev 856)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -62,6 +62,8 @@
import org.apache.jackrabbit.test.api.SetPropertyInputStreamTest;
import org.apache.jackrabbit.test.api.SetPropertyLongTest;
import org.apache.jackrabbit.test.api.SetPropertyNodeTest;
+import org.apache.jackrabbit.test.api.SetPropertyStringTest;
+import org.apache.jackrabbit.test.api.SetPropertyValueTest;
import org.apache.jackrabbit.test.api.SetValueBinaryTest;
import org.apache.jackrabbit.test.api.SetValueBooleanTest;
import org.apache.jackrabbit.test.api.SetValueConstraintViolationExceptionTest;
@@ -216,8 +218,8 @@
addTestSuite(SetPropertyInputStreamTest.class);
addTestSuite(SetPropertyLongTest.class);
addTestSuite(SetPropertyNodeTest.class);
- // addTestSuite(SetPropertyStringTest.class);
- // addTestSuite(SetPropertyValueTest.class);
+ addTestSuite(SetPropertyStringTest.class);
+ addTestSuite(SetPropertyValueTest.class);
addTestSuite(SetPropertyConstraintViolationExceptionTest.class);
// addTestSuite(SetPropertyAssumeTypeTest.class);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/SessionCacheTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/SessionCacheTest.java 2009-04-23 21:51:50 UTC (rev 856)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/SessionCacheTest.java 2009-04-27 18:45:16 UTC (rev 857)
@@ -188,6 +188,8 @@
}
} else if (propertyName.equals(JcrLexicon.PRIMARY_TYPE)) {
// This is okay
+ } else if (propertyName.equals(DnaIntLexicon.MULTI_VALUED_PROPERTIES)) {
+ // This is okay
} else {
fail("missing property \"" + propertyName + "\" on " + dnaNode);
}
16 years, 8 months
DNA SVN: r856 - in trunk/dna-repository/src: test/java/org/jboss/dna/repository and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-23 17:51:50 -0400 (Thu, 23 Apr 2009)
New Revision: 856
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
Log:
DNA-58 Create repository configuration and component
Minor change to allow the configuration to have more than one PathExpression in any sequencer.
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-04-23 20:35:30 UTC (rev 855)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-04-23 21:51:50 UTC (rev 856)
@@ -21,8 +21,10 @@
*/
package org.jboss.dna.repository;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.component.ClassLoaderFactory;
@@ -737,6 +739,7 @@
protected class GraphSequencerDetails implements SequencerDetails {
private final Path path;
+ private final List<String> compiledExpressions = new ArrayList<String>();
protected GraphSequencerDetails( Path path ) {
assert path != null;
@@ -780,7 +783,9 @@
*/
public SequencerDetails sequencingFrom( PathExpression expression ) {
CheckArg.isNotNull(expression, "expression");
- configuration().set(DnaLexicon.PATH_EXPRESSIONS).on(path).to(expression.getExpression());
+ String compiledExpression = expression.getExpression();
+ if (!compiledExpressions.contains(compiledExpression)) compiledExpressions.add(compiledExpression);
+ configuration().set(DnaLexicon.PATH_EXPRESSIONS).on(path).to(compiledExpressions);
return this;
}
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-04-23 20:35:30 UTC (rev 855)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-04-23 21:51:50 UTC (rev 856)
@@ -253,8 +253,8 @@
.usingClass(MockSequencerA.class)
.named("The (Main) Sequencer")
.describedAs("Mock Sequencer A")
- // .sequencingFrom("/foo/source")
- // .andOutputtingTo("/foo/target")
+ .sequencingFrom("/foo/source")
+ .andOutputtingTo("/foo/target")
.sequencingFrom("/bar/source")
.andOutputtingTo("/bar/target")
.and()
@@ -276,7 +276,7 @@
MockSequencerA.class.getName()));
System.out.println(subgraph.getNode("/dna:sequencers/sequencerA").getProperty(DnaLexicon.PATH_EXPRESSIONS));
assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.PATH_EXPRESSIONS,
- // "/foo/source => /foo/target",
+ "/foo/source => /foo/target",
"/bar/source => /bar/target"));
}
@@ -286,6 +286,14 @@
configuration.addMimeTypeDetector("detector")
.usingClass(ExtensionBasedMimeTypeDetector.class)
.describedAs("default detector");
+ configuration.addSequencer("sequencerA")
+ .usingClass(MockSequencerA.class)
+ .named("The (Main) Sequencer")
+ .describedAs("Mock Sequencer A")
+ .sequencingFrom("/foo/source")
+ .andOutputtingTo("/foo/target")
+ .sequencingFrom("/bar/source")
+ .andOutputtingTo("/bar/target");
configuration.save();
// Verify that the graph has been updated correctly ...
@@ -302,5 +310,15 @@
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"), hasProperty(DnaLexicon.DESCRIPTION, "default detector"));
assertThat(subgraph.getNode("/dna:mimeTypeDetectors/detector"),
hasProperty(DnaLexicon.CLASSNAME, ExtensionBasedMimeTypeDetector.class.getName()));
+ assertThat(subgraph.getNode("/dna:sequencers").getChildren(), hasChild(segment("sequencerA")));
+ assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), is(notNullValue()));
+ assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.READABLE_NAME, "The (Main) Sequencer"));
+ assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.DESCRIPTION, "Mock Sequencer A"));
+ assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.CLASSNAME,
+ MockSequencerA.class.getName()));
+ System.out.println(subgraph.getNode("/dna:sequencers/sequencerA").getProperty(DnaLexicon.PATH_EXPRESSIONS));
+ assertThat(subgraph.getNode("/dna:sequencers/sequencerA"), hasProperty(DnaLexicon.PATH_EXPRESSIONS,
+ "/foo/source => /foo/target",
+ "/bar/source => /bar/target"));
}
}
16 years, 8 months
DNA SVN: r855 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-23 16:35:30 -0400 (Thu, 23 Apr 2009)
New Revision: 855
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
Log:
DNA-382 Workspace.move Is Not Supported
Applied the patch to implement Workspace.move
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-04-23 19:37:08 UTC (rev 854)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-04-23 20:35:30 UTC (rev 855)
@@ -349,30 +349,31 @@
*
* @see javax.jcr.Workspace#move(java.lang.String, java.lang.String)
*/
- @SuppressWarnings( "unused" )
public void move( String srcAbsPath,
String destAbsPath ) throws PathNotFoundException, RepositoryException {
- CheckArg.isNotEmpty(srcAbsPath, "srcAbsPath");
- CheckArg.isNotEmpty(destAbsPath, "destAbsPath");
+ CheckArg.isNotNull(srcAbsPath, "srcAbsPath");
+ CheckArg.isNotNull(destAbsPath, "destAbsPath");
- // Create the paths ...
- PathFactory factory = context.getValueFactories().getPathFactory();
- Path srcPath = null;
- Path destPath = null;
- try {
- srcPath = factory.create(srcAbsPath);
- } catch (ValueFormatException e) {
- throw new RepositoryException(JcrI18n.invalidPathParameter.text(srcAbsPath, "srcAbsPath"), e);
+ // Use the session's execution context so that we get the transient namespace mappings
+ PathFactory pathFactory = session.getExecutionContext().getValueFactories().getPathFactory();
+ Path destPath = pathFactory.create(destAbsPath);
+
+ Path.Segment newNodeName = destPath.getSegment(destPath.size() - 1);
+ // Doing a literal test here because the path factory will canonicalize "/node[1]" to "/node"
+ if (destAbsPath.endsWith("]")) {
+ throw new RepositoryException();
}
- try {
- destPath = factory.create(destAbsPath);
- } catch (ValueFormatException e) {
- throw new RepositoryException(JcrI18n.invalidPathParameter.text(destAbsPath, "destAbsPath"), e);
+
+ AbstractJcrNode sourceNode = session.getNode(pathFactory.create(srcAbsPath));
+ AbstractJcrNode newParentNode = session.getNode(destPath.getParent());
+
+ if (newParentNode.hasNode(newNodeName.getString(session.getExecutionContext().getNamespaceRegistry()))) {
+ throw new ItemExistsException();
}
- // Perform the copy operation, but use the "to" form (not the "into", which takes the parent) ...
- // graph.move(srcPath).to(destPath);
- throw new UnsupportedOperationException();
+ Graph.Batch operations = session.createBatch();
+ newParentNode.editorFor(operations).moveToBeChild(sourceNode, newNodeName.getName());
+ operations.execute();
}
/**
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-04-23 19:37:08 UTC (rev 854)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-04-23 20:35:30 UTC (rev 855)
@@ -178,7 +178,6 @@
assertThat(workspace.getQueryManager(), notNullValue());
}
- @Test
public void shouldCreateQuery() throws Exception {
String statement = "Some query syntax";
@@ -241,8 +240,8 @@
workspace.move(null, null);
}
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowMoveFromPathToAnotherPathInSameWorkspace() throws Exception {
+ @Test
+ public void shouldAllowMoveFromPathToAnotherPathInSameWorkspace() throws Exception {
workspace.move("/a/b", "/b/b-copy");
}
16 years, 8 months
DNA SVN: r854 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-23 15:37:08 -0400 (Thu, 23 Apr 2009)
New Revision: 854
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
DNA-364 Session.move Is Not Implemented
Applied the patch. Some changes were required, as the before code was a little different than the patch was expecting.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-23 18:45:00 UTC (rev 853)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-23 19:37:08 UTC (rev 854)
@@ -180,7 +180,7 @@
JcrWorkspace workspace() {
return this.workspace;
}
-
+
Graph.Batch createBatch() {
return graph.batch();
}
@@ -619,6 +619,7 @@
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
+
parser.setContentHandler(getImportContentHandler(parentAbsPath, uuidBehavior));
parser.parse(new InputSource(in));
} catch (EnclosingSAXException ese) {
@@ -706,7 +707,7 @@
throw new ItemExistsException();
}
- newParentNode.editor().moveToBeChild(sourceNode.nodeUuid, newNodeName.getName());
+ newParentNode.editor().moveToBeChild(sourceNode, newNodeName.getName());
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-23 18:45:00 UTC (rev 853)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-23 19:37:08 UTC (rev 854)
@@ -1219,7 +1219,7 @@
* Move the child specified by the supplied UUID to be a child of this node, appending the child to the end of the current
* list of children. This method automatically disconnects the node from its current parent.
*
- * @param nodeUuid the UUID of the existing node; may not be null
+ * @param child the UUID of the existing node; may not be null
* @param newNodeName
* @return the representation of the newly-added child, which includes the {@link ChildNode#getSnsIndex()
* same-name-sibling index}
@@ -1228,11 +1228,11 @@
* @throws ConstraintViolationException if moving the node into this node violates this node's definition
* @throws RepositoryException if any other error occurs while reading information from the repository
*/
- public ChildNode moveToBeChild( UUID nodeUuid,
+ public ChildNode moveToBeChild( AbstractJcrNode child,
Name newNodeName )
throws ItemNotFoundException, InvalidItemStateException, ConstraintViolationException, RepositoryException {
- // UUID nodeUuid = child.nodeUuid;
+ UUID nodeUuid = child.nodeUuid;
if (nodeUuid.equals(node.getUuid()) || isAncestor(nodeUuid)) {
Path pathOfNode = getPathFor(nodeUuid);
Path thisPath = currentLocation.getPath();
@@ -1241,8 +1241,9 @@
}
// Is the node already a child?
+ boolean nameDoesNotChange = newNodeName == null || newNodeName.equals(child.path().getLastSegment());
ChildNode existingChild = node.getChildren().getChild(nodeUuid);
- if (existingChild != null) return existingChild;
+ if (existingChild != null && nameDoesNotChange) return existingChild;
JcrNodeDefinition definition = findBestNodeDefinition(node.getUuid(), newNodeName, null);
@@ -1287,7 +1288,11 @@
existingParentInfo.addPeer(node.getUuid());
// Now, record the operation to do this ...
- operations.move(newChildEditor.currentLocation).into(currentLocation);
+ if (nameDoesNotChange) {
+ operations.move(newChildEditor.currentLocation).into(currentLocation);
+ } else {
+ operations.move(newChildEditor.currentLocation).as(newNodeName).into(currentLocation);
+ }
return newChild;
}
@@ -1592,19 +1597,18 @@
JcrNodeDefinition definition = nodeTypes().getNodeDefinition(nodeDefinitionId);
assert definition != null;
- if (root == null) {
- // Need to determine if this is the root node ...
- if (location.getPath().isRoot()) {
- // It is a root node ...
- JcrRootNode node = new JcrRootNode(this, uuid);
- jcrNodes.put(uuid, node);
- root = uuid;
- return node;
- }
+ // Need to determine if this is the root node ...
+ if (location.getPath().isRoot()) {
+ // It is a root node ...
+ JcrRootNode node = new JcrRootNode(this, uuid);
+ jcrNodes.put(uuid, node);
+ root = uuid;
+ return node;
}
// It is not a root node ...
JcrNode node = new JcrNode(this, uuid);
+ assert !uuid.equals(root);
jcrNodes.put(uuid, node);
return node;
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2009-04-23 18:45:00 UTC (rev 853)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2009-04-23 19:37:08 UTC (rev 854)
@@ -30,6 +30,7 @@
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import java.io.ByteArrayInputStream;
@@ -46,6 +47,7 @@
import javax.jcr.Item;
import javax.jcr.NamespaceException;
import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.Repository;
@@ -509,4 +511,18 @@
node.getUUID();
}
+ @Test
+ public void shouldMoveToNewName() throws Exception {
+ session.move("/a/b/c", "/a/b/d");
+
+ session.getRootNode().getNode("a").getNode("b").getNode("d");
+ try {
+ session.getRootNode().getNode("a").getNode("b").getNode("c");
+
+ fail("Node still exists at /a/b/c after move");
+ }
+ catch (PathNotFoundException e) {
+ // Expected
+ }
+ }
}
16 years, 8 months
DNA SVN: r853 - in trunk/dna-jcr/src: main/resources/org/jboss/dna/jcr and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-23 14:45:00 -0400 (Thu, 23 Apr 2009)
New Revision: 853
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java
trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
Log:
DNA-365 Workspace.importXml and getContentHandler Are Not Implemented
DNA-369 Nodes Can Be Saved Without Mandatory Properties or Child Nodes Present
Applied the patches from these two issues. Unfortunately, they couldn't easily be applied separately.
Note that several TCK unit tests had to be commented out (relative to the patch), since they must be testing behavior that is not yet committed to trunk. (There were a few regressions, but it looks like they're actually related to DNA-374.)
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -63,6 +63,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.property.Binary;
import org.jboss.dna.graph.property.DateTime;
import org.jboss.dna.graph.property.Name;
@@ -73,7 +74,6 @@
import org.jboss.dna.jcr.cache.ChildNode;
import org.jboss.dna.jcr.cache.Children;
import org.jboss.dna.jcr.cache.NodeInfo;
-import org.jboss.dna.jcr.cache.PropertyInfo;
/**
* An abstract implementation of the JCR {@link Node} interface. Instances of this class are created and managed by the
@@ -126,6 +126,18 @@
throw new RepositoryException(msg);
}
}
+
+ final NodeEditor editorFor(Graph.Batch operations) throws RepositoryException {
+ try {
+ return cache.getEditorFor(nodeUuid, operations);
+ } catch (ItemNotFoundException err) {
+ String msg = JcrI18n.nodeHasAlreadyBeenRemovedFromThisSession.text(nodeUuid, cache.workspaceName());
+ throw new RepositoryException(msg);
+ } catch (InvalidItemStateException err) {
+ String msg = JcrI18n.nodeHasAlreadyBeenRemovedFromThisSession.text(nodeUuid, cache.workspaceName());
+ throw new RepositoryException(msg);
+ }
+ }
final JcrValue valueFrom( int propertyType,
Object value ) {
@@ -237,6 +249,10 @@
return session().nodeTypeManager().getNodeType(primaryTypeName);
}
+ Name getPrimaryTypeName() throws RepositoryException {
+ return nodeInfo().getPrimaryTypeName();
+ }
+
/**
* {@inheritDoc}
*
@@ -256,6 +272,10 @@
return mixinNodeTypes.toArray(new NodeType[mixinNodeTypes.size()]);
}
+ List<Name> getMixinTypeNames() throws RepositoryException {
+ return nodeInfo().getMixinTypeNames();
+ }
+
/**
* {@inheritDoc}
*
@@ -729,50 +749,7 @@
throw new ConstraintViolationException();
}
- Property existingMixinProperty = getProperty(JcrLexicon.MIXIN_TYPES);
- Value[] existingMixinValues;
- if (existingMixinProperty != null) {
- existingMixinValues = existingMixinProperty.getValues();
- } else {
- existingMixinValues = new Value[0];
- }
-
- Value[] newMixinValues = new Value[existingMixinValues.length + 1];
- System.arraycopy(existingMixinValues, 0, newMixinValues, 0, existingMixinValues.length);
- newMixinValues[newMixinValues.length - 1] = valueFrom(PropertyType.NAME, mixinCandidateType.getInternalName());
-
- cache.findJcrProperty(editor().setProperty(JcrLexicon.MIXIN_TYPES, newMixinValues, false));
-
- // ------------------------------------------------------------------------------
- // Create any auto-created properties/nodes from new type
- // ------------------------------------------------------------------------------
-
- for (JcrPropertyDefinition propertyDefinition : mixinCandidateType.propertyDefinitions()) {
- if (propertyDefinition.isAutoCreated() && !propertyDefinition.isProtected()) {
- if (null == cache.findJcrProperty(new PropertyId(nodeUuid, propertyDefinition.getInternalName()))) {
- assert propertyDefinition.getDefaultValues() != null;
- if (propertyDefinition.isMultiple()) {
- setProperty(propertyDefinition.getName(), propertyDefinition.getDefaultValues());
- } else {
- assert propertyDefinition.getDefaultValues().length == 1;
- setProperty(propertyDefinition.getName(), propertyDefinition.getDefaultValues()[0]);
- }
- }
- }
- }
-
- for (JcrNodeDefinition nodeDefinition : mixinCandidateType.childNodeDefinitions()) {
- if (nodeDefinition.isAutoCreated() && !nodeDefinition.isProtected()) {
- Name nodeName = nodeDefinition.getInternalName();
- if (!nodeInfo().getChildren().getChildren(nodeName).hasNext()) {
- assert nodeDefinition.getDefaultPrimaryType() != null;
- editor().createChild(nodeName,
- (UUID)null,
- ((JcrNodeType)nodeDefinition.getDefaultPrimaryType()).getInternalName());
- }
- }
- }
-
+ this.editor().addMixin(mixinCandidateType);
}
/**
@@ -891,7 +868,7 @@
}
}
- cache.findJcrProperty(editor().setProperty(JcrLexicon.MIXIN_TYPES, newMixinValues, false));
+ cache.findJcrProperty(editor().setProperty(JcrLexicon.MIXIN_TYPES, newMixinValues, PropertyType.NAME, false));
}
@@ -1022,31 +999,16 @@
throw new UnsupportedOperationException();
}
- /**
- * Checks whether there is an existing property with this name that does not match the given cardinality. If such a property
- * exists, a {@code javax.jcr.ValueFormatException} is thrown, as per section 7.1.5 of the JCR 1.0.1 specification.
- *
- * @param propertyName the name of the property
- * @param isMultiple whether the property must have multiple values
- * @throws javax.jcr.ValueFormatException if the property exists but has the opposite cardinality
- * @throws RepositoryException if any other error occurs
- */
- private void checkCardinalityOfExistingProperty( Name propertyName,
- boolean isMultiple )
- throws javax.jcr.ValueFormatException, RepositoryException {
- // Check for existing single-valued property - can't set multiple values on single-valued property
- PropertyInfo propInfo = this.nodeInfo().getProperty(propertyName);
- if (propInfo != null && propInfo.isMultiValued() != isMultiple) {
- if (isMultiple) {
- I18n msg = JcrI18n.unableToSetSingleValuedPropertyUsingMultipleValues;
- throw new ValueFormatException(msg.text(getPath(),
- propertyName.getString(cache.namespaces),
- cache.workspaceName()));
- }
- I18n msg = JcrI18n.unableToSetMultiValuedPropertyUsingSingleValue;
- throw new ValueFormatException(msg.text(getPath(), propertyName, cache.workspaceName()));
+ protected final Property removeExistingValuedProperty( String name )
+ throws ConstraintViolationException, RepositoryException {
+ PropertyId id = new PropertyId(nodeUuid, nameFrom(name));
+ AbstractJcrProperty property = cache.findJcrProperty(id);
+ if (property != null) {
+ property.remove();
+ return property;
}
-
+ // else the property doesn't exist ...
+ throw new RepositoryException(JcrI18n.propertyNotFoundOnNode.text(name, getPath(), cache.workspaceName()));
}
/**
@@ -1057,10 +1019,7 @@
public final Property setProperty( String name,
boolean value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(PropertyType.BOOLEAN, value)));
-
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(PropertyType.BOOLEAN, value)));
}
/**
@@ -1071,15 +1030,12 @@
public final Property setProperty( String name,
Calendar value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
+
if (value == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(value)));
-
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(value)));
}
/**
@@ -1090,10 +1046,7 @@
public final Property setProperty( String name,
double value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(PropertyType.DOUBLE, value)));
-
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(PropertyType.DOUBLE, value)));
}
/**
@@ -1105,12 +1058,10 @@
InputStream value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (value == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(value)));
+
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(value)));
}
/**
@@ -1121,9 +1072,7 @@
public final Property setProperty( String name,
long value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(PropertyType.LONG, value)));
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(PropertyType.LONG, value)));
}
/**
@@ -1135,13 +1084,10 @@
Node value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (value == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(value)));
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(value)));
}
/**
@@ -1153,12 +1099,10 @@
String value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (value == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(PropertyType.STRING, value)));
+
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(PropertyType.STRING, value)));
}
/**
@@ -1171,12 +1115,10 @@
int type )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (value == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, valueFrom(type, value)));
+
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(type, value)));
}
/**
@@ -1188,12 +1130,10 @@
String[] values )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (values == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, true);
- return cache.findJcrProperty(editor().setProperty(propertyName, valuesFrom(PropertyType.STRING, values)));
+
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valuesFrom(PropertyType.STRING, values), PropertyType.UNDEFINED));
}
/**
@@ -1206,12 +1146,10 @@
int type )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (values == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, true);
- return cache.findJcrProperty(editor().setProperty(propertyName, valuesFrom(type, values)));
+
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), valuesFrom(type, values), PropertyType.UNDEFINED));
}
/**
@@ -1223,24 +1161,10 @@
Value value )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (value == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, (JcrValue)value));
- }
- protected final Property removeExistingValuedProperty( String name )
- throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
- PropertyId id = new PropertyId(nodeUuid, nameFrom(name));
- AbstractJcrProperty property = cache.findJcrProperty(id);
- if (property != null) {
- property.remove();
- return property;
- }
- // else the property doesn't exist ...
- throw new RepositoryException(JcrI18n.propertyNotFoundOnNode.text(name, getPath(), cache.workspaceName()));
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), (JcrValue)value));
}
/**
@@ -1253,12 +1177,10 @@
int type )
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
if (value == null) {
- // If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, false);
- return cache.findJcrProperty(editor().setProperty(propertyName, ((JcrValue)value).asType(type)));
+
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), ((JcrValue)value).asType(type)));
}
/**
@@ -1273,44 +1195,8 @@
// If there is an existing property, then remove it ...
return removeExistingValuedProperty(name);
}
- int len = values.length;
- Value[] newValues = null;
- if (len == 0) {
- newValues = JcrMultiValueProperty.EMPTY_VALUES;
- } else {
- List<Value> valuesWithDesiredType = new ArrayList<Value>(len);
- int expectedType = -1;
- for (int i = 0; i != len; ++i) {
- Value value = values[i];
- if (value == null) continue;
- if (expectedType == -1) {
- expectedType = value.getType();
- } else if (value.getType() != expectedType) {
- // Make sure the type of each value is the same, as per Javadoc in section 7.1.5 of the JCR 1.0.1 spec
- StringBuilder sb = new StringBuilder();
- sb.append('[');
- for (int j = 0; j != values.length; ++j) {
- if (j != 0) sb.append(",");
- sb.append(values[j].toString());
- }
- sb.append(']');
- String propType = PropertyType.nameFromValue(expectedType);
- I18n msg = JcrI18n.allPropertyValuesMustHaveSameType;
- throw new ValueFormatException(msg.text(name, values, propType, getPath(), cache.workspaceName()));
- }
- valuesWithDesiredType.add(value);
- }
- if (valuesWithDesiredType.isEmpty()) {
- newValues = JcrMultiValueProperty.EMPTY_VALUES;
- } else {
- newValues = valuesWithDesiredType.toArray(new Value[valuesWithDesiredType.size()]);
- }
- }
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, true);
- // Set the value, perhaps to an empty array ...
- return cache.findJcrProperty(editor().setProperty(propertyName, newValues));
+ return setProperty(name, values, PropertyType.UNDEFINED);
}
/**
@@ -1327,48 +1213,8 @@
return removeExistingValuedProperty(name);
}
- int len = values.length;
- Value[] newValues = null;
- if (len == 0) {
- newValues = JcrMultiValueProperty.EMPTY_VALUES;
- } else {
- List<Value> valuesWithDesiredType = new ArrayList<Value>(len);
- int expectedType = -1;
- for (int i = 0; i != len; ++i) {
- Value value = values[i];
-
- if (value == null) continue;
- if (expectedType == -1) {
- expectedType = value.getType();
- } else if (value.getType() != expectedType) {
- // Make sure the type of each value is the same, as per Javadoc in section 7.1.5 of the JCR 1.0.1 spec
- StringBuilder sb = new StringBuilder();
- sb.append('[');
- for (int j = 0; j != values.length; ++j) {
- if (j != 0) sb.append(",");
- sb.append(values[j].toString());
- }
- sb.append(']');
- String propType = PropertyType.nameFromValue(expectedType);
- I18n msg = JcrI18n.allPropertyValuesMustHaveSameType;
- throw new ValueFormatException(msg.text(name, values, propType, getPath(), cache.workspaceName()));
- }
- if (value.getType() != type) {
- value = ((JcrValue)value).asType(type);
- }
- valuesWithDesiredType.add(value);
- }
- if (valuesWithDesiredType.isEmpty()) {
- newValues = JcrMultiValueProperty.EMPTY_VALUES;
- } else {
- newValues = valuesWithDesiredType.toArray(new Value[valuesWithDesiredType.size()]);
- }
- }
-
- Name propertyName = nameFrom(name);
- checkCardinalityOfExistingProperty(propertyName, true);
// Set the value, perhaps to an empty array ...
- return cache.findJcrProperty(editor().setProperty(propertyName, newValues));
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), values, type));
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -32,16 +32,19 @@
import java.util.UUID;
import javax.jcr.ImportUUIDBehavior;
import javax.jcr.ItemExistsException;
-import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.ConstraintViolationException;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.XmlNameEncoder;
import org.jboss.dna.common.util.Base64;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NameFactory;
import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.xml.sax.Attributes;
@@ -71,9 +74,10 @@
protected static final TextDecoder DOCUMENT_VIEW_NAME_DECODER = new JcrDocumentViewExporter.JcrDocumentViewPropertyEncoder();
+ private final NameFactory nameFactory;
+
protected final JcrSession session;
protected final int uuidBehavior;
- protected final SaveMode saveMode;
protected final String primaryTypeName;
protected final String mixinTypesName;
@@ -82,6 +86,8 @@
private AbstractJcrNode currentNode;
private ContentHandler delegate;
+ private Graph.Batch pendingOperations;
+
enum SaveMode {
WORKSPACE,
SESSION
@@ -99,15 +105,37 @@
|| uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW;
this.session = session;
+ this.nameFactory = session.getExecutionContext().getValueFactories().getNameFactory();
this.currentNode = session.getNode(parentPath);
this.uuidBehavior = uuidBehavior;
- this.saveMode = saveMode;
+ if (saveMode == SaveMode.WORKSPACE) {
+ this.pendingOperations = session.createBatch();
+ }
+
this.primaryTypeName = JcrLexicon.PRIMARY_TYPE.getString(this.session.namespaces());
this.mixinTypesName = JcrLexicon.MIXIN_TYPES.getString(this.session.namespaces());
this.uuidName = JcrLexicon.UUID.getString(this.session.namespaces());
}
+ protected final Name nameFor( String name ) {
+ return nameFactory.create(name);
+ }
+
+ protected final Value valueFor( String value,
+ int type ) throws ValueFormatException {
+ return session.getValueFactory().createValue(value, type);
+ // return new JcrValue(session.getExecutionContext().getValueFactories(), cache(), type, value);
+ }
+
+ protected final SessionCache cache() {
+ return session.cache();
+ }
+
+ protected final Graph.Batch operations() {
+ return pendingOperations;
+ }
+
/**
* {@inheritDoc}
*
@@ -124,6 +152,20 @@
/**
* {@inheritDoc}
*
+ * @see org.xml.sax.helpers.DefaultHandler#endDocument()
+ */
+ @Override
+ public void endDocument() throws SAXException {
+ if (pendingOperations != null) {
+ pendingOperations.execute();
+ }
+
+ super.endDocument();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
@@ -273,9 +315,10 @@
uuid = UUID.fromString(rawUuid.get(0).getString());
}
- AbstractJcrNode newNode = parentNode.addNode(currentNodeName, currentProps.get(primaryTypeName)
- .get(0)
- .getString(), uuid);
+ String typeName = currentProps.get(primaryTypeName).get(0).getString();
+ AbstractJcrNode newNode = cache().findJcrNode(parentNode.editorFor(operations()).createChild(nameFor(currentNodeName),
+ uuid,
+ nameFor(typeName)).getUuid());
for (Map.Entry<String, List<Value>> entry : currentProps.entrySet()) {
if (entry.getKey().equals(primaryTypeName)) {
@@ -284,7 +327,8 @@
if (entry.getKey().equals(mixinTypesName)) {
for (Value value : entry.getValue()) {
- newNode.addMixin(value.getString());
+ JcrNodeType mixinType = session.workspace().nodeTypeManager().getNodeType(nameFor(value.getString()));
+ newNode.editorFor(operations()).addMixin(mixinType);
}
continue;
}
@@ -296,9 +340,11 @@
List<Value> values = entry.getValue();
if (values.size() == 1) {
- newNode.setProperty(entry.getKey(), values.get(0));
+ newNode.editorFor(operations()).setProperty(nameFor(entry.getKey()), (JcrValue)values.get(0));
} else {
- newNode.setProperty(entry.getKey(), values.toArray(new Value[values.size()]));
+ newNode.editorFor(operations()).setProperty(nameFor(entry.getKey()),
+ values.toArray(new Value[values.size()]),
+ PropertyType.UNDEFINED);
}
}
@@ -385,7 +431,7 @@
switch (uuidBehavior) {
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
parentNode = (AbstractJcrNode)existingNodeWithUuid.getParent();
- existingNodeWithUuid.remove();
+ parentNode.editorFor(operations()).destroyChild(uuid);
break;
case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
uuid = UUID.randomUUID();
@@ -394,7 +440,8 @@
if (existingNodeWithUuid.path().isAtOrAbove(parentStack.firstElement().path())) {
throw new ConstraintViolationException();
}
- existingNodeWithUuid.remove();
+ AbstractJcrNode temp = (AbstractJcrNode)existingNodeWithUuid.getParent();
+ temp.editorFor(operations()).destroyChild(uuid);
break;
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
throw new ItemExistsException();
@@ -403,7 +450,9 @@
}
name = DOCUMENT_VIEW_NAME_DECODER.decode(name);
- AbstractJcrNode currentNode = parentNode.addNode(name, primaryTypeName, uuid);
+ AbstractJcrNode currentNode = cache().findJcrNode(parentNode.editorFor(operations()).createChild(nameFor(name),
+ uuid,
+ nameFor(primaryTypeName)).getUuid());
for (int i = 0; i < atts.getLength(); i++) {
if (JcrContentHandler.this.primaryTypeName.equals(atts.getQName(i))) {
@@ -411,7 +460,8 @@
}
if (mixinTypesName.equals(atts.getQName(i))) {
- currentNode.addMixin(atts.getValue(i));
+ JcrNodeType mixinType = session.workspace().nodeTypeManager().getNodeType(nameFor(atts.getValue(i)));
+ currentNode.editorFor(operations()).addMixin(mixinType);
continue;
}
@@ -424,7 +474,8 @@
// String value = DOCUMENT_VIEW_NAME_DECODER.decode(atts.getValue(i));
String value = atts.getValue(i);
String propertyName = DOCUMENT_VIEW_NAME_DECODER.decode(atts.getQName(i));
- currentNode.setProperty(propertyName, value);
+ currentNode.editorFor(operations()).setProperty(nameFor(propertyName),
+ (JcrValue)valueFor(value, PropertyType.STRING));
}
parentStack.push(currentNode);
@@ -451,12 +502,14 @@
int start,
int length ) throws SAXException {
try {
- NamespaceRegistry namespaces = session.getExecutionContext().getNamespaceRegistry();
- Node parentNode = parentStack.peek();
- Node currentNode = parentNode.addNode(JcrLexicon.XMLTEXT.getString(namespaces),
- JcrNtLexicon.UNSTRUCTURED.getString(namespaces));
+ AbstractJcrNode parentNode = parentStack.peek();
+ AbstractJcrNode currentNode = cache().findJcrNode(parentNode.editorFor(operations()).createChild(JcrLexicon.XMLTEXT,
+ null,
+ JcrNtLexicon.UNSTRUCTURED).getUuid());
+
String s = new String(ch, start, length);
- currentNode.setProperty(JcrLexicon.XMLCHARACTERS.getString(namespaces), s);
+ currentNode.editorFor(operations()).setProperty(JcrLexicon.XMLCHARACTERS,
+ (JcrValue)valueFor(s, PropertyType.STRING));
} catch (RepositoryException re) {
throw new EnclosingSAXException(re);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -128,6 +128,10 @@
public static I18n autocreatedPropertyNeedsDefault;
public static I18n singleValuedPropertyNeedsSingleValuedDefault;
+ public static I18n noDefinition;
+ public static I18n noSnsDefinition;
+ public static I18n missingMandatoryItem;
+
static {
try {
I18n.initialize(JcrI18n.class);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -37,9 +37,7 @@
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.ValueFactory;
/**
* @author jverhaeg
@@ -191,88 +189,7 @@
return;
}
- Value[] newValues = null;
- if (values.length != 0) {
- int numValues = values.length;
- int valueType = -1;
- List<Value> valuesList = new ArrayList<Value>(numValues);
- ValueFactory<?> factory = null;
- for (int i = 0; i != numValues; ++i) {
- Value value = values[i];
- if (value == null) {
- // skip null values ...
- continue;
- }
- if (valueType == -1) {
- valueType = value.getType();
- } else if (value.getType() != valueType) {
- // Make sure the type of each value is the same, as per Javadoc in section 7.1.5 of the JCR 1.0.1 spec
- StringBuilder sb = new StringBuilder();
- sb.append('[');
- for (int j = 0; j != values.length; ++j) {
- if (j != 0) sb.append(",");
- sb.append(values[j].toString());
- }
- sb.append(']');
- String propType = PropertyType.nameFromValue(valueType);
- I18n msg = JcrI18n.allPropertyValuesMustHaveSameType;
- throw new ValueFormatException(msg.text(getName(), values, propType, getPath(), cache.workspaceName()));
- }
-
- if (value instanceof JcrValue) {
- // just use the value ...
- valuesList.add(value);
- } else {
- // This isn't our implementation, so create one for use
- if (factory == null) {
- int currentType = this.getType();
- factory = context().getValueFactories().getValueFactory(PropertyTypeUtil.dnaPropertyTypeFor(currentType));
- }
- int type = value.getType();
- Object data = null;
- switch (value.getType()) {
- case PropertyType.STRING:
- data = value.getString();
- break;
- case PropertyType.BINARY:
- data = value.getStream();
- break;
- case PropertyType.BOOLEAN:
- data = value.getBoolean();
- break;
- case PropertyType.DATE:
- data = value.getDate();
- break;
- case PropertyType.DOUBLE:
- data = value.getDouble();
- break;
- case PropertyType.LONG:
- data = value.getLong();
- break;
- case PropertyType.NAME:
- data = value.getString();
- break;
- case PropertyType.PATH:
- data = value.getString();
- break;
- case PropertyType.REFERENCE:
- data = value.getString();
- break;
- default:
- throw new RepositoryException();
- }
- valuesList.add(createValue(factory.create(data), type));
- }
- }
- if (valuesList.isEmpty()) {
- newValues = EMPTY_VALUES;
- } else {
- newValues = valuesList.toArray(new Value[valuesList.size()]);
- }
- } else {
- newValues = EMPTY_VALUES;
- }
- cache.getEditorFor(propertyId.getNodeId()).setProperty(propertyId.getPropertyName(), newValues);
+ cache.getEditorFor(propertyId.getNodeId()).setProperty(propertyId.getPropertyName(), values, PropertyType.UNDEFINED);
}
/**
@@ -305,7 +222,8 @@
} else {
jcrValues = EMPTY_VALUES;
}
- cache.getEditorFor(propertyId.getNodeId()).setProperty(propertyId.getPropertyName(), jcrValues);
+
+ cache.getEditorFor(propertyId.getNodeId()).setProperty(propertyId.getPropertyName(), jcrValues, PropertyType.STRING);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -215,6 +215,25 @@
defaultPrimaryTypeName, required);
}
+
+
+ @Override
+ public int hashCode() {
+ return getId().toString().hashCode();
+ }
+
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ JcrNodeDefinition other = (JcrNodeDefinition)obj;
+ if (id == null) {
+ if (other.id != null) return false;
+ } else if (!id.equals(other.id)) return false;
+ return true;
+ }
+
/**
* {@inheritDoc}
*
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -310,7 +310,25 @@
throw new IllegalStateException("Invalid property type: " + type);
}
}
+
+ @Override
+ public int hashCode() {
+ return getId().toString().hashCode();
+ }
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ JcrPropertyDefinition other = (JcrPropertyDefinition)obj;
+ if (id == null) {
+ if (other.id != null) return false;
+ } else if (!id.equals(other.id)) return false;
+ return true;
+ }
+
+
/**
* Interface that encapsulates a reusable method that can test values to determine if they match a specific list of
* constraints for the semantics associated with a single {@link PropertyType}.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -180,6 +180,10 @@
JcrWorkspace workspace() {
return this.workspace;
}
+
+ Graph.Batch createBatch() {
+ return graph.batch();
+ }
/**
* {@inheritDoc}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -34,6 +34,7 @@
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Workspace;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
@@ -46,11 +47,9 @@
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
-import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.connector.RepositorySourceException;
-import org.jboss.dna.graph.io.GraphImporter;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
@@ -58,8 +57,15 @@
import org.jboss.dna.graph.property.PropertyFactory;
import org.jboss.dna.graph.property.ValueFormatException;
import org.jboss.dna.graph.property.basic.GraphNamespaceRegistry;
+import org.jboss.dna.jcr.JcrContentHandler.EnclosingSAXException;
+import org.jboss.dna.jcr.JcrContentHandler.SaveMode;
import org.jboss.dna.jcr.JcrRepository.Options;
import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author John Verhaeg
@@ -224,8 +230,8 @@
/**
* {@inheritDoc}
*/
- public final ObservationManager getObservationManager() {
- throw new UnsupportedOperationException();
+ public final ObservationManager getObservationManager() throws UnsupportedRepositoryOperationException {
+ throw new UnsupportedRepositoryOperationException();
}
/**
@@ -292,17 +298,16 @@
*
* @see javax.jcr.Workspace#getImportContentHandler(java.lang.String, int)
*/
- @SuppressWarnings( "unused" )
public ContentHandler getImportContentHandler( String parentAbsPath,
int uuidBehavior )
throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, AccessDeniedException,
RepositoryException {
- CheckArg.isNotEmpty(parentAbsPath, "parentAbsPath");
- // Create a graph importer, which can return the content handler that can be used by the caller
- // to call the handler's event methods to create content...
- GraphImporter importer = new GraphImporter(graph);
- Path parentPath = context.getValueFactories().getPathFactory().create(parentAbsPath);
- return importer.getHandlerForImportingXml(Location.create(parentPath), false);
+
+ CheckArg.isNotNull(parentAbsPath, "parentAbsPath");
+
+ Path parentPath = this.context.getValueFactories().getPathFactory().create(parentAbsPath);
+
+ return new JcrContentHandler(this.session, parentPath, uuidBehavior, SaveMode.WORKSPACE);
}
/**
@@ -310,19 +315,33 @@
*
* @see javax.jcr.Workspace#importXML(java.lang.String, java.io.InputStream, int)
*/
- @SuppressWarnings( "unused" )
public void importXML( String parentAbsPath,
InputStream in,
int uuidBehavior )
throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException,
InvalidSerializedDataException, LockException, AccessDeniedException, RepositoryException {
- // try {
- // graph.importXmlFrom(in).into(parentAbsPath);
- // } catch (org.jboss.dna.graph.property.PathNotFoundException e) {
- // throw new PathNotFoundException(e.getMessage(), e);
- // } catch (SAXException err) {
- // }
- throw new UnsupportedOperationException();
+
+ CheckArg.isNotNull(parentAbsPath, "parentAbsPath");
+ CheckArg.isNotNull(in, "in");
+
+ try {
+ XMLReader parser = XMLReaderFactory.createXMLReader();
+ parser.setContentHandler(getImportContentHandler(parentAbsPath, uuidBehavior));
+ parser.parse(new InputSource(in));
+ } catch (EnclosingSAXException ese) {
+ Exception cause = ese.getException();
+ if (cause instanceof ItemExistsException) {
+ throw (ItemExistsException)cause;
+ } else if (cause instanceof ConstraintViolationException) {
+ throw (ConstraintViolationException)cause;
+ }
+ throw new RepositoryException(cause);
+ } catch (SAXParseException se) {
+ throw new InvalidSerializedDataException(se);
+ } catch (SAXException se) {
+ throw new RepositoryException(se);
+ }
+
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -355,12 +355,205 @@
}
/**
+ * Checks that the child items of the node are consistent with the definitions required by the node's primary type and mixin
+ * types (if any).
+ * <p>
+ * This method first checks that all of the child nodes and properties for the node have definitions based on the current
+ * primary and mixin node types for the node as held in the node type registry. The method then checks that all mandatory (and
+ * non-protected) items are populated.
+ * </p>
+ *
+ * @param nodeUuid the UUID of the node to check
+ * @param checkSns if true indicates that this method should distinguish between child nodes that have no matching definition
+ * and child nodes that would have a definition that would match if it allowed same-name siblings. This flag determines
+ * which exception type should be thrown in that case.
+ * @throws ItemExistsException if checkSns is true and there is no definition that allows same-name siblings for one of the
+ * node's child nodes and the node already has a child node with the given name
+ * @throws ConstraintViolationException if one of the node's properties or child nodes does not have a matching definition for
+ * the name and type among the node's primary and mixin types; this should only occur if type definitions have been
+ * modified since the node was loaded or modified.
+ * @throws RepositoryException if any other error occurs
+ */
+ private void checkAgainstTypeDefinitions( UUID nodeUuid,
+ boolean checkSns )
+ throws ConstraintViolationException, ItemExistsException, RepositoryException {
+
+ NodeInfo nodeInfo = findNodeInfo(nodeUuid);
+ AbstractJcrNode node = findJcrNode(nodeUuid);
+
+ Name primaryTypeName = node.getPrimaryTypeName();
+ List<Name> mixinTypeNames = node.getMixinTypeNames();
+ Set<JcrNodeDefinition> satisfiedChildNodes = new HashSet<JcrNodeDefinition>();
+ Set<JcrPropertyDefinition> satisfiedProperties = new HashSet<JcrPropertyDefinition>();
+
+ for (AbstractJcrProperty property : findJcrPropertiesFor(nodeUuid)) {
+ JcrPropertyDefinition definition = findBestPropertyDefintion(primaryTypeName,
+ mixinTypeNames,
+ property.property(),
+ property.getType(),
+ false);
+ if (definition == null) {
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("property",
+ property.getName(),
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+
+ satisfiedProperties.add(definition);
+ }
+
+ Children children = nodeInfo.getChildren();
+ for (ChildNode child : children) {
+ int snsCount = children.getCountOfSameNameSiblingsWithName(child.getName());
+ NodeInfo childInfo = findNodeInfo(child.getUuid());
+ JcrNodeDefinition definition = nodeTypes().findChildNodeDefinition(primaryTypeName,
+ mixinTypeNames,
+ child.getName(),
+ childInfo.getPrimaryTypeName(),
+ snsCount,
+ false);
+ if (definition == null) {
+ if (checkSns && snsCount > 1) {
+ definition = nodeTypes().findChildNodeDefinition(primaryTypeName,
+ mixinTypeNames,
+ child.getName(),
+ childInfo.getPrimaryTypeName(),
+ 1,
+ false);
+
+ if (definition != null) {
+ throw new ItemExistsException(JcrI18n.noSnsDefinition.text(child.getName(),
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+ }
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("child node",
+ child.getName(),
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+ satisfiedChildNodes.add(definition);
+ }
+
+ JcrNodeType primaryType = nodeTypes().getNodeType(primaryTypeName);
+ for (JcrPropertyDefinition definition : primaryType.getPropertyDefinitions()) {
+ if (definition.isMandatory() && !definition.isProtected() && !satisfiedProperties.contains(definition)) {
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("property",
+ definition.getName(),
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+ }
+ for (JcrNodeDefinition definition : primaryType.getChildNodeDefinitions()) {
+ if (definition.isMandatory() && !definition.isProtected() && !satisfiedChildNodes.contains(definition)) {
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("child node",
+ definition.getName(),
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+ }
+
+ for (Name mixinTypeName : mixinTypeNames) {
+ JcrNodeType mixinType = nodeTypes().getNodeType(mixinTypeName);
+ for (JcrPropertyDefinition definition : mixinType.getPropertyDefinitions()) {
+ if (definition.isMandatory() && !definition.isProtected() && !satisfiedProperties.contains(definition)) {
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("child node",
+ definition.getName(),
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+ }
+ for (JcrNodeDefinition definition : mixinType.getChildNodeDefinitions()) {
+ if (definition.isMandatory() && !definition.isProtected() && !satisfiedChildNodes.contains(definition)) {
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("child node",
+ definition.getName(),
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Find the best definition for the child node with the given name on the node with the given UUID.
+ *
+ * @param nodeUuid the parent node; may not be null
+ * @param newNodeName the name of the potential new child node; may not be null
+ * @param newNodePrimaryTypeName the primary type of the potential new child node; may not be null
+ * @return the definition that best fits the new node name and type
+ * @throws ItemExistsException if there is no definition that allows same-name siblings for the name and type and the parent
+ * node already has a child node with the given name
+ * @throws ConstraintViolationException if there is no definition for the name and type among the parent node's primary and
+ * mixin types
+ * @throws RepositoryException if any other error occurs
+ */
+ protected JcrNodeDefinition findBestNodeDefinition( UUID nodeUuid,
+ Name newNodeName,
+ Name newNodePrimaryTypeName )
+ throws ItemExistsException, ConstraintViolationException, RepositoryException {
+ assert (nodeUuid != null);
+ assert (newNodeName != null);
+
+ NodeInfo nodeInfo = findNodeInfo(nodeUuid);
+ AbstractJcrNode node = findJcrNode(nodeUuid);
+
+ Name primaryTypeName = node.getPrimaryTypeName();
+ List<Name> mixinTypeNames = node.getMixinTypeNames();
+
+ Children children = nodeInfo.getChildren();
+ int snsCount = children.getCountOfSameNameSiblingsWithName(newNodeName);
+ JcrNodeDefinition definition = nodeTypes().findChildNodeDefinition(primaryTypeName,
+ mixinTypeNames,
+ newNodeName,
+ newNodePrimaryTypeName,
+ snsCount,
+ true);
+ if (definition == null) {
+ if (snsCount > 1) {
+ definition = nodeTypes().findChildNodeDefinition(primaryTypeName,
+ mixinTypeNames,
+ newNodeName,
+ newNodePrimaryTypeName,
+ 1,
+ true);
+
+ if (definition != null) {
+ throw new ItemExistsException(JcrI18n.noSnsDefinition.text(newNodeName,
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+ }
+
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("child node",
+ newNodeName,
+ node.getPath(),
+ primaryTypeName,
+ mixinTypeNames));
+ }
+
+ return definition;
+ }
+
+ /**
* Save any changes that have been accumulated by this session.
*
* @throws RepositoryException if any error resulting while saving the changes to the repository
*/
public void save() throws RepositoryException {
if (operations.isExecuteRequired()) {
+ for (UUID changedUuid : changedNodes.keySet()) {
+ checkAgainstTypeDefinitions(changedUuid, false);
+ }
+
// Execute the batched operations ...
try {
operations.execute();
@@ -453,7 +646,7 @@
for (ChildNode childNode : changedNode.getChildren()) {
uuidsUnderBranch.add(childNode.getUuid());
}
-
+
Collection<UUID> peers = changedNode.getPeers();
if (peers != null) peersToCheck.addAll(peers);
}
@@ -468,7 +661,7 @@
throw new ConstraintViolationException();
}
}
-
+
// Now execute the branch ...
Graph.Batch branchBatch = store.batch(new BatchRequestBuilder(branchRequests));
try {
@@ -653,7 +846,9 @@
/**
* Obtain an {@link NodeEditor editor} that can be used to manipulate the properties or children on the node identified by the
* supplied UUID. The node must exist prior to this call, either as a node that exists in the workspace or as a node that was
- * created within this session but not yet persited to the workspace.
+ * created within this session but not yet persisted to the workspace. This method returns an editor that batches all changes
+ * in transient storage from where they can be persisted to the repository by {@link javax.jcr.Session#save() saving the
+ * session} or by {@link javax.jcr.Item#save() saving an ancestor}.
*
* @param uuid the UUID of the node that is to be changed; may not be null and must represent an <i>existing</i> node
* @return the editor; never null
@@ -662,6 +857,26 @@
* @throws RepositoryException if any other error occurs while reading information from the repository
*/
public NodeEditor getEditorFor( UUID uuid ) throws ItemNotFoundException, InvalidItemStateException, RepositoryException {
+ return getEditorFor(uuid, this.operations);
+ }
+
+ /**
+ * Obtain an {@link NodeEditor editor} that can be used to manipulate the properties or children on the node identified by the
+ * supplied UUID. The node must exist prior to this call, either as a node that exists in the workspace or as a node that was
+ * created within this session but not yet persisted to the workspace.
+ *
+ * @param uuid the UUID of the node that is to be changed; may not be null and must represent an <i>existing</i> node
+ * @param operationsBatch the {@link Graph.Batch} to use for batching operations. This should be populated for direct
+ * persistence (q.v. section 7.1.3.7 of the JCR 1.0.1 specification) and should be null to use session-based
+ * persistence.
+ * @return the editor; never null
+ * @throws ItemNotFoundException if no such node could be found in the session or workspace
+ * @throws InvalidItemStateException if the item has been marked for deletion within this session
+ * @throws RepositoryException if any other error occurs while reading information from the repository
+ */
+ public NodeEditor getEditorFor( UUID uuid,
+ Graph.Batch operationsBatch )
+ throws ItemNotFoundException, InvalidItemStateException, RepositoryException {
// See if we already have something in the changed nodes ...
ChangedNodeInfo info = changedNodes.get(uuid);
Location currentLocation = null;
@@ -679,7 +894,7 @@
// compute the current location ...
currentLocation = Location.create(getPathFor(info), uuid);
}
- return new NodeEditor(info, currentLocation);
+ return new NodeEditor(info, currentLocation, operationsBatch == null ? this.operations : operationsBatch);
}
/**
@@ -688,14 +903,49 @@
public final class NodeEditor {
private final ChangedNodeInfo node;
private final Location currentLocation;
+ private final Graph.Batch operations;
protected NodeEditor( ChangedNodeInfo node,
- Location currentLocation ) {
+ Location currentLocation,
+ Graph.Batch operations ) {
this.node = node;
this.currentLocation = currentLocation;
+ this.operations = operations;
}
/**
+ * Checks whether there is an existing property with this name that does not match the given cardinality. If such a
+ * property exists, a {@code javax.jcr.ValueFormatException} is thrown, as per section 7.1.5 of the JCR 1.0.1
+ * specification.
+ *
+ * @param propertyName the name of the property
+ * @param isMultiple whether the property must have multiple values
+ * @throws javax.jcr.ValueFormatException if the property exists but has the opposite cardinality
+ * @throws RepositoryException if any other error occurs
+ */
+ private void checkCardinalityOfExistingProperty( Name propertyName,
+ boolean isMultiple )
+ throws javax.jcr.ValueFormatException, RepositoryException {
+ // Check for existing single-valued property - can't set multiple values on single-valued property
+ PropertyInfo propInfo = this.node.getProperty(propertyName);
+ if (propInfo != null && propInfo.isMultiValued() != isMultiple) {
+ NamespaceRegistry namespaces = SessionCache.this.namespaces;
+ String workspaceName = SessionCache.this.workspaceName();
+ if (isMultiple) {
+ I18n msg = JcrI18n.unableToSetSingleValuedPropertyUsingMultipleValues;
+ throw new javax.jcr.ValueFormatException(msg.text(propertyName.getString(namespaces),
+ getPathFor(this.node).getString(namespaces),
+ workspaceName));
+ }
+ I18n msg = JcrI18n.unableToSetMultiValuedPropertyUsingSingleValue;
+ throw new javax.jcr.ValueFormatException(msg.text(getPathFor(this.node).getString(namespaces),
+ propertyName,
+ workspaceName));
+ }
+
+ }
+
+ /**
* Set the value for the property. If the property does not exist, it will be added. If the property does exist, the
* existing values will be replaced with the supplied value.
*
@@ -704,20 +954,23 @@
* @return the identifier for the property; never null
* @throws ConstraintViolationException if the property could not be set because of a node type constraint or property
* definition constraint
+ * @throws RepositoryException if any other error occurs
*/
public PropertyId setProperty( Name name,
- JcrValue value ) throws ConstraintViolationException {
+ JcrValue value ) throws ConstraintViolationException, RepositoryException {
return setProperty(name, value, true);
}
public PropertyId setProperty( Name name,
JcrValue value,
- boolean skipProtected ) throws ConstraintViolationException {
+ boolean skipProtected ) throws ConstraintViolationException, RepositoryException {
assert name != null;
assert value != null;
JcrPropertyDefinition definition = null;
PropertyId id = null;
+ checkCardinalityOfExistingProperty(name, false);
+
// Look for an existing property ...
PropertyInfo existing = node.getProperty(name);
if (existing != null) {
@@ -789,13 +1042,18 @@
* @param name the property name; may not be null
* @param values new property values, all of which must have the same {@link Value#getType() property type}; may not be
* null but may be empty
+ * @param valueType
* @return the identifier for the property; never null
* @throws ConstraintViolationException if the property could not be set because of a node type constraint or property
* definition constraint
+ * @throws javax.jcr.ValueFormatException
+ * @throws RepositoryException
*/
public PropertyId setProperty( Name name,
- Value[] values ) throws ConstraintViolationException {
- return setProperty(name, values, true);
+ Value[] values,
+ int valueType )
+ throws ConstraintViolationException, RepositoryException, javax.jcr.ValueFormatException {
+ return setProperty(name, values, valueType, true);
}
/**
@@ -807,16 +1065,66 @@
* null but may be empty
* @param skipProtected if true, attempts to set protected properties will fail. If false, attempts to set protected
* properties will be allowed.
+ * @param valueType
* @return the identifier for the property; never null
* @throws ConstraintViolationException if the property could not be set because of a node type constraint or property
* definition constraint
+ * @throws javax.jcr.ValueFormatException
+ * @throws RepositoryException
*/
public PropertyId setProperty( Name name,
Value[] values,
- boolean skipProtected ) throws ConstraintViolationException {
+ int valueType,
+ boolean skipProtected )
+ throws ConstraintViolationException, RepositoryException, javax.jcr.ValueFormatException {
assert name != null;
assert values != null;
- int numValues = values.length;
+
+ // TODO: Re-add following line!
+ // checkCardinalityOfExistingProperty(name, true);
+
+ int len = values.length;
+ Value[] newValues = null;
+ if (len == 0) {
+ newValues = JcrMultiValueProperty.EMPTY_VALUES;
+ } else {
+ List<Value> valuesWithDesiredType = new ArrayList<Value>(len);
+ int expectedType = -1;
+ for (int i = 0; i != len; ++i) {
+ Value value = values[i];
+
+ if (value == null) continue;
+ if (expectedType == -1) {
+ expectedType = value.getType();
+ } else if (value.getType() != expectedType) {
+ // Make sure the type of each value is the same, as per Javadoc in section 7.1.5 of the JCR 1.0.1 spec
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (int j = 0; j != values.length; ++j) {
+ if (j != 0) sb.append(",");
+ sb.append(values[j].toString());
+ }
+ sb.append(']');
+ String propType = PropertyType.nameFromValue(expectedType);
+ I18n msg = JcrI18n.allPropertyValuesMustHaveSameType;
+ NamespaceRegistry namespaces = SessionCache.this.namespaces;
+ String path = getPathFor(node.getUuid()).getString(namespaces);
+ String workspaceName = SessionCache.this.workspaceName();
+ throw new javax.jcr.ValueFormatException(msg.text(name, values, propType, path, workspaceName));
+ }
+ if (value.getType() != valueType && valueType != PropertyType.UNDEFINED) {
+ value = ((JcrValue)value).asType(valueType);
+ }
+ valuesWithDesiredType.add(value);
+ }
+ if (valuesWithDesiredType.isEmpty()) {
+ newValues = JcrMultiValueProperty.EMPTY_VALUES;
+ } else {
+ newValues = valuesWithDesiredType.toArray(new Value[valuesWithDesiredType.size()]);
+ }
+ }
+
+ int numValues = newValues.length;
JcrPropertyDefinition definition = null;
PropertyId id = null;
@@ -836,14 +1144,14 @@
// Just use the definition as is ...
} else {
// Use the property type for the first non-null value ...
- int type = values[0].getType();
+ int type = newValues[0].getType();
if (definition.getRequiredType() != PropertyType.UNDEFINED && definition.getRequiredType() != type) {
// The property type is not right, so we have to check if we can cast.
// It's easier and could save more work if we just find a new property definition that works ...
definition = null;
} else {
// The types match, so see if the value satisfies the constraints ...
- if (!definition.satisfiesConstraints(values)) definition = null;
+ if (!definition.satisfiesConstraints(newValues)) definition = null;
}
}
}
@@ -856,21 +1164,21 @@
definition = nodeTypes().findPropertyDefinition(node.getPrimaryTypeName(),
node.getMixinTypeNames(),
name,
- values,
+ newValues,
skipProtected);
if (definition == null) {
throw new ConstraintViolationException();
}
}
// Create the DNA property ...
- int type = values.length != 0 ? values[0].getType() : definition.getRequiredType();
- Object[] objValues = new Object[values.length];
+ int type = newValues.length != 0 ? newValues[0].getType() : definition.getRequiredType();
+ Object[] objValues = new Object[newValues.length];
int propertyType = definition.getRequiredType();
if (propertyType == PropertyType.UNDEFINED || propertyType == type) {
// Can use the values as is ...
propertyType = type;
for (int i = 0; i != numValues; ++i) {
- objValues[i] = ((JcrValue)values[i]).value();
+ objValues[i] = ((JcrValue)newValues[i]).value();
}
} else {
// A cast is required ...
@@ -878,7 +1186,7 @@
org.jboss.dna.graph.property.PropertyType dnaPropertyType = PropertyTypeUtil.dnaPropertyTypeFor(propertyType);
ValueFactory<?> factory = factories().getValueFactory(dnaPropertyType);
for (int i = 0; i != numValues; ++i) {
- objValues[i] = factory.create(((JcrValue)values[i]).value());
+ objValues[i] = factory.create(((JcrValue)newValues[i]).value());
}
}
Property dnaProp = propertyFactory.create(name, objValues);
@@ -920,9 +1228,11 @@
* @throws ConstraintViolationException if moving the node into this node violates this node's definition
* @throws RepositoryException if any other error occurs while reading information from the repository
*/
- public ChildNode moveToBeChild( UUID nodeUuid, Name newNodeName )
+ public ChildNode moveToBeChild( UUID nodeUuid,
+ Name newNodeName )
throws ItemNotFoundException, InvalidItemStateException, ConstraintViolationException, RepositoryException {
+ // UUID nodeUuid = child.nodeUuid;
if (nodeUuid.equals(node.getUuid()) || isAncestor(nodeUuid)) {
Path pathOfNode = getPathFor(nodeUuid);
Path thisPath = currentLocation.getPath();
@@ -931,33 +1241,19 @@
}
// Is the node already a child?
- ChildNode child = node.getChildren().getChild(nodeUuid);
- if (child != null) return child;
+ ChildNode existingChild = node.getChildren().getChild(nodeUuid);
+ if (existingChild != null) return existingChild;
+ JcrNodeDefinition definition = findBestNodeDefinition(node.getUuid(), newNodeName, null);
+
// Get an editor for the child (in its current location) and one for its parent ...
- NodeEditor existingNodeEditor = getEditorFor(nodeUuid);
- ChangedNodeInfo existingNodeInfo = existingNodeEditor.node;
- UUID existingParent = existingNodeInfo.getParent();
- NodeEditor existingParentEditor = getEditorFor(existingParent);
- ChangedNodeInfo existingParentInfo = existingParentEditor.node;
+ NodeEditor newChildEditor = getEditorFor(nodeUuid);
- // Verify that this node's definition allows the specified child ...
- Name childName = existingParentInfo.getChildren().getChild(nodeUuid).getName();
- int numSns = node.getChildren().getCountOfSameNameSiblingsWithName(childName);
- JcrNodeDefinition definition = nodeTypes().findChildNodeDefinition(node.getPrimaryTypeName(),
- node.getMixinTypeNames(),
- childName,
- childName,
- numSns,
- true);
- if (definition == null) {
- throw new ConstraintViolationException();
- }
if (!definition.getId().equals(node.getDefinitionId())) {
// The node definition changed, so try to set the property ...
try {
- JcrValue value = new JcrValue(factories(), SessionCache.this, PropertyType.STRING,
- definition.getId().getString());
+ JcrValue value = new JcrValue(factories(), SessionCache.this, PropertyType.STRING, definition.getId()
+ .getString());
setProperty(DnaLexicon.NODE_DEFINITON, value);
} catch (ConstraintViolationException e) {
// We can't set this property on the node (according to the node definition).
@@ -967,27 +1263,85 @@
node.setDefinitionId(definition.getId());
// And remove the property from the info ...
- existingNodeEditor.removeProperty(DnaLexicon.NODE_DEFINITON);
+ newChildEditor.removeProperty(DnaLexicon.NODE_DEFINITON);
}
}
// Remove the node from the current parent and add it to this ...
- child = existingParentInfo.removeChild(nodeUuid, pathFactory);
- ChildNode newChild = node.addChild(newNodeName, child.getUuid(), pathFactory);
+ ChangedNodeInfo newChildInfo = newChildEditor.node;
+ UUID existingParent = newChildInfo.getParent();
+ ChangedNodeInfo existingParentInfo = getEditorFor(existingParent).node;
+ existingChild = existingParentInfo.removeChild(nodeUuid, pathFactory);
+ ChildNode newChild = node.addChild(newNodeName, existingChild.getUuid(), pathFactory);
+
// Set the child's changed representation to point to this node as its parent ...
- existingNodeInfo.setParent(node.getUuid());
-
+ newChildInfo.setParent(node.getUuid());
+
// Set up the peer relationship between the two nodes that must be saved together
node.addPeer(existingParent);
existingParentInfo.addPeer(node.getUuid());
-
+
+ // Set up the peer relationship between the two nodes that must be saved together
+ node.addPeer(existingParent);
+ existingParentInfo.addPeer(node.getUuid());
+
// Now, record the operation to do this ...
- operations.move(existingNodeEditor.currentLocation).into(currentLocation);
-
+ operations.move(newChildEditor.currentLocation).into(currentLocation);
+
return newChild;
}
+ public void addMixin( JcrNodeType mixinCandidateType ) throws javax.jcr.ValueFormatException, RepositoryException {
+ PropertyInfo existingMixinProperty = node.getProperty(JcrLexicon.MIXIN_TYPES);
+
+ // getProperty(JcrLexicon.MIXIN_TYPES);
+ Value[] existingMixinValues;
+ if (existingMixinProperty != null) {
+ existingMixinValues = findJcrProperty(existingMixinProperty.getPropertyId()).getValues();
+ } else {
+ existingMixinValues = new Value[0];
+ }
+
+ Value[] newMixinValues = new Value[existingMixinValues.length + 1];
+ System.arraycopy(existingMixinValues, 0, newMixinValues, 0, existingMixinValues.length);
+ newMixinValues[newMixinValues.length - 1] = new JcrValue(factories(), SessionCache.this, PropertyType.NAME,
+ mixinCandidateType.getInternalName());
+
+ findJcrProperty(setProperty(JcrLexicon.MIXIN_TYPES, newMixinValues, PropertyType.NAME, false));
+
+ // ------------------------------------------------------------------------------
+ // Create any auto-created properties/nodes from new type
+ // ------------------------------------------------------------------------------
+
+ for (JcrPropertyDefinition propertyDefinition : mixinCandidateType.propertyDefinitions()) {
+ if (propertyDefinition.isAutoCreated() && !propertyDefinition.isProtected()) {
+ if (null == findJcrProperty(new PropertyId(node.getUuid(), propertyDefinition.getInternalName()))) {
+ assert propertyDefinition.getDefaultValues() != null;
+ if (propertyDefinition.isMultiple()) {
+ setProperty(propertyDefinition.getInternalName(),
+ propertyDefinition.getDefaultValues(),
+ propertyDefinition.getRequiredType());
+ } else {
+ assert propertyDefinition.getDefaultValues().length == 1;
+ setProperty(propertyDefinition.getInternalName(), (JcrValue)propertyDefinition.getDefaultValues()[0]);
+ }
+ }
+ }
+ }
+
+ for (JcrNodeDefinition nodeDefinition : mixinCandidateType.childNodeDefinitions()) {
+ if (nodeDefinition.isAutoCreated() && !nodeDefinition.isProtected()) {
+ Name nodeName = nodeDefinition.getInternalName();
+ if (!node.getChildren().getChildren(nodeName).hasNext()) {
+ assert nodeDefinition.getDefaultPrimaryType() != null;
+ createChild(nodeName, (UUID)null, ((JcrNodeType)nodeDefinition.getDefaultPrimaryType()).getInternalName());
+ }
+ }
+ }
+
+ }
+
/**
* Create a new node as a child of this node, using the supplied name and (optionally) the supplied UUID.
*
@@ -1172,7 +1526,7 @@
}
/**
- * Find the best property definition in this node's
+ * Find the best property definition in this node's primary type and mixin types.
*
* @param primaryTypeNameOfParent the name of the primary type for the parent node; may not be null
* @param mixinTypeNamesOfParent the names of the mixin types for the parent node; may be null or empty if there are no mixins
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-04-23 18:45:00 UTC (rev 853)
@@ -112,3 +112,7 @@
cannotRedefineProperty=Cannot redefine property '{0}' with new type '{1}' when existing property with same name in type '{2}' has incompatible type '{3}'
autocreatedPropertyNeedsDefault=Auto-created property '{0}' in type '{1}' must specify a default value
singleValuedPropertyNeedsSingleValuedDefault=Single-valued property '{0}' in type '{1}' cannot have multiple default values
+
+noDefinition=Cannot find a definition for the {0} named '{1}' on the node at '{2}' with primary type '{3}' and mixin types: {4}
+noSnsDefinition=Cannot find a definition that allows same-name siblings for the child node named '{0}' on the node at '{1}' with primary type '{2}' and mixin types: {3} and a child node already exists with this name
+missingMandatoryItem=The mandatory {0} named '{1}' defined in type '{2}' is missing from the node at '{3}'
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -35,11 +35,13 @@
import java.util.Map;
import java.util.Properties;
import javax.jcr.Credentials;
+import javax.jcr.PropertyType;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.jackrabbit.test.JCRTestSuite;
import org.apache.jackrabbit.test.RepositoryStub;
import org.apache.jackrabbit.test.api.AddNodeTest;
+import org.apache.jackrabbit.test.api.DocumentViewImportTest;
import org.apache.jackrabbit.test.api.NamespaceRegistryTest;
import org.apache.jackrabbit.test.api.NodeAddMixinTest;
import org.apache.jackrabbit.test.api.NodeCanAddMixinTest;
@@ -50,6 +52,8 @@
import org.apache.jackrabbit.test.api.PropertyItemIsNewTest;
import org.apache.jackrabbit.test.api.PropertyTest;
import org.apache.jackrabbit.test.api.RepositoryLoginTest;
+import org.apache.jackrabbit.test.api.SerializationTest;
+import org.apache.jackrabbit.test.api.SessionTest;
import org.apache.jackrabbit.test.api.SessionUUIDTest;
import org.apache.jackrabbit.test.api.SetPropertyBooleanTest;
import org.apache.jackrabbit.test.api.SetPropertyCalendarTest;
@@ -58,8 +62,6 @@
import org.apache.jackrabbit.test.api.SetPropertyInputStreamTest;
import org.apache.jackrabbit.test.api.SetPropertyLongTest;
import org.apache.jackrabbit.test.api.SetPropertyNodeTest;
-import org.apache.jackrabbit.test.api.SetPropertyStringTest;
-import org.apache.jackrabbit.test.api.SetPropertyValueTest;
import org.apache.jackrabbit.test.api.SetValueBinaryTest;
import org.apache.jackrabbit.test.api.SetValueBooleanTest;
import org.apache.jackrabbit.test.api.SetValueConstraintViolationExceptionTest;
@@ -77,6 +79,7 @@
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesReferenceableTest;
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesSameNameSibsTest;
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesTest;
+import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesVersionableTest;
import org.apache.jackrabbit.test.api.WorkspaceCopyVersionableTest;
import org.apache.jackrabbit.test.api.WorkspaceMoveVersionableTest;
import org.jboss.dna.graph.ExecutionContext;
@@ -189,7 +192,7 @@
addTestSuite(AddNodeTest.class);
addTestSuite(NamespaceRegistryTest.class);
// addTestSuite(ReferencesTest.class);
- // addTestSuite(SessionTest.class);
+ addTestSuite(SessionTest.class);
addTestSuite(SessionUUIDTest.class);
// addTestSuite(NodeTest.class);
// addTestSuite(NodeUUIDTest.class);
@@ -213,8 +216,8 @@
addTestSuite(SetPropertyInputStreamTest.class);
addTestSuite(SetPropertyLongTest.class);
addTestSuite(SetPropertyNodeTest.class);
- addTestSuite(SetPropertyStringTest.class);
- addTestSuite(SetPropertyValueTest.class);
+ // addTestSuite(SetPropertyStringTest.class);
+ // addTestSuite(SetPropertyValueTest.class);
addTestSuite(SetPropertyConstraintViolationExceptionTest.class);
// addTestSuite(SetPropertyAssumeTypeTest.class);
@@ -234,7 +237,7 @@
addTestSuite(WorkspaceCopyBetweenWorkspacesReferenceableTest.class);
addTestSuite(WorkspaceCopyBetweenWorkspacesSameNameSibsTest.class);
addTestSuite(WorkspaceCopyBetweenWorkspacesTest.class);
- // addTestSuite(WorkspaceCopyBetweenWorkspacesVersionableTest.class);
+ addTestSuite(WorkspaceCopyBetweenWorkspacesVersionableTest.class);
// addTestSuite(WorkspaceCopyReferenceableTest.class);
// addTestSuite(WorkspaceCopySameNameSibsTest.class);
// addTestSuite(WorkspaceCopyTest.class);
@@ -248,8 +251,8 @@
// addTestSuite(ImpersonateTest.class);
// addTestSuite(CheckPermissionTest.class);
- // addTestSuite(DocumentViewImportTest.class);
- // addTestSuite(SerializationTest.class);
+ addTestSuite(DocumentViewImportTest.class);
+ addTestSuite(SerializationTest.class);
addTestSuite(ValueFactoryTest.class);
}
@@ -264,7 +267,7 @@
// We currently don't pass the tests in those suites that are commented out
// See https://jira.jboss.org/jira/browse/DNA-285
- // addTest(org.apache.jackrabbit.test.api.observation.TestAll.suite());
+ addTest(org.apache.jackrabbit.test.api.observation.TestAll.suite());
// addTest(org.apache.jackrabbit.test.api.version.TestAll.suite());
// addTest(org.apache.jackrabbit.test.api.lock.TestAll.suite());
addTest(org.apache.jackrabbit.test.api.util.TestAll.suite());
@@ -456,10 +459,51 @@
TestLexicon.REFERENCEABLE_UNSTRUCTURED,
Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, NO_PROPERTIES,
- NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+ NOT_MIXIN, ORDERABLE_CHILD_NODES);
- nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {referenceableUnstructured, noSameNameSibs}));
+ JcrNodeType nodeWithMandatoryProperty = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.NODE_WITH_MANDATORY_PROPERTY,
+ Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ context,
+ null,
+ TestLexicon.MANDATORY_STRING,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false,
+ true,
+ false,
+ NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED,
+ NO_CONSTRAINTS,
+ false)}),
+ NOT_MIXIN, ORDERABLE_CHILD_NODES);
+ JcrNodeType nodeWithMandatoryChild = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.NODE_WITH_MANDATORY_CHILD,
+ Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ context,
+ null,
+ TestLexicon.MANDATORY_CHILD,
+ OnParentVersionBehavior.VERSION.getJcrValue(),
+ false,
+ true,
+ false,
+ false,
+ JcrNtLexicon.UNSTRUCTURED,
+ new JcrNodeType[] {base}),}),
+ NO_PROPERTIES, NOT_MIXIN, ORDERABLE_CHILD_NODES);
+
+ nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {referenceableUnstructured, noSameNameSibs,
+ nodeWithMandatoryProperty, nodeWithMandatoryChild,}));
+
}
/**
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -27,10 +27,12 @@
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.stub;
+import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.NamespaceRegistry;
import javax.jcr.Node;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import org.jboss.dna.graph.ExecutionContext;
@@ -166,7 +168,7 @@
assertThat(workspace.getNodeTypeManager(), is(notNullValue()));
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test( expected = UnsupportedRepositoryOperationException.class )
public void shouldNotAllowGetObservationManager() throws Exception {
workspace.getObservationManager();
}
@@ -224,9 +226,14 @@
assertThat(workspace.getSession(), is(notNullValue()));
}
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowImportXml() throws Exception {
- workspace.importXML(null, null, 0);
+ @Test
+ public void shouldAllowImportXml() throws Exception {
+ String inputData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<sv:node xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" "
+ + "xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" sv:name=\"workspaceTestNode\">"
+ + "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">"
+ + "<sv:value>nt:unstructured</sv:value></sv:property></sv:node>";
+ workspace.importXML("/", new ByteArrayInputStream(inputData.getBytes()), 0);
}
@Test( expected = IllegalArgumentException.class )
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java 2009-04-23 18:45:00 UTC (rev 853)
@@ -47,7 +47,12 @@
public static final Name CONSTRAINED_REFERENCE = new BasicName(Namespace.URI, "constrainedReference");
public static final Name CONSTRAINED_STRING = new BasicName(Namespace.URI, "constrainedString");
+ public static final Name MANDATORY_STRING = new BasicName(Namespace.URI, "mandatoryString");
+ public static final Name MANDATORY_CHILD = new BasicName(Namespace.URI, "mandatoryChild");
+
public static final Name REFERENCEABLE_UNSTRUCTURED = new BasicName(Namespace.URI, "referenceableUnstructured");
public static final Name NO_SAME_NAME_SIBS = new BasicName(Namespace.URI, "noSameNameSibs");
+ public static final Name NODE_WITH_MANDATORY_PROPERTY = new BasicName(Namespace.URI, "nodeWithMandatoryProperty");
+ public static final Name NODE_WITH_MANDATORY_CHILD = new BasicName(Namespace.URI, "nodeWithMandatoryChild");
}
Modified: trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-04-23 18:21:01 UTC (rev 852)
+++ trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-04-23 18:45:00 UTC (rev 853)
@@ -22,6 +22,8 @@
javax.jcr.tck.referenceableNodeTestNode=referenceableNodeTestNode
javax.jcr.tck.orderChildrenTestNode=orderChildrenTestNode
javax.jcr.tck.namespaceTestNode=namespaceTestNode
+javax.jcr.tck.sameNameSibsTrueNodeType=nt\:unstructured
+javax.jcr.tck.sameNameSibsFalseNodeType=dnatest\:noSameNameSibs
javax.jcr.tck.sameNameSibsFalseChildNodeDefinition=dnatest\:noSameNameSibs
javax.jcr.tck.stringTestProperty=stringTestProperty
javax.jcr.tck.binaryTestProperty=binaryTestProperty
@@ -33,4 +35,9 @@
javax.jcr.tck.pathTestProperty=pathTestProperty
javax.jcr.tck.referenceTestProperty=referenceTestProperty
javax.jcr.tck.multiValueTestProperty=multiValueTestProperty
-javax.jcr.tck.NodeTest.testAddNodeItemExistsException.nodetype=dnatest\:noSameNameSibs
\ No newline at end of file
+javax.jcr.tck.NodeTest.testAddNodeItemExistsException.nodetype=dnatest\:noSameNameSibs
+javax.jcr.tck.NodeOrderableChildNodesTest.nodetype2=dnatest\:referenceableUnstructured
+javax.jcr.tck.SessionTest.testSaveContstraintViolationException.nodetype2=dnatest\:nodeWithMandatoryProperty
+javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype2=dnatest\:nodeWithMandatoryChild
+javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodename3=dnatest\:mandatoryChild
+javax.jcr.tck.NodeTest.testSaveContstraintViolationException.nodetype2=dnatest\:nodeWithMandatoryProperty
16 years, 8 months
DNA SVN: r852 - trunk.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-23 14:21:01 -0400 (Thu, 23 Apr 2009)
New Revision: 852
Modified:
trunk/pom.xml
Log:
Corrected POM.xml file to add back in the projects that were temporarily commented out
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-04-23 18:13:36 UTC (rev 851)
+++ trunk/pom.xml 2009-04-23 18:21:01 UTC (rev 852)
@@ -115,13 +115,13 @@
<module>dna-graph</module>
<module>dna-repository</module>
<module>dna-cnd</module>
- <!--module>dna-jcr</module-->
+ <module>dna-jcr</module>
<module>extensions/dna-classloader-maven</module>
<module>extensions/dna-sequencer-images</module>
<module>extensions/dna-sequencer-mp3</module>
<module>extensions/dna-sequencer-jbpm-jpdl</module>
<!--module>extensions/dna-sequencer-esbMessage</module-->
- <!--module>extensions/dna-sequencer-cnd</module-->
+ <module>extensions/dna-sequencer-cnd</module>
<module>extensions/dna-sequencer-java</module>
<module>extensions/dna-sequencer-msoffice</module>
<module>extensions/dna-sequencer-xml</module>
16 years, 8 months
DNA SVN: r851 - trunk/dna-repository/src/main/java/org/jboss/dna/repository.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-23 14:13:36 -0400 (Thu, 23 Apr 2009)
New Revision: 851
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
Log:
DNA-58 Create repository configuration and component
Minor change to allow a subclass to define the SessionFactory used by the SequencingService. The configuration for the JCR engine may need to provide its own SessionFactory implementation (or instance).
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-04-23 18:09:01 UTC (rev 850)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-04-23 18:13:36 UTC (rev 851)
@@ -76,6 +76,7 @@
private final ExecutionContext context;
private final List<AdministeredService> services;
+ private final SessionFactory jcrSessionFactory;
private final RepositoryService repositoryService;
private final ObservationService observationService;
private final SequencingService sequencingService;
@@ -109,8 +110,8 @@
// Create the sequencing service ...
executorService = new ScheduledThreadPoolExecutor(10); // Use a magic number for now
sequencingService = new SequencingService();
- SessionFactory sessionFactory = new SimpleSessionFactory();
- JcrExecutionContext jcrContext = new JcrExecutionContext(context, sessionFactory, "");
+ jcrSessionFactory = createSessionFactory();
+ JcrExecutionContext jcrContext = new JcrExecutionContext(context, jcrSessionFactory, "");
sequencingService.setExecutionContext(jcrContext);
sequencingService.setExecutorService(executorService);
for (SequencerConfig sequencerConfig : scanner.getSequencingConfigurations()) {
@@ -135,6 +136,15 @@
}
/**
+ * Method that can be overridden in subclasses to create (and populate) the SessionFactory used by the sequencing service.
+ *
+ * @return a session factory, which may not be null
+ */
+ protected SessionFactory createSessionFactory() {
+ return new SimpleSessionFactory();
+ }
+
+ /**
* Get the problems that were encountered when setting up this engine from the configuration.
*
* @return the problems, which may be empty but will never be null
16 years, 8 months
DNA SVN: r850 - in trunk/dna-repository/src: test/java/org/jboss/dna/repository and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-23 14:09:01 -0400 (Thu, 23 Apr 2009)
New Revision: 850
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
Log:
DNA-58 Create repository configuration and component
Changed DnaConfiguration to make it more tolernant of changes to the source pointing to the configuration repository. In particular, this allows the DnaEngine to obtain an immutable definition of the configuration source, which allows the engine to properly access the source even if the DnaConfiguration instance is changed.
The DnaEngine was also refactored to pull into a nested scanner class the code that reads the configuration content.
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-04-23 16:43:27 UTC (rev 849)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaConfiguration.java 2009-04-23 18:09:01 UTC (rev 850)
@@ -41,6 +41,7 @@
import org.jboss.dna.graph.property.PathExpression;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.ValueFormatException;
+import org.jboss.dna.graph.property.basic.RootPath;
import org.jboss.dna.repository.sequencer.Sequencer;
/**
@@ -61,14 +62,56 @@
NAMES_TO_MAP = Collections.unmodifiableMap(names);
}
- protected class Source {
- protected RepositorySource source;
- protected String description;
- protected Path path;
+ @Immutable
+ protected class ConfigurationRepository {
+ private final RepositorySource source;
+ private final String description;
+ private final Path path;
+
+ protected ConfigurationRepository( RepositorySource source ) {
+ this(source, null, null);
+ }
+
+ protected ConfigurationRepository( RepositorySource source,
+ String description,
+ Path path ) {
+ this.source = source;
+ this.description = description != null ? description : "";
+ this.path = path != null ? path : RootPath.INSTANCE;
+ }
+
+ /**
+ * @return source
+ */
+ public RepositorySource getRepositorySource() {
+ return source;
+ }
+
+ /**
+ * @return description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @return path
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ public ConfigurationRepository with( String description ) {
+ return new ConfigurationRepository(source, description, path);
+ }
+
+ public ConfigurationRepository with( Path path ) {
+ return new ConfigurationRepository(source, description, path);
+ }
}
private final ExecutionContext context;
- protected Source configurationSource;
+ protected ConfigurationRepository configurationSource;
private Path sourcesPath;
private Path sequencersPath;
private Path detectorsPath;
@@ -102,13 +145,10 @@
*
* @return the default repository source
*/
- protected Source createDefaultConfigurationSource() {
+ protected ConfigurationRepository createDefaultConfigurationSource() {
InMemoryRepositorySource defaultSource = new InMemoryRepositorySource();
defaultSource.setName("Configuration");
- Source result = new Source();
- result.source = defaultSource;
- result.path = this.context.getValueFactories().getPathFactory().createRootPath();
- result.description = "Configuration Repository";
+ ConfigurationRepository result = new ConfigurationRepository(defaultSource, "Configuration Repository", null);
return result;
}
@@ -129,7 +169,7 @@
*/
protected final Graph graph() {
if (this.graph == null) {
- this.graph = Graph.create(configurationSource.source, context);
+ this.graph = Graph.create(configurationSource.getRepositorySource(), context);
}
return this.graph;
}
@@ -170,7 +210,6 @@
* be used for the configuration repository; never null
*/
public ChooseClass<RepositorySource, ConfigRepositoryDetails> withConfigurationRepository() {
- final Source source = this.configurationSource;
// The config repository is different, since it has to load immediately ...
return new ChooseClass<RepositorySource, ConfigRepositoryDetails>() {
public LoadedFrom<ConfigRepositoryDetails> usingClass( final String className ) {
@@ -203,7 +242,7 @@
public ConfigRepositoryDetails usingClass( Class<? extends RepositorySource> repositorySource ) {
try {
- source.source = repositorySource.newInstance();
+ DnaConfiguration.this.configurationSource = new ConfigurationRepository(repositorySource.newInstance());
} catch (InstantiationException err) {
I18n msg = RepositoryI18n.errorCreatingInstanceOfClass;
throw new DnaConfigurationException(msg.text(repositorySource.getName(), err.getLocalizedMessage()), err);
@@ -318,7 +357,7 @@
protected Path sourcesPath() {
// Make sure the "dna:sources" node is there
if (sourcesPath == null) {
- Path path = pathFactory().create(this.configurationSource.path, DnaLexicon.SOURCES);
+ Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.SOURCES);
Node node = graph().createIfMissing(path).andReturn();
this.sourcesPath = node.getLocation().getPath();
}
@@ -328,7 +367,7 @@
protected Path sequencersPath() {
// Make sure the "dna:sequencers" node is there
if (sequencersPath == null) {
- Path path = pathFactory().create(this.configurationSource.path, DnaLexicon.SEQUENCERS);
+ Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.SEQUENCERS);
Node node = graph().createIfMissing(path).andReturn();
this.sequencersPath = node.getLocation().getPath();
}
@@ -338,7 +377,7 @@
protected Path detectorsPath() {
// Make sure the "dna:mimeTypeDetectors" node is there
if (detectorsPath == null) {
- Path path = pathFactory().create(this.configurationSource.path, DnaLexicon.MIME_TYPE_DETECTORS);
+ Path path = pathFactory().create(this.configurationSource.getPath(), DnaLexicon.MIME_TYPE_DETECTORS);
Node node = graph().createIfMissing(path).andReturn();
this.detectorsPath = node.getLocation().getPath();
}
@@ -612,7 +651,7 @@
* @see org.jboss.dna.repository.DnaConfiguration.SetDescription#describedAs(java.lang.String)
*/
public ConfigRepositoryDetails describedAs( String description ) {
- DnaConfiguration.this.configurationSource.description = description;
+ DnaConfiguration.this.configurationSource = DnaConfiguration.this.configurationSource.with(description);
return this;
}
@@ -622,7 +661,8 @@
* @see org.jboss.dna.repository.DnaConfiguration.SetProperties#with(java.lang.String)
*/
public PropertySetter<ConfigRepositoryDetails> with( String propertyName ) {
- return new BeanPropertySetter<ConfigRepositoryDetails>(DnaConfiguration.this.configurationSource.source,
+ return new BeanPropertySetter<ConfigRepositoryDetails>(
+ DnaConfiguration.this.configurationSource.getRepositorySource(),
propertyName, this);
}
@@ -633,7 +673,8 @@
*/
public ConfigRepositoryDetails under( String path ) {
CheckArg.isNotNull(path, "path");
- DnaConfiguration.this.configurationSource.path = context().getValueFactories().getPathFactory().create(path);
+ Path newPath = context().getValueFactories().getPathFactory().create(path);
+ DnaConfiguration.this.configurationSource = DnaConfiguration.this.configurationSource.with(newPath);
return null;
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-04-23 16:43:27 UTC (rev 849)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/DnaEngine.java 2009-04-23 18:09:01 UTC (rev 850)
@@ -61,13 +61,17 @@
import org.jboss.dna.repository.util.SimpleSessionFactory;
/**
- * @author Randall Hauch
+ * A single instance of the DNA services, which is obtained after setting up the {@link DnaConfiguration#build() configuration}.
+ *
+ * @see DnaConfiguration
*/
@Immutable
public class DnaEngine {
public static final String CONFIGURATION_REPOSITORY_NAME = "dna:configuration";
+ private final DnaConfiguration.ConfigurationRepository configuration;
+ private final ConfigurationScanner scanner;
private final Problems problems;
private final ExecutionContext context;
private final List<AdministeredService> services;
@@ -85,17 +89,20 @@
// Use the configuration's context ...
this.context = configuration.context();
+ // And set up the scanner ...
+ this.configuration = configuration.configurationSource;
+ this.scanner = new ConfigurationScanner(this.problems, this.context, this.configuration);
+
// Add the configuration source to the repository library ...
- final DnaConfiguration.Source configSourceInfo = configuration.configurationSource;
- final RepositorySource configSource = configSourceInfo.source;
+ final RepositorySource configSource = this.configuration.getRepositorySource();
RepositoryLibrary library = new RepositoryLibrary();
library.addSource(configSource);
// Create the RepositoryService, pointing it to the configuration repository ...
- Path pathToConfigurationRoot = configSourceInfo.path;
+ Path pathToConfigurationRoot = this.configuration.getPath();
repositoryService = new RepositoryService(library, configSource.getName(), "", pathToConfigurationRoot, context);
- for (MimeTypeDetectorConfig config : loadMimeTypeDetectors(problems, context, configSourceInfo)) {
+ for (MimeTypeDetectorConfig config : scanner.getMimeTypeDetectors()) {
library.getMimeTypeDetectors().addDetector(config);
}
@@ -106,7 +113,7 @@
JcrExecutionContext jcrContext = new JcrExecutionContext(context, sessionFactory, "");
sequencingService.setExecutionContext(jcrContext);
sequencingService.setExecutorService(executorService);
- for (SequencerConfig sequencerConfig : loadSequencingConfigurations(problems, context, configSourceInfo)) {
+ for (SequencerConfig sequencerConfig : scanner.getSequencingConfigurations()) {
sequencingService.addSequencer(sequencerConfig);
}
@@ -127,136 +134,6 @@
};
}
- protected static List<MimeTypeDetectorConfig> loadMimeTypeDetectors( Problems problems,
- ExecutionContext context,
- DnaConfiguration.Source source ) {
- List<MimeTypeDetectorConfig> detectors = new ArrayList<MimeTypeDetectorConfig>();
- Graph graph = Graph.create(source.source, context);
- Path pathToSequencersNode = context.getValueFactories().getPathFactory().create(source.path,
- DnaLexicon.MIME_TYPE_DETECTORS);
- try {
- Subgraph subgraph = graph.getSubgraphOfDepth(2).at(pathToSequencersNode);
-
- Set<Name> skipProperties = new HashSet<Name>();
- skipProperties.add(DnaLexicon.READABLE_NAME);
- skipProperties.add(DnaLexicon.DESCRIPTION);
- skipProperties.add(DnaLexicon.CLASSNAME);
- skipProperties.add(DnaLexicon.CLASSPATH);
- skipProperties.add(DnaLexicon.PATH_EXPRESSIONS);
- Set<String> skipNamespaces = new HashSet<String>();
- skipNamespaces.add(JcrLexicon.Namespace.URI);
- skipNamespaces.add(JcrNtLexicon.Namespace.URI);
- skipNamespaces.add(JcrMixLexicon.Namespace.URI);
-
- for (Location sequencerLocation : subgraph.getRoot().getChildren()) {
- Node sequencerNode = subgraph.getNode(sequencerLocation);
- String name = stringValueOf(context, sequencerNode, DnaLexicon.READABLE_NAME);
- String desc = stringValueOf(context, sequencerNode, DnaLexicon.DESCRIPTION);
- String classname = stringValueOf(context, sequencerNode, DnaLexicon.CLASSNAME);
- String[] classpath = stringValuesOf(context, sequencerNode, DnaLexicon.CLASSPATH);
- Map<String, Object> properties = new HashMap<String, Object>();
- for (Property property : sequencerNode.getProperties()) {
- Name propertyName = property.getName();
- if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue;
- if (skipProperties.contains(propertyName)) continue;
- if (property.isSingle()) {
- properties.put(propertyName.getLocalName(), property.getFirstValue());
- } else {
- properties.put(propertyName.getLocalName(), property.getValuesAsArray());
- }
- }
- MimeTypeDetectorConfig config = new MimeTypeDetectorConfig(name, desc, properties, classname, classpath);
- detectors.add(config);
- }
- } catch (PathNotFoundException e) {
- // no detectors registered ...
- }
- return detectors;
- }
-
- protected static List<SequencerConfig> loadSequencingConfigurations( Problems problems,
- ExecutionContext context,
- DnaConfiguration.Source source ) {
- List<SequencerConfig> configs = new ArrayList<SequencerConfig>();
- Graph graph = Graph.create(source.source, context);
- Path pathToSequencersNode = context.getValueFactories().getPathFactory().create(source.path, DnaLexicon.SEQUENCERS);
- try {
- Subgraph subgraph = graph.getSubgraphOfDepth(2).at(pathToSequencersNode);
-
- Set<Name> skipProperties = new HashSet<Name>();
- skipProperties.add(DnaLexicon.READABLE_NAME);
- skipProperties.add(DnaLexicon.DESCRIPTION);
- skipProperties.add(DnaLexicon.CLASSNAME);
- skipProperties.add(DnaLexicon.CLASSPATH);
- skipProperties.add(DnaLexicon.PATH_EXPRESSIONS);
- Set<String> skipNamespaces = new HashSet<String>();
- skipNamespaces.add(JcrLexicon.Namespace.URI);
- skipNamespaces.add(JcrNtLexicon.Namespace.URI);
- skipNamespaces.add(JcrMixLexicon.Namespace.URI);
-
- for (Location sequencerLocation : subgraph.getRoot().getChildren()) {
- Node sequencerNode = subgraph.getNode(sequencerLocation);
- String name = stringValueOf(context, sequencerNode, DnaLexicon.READABLE_NAME);
- String desc = stringValueOf(context, sequencerNode, DnaLexicon.DESCRIPTION);
- String classname = stringValueOf(context, sequencerNode, DnaLexicon.CLASSNAME);
- String[] classpath = stringValuesOf(context, sequencerNode, DnaLexicon.CLASSPATH);
- String[] expressionStrings = stringValuesOf(context, sequencerNode, DnaLexicon.PATH_EXPRESSIONS);
- List<PathExpression> pathExpressions = new ArrayList<PathExpression>();
- if (expressionStrings != null) {
- for (String expressionString : expressionStrings) {
- try {
- pathExpressions.add(PathExpression.compile(expressionString));
- } catch (Throwable t) {
- problems.addError(t,
- RepositoryI18n.pathExpressionIsInvalidOnSequencer,
- expressionString,
- name,
- t.getLocalizedMessage());
- }
- }
- }
- String[] goodExpressionStrings = new String[pathExpressions.size()];
- for (int i = 0; i != pathExpressions.size(); ++i) {
- PathExpression expression = pathExpressions.get(i);
- goodExpressionStrings[i] = expression.getExpression();
- }
- Map<String, Object> properties = new HashMap<String, Object>();
- for (Property property : sequencerNode.getProperties()) {
- Name propertyName = property.getName();
- if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue;
- if (skipProperties.contains(propertyName)) continue;
- if (property.isSingle()) {
- properties.put(propertyName.getLocalName(), property.getFirstValue());
- } else {
- properties.put(propertyName.getLocalName(), property.getValuesAsArray());
- }
- }
- SequencerConfig config = new SequencerConfig(name, desc, properties, classname, classpath, goodExpressionStrings);
- configs.add(config);
- }
- } catch (PathNotFoundException e) {
- // no detectors registered ...
- }
- return configs;
- }
-
- private static String stringValueOf( ExecutionContext context,
- Node node,
- Name propertyName ) {
- Property property = node.getProperty(propertyName);
- if (property == null) return null;
- if (property.isEmpty()) return null;
- return context.getValueFactories().getStringFactory().create(property.getFirstValue());
- }
-
- private static String[] stringValuesOf( ExecutionContext context,
- Node node,
- Name propertyName ) {
- Property property = node.getProperty(propertyName);
- if (property == null) return null;
- return context.getValueFactories().getStringFactory().create(property.getValuesAsArray());
- }
-
/**
* Get the problems that were encountered when setting up this engine from the configuration.
*
@@ -316,4 +193,149 @@
}
executorService.shutdown();
}
+
+ /**
+ * The component responsible for reading the configuration repository and (eventually) for propagating changes in the
+ * configuration repository into the services.
+ */
+ protected class ConfigurationScanner {
+ private final Problems problems;
+ private final ExecutionContext context;
+ private final DnaConfiguration.ConfigurationRepository configurationRepository;
+
+ protected ConfigurationScanner( Problems problems,
+ ExecutionContext context,
+ DnaConfiguration.ConfigurationRepository configurationRepository ) {
+ this.problems = problems;
+ this.context = context;
+ this.configurationRepository = configurationRepository;
+ }
+
+ public List<MimeTypeDetectorConfig> getMimeTypeDetectors() {
+ List<MimeTypeDetectorConfig> detectors = new ArrayList<MimeTypeDetectorConfig>();
+ Graph graph = Graph.create(configurationRepository.getRepositorySource(), context);
+ Path pathToSequencersNode = context.getValueFactories().getPathFactory().create(configurationRepository.getPath(),
+ DnaLexicon.MIME_TYPE_DETECTORS);
+ try {
+ Subgraph subgraph = graph.getSubgraphOfDepth(2).at(pathToSequencersNode);
+
+ Set<Name> skipProperties = new HashSet<Name>();
+ skipProperties.add(DnaLexicon.READABLE_NAME);
+ skipProperties.add(DnaLexicon.DESCRIPTION);
+ skipProperties.add(DnaLexicon.CLASSNAME);
+ skipProperties.add(DnaLexicon.CLASSPATH);
+ skipProperties.add(DnaLexicon.PATH_EXPRESSIONS);
+ Set<String> skipNamespaces = new HashSet<String>();
+ skipNamespaces.add(JcrLexicon.Namespace.URI);
+ skipNamespaces.add(JcrNtLexicon.Namespace.URI);
+ skipNamespaces.add(JcrMixLexicon.Namespace.URI);
+
+ for (Location detectorLocation : subgraph.getRoot().getChildren()) {
+ Node node = subgraph.getNode(detectorLocation);
+ String name = stringValueOf(node, DnaLexicon.READABLE_NAME);
+ String desc = stringValueOf(node, DnaLexicon.DESCRIPTION);
+ String classname = stringValueOf(node, DnaLexicon.CLASSNAME);
+ String[] classpath = stringValuesOf(node, DnaLexicon.CLASSPATH);
+ Map<String, Object> properties = new HashMap<String, Object>();
+ for (Property property : node.getProperties()) {
+ Name propertyName = property.getName();
+ if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue;
+ if (skipProperties.contains(propertyName)) continue;
+ if (property.isSingle()) {
+ properties.put(propertyName.getLocalName(), property.getFirstValue());
+ } else {
+ properties.put(propertyName.getLocalName(), property.getValuesAsArray());
+ }
+ }
+ MimeTypeDetectorConfig config = new MimeTypeDetectorConfig(name, desc, properties, classname, classpath);
+ detectors.add(config);
+ }
+ } catch (PathNotFoundException e) {
+ // no detectors registered ...
+ }
+ return detectors;
+ }
+
+ public List<SequencerConfig> getSequencingConfigurations() {
+ List<SequencerConfig> configs = new ArrayList<SequencerConfig>();
+ Graph graph = Graph.create(configurationRepository.getRepositorySource(), context);
+ Path pathToSequencersNode = context.getValueFactories().getPathFactory().create(configurationRepository.getPath(),
+ DnaLexicon.SEQUENCERS);
+ try {
+ Subgraph subgraph = graph.getSubgraphOfDepth(2).at(pathToSequencersNode);
+
+ Set<Name> skipProperties = new HashSet<Name>();
+ skipProperties.add(DnaLexicon.READABLE_NAME);
+ skipProperties.add(DnaLexicon.DESCRIPTION);
+ skipProperties.add(DnaLexicon.CLASSNAME);
+ skipProperties.add(DnaLexicon.CLASSPATH);
+ skipProperties.add(DnaLexicon.PATH_EXPRESSIONS);
+ Set<String> skipNamespaces = new HashSet<String>();
+ skipNamespaces.add(JcrLexicon.Namespace.URI);
+ skipNamespaces.add(JcrNtLexicon.Namespace.URI);
+ skipNamespaces.add(JcrMixLexicon.Namespace.URI);
+
+ for (Location sequencerLocation : subgraph.getRoot().getChildren()) {
+ Node sequencerNode = subgraph.getNode(sequencerLocation);
+ String name = stringValueOf(sequencerNode, DnaLexicon.READABLE_NAME);
+ String desc = stringValueOf(sequencerNode, DnaLexicon.DESCRIPTION);
+ String classname = stringValueOf(sequencerNode, DnaLexicon.CLASSNAME);
+ String[] classpath = stringValuesOf(sequencerNode, DnaLexicon.CLASSPATH);
+ String[] expressionStrings = stringValuesOf(sequencerNode, DnaLexicon.PATH_EXPRESSIONS);
+ List<PathExpression> pathExpressions = new ArrayList<PathExpression>();
+ if (expressionStrings != null) {
+ for (String expressionString : expressionStrings) {
+ try {
+ pathExpressions.add(PathExpression.compile(expressionString));
+ } catch (Throwable t) {
+ problems.addError(t,
+ RepositoryI18n.pathExpressionIsInvalidOnSequencer,
+ expressionString,
+ name,
+ t.getLocalizedMessage());
+ }
+ }
+ }
+ String[] goodExpressionStrings = new String[pathExpressions.size()];
+ for (int i = 0; i != pathExpressions.size(); ++i) {
+ PathExpression expression = pathExpressions.get(i);
+ goodExpressionStrings[i] = expression.getExpression();
+ }
+ Map<String, Object> properties = new HashMap<String, Object>();
+ for (Property property : sequencerNode.getProperties()) {
+ Name propertyName = property.getName();
+ if (skipNamespaces.contains(propertyName.getNamespaceUri())) continue;
+ if (skipProperties.contains(propertyName)) continue;
+ if (property.isSingle()) {
+ properties.put(propertyName.getLocalName(), property.getFirstValue());
+ } else {
+ properties.put(propertyName.getLocalName(), property.getValuesAsArray());
+ }
+ }
+ SequencerConfig config = new SequencerConfig(name, desc, properties, classname, classpath,
+ goodExpressionStrings);
+ configs.add(config);
+ }
+ } catch (PathNotFoundException e) {
+ // no detectors registered ...
+ }
+ return configs;
+ }
+
+ private String stringValueOf( Node node,
+ Name propertyName ) {
+ Property property = node.getProperty(propertyName);
+ if (property == null) return null;
+ if (property.isEmpty()) return null;
+ return context.getValueFactories().getStringFactory().create(property.getFirstValue());
+ }
+
+ private String[] stringValuesOf( Node node,
+ Name propertyName ) {
+ Property property = node.getProperty(propertyName);
+ if (property == null) return null;
+ return context.getValueFactories().getStringFactory().create(property.getValuesAsArray());
+ }
+
+ }
}
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-04-23 16:43:27 UTC (rev 849)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/DnaConfigurationTest.java 2009-04-23 18:09:01 UTC (rev 850)
@@ -85,8 +85,8 @@
.and()
.save();
assertThat(config, is(notNullValue()));
- assertThat(config.configurationSource.source, is(instanceOf(InMemoryRepositorySource.class)));
- InMemoryRepositorySource source = (InMemoryRepositorySource)config.configurationSource.source;
+ assertThat(config.configurationSource.getRepositorySource(), is(instanceOf(InMemoryRepositorySource.class)));
+ InMemoryRepositorySource source = (InMemoryRepositorySource)config.configurationSource.getRepositorySource();
assertThat(source.getName(), is("repository name"));
assertThat(source.getRetryLimit(), is(5));
}
16 years, 8 months