DNA SVN: r775 - trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-12 16:40:20 -0400 (Thu, 12 Mar 2009)
New Revision: 775
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/NameValueFactory.java
Log:
DNA-194 Implement update JCR capability
Small optimization in the NameValueFactory that maintains a single static/shared instance for Name objects that have no namespace URI and a local name of "*". These are use pretty prevelently in the JCR type manager to represent residual child and property definitions.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/NameValueFactory.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/NameValueFactory.java 2009-03-12 20:14:20 UTC (rev 774)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/NameValueFactory.java 2009-03-12 20:40:20 UTC (rev 775)
@@ -66,6 +66,9 @@
private static final String PREFIXED_NAME_PATTERN_STRING = "(([^:/]*):)?(.*)";
private static final Pattern PREFIXED_NAME_PATTERN = Pattern.compile(PREFIXED_NAME_PATTERN_STRING);
+ private static Name BLANK_NAME;
+ private static Name ANY_NAME;
+
private final NamespaceRegistry namespaceRegistry;
public NameValueFactory( NamespaceRegistry namespaceRegistry,
@@ -92,9 +95,15 @@
if (decoder == null) decoder = getDecoder();
try {
if (value.length() == 0) {
- return new BasicName("", "");
+ if (BLANK_NAME == null) BLANK_NAME = new BasicName("", "");
+ return BLANK_NAME;
}
- if (value.charAt(0) != '{') {
+ char firstChar = value.charAt(0);
+ if (value.length() == 1 && firstChar == '*') {
+ if (ANY_NAME == null) ANY_NAME = new BasicName("", "*");
+ return ANY_NAME;
+ }
+ if (firstChar != '{') {
// First, see whether the value fits the prefixed name pattern ...
Matcher matcher = PREFIXED_NAME_PATTERN.matcher(value);
if (matcher.matches()) {
15 years, 1 month
DNA SVN: r774 - in trunk/dna-graph/src/main: java/org/jboss/dna/graph/property and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-12 16:14:20 -0400 (Thu, 12 Mar 2009)
New Revision: 774
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathNotFoundException.java
trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
Log:
DNA-300 The DNA PathNotFoundException message text does not include the lowest existing path that was found
Added the lowest existing path to the message (and localized message) of the PathNotFoundException in the DNA Graph API. Of course, this is only added when there is a lowest existing path.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2009-03-12 19:19:34 UTC (rev 773)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2009-03-12 20:14:20 UTC (rev 774)
@@ -62,6 +62,7 @@
public static I18n pathExpressionHasInvalidMatch;
public static I18n messageDigestNotFound;
public static I18n unableToAccessResourceFileFromClassLoader;
+ public static I18n pathNotFoundExceptionLowestExistingLocationFound;
public static I18n executingRequest;
public static I18n executedRequest;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathNotFoundException.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathNotFoundException.java 2009-03-12 19:19:34 UTC (rev 773)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathNotFoundException.java 2009-03-12 20:14:20 UTC (rev 774)
@@ -23,6 +23,7 @@
*/
package org.jboss.dna.graph.property;
+import org.jboss.dna.graph.GraphI18n;
import org.jboss.dna.graph.Location;
/**
@@ -97,6 +98,20 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Throwable#getMessage()
+ */
+ @Override
+ public String getMessage() {
+ if (this.lowestAncestorThatDoesExist != null) {
+ return GraphI18n.pathNotFoundExceptionLowestExistingLocationFound.text(super.getMessage(),
+ this.lowestAncestorThatDoesExist);
+ }
+ return super.getMessage();
+ }
+
+ /**
* Get the path that was not found
*
* @return the path that was not found
Modified: trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
===================================================================
--- trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-03-12 19:19:34 UTC (rev 773)
+++ trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-03-12 20:14:20 UTC (rev 774)
@@ -48,7 +48,8 @@
pathExpressionHasInvalidSelect = Invalid select expression "{0}" in the path expression "{1}"
pathExpressionHasInvalidMatch = Invalid match expression "{0}" in the path expression "{1}"
messageDigestNotFound = The "{0}" message digest algorithm could not be found
-unableToAccessResourceFileFromClassLoader = Unable to access "{0}" resource from the class loader
+unableToAccessResourceFileFromClassLoader = Unable to access "{0}" resource from the class loader
+pathNotFoundExceptionLowestExistingLocationFound = {0}; lowest existing path is {1}
executingRequest = Executing {0}
executedRequest = Executed {0}
15 years, 1 month
DNA SVN: r773 - in trunk/dna-graph/src: test/java/org/jboss/dna/graph/property/basic and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-12 15:19:34 -0400 (Thu, 12 Mar 2009)
New Revision: 773
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/ChildPath.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/ChildPathTest.java
Log:
DNA-299 Path.isNormalized() is incorrect if the path begins with parent reference(s)
Added the tests to verify it was failing, then corrected the logic in all Path implementations (although RootPath was correct, since it always considered itself normalized).
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-03-12 16:10:03 UTC (rev 772)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-03-12 19:19:34 UTC (rev 773)
@@ -126,8 +126,16 @@
private transient int hc = 0;
protected boolean isNormalized( List<Segment> segments ) {
+ boolean nonParentReference = false;
+ boolean first = isAbsolute(); // only care about first one when it's absolute
for (Segment segment : segments) {
- if (segment.isSelfReference() || segment.isParentReference()) return false;
+ if (segment.isSelfReference()) return false;
+ if (segment.isParentReference()) {
+ if (nonParentReference || first) return false;
+ } else {
+ nonParentReference = true;
+ }
+ first = false;
}
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/ChildPath.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/ChildPath.java 2009-03-12 16:10:03 UTC (rev 772)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/ChildPath.java 2009-03-12 19:19:34 UTC (rev 773)
@@ -187,8 +187,15 @@
* @see org.jboss.dna.graph.property.Path#isNormalized()
*/
public boolean isNormalized() {
- if (child.isParentReference() || child.isSelfReference()) return false;
- return parent.isNormalized();
+ if (child.isSelfReference()) return false;
+ if (!parent.isNormalized()) return false;
+ // Otherwise, the parent is normalized, so this child will be normalized if this child is not a parent reference ...
+ if (!child.isParentReference()) return true;
+ // The path ends with a parent reference. It is normalized only if all other path segments are parent references ...
+ for (Path.Segment segment : parent) {
+ if (!segment.isParentReference()) return false;
+ }
+ return true;
}
/**
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java 2009-03-12 16:10:03 UTC (rev 772)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java 2009-03-12 19:19:34 UTC (rev 773)
@@ -102,7 +102,7 @@
}
@Test
- public void shouldCreateAbsolutePathWithParentSegment() {
+ public void shouldConsiderAsNotNormalizedAnAbsolutePathWithParentSegmentAtEnd() {
validSegmentsList.add(Path.PARENT_SEGMENT);
path = new BasicPath(validSegmentsList, true);
assertThat(path.isAbsolute(), is(true));
@@ -112,7 +112,7 @@
}
@Test
- public void shouldCreateRelativePathWithParentSegment() {
+ public void shouldConsiderAsNotNormalizedARelativePathWithParentSegmentAtEnd() {
validSegmentsList.add(Path.PARENT_SEGMENT);
path = new BasicPath(validSegmentsList, false);
assertThat(path.isAbsolute(), is(false));
@@ -122,6 +122,82 @@
}
@Test
+ public void shouldConsiderAsNotNormalizedAnAbsolutePathWithParentSegmentAtFront() {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ segments.add(Path.PARENT_SEGMENT);
+ segments.addAll(validSegmentsList);
+ path = new BasicPath(segments, true);
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getSegmentsList(), is(segments));
+ assertThat(path.size(), is(segments.size()));
+ }
+
+ @Test
+ public void shouldConsiderAsNormalizedARelativePathWithParentSegmentAtFront() {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ segments.add(Path.PARENT_SEGMENT);
+ segments.addAll(validSegmentsList);
+ path = new BasicPath(segments, false);
+ assertThat(path.isAbsolute(), is(false));
+ assertThat(path.isNormalized(), is(true));
+ assertThat(path.getSegmentsList(), is(segments));
+ assertThat(path.size(), is(segments.size()));
+ }
+
+ @Test
+ public void shouldConsiderAsNotNormalizedAnAbsolutePathWithAllParentReferences() {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ for (int i = 0; i != 10; ++i) {
+ segments.add(Path.PARENT_SEGMENT);
+ }
+ path = new BasicPath(segments, true);
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getSegmentsList(), is(segments));
+ assertThat(path.size(), is(segments.size()));
+ }
+
+ @Test
+ public void shouldConsiderAsNormalizedARelativePathWithAllParentReferences() {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ for (int i = 0; i != 10; ++i) {
+ segments.add(Path.PARENT_SEGMENT);
+ }
+ path = new BasicPath(segments, false);
+ assertThat(path.isAbsolute(), is(false));
+ assertThat(path.isNormalized(), is(true));
+ assertThat(path.getSegmentsList(), is(segments));
+ assertThat(path.size(), is(segments.size()));
+ }
+
+ @Test
+ public void shouldConsiderAsNotNormalizedPathWithMostParentReferencesAndOneNonParentReferenceInMiddle() {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ segments.add(Path.PARENT_SEGMENT);
+ segments.add(Path.PARENT_SEGMENT);
+ segments.add(pathFactory.createSegment("nonParentSegment"));
+ segments.add(Path.PARENT_SEGMENT);
+ segments.add(Path.PARENT_SEGMENT);
+ path = new BasicPath(segments, true);
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getSegmentsList(), is(segments));
+ assertThat(path.size(), is(segments.size()));
+ }
+
+ @Test
+ public void shouldConsiderAsNotNormalizedAnAbsolutePathThatBeginsWithParentReference() {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ segments.add(Path.PARENT_SEGMENT);
+ segments.add(pathFactory.createSegment("nonParentSegment"));
+ segments.add(pathFactory.createSegment("nonParentSegment2"));
+ path = new BasicPath(segments, true);
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.isNormalized(), is(false));
+ }
+
+ @Test
public void shouldCreateAbsolutePathWithSelfSegment() {
validSegmentsList.add(Path.SELF_SEGMENT);
path = new BasicPath(validSegmentsList, true);
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/ChildPathTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/ChildPathTest.java 2009-03-12 16:10:03 UTC (rev 772)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/ChildPathTest.java 2009-03-12 19:19:34 UTC (rev 773)
@@ -35,11 +35,6 @@
import java.util.List;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.basic.BasicName;
-import org.jboss.dna.graph.property.basic.BasicPath;
-import org.jboss.dna.graph.property.basic.BasicPathSegment;
-import org.jboss.dna.graph.property.basic.ChildPath;
-import org.jboss.dna.graph.property.basic.RootPath;
import org.junit.Before;
import org.junit.Test;
@@ -163,6 +158,41 @@
assertThat(path.getParent(), is(sameInstance(parent)));
}
+ @Test
+ public void shouldConsiderAsNotNormalizedAPathWithParentSegmentAtEnd() {
+ path = new ChildPath(parent, Path.PARENT_SEGMENT);
+ assertThat(path.isAbsolute(), is(parent.isAbsolute()));
+ assertThat(path.isNormalized(), is(false));
+ }
+
+ @Test
+ public void shouldConsiderAsNormalizedARelativePathWithParentSegmentAtFront() {
+ parent = path("../../a/b/c/d");
+ path = new ChildPath(parent, segment("e"));
+ assertThat(path.isNormalized(), is(true));
+ }
+
+ @Test
+ public void shouldConsiderAsNormalizedAnAbsolutePathWithParentSegmentAtFront() {
+ parent = path("/../a/b");
+ path = new ChildPath(parent, segment("c"));
+ assertThat(path.isNormalized(), is(false));
+ }
+
+ @Test
+ public void shouldConsiderAsNormalizedPathWithAllParentReferences() {
+ parent = path("../../../../..");
+ path = new ChildPath(parent, Path.PARENT_SEGMENT);
+ assertThat(path.isNormalized(), is(true));
+ }
+
+ @Test
+ public void shouldConsiderAsNotNormalizedPathWithMostParentReferencesAndOneNonParentReferenceInMiddle() {
+ parent = path("../../a/b/../..");
+ path = new ChildPath(parent, Path.PARENT_SEGMENT);
+ assertThat(path.isNormalized(), is(false));
+ }
+
// @Test
// public void shouldReturnRootForLowestCommonAncestorWithAnyNodePath() {
// Path other = mock(Path.class);
15 years, 1 month
DNA SVN: r772 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-12 12:10:03 -0400 (Thu, 12 Mar 2009)
New Revision: 772
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
Log:
DNA-298 SVNRepositoryTest Fails on Windows
Applied the patch and verified the patch does not change the behavior on OS-X. So, I'm committing.
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2009-03-11 19:13:08 UTC (rev 771)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2009-03-12 16:10:03 UTC (rev 772)
@@ -276,7 +276,7 @@
if (this.svnRepository == null) {
try {
svnURL = SVNURL.parseURIDecoded(getSVNURL());
- String usedProtocol = this.getSVNURL().substring(0, this.getSVNURL().lastIndexOf(":"));
+ String usedProtocol = this.getSVNURL().substring(0, this.getSVNURL().indexOf(":"));
if (usedProtocol.equals(SVNProtocol.SVN.value()) || usedProtocol.equals(SVNProtocol.SVN_SSH.value())) {
SVNRepositoryFactoryImpl.setup();
this.svnRepository = SVNRepositoryFactory.create(svnURL);
15 years, 1 month
DNA SVN: r771 - in trunk/dna-jcr/src: test/resources and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-11 15:13:08 -0400 (Wed, 11 Mar 2009)
New Revision: 771
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml
Log:
DNA-296 JcrSession Sometimes Eschews Single-Valued Variants of PropertyDefinitions
Applied the patch that corrects the assignment of the PropertyDefinition to each Property instance.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java 2009-03-11 14:44:39 UTC (rev 770)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java 2009-03-11 19:13:08 UTC (rev 771)
@@ -136,49 +136,10 @@
}), NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES);
- /* Name of node type that holds xmltext from document view import (see JCR 1.0 spec section 7.3.2) */
- JcrNodeType xmlText = new JcrNodeType(
- session,
- DnaLexicon.XML_TEXT,
- Arrays.asList(new NodeType[] {base}),
- NO_PRIMARY_ITEM_NAME,
- NO_CHILD_NODES,
- Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
- session,
- null,
- JcrLexicon.XMLCHARACTERS,
- OnParentVersionBehavior.VERSION.getJcrValue(),
- true,
- true,
- true,
- NO_DEFAULT_VALUES,
- PropertyType.STRING,
- NO_CONSTRAINTS,
- false)}),
- NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ primaryNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {root, system, namespaces, namespace, }));
+ mixinNodeTypes.addAll(Arrays.asList(new JcrNodeType[] { }));
- /* Mixin type that indicates the node contains an xmltext node which holds xmltext from document view import (see JCR 1.0 spec section 7.3.2) */
- JcrNodeType xmlContent = new JcrNodeType(
- session,
- DnaLexicon.XML_CONTENT,
- Arrays.asList(new NodeType[] {base}),
- NO_PRIMARY_ITEM_NAME,
- Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
- session,
- null,
- JcrLexicon.XMLTEXT,
- OnParentVersionBehavior.VERSION.getJcrValue(),
- false,
- true,
- false,
- false,
- DnaLexicon.XML_TEXT,
- new NodeType[] {xmlText})}),
- NO_PROPERTIES, IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
-
- primaryNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {root, system, namespaces, namespace, xmlText,}));
- mixinNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {xmlContent}));
-
}
/**
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-03-11 14:44:39 UTC (rev 770)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-03-11 19:13:08 UTC (rev 771)
@@ -38,17 +38,5 @@
public static final Name SYSTEM = new BasicName(Namespace.URI, "system");
public static final Name URI = new BasicName(Namespace.URI, "uri");
- /**
- * Mixin type that indicates the node contains an xmltext node which holds xmltext from document view import (see JCR 1.0
- * specification section 7.3.2). This node has a child node named {@link JcrLexicon#XMLTEXT} of type
- * {@link DnaLexicon#XML_TEXT}.
- */
- public static final Name XML_CONTENT = new BasicName(Namespace.URI, "xmlContent");
- /**
- * Name of node type that holds xmltext from document view import (see JCR 1.0 specification section 7.3.2). It is defined in
- * the node type named {@link DnaLexicon#XML_CONTENT}.
- */
- public static final Name XML_TEXT = new BasicName(Namespace.URI, "xmlText");
-
}
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-03-11 14:44:39 UTC (rev 770)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-11 19:13:08 UTC (rev 771)
@@ -862,7 +862,12 @@
// Create JCR properties for corresponding DNA properties
// ------------------------------------------------------
// First get the property type for each property, based upon the primary type and mixins ...
- Map<Name, PropertyDefinition> propertyDefinitionsByPropertyName = new HashMap<Name, PropertyDefinition>();
+ // The map with single-valued properties...
+ Map<Name, PropertyDefinition> svPropertyDefinitionsByPropertyName = new HashMap<Name, PropertyDefinition>();
+ // ... and the map with multi-valued properties
+ Map<Name, PropertyDefinition> mvPropertyDefinitionsByPropertyName = new HashMap<Name, PropertyDefinition>();
+
+
boolean referenceable = false;
NamespaceRegistry registry = namespaces();
@@ -881,8 +886,15 @@
continue;
}
Name name = nameFactory.create(nameString);
- PropertyDefinition prev = propertyDefinitionsByPropertyName.put(name, propertyDefn);
- if (prev != null) propertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
+
+ if (propertyDefn.isMultiple()) {
+ PropertyDefinition prev = mvPropertyDefinitionsByPropertyName.put(name, propertyDefn);
+ if (prev != null) mvPropertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
+ }
+ else {
+ PropertyDefinition prev = svPropertyDefinitionsByPropertyName.put(name, propertyDefn);
+ if (prev != null) svPropertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
+ }
}
// The process the mixin types ...
org.jboss.dna.graph.property.Property mixinTypesProperty = graphNode.getProperty(JcrLexicon.MIXIN_TYPES);
@@ -899,8 +911,14 @@
continue;
}
Name name = nameFactory.create(nameString);
- PropertyDefinition prev = propertyDefinitionsByPropertyName.put(name, propertyDefn);
- if (prev != null) propertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
+ if (propertyDefn.isMultiple()) {
+ PropertyDefinition prev = mvPropertyDefinitionsByPropertyName.put(name, propertyDefn);
+ if (prev != null) mvPropertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
+ }
+ else {
+ PropertyDefinition prev = svPropertyDefinitionsByPropertyName.put(name, propertyDefn);
+ if (prev != null) svPropertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
+ }
}
}
}
@@ -908,7 +926,8 @@
// Now create the JCR property object wrapper around the "jcr:uuid" property ...
Map<Name, Property> properties = new HashMap<Name, Property>();
if (referenceable) {
- PropertyDefinition propertyDefinition = propertyDefinitionsByPropertyName.get(JcrLexicon.UUID);
+ // We know that this property is single-valued
+ PropertyDefinition propertyDefinition = svPropertyDefinitionsByPropertyName.get(JcrLexicon.UUID);
properties.put(JcrLexicon.UUID, new JcrSingleValueProperty(node, propertyDefinition, PropertyType.STRING,
uuidProperty));
}
@@ -921,25 +940,35 @@
if (JcrLexicon.UUID.equals(name) || DnaLexicon.UUID.equals(name)) continue;
// Figure out the JCR property type for this property ...
- PropertyDefinition propertyDefinition = propertyDefinitionsByPropertyName.get(name);
+ PropertyDefinition propertyDefinition;
+
+ if (dnaProp.isMultiple()) {
+ propertyDefinition = mvPropertyDefinitionsByPropertyName.get(name);
+ }
+ else {
+ propertyDefinition = svPropertyDefinitionsByPropertyName.get(name);
+
+ // If the property has only one value, dnaProp.isMultiple() will return false, but the
+ // property may actually be a multi-valued property that happens to have one property set.
+ if (propertyDefinition == null) {
+ propertyDefinition = mvPropertyDefinitionsByPropertyName.get(name);
+ }
+ }
// If no property type was found for this property, see if there is a wildcard property ...
- if (propertyDefinition == null && !anyPropertyDefinitions.isEmpty()) {
- Iterator<PropertyDefinition> iter = anyPropertyDefinitions.iterator();
- propertyDefinition = iter.next(); // use the first one by default ...
- if (iter.hasNext()) {
- // Look for a better one if not multiple but the property has multiple values ...
- if (!propertyDefinition.isMultiple() && dnaProp.isMultiple()) {
- while (iter.hasNext()) {
- PropertyDefinition next = iter.next();
- if (next.isMultiple()) {
- propertyDefinition = next;
- break;
- }
- }
+ if (propertyDefinition == null) {
+ for (Iterator<PropertyDefinition> iter = anyPropertyDefinitions.iterator(); iter.hasNext(); ) {
+ PropertyDefinition nextDef = iter.next();
+
+ // Grab the first residual definition that matches on cardinality (single-valued vs. multi-valued)
+ if ((nextDef.isMultiple() && dnaProp.isMultiple())
+ || (!nextDef.isMultiple() && !dnaProp.isMultiple())) {
+ propertyDefinition = nextDef;
+ break;
}
}
}
+
// If there still is no property type defined ...
if (propertyDefinition == null) {
Modified: trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml 2009-03-11 14:44:39 UTC (rev 770)
+++ trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml 2009-03-11 19:13:08 UTC (rev 771)
@@ -30,7 +30,7 @@
jcr:primaryType="nt:unstructured">
<nt:unstructured jcr:name="node1" prop1="<foo&foo>" >
<!-- This stanza checks for the jcr:xmltext special case for document export. DO NOT change this element. -->
- <dna:xmlText jcr:name="jcr:xmltext" jcr:xmlcharacters="This is my "XML" text!" />
+ <nt:unstructured jcr:name="jcr:xmltext" jcr:xmlcharacters="This is my "XML" text!" />
</nt:unstructured>
<nt:unstructured jcr:name="node2 has a multi-word name" prop2="bar" />
<nt:unstructured jcr:name="node3" />
15 years, 1 month
DNA SVN: r770 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-11 10:44:39 -0400 (Wed, 11 Mar 2009)
New Revision: 770
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
Log:
DNA-194 Implement update JCR capability
Applied the "...move_value_cast" patch, which moves the JcrNodeType logic determining whether a value can be cast to another type into the JcrValue class where it can be used to actually convert the value to a value of another type. Also made the "createValueFormatException(...)" methods private to increase likelihood they'll be inlined. All tests pass.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java 2009-03-10 19:43:15 UTC (rev 769)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java 2009-03-11 14:44:39 UTC (rev 770)
@@ -29,7 +29,6 @@
import java.util.List;
import java.util.Set;
import java.util.Stack;
-import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.nodetype.NodeDefinition;
@@ -38,10 +37,6 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.ValueFactories;
-import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.Path.Segment;
/**
* DNA implementation of JCR {@link NodeType}s.
@@ -329,100 +324,16 @@
if (value == null) {
return !property.isMandatory();
}
-
- return canCastValueToType(value, property.getRequiredType());
- }
-
- /**
- * Internal method to validate that a value can be cast to a given JCR property type. The values are set according to the
- * following rules:
- * <ol>
- * <li>If <code>property.getRequiredType()</code> is {@link PropertyType#UNDEFINED}, return <code>true</code></li>
- * <li>Compare the type of the given value to the required type and see if they are compatible based on the rules in the JCR
- * 1.0 spec.</li>
- * </ol>
- *
- * @param jcrPropertyType a value from the {@link PropertyType} constants to which this value MAY be able to be casted.
- * @param value the value to set (may not be <code>null</code>)
- * @return whether the value can be cast to the given property type
- */
- private boolean canCastValueToType( Value value,
- int jcrPropertyType ) {
- assert value != null;
-
- int valueType = value.getType();
-
- // Trivial case - no cast required
- if (valueType == jcrPropertyType) {
- return true;
- }
-
+
try {
- switch (jcrPropertyType) {
- case PropertyType.BOOLEAN:
- if (valueType == PropertyType.STRING) {
- return true;
- }
-
- if (valueType == PropertyType.BINARY) {
- // If the binary can be converted to a UTF-8 string, it can be set onto a boolean property
- value.getString();
- return true;
- }
- return false;
-
- case PropertyType.DATE:
- if (valueType == PropertyType.DOUBLE || valueType == PropertyType.LONG) {
- return true;
- }
-
- if (valueType == PropertyType.STRING || valueType == PropertyType.BINARY) {
- // If the binary can be converted to a date, it can be set onto a date property
- value.getDate();
- return true;
- }
- return false;
-
- case PropertyType.NAME:
- ValueFactories valueFactories = session.getExecutionContext().getValueFactories();
- if (valueType == PropertyType.STRING || valueType == PropertyType.BINARY) {
- valueFactories.getNameFactory().create(value.getString());
- return true;
- }
-
- if (valueType == PropertyType.PATH) {
- Path path = valueFactories.getPathFactory().create(value.getString());
-
- Segment[] segments = path.getSegmentsArray();
- return !path.isAbsolute() && segments.length == 1 && !segments[0].hasIndex();
- }
-
- return false;
-
- case PropertyType.PATH:
- return value.getType() == PropertyType.STRING;
-
- // Nothing can be converted to these types (except themselves)
- case PropertyType.REFERENCE:
- case PropertyType.DOUBLE:
- case PropertyType.LONG:
- return false;
-
- // Anything can be converted to these types
- case PropertyType.BINARY:
- case PropertyType.STRING:
- case PropertyType.UNDEFINED:
- return true;
- default:
- assert false : "Unexpected JCR property type " + jcrPropertyType;
- // This should still throw an exception even if assertions are turned off
- throw new IllegalStateException("Invalid property type " + jcrPropertyType);
- }
- } catch (RepositoryException re) {
+ assert value instanceof JcrValue : "Illegal implementation of Value interface";
+ ((JcrValue) value).asType(property.getRequiredType());
+ }
+ catch (javax.jcr.ValueFormatException vfe) {
+ // Cast failed
return false;
- } catch (ValueFormatException vfe) {
- return false;
}
+ return true;
}
/**
@@ -455,7 +366,12 @@
for (int i = 0; i < values.length; i++) {
if (values[i] != null) {
- if (!canCastValueToType(values[i], property.getRequiredType())) {
+ try {
+ assert values[i] instanceof JcrValue : "Illegal implementation of Value interface";
+ ((JcrValue) values[i]).asType(property.getRequiredType());
+ }
+ catch (javax.jcr.ValueFormatException vfe) {
+ // Cast failed
return false;
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-03-10 19:43:15 UTC (rev 769)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-03-11 14:44:39 UTC (rev 770)
@@ -25,13 +25,17 @@
import java.io.InputStream;
import java.util.Calendar;
+import javax.jcr.Node;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.graph.property.Binary;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.ValueFactories;
+import org.jboss.dna.graph.property.Path.Segment;
/**
* @author jverhaeg
@@ -58,10 +62,14 @@
private State state = State.NEVER_CONSUMED;
- ValueFormatException createValueFormatException( Class<?> type ) {
+ private ValueFormatException createValueFormatException( Class<?> type ) {
return new ValueFormatException(JcrI18n.cannotConvertValue.text(value.getClass().getSimpleName(), type.getSimpleName()));
}
+ private ValueFormatException createValueFormatException( org.jboss.dna.graph.property.ValueFormatException vfe ) {
+ return new ValueFormatException(vfe);
+ }
+
/**
* {@inheritDoc}
*
@@ -177,6 +185,112 @@
return type;
}
+ /**
+ * Returns a copy of the current {@link JcrValue} cast to the JCR type specified by the <code>type</code> argument. If the
+ * value cannot be converted base don the JCR type conversion rules, a {@link ValueFormatException} will be thrown.
+ *
+ * @param type the JCR type from {@link PropertyType} that the new {@link JcrValue} should have.
+ * @return a new {@link JcrValue} with the given JCR type and an equivalent value.
+ * @throws ValueFormatException if the value contained by this {@link JcrValue} cannot be converted to the desired type.
+ * @see PropertyType
+ */
+ JcrValue asType( int type ) throws ValueFormatException {
+
+ if (type == this.type) {
+ return new JcrValue(this.valueFactories, this.type, this.value);
+ }
+
+ switch (type) {
+ case PropertyType.BOOLEAN:
+ try {
+ if (this.type == PropertyType.STRING || this.type == PropertyType.BINARY) {
+ return new JcrValue(this.valueFactories, type, valueFactories.getBooleanFactory().create(value));
+ }
+ } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+ throw createValueFormatException(vfe);
+ }
+ throw createValueFormatException(boolean.class);
+
+ case PropertyType.DATE:
+ try {
+ if (this.type == PropertyType.DOUBLE || this.type == PropertyType.LONG || this.type == PropertyType.STRING
+ || this.type == PropertyType.BINARY) {
+ return new JcrValue(this.valueFactories, type, valueFactories.getDateFactory().create(value));
+ }
+ } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+ throw createValueFormatException(vfe);
+ }
+
+ throw createValueFormatException(Calendar.class);
+
+ case PropertyType.NAME:
+ try {
+ if (this.type == PropertyType.STRING) {
+ return new JcrValue(this.valueFactories, type, this.valueFactories.getNameFactory().create(value));
+ }
+
+ String valueAsString = this.valueFactories.getStringFactory().create(value);
+ if (this.type == PropertyType.BINARY) {
+ return new JcrValue(this.valueFactories, type, this.valueFactories.getNameFactory().create(valueAsString));
+
+ }
+
+ if (this.type == PropertyType.PATH) {
+ Path path = valueFactories.getPathFactory().create(valueAsString);
+
+ Segment[] segments = path.getSegmentsArray();
+ if (!path.isAbsolute() && segments.length == 1 && !segments[0].hasIndex()) {
+ return new JcrValue(this.valueFactories, type, this.valueFactories.getNameFactory()
+ .create(valueAsString));
+
+ }
+ }
+ } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+ throw createValueFormatException(vfe);
+ }
+
+ throw createValueFormatException(Name.class);
+
+ case PropertyType.PATH:
+ try {
+ if (this.type == PropertyType.STRING) {
+ return new JcrValue(this.valueFactories, type, this.valueFactories.getPathFactory().create(value));
+ }
+ } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+ throw createValueFormatException(vfe);
+ }
+ throw createValueFormatException(Path.class);
+
+ // Nothing can be converted to these types (except themselves)
+ case PropertyType.REFERENCE:
+ throw createValueFormatException(Node.class);
+ case PropertyType.DOUBLE:
+ throw createValueFormatException(double.class);
+ case PropertyType.LONG:
+ throw createValueFormatException(long.class);
+
+ // Anything can be converted to these types
+ case PropertyType.BINARY:
+ try {
+ return new JcrValue(this.valueFactories, type, valueFactories.getBinaryFactory().create(value));
+ } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+ throw createValueFormatException(vfe);
+ }
+ case PropertyType.STRING:
+ try {
+ return new JcrValue(this.valueFactories, type, valueFactories.getStringFactory().create(value));
+ } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+ throw createValueFormatException(vfe);
+ }
+ case PropertyType.UNDEFINED:
+ return new JcrValue(this.valueFactories, this.type, this.value);
+ default:
+ assert false : "Unexpected JCR property type " + type;
+ // This should still throw an exception even if assertions are turned off
+ throw new IllegalStateException("Invalid property type " + type);
+ }
+ }
+
void nonInputStreamConsumed() {
if (state == State.INPUT_STREAM_CONSUMED) {
throw new IllegalStateException(JcrI18n.inputStreamConsumed.text());
15 years, 1 month
DNA SVN: r769 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph/property/basic and 3 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-10 15:43:15 -0400 (Tue, 10 Mar 2009)
New Revision: 769
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathFactory.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/PathValueFactory.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/AbstractPathTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/RootPathTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
Log:
DNA-194 Implement update JCR capability
Small refactoring to make the loading of nodes more efficient. This includes the addition of a new method on Path to obtain an Iterator<Path> from the root node to that instance.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -495,6 +495,14 @@
public Iterator<Segment> iterator();
/**
+ * Return an iterator that walks the paths from the root path down to this path. This method always returns at least one path
+ * (the root returns an iterator containing itself).
+ *
+ * @return the path iterator; never null
+ */
+ public Iterator<Path> pathsFromRoot();
+
+ /**
* Obtain a copy of the segments in this path. None of the segments are encoded.
*
* @return the array of segments as a copy
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathFactory.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathFactory.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PathFactory.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -133,6 +133,19 @@
int index );
/**
+ * Create a path by appending the supplied names to the parent path.
+ *
+ * @param parentPath the path that is to provide the basis for the new path
+ * @param segmentName the name of the segment to be appended to the parent path
+ * @param index the index for the new segment
+ * @return the new path
+ * @throws IllegalArgumentException if the parent path reference or the segment name is null, or if the index is invalid
+ */
+ Path create( Path parentPath,
+ String segmentName,
+ int index );
+
+ /**
* Create a path by appending the supplied names to the parent path. If no names are appended, the parent path is returned.
*
* @param parentPath the path that is to provide the basis for the new path
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -29,6 +29,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
+import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.CommonI18n;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.CheckArg;
@@ -83,6 +84,45 @@
}
};
+ @NotThreadSafe
+ protected static class SingleIterator<T> implements Iterator<T> {
+ private T value;
+
+ protected SingleIterator( T value ) {
+ this.value = value;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return value != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public T next() {
+ if (value == null) throw new NoSuchElementException();
+ T next = value;
+ value = null;
+ return next;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
private transient int hc = 0;
protected boolean isNormalized( List<Segment> segments ) {
@@ -368,7 +408,23 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.property.Path#pathsFromRoot()
*/
+ public Iterator<Path> pathsFromRoot() {
+ LinkedList<Path> paths = new LinkedList<Path>();
+ Path path = this;
+ while (path != null) {
+ paths.addFirst(path);
+ if (path.isRoot()) break;
+ path = path.getParent();
+ }
+ return paths.iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Path relativeTo( Path startingPath ) {
CheckArg.isNotNull(startingPath, "to");
if (!this.isAbsolute()) {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/PathValueFactory.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/PathValueFactory.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/PathValueFactory.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -401,8 +401,7 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.property.PathFactory#create(org.jboss.dna.graph.property.Path,
- * org.jboss.dna.graph.property.Path)
+ * @see org.jboss.dna.graph.property.PathFactory#create(org.jboss.dna.graph.property.Path, org.jboss.dna.graph.property.Path)
*/
public Path create( Path parentPath,
Path childPath ) {
@@ -438,8 +437,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.property.PathFactory#create(org.jboss.dna.graph.property.Path, java.lang.String, int)
*/
public Path create( Path parentPath,
+ String segmentName,
+ int index ) {
+ return create(parentPath, nameValueFactory.create(segmentName), index);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Path parentPath,
Name... segmentNames ) {
CheckArg.isNotNull(parentPath, "parent path");
if (segmentNames == null || segmentNames.length == 0) return parentPath;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -342,6 +342,16 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.graph.property.Path#pathsFromRoot()
+ */
+ @Override
+ public Iterator<Path> pathsFromRoot() {
+ return new SingleIterator<Path>(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.graph.property.Path#size()
*/
public int size() {
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/AbstractPathTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/AbstractPathTest.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/AbstractPathTest.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -30,7 +30,9 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.graph.property.InvalidPathException;
import org.jboss.dna.graph.property.NamespaceRegistry;
@@ -231,4 +233,18 @@
assertThat(path.toString(), is(notNullValue()));
}
+ @Test
+ public void shouldGetPathsFromRoot() {
+ Iterator<Path> iter = path.pathsFromRoot();
+ List<Path.Segment> segments = path.getSegmentsList();
+ List<Path.Segment> lastSegments = new ArrayList<Path.Segment>();
+ while (iter.hasNext()) {
+ Path next = iter.next();
+ assertThat(next, is(notNullValue()));
+ if (!next.isRoot()) lastSegments.add(next.getLastSegment());
+ }
+ assertThat(lastSegments.size(), is(path.size()));
+ assertThat(lastSegments, is(segments));
+ }
+
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/RootPathTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/RootPathTest.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/RootPathTest.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -30,15 +30,12 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.graph.property.InvalidPathException;
import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.basic.BasicName;
-import org.jboss.dna.graph.property.basic.BasicPath;
-import org.jboss.dna.graph.property.basic.BasicPathSegment;
-import org.jboss.dna.graph.property.basic.RootPath;
import org.junit.Before;
import org.junit.Test;
@@ -253,4 +250,12 @@
assertThat(root.equals(root), is(true));
}
+ @Test
+ public void shouldReturnIteratorWithRootPathFromPathsFromRoot() {
+ Iterator<Path> iter = root.pathsFromRoot();
+ assertThat(iter.hasNext(), is(true));
+ assertThat(iter.next(), is(root));
+ assertThat(iter.hasNext(), is(false));
+ }
+
}
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-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -58,7 +58,6 @@
import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.Path.Segment;
/**
* @author jverhaeg
@@ -72,7 +71,7 @@
private final NodeDefinition definition;
protected Location location;
private Map<Name, Property> properties;
- private List<Path.Segment> children;
+ private List<Location> children;
AbstractJcrNode( JcrSession session,
Location location,
@@ -114,7 +113,7 @@
location = location.with(uuid);
}
- final void setChildren( List<Segment> children ) {
+ final void setChildren( List<Location> children ) {
assert children != null;
this.children = children;
}
@@ -418,8 +417,9 @@
.getValueFactories()
.getPathFactory()
.createSegment(relativePath);
- for (Path.Segment child : children) {
- if (child.equals(segment)) return true;
+ for (Location child : children) {
+ Path.Segment childSegment = child.getPath().getLastSegment();
+ if (childSegment.equals(segment)) return true;
}
} catch (ValueFormatException e) {
throw new RepositoryException(JcrI18n.invalidRelativePath.text(relativePath));
@@ -462,7 +462,7 @@
if (children == null) {
return new JcrEmptyNodeIterator();
}
- return new JcrChildNodeIterator(this, namespaces(), children);
+ return new JcrChildNodeIterator(this, children);
}
/**
@@ -479,11 +479,11 @@
List<Object> patterns = createPatternsFor(namePattern);
// Implementing exact-matching only for now to prototype types as properties
- List<Path.Segment> matchingChildren = new LinkedList<Path.Segment>();
+ List<Location> matchingChildren = new LinkedList<Location>();
NamespaceRegistry registry = namespaces();
boolean foundMatch = false;
- for (Path.Segment child : children) {
- String childName = child.getName().getString(registry);
+ for (Location child : children) {
+ String childName = child.getPath().getLastSegment().getName().getString(registry);
for (Object patternOrMatch : patterns) {
if (patternOrMatch instanceof Pattern) {
Pattern pattern = (Pattern)patternOrMatch;
@@ -499,7 +499,7 @@
}
}
}
- return new JcrChildNodeIterator(this, registry, matchingChildren);
+ return new JcrChildNodeIterator(this, matchingChildren);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -30,8 +30,7 @@
import javax.jcr.RepositoryException;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.property.NamespaceRegistry;
-import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.Location;
/**
* @author jverhaeg
@@ -39,20 +38,18 @@
@Immutable
final class JcrChildNodeIterator implements NodeIterator {
- private final NamespaceRegistry registry;
- private final Node parent;
- private final Iterator<Path.Segment> iterator;
+ private final AbstractJcrNode parent;
+ private final Iterator<Location> iterator;
+ private final JcrSession session;
private int ndx;
private int size;
- JcrChildNodeIterator( Node parent,
- NamespaceRegistry registry,
- List<Path.Segment> children ) {
+ JcrChildNodeIterator( AbstractJcrNode parent,
+ List<Location> children ) {
assert parent != null;
- assert registry != null;
assert children != null;
- this.registry = registry;
this.parent = parent;
+ this.session = parent.session();
iterator = children.iterator();
size = children.size();
}
@@ -99,11 +96,10 @@
* @see javax.jcr.NodeIterator#nextNode()
*/
public Node nextNode() {
- Path.Segment childSegment = iterator.next();
+ Location location = iterator.next();
ndx++;
- String childName = childSegment.getString(registry);
try {
- return parent.getNode(childName);
+ return session.getChild(parent, location);
} catch (RepositoryException error) {
throw new RuntimeException(error);
}
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-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -123,10 +123,10 @@
*/
private final Map<String, Object> sessionAttributes;
- private final ReferenceMap<UUID, Node> nodesByUuid;
- private final ReferenceMap<String, Node> nodesByJcrUuid;
+ private final ReferenceMap<UUID, AbstractJcrNode> nodesByUuid;
+ private final ReferenceMap<String, AbstractJcrNode> nodesByJcrUuid;
private boolean isLive;
- private AbstractJcrNode rootNode;
+ private JcrRootNode rootNode;
private PropertyDefinition anyMultiplePropertyDefinition;
private transient org.jboss.dna.graph.property.Property defaultPrimaryType;
@@ -153,8 +153,8 @@
this.repository.getConnectionFactory(),
this.executionContext);
- this.nodesByUuid = new ReferenceMap<UUID, Node>(ReferenceType.STRONG, ReferenceType.SOFT);
- this.nodesByJcrUuid = new ReferenceMap<String, Node>(ReferenceType.STRONG, ReferenceType.SOFT);
+ this.nodesByUuid = new ReferenceMap<UUID, AbstractJcrNode>(ReferenceType.STRONG, ReferenceType.SOFT);
+ this.nodesByJcrUuid = new ReferenceMap<String, AbstractJcrNode>(ReferenceType.STRONG, ReferenceType.SOFT);
this.isLive = true;
assert this.repository != null;
@@ -182,7 +182,7 @@
*
* @return nodesByUuid
*/
- Map<UUID, Node> getNodesByUuid() {
+ Map<UUID, AbstractJcrNode> getNodesByUuid() {
return Collections.unmodifiableMap(nodesByUuid);
}
@@ -394,26 +394,16 @@
}
// Since we don't know whether path refers to a node or a property, look to see if we can tell it's a node ...
if (path.getLastSegment().hasIndex()) {
- try {
- return getNode(path);
- } catch (org.jboss.dna.graph.property.PathNotFoundException e) {
- // If the node isn't found, throw a PathNotFoundException
- throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
- }
+ return getNode(path);
}
// We can't tell from the name, so try a node first ...
try {
return getNode(path);
- } catch (org.jboss.dna.graph.property.PathNotFoundException e) {
- // A node was not found, so treat look for a node using the parent as the node's path ...
+ } catch (PathNotFoundException e) {
+ // A node was not found, so look for a node using the parent as the node's path ...
Path parentPath = path.getParent();
Name propertyName = path.getLastSegment().getName();
- try {
- return getNode(parentPath).getProperty(propertyName.getString(namespaces()));
- } catch (org.jboss.dna.graph.property.PathNotFoundException e2) {
- // If the node isn't found, throw a PathNotFoundException
- throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
- }
+ return getNode(parentPath).getProperty(propertyName.getString(namespaces()));
}
}
@@ -427,19 +417,65 @@
throw new UnsupportedOperationException();
}
+ Node getChild( AbstractJcrNode parent,
+ Location location ) throws RepositoryException {
+ Node child = null;
+ UUID uuid = location.getUuid();
+ if (uuid != null) {
+ // The location has a UUID, so look up the node by this UUID in the session ...
+ child = getNode(uuid);
+ }
+ if (child == null) {
+ // The child was not found in the session's cache, so create the node using its path ...
+ child = loadNode(parent, location.getPath());
+ }
+ return child;
+ }
+
/**
* Find or create a JCR Node for the given path. This method works for the root node, too.
*
* @param path the path; may not be null
* @return the JCR node instance for the given path; never null
+ * @throws PathNotFoundException if the path could not be found
* @throws RepositoryException if there is a problem
*/
- private Node getNode( Path path ) throws RepositoryException {
+ Node getNode( Path path ) throws RepositoryException, PathNotFoundException {
+ if (path.isRoot()) return rootNode();
+
+ // Start at the root and walk down the path ...
+ AbstractJcrNode parent = rootNode();
+ AbstractJcrNode node = null;
+ Iterator<Path> pathIter = path.pathsFromRoot();
+ while (pathIter.hasNext()) {
+ node = loadNode(parent, pathIter.next()); // should throw PathNotFoundException if not there
+ parent = node;
+ }
+ return node;
+ }
+
+ /**
+ * Find or create a JCR Node for the given path. This method works for the root node, too.
+ *
+ * @param parent the parent of the node, if known; null if the parent is not known
+ * @param path the path; may not be null
+ * @return the JCR node instance for the given path; never null
+ * @throws PathNotFoundException if the path could not be found
+ * @throws RepositoryException if there is a problem
+ */
+ private AbstractJcrNode loadNode( AbstractJcrNode parent,
+ Path path ) throws RepositoryException, PathNotFoundException {
boolean isRoot = path.isRoot();
if (isRoot && rootNode != null) return rootNode;
// Get node from source and get it's UUID ...
- org.jboss.dna.graph.Node graphNode = graph.getNodeAt(path);
+ org.jboss.dna.graph.Node graphNode = null;
+ try {
+ graphNode = graph.getNodeAt(path);
+ } catch (org.jboss.dna.graph.property.PathNotFoundException e) {
+ // If the node isn't found, throw a PathNotFoundException
+ throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
+ }
// Now get the DNA node's UUID ...
Location location = graphNode.getLocation();
@@ -447,6 +483,10 @@
UUID uuid = location.getUuid();
org.jboss.dna.graph.property.Property uuidProperty = null;
if (uuid != null) {
+ // Check for an existing node at this UUID ...
+ AbstractJcrNode existing = nodesByUuid.get(uuid);
+ if (existing != null) return existing;
+
// Considered an identification property ...
uuidProperty = location.getIdProperty(JcrLexicon.UUID);
if (uuidProperty == null) uuidProperty = location.getIdProperty(DnaLexicon.UUID);
@@ -485,7 +525,7 @@
// See if there is already a JCR node object for this UUID ...
if (uuid != null && !isRoot) {
- Node node = getNode(uuid);
+ AbstractJcrNode node = getNode(uuid);
if (node != null) return node;
}
@@ -538,7 +578,10 @@
node = new JcrRootNode(this, location, definition);
} else {
// Find the parent ...
- AbstractJcrNode parent = (AbstractJcrNode)getNode(path.getParent());
+ if (parent == null) {
+ parent = (AbstractJcrNode)getNode(path.getParent());
+ }
+ assert parent != null;
// Find the node definition for this node ...
if (definition == null) {
@@ -558,11 +601,11 @@
// Now populate the node and add to the cache ...
populateNode(node, graphNode, uuid, uuidProperty, primaryTypeProperty);
- if (isRoot) rootNode = node;
+ if (isRoot) rootNode = (JcrRootNode)node;
return node;
}
- Node getNode( UUID uuid ) {
+ AbstractJcrNode getNode( UUID uuid ) {
return nodesByUuid.get(uuid);
}
@@ -586,17 +629,24 @@
return result;
}
+ JcrRootNode rootNode() throws RepositoryException {
+ // Return cached root node if available
+ if (rootNode != null) {
+ return rootNode;
+ }
+ Path rootPath = executionContext.getValueFactories().getPathFactory().createRootPath();
+ loadNode(null, rootPath); // sets the root node
+ assert rootNode != null;
+ return rootNode;
+ }
+
/**
* {@inheritDoc}
*
* @see javax.jcr.Session#getRootNode()
*/
public Node getRootNode() throws RepositoryException {
- // Return cached root node if available
- if (rootNode != null) {
- return rootNode;
- }
- return getNode(executionContext.getValueFactories().getPathFactory().createRootPath());
+ return rootNode();
}
/**
@@ -806,7 +856,7 @@
// --------------------------------------------------
// Create JCR children for corresponding DNA children
// --------------------------------------------------
- node.setChildren(graphNode.getChildrenSegments());
+ node.setChildren(graphNode.getChildren());
// ------------------------------------------------------
// Create JCR properties for corresponding DNA properties
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -52,7 +52,7 @@
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path.Segment;
+import org.jboss.dna.graph.property.Path;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -67,13 +67,18 @@
static MockAbstractJcrNode createChild( JcrSession session,
String name,
int index,
- List<Segment> children,
- Node parent ) throws Exception {
+ List<Location> children,
+ AbstractJcrNode parent ) throws Exception {
MockAbstractJcrNode child = new MockAbstractJcrNode(session, name, parent);
- Segment seg = session.getExecutionContext().getValueFactories().getPathFactory().createSegment(name, index);
- children.add(seg);
+ String parentPath = parent.getPath();
+ String childPath = parentPath + "/" + name + "[" + index + "]";
+ Path path = session.getExecutionContext().getValueFactories().getPathFactory().create(childPath);
+ Location location = Location.create(path, UUID.randomUUID());
+ children.add(location);
// Stub the session to return this node ...
- String absolutePath = parent.getPath() + "/" + seg.getString(session.getExecutionContext().getNamespaceRegistry());
+ String absolutePath = path.getString(session.getExecutionContext().getNamespaceRegistry());
+ stub(session.getChild(parent, location)).toReturn(child);
+ stub(session.getNode(location.getUuid())).toReturn(child);
stub(session.getItem(absolutePath)).toReturn(child);
return child;
}
@@ -120,7 +125,7 @@
private Workspace workspace;
@Mock
private Repository repository;
- private List<Segment> children;
+ private List<Location> children;
private Map<Name, Property> properties;
private ExecutionContext context;
@@ -129,7 +134,7 @@
MockitoAnnotations.initMocks(this);
context = new ExecutionContext();
stub(session.getExecutionContext()).toReturn(context);
- children = new ArrayList<Segment>();
+ children = new ArrayList<Location>();
properties = new HashMap<Name, Property>();
node = new MockAbstractJcrNode(session, "node", null);
node.setProperties(properties);
@@ -397,8 +402,8 @@
stub(prop.getName()).toReturn("prop");
properties.put(name(prop.getName()), prop);
assertThat(node.hasNode("prop"), is(false));
- Node child = createChild(session, "child", 1, children, node);
- Node child2 = createChild(session, "child2", 1, children, child);
+ AbstractJcrNode child = createChild(session, "child", 1, children, node);
+ AbstractJcrNode child2 = createChild(session, "child2", 1, children, child);
node.setChildren(children);
assertThat(node.hasNode("child"), is(true));
stub(session.getItem("/node/child/{}child2")).toReturn(child2);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -32,7 +32,7 @@
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Path.Segment;
+import org.jboss.dna.graph.Location;
import org.jboss.dna.jcr.AbstractJcrNodeTest.MockAbstractJcrNode;
import org.junit.Before;
import org.junit.Test;
@@ -47,14 +47,14 @@
private AbstractJcrNode node;
@Mock
private JcrSession session;
- private List<Segment> children;
+ private List<Location> children;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
ExecutionContext context = new ExecutionContext();
stub(session.getExecutionContext()).toReturn(context);
- children = new ArrayList<Segment>();
+ children = new ArrayList<Location>();
node = new MockAbstractJcrNode(session, "node", null);
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -30,14 +30,12 @@
import java.util.HashMap;
import java.util.UUID;
import javax.jcr.ItemNotFoundException;
-import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.nodetype.NodeDefinition;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.Path.Segment;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@@ -49,7 +47,7 @@
public class JcrNodeTest {
private JcrNode node;
- private Node root;
+ private AbstractJcrNode root;
@Mock
private JcrSession session;
@Mock
@@ -73,7 +71,7 @@
stub(session.getNode(rootUuid)).toReturn(root);
stub(session.getNode(uuid)).toReturn(node);
node.setProperties(new HashMap<Name, Property>());
- node.setChildren(new ArrayList<Segment>());
+ node.setChildren(new ArrayList<Location>());
}
@Test( expected = ItemNotFoundException.class )
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-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -281,7 +281,7 @@
@Test
public void shouldProvideRootNode() throws Exception {
- Map<UUID, Node> nodesByUuid = session.getNodesByUuid();
+ Map<UUID, AbstractJcrNode> nodesByUuid = session.getNodesByUuid();
assertThat(nodesByUuid.isEmpty(), is(true));
Node root = session.getRootNode();
assertThat(root, notNullValue());
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java 2009-03-10 16:51:50 UTC (rev 768)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java 2009-03-10 19:43:15 UTC (rev 769)
@@ -111,10 +111,10 @@
public void shouldProvideNode() throws Exception {
UUID referencedUuid = UUID.randomUUID();
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, referencedUuid);
- Node referencedNode = mock(Node.class);
+ AbstractJcrNode referencedNode = mock(AbstractJcrNode.class);
stub(session.getNode(referencedUuid)).toReturn(referencedNode);
prop = new JcrSingleValueProperty(node, definition, PropertyType.REFERENCE, dnaProperty);
- assertThat(prop.getNode(), is(referencedNode));
+ assertThat(prop.getNode(), is((Node)referencedNode));
assertThat(prop.getType(), is(PropertyType.REFERENCE));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
}
15 years, 1 month
DNA SVN: r768 - in trunk/dna-jcr/src/test: resources and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-10 12:51:50 -0400 (Tue, 10 Mar 2009)
New Revision: 768
Added:
trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml
Removed:
trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml
Modified:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
Log:
Renamed the file containing the repository content for our TCK unit tests.
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-03-10 16:37:29 UTC (rev 767)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-03-10 16:51:50 UTC (rev 768)
@@ -48,7 +48,8 @@
import org.jboss.dna.graph.property.Path;
/**
- * Test suite to wrap Apache Jackrabbit JCR technology compatibility kit (TCK) unit tests.
+ * Test suite to wrap Apache Jackrabbit JCR technology compatibility kit (TCK) unit tests. Note that technically these are not the
+ * actual TCK, but these are unit tests that happen to be similar to (or provided the basis for) a subset of the TCK.
*/
public class JcrTckTest {
@@ -287,7 +288,7 @@
Path destinationPath = executionContext.getValueFactories().getPathFactory().create("/");
GraphImporter importer = new GraphImporter(graph);
- URI xmlContent = new File("src/test/resources/repositoryJackrabbitTck.xml").toURI();
+ URI xmlContent = new File("src/test/resources/repositoryForTckTests.xml").toURI();
Graph.Batch batch = importer.importXml(xmlContent, Location.create(destinationPath));
batch.execute();
Copied: trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml (from rev 764, trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml)
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml (rev 0)
+++ trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml 2009-03-10 16:51:50 UTC (rev 768)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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 distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<testroot xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ xmlns:dna="http://www.jboss.org/dna/1.0"
+ jcr:primaryType="nt:unstructured">
+ <nt:unstructured jcr:name="node1" prop1="<foo&foo>" >
+ <!-- This stanza checks for the jcr:xmltext special case for document export. DO NOT change this element. -->
+ <dna:xmlText jcr:name="jcr:xmltext" jcr:xmlcharacters="This is my "XML" text!" />
+ </nt:unstructured>
+ <nt:unstructured jcr:name="node2 has a multi-word name" prop2="bar" />
+ <nt:unstructured jcr:name="node3" />
+ <nt:unstructured jcr:name="node4" />
+</testroot>
\ No newline at end of file
Deleted: trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml 2009-03-10 16:37:29 UTC (rev 767)
+++ trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml 2009-03-10 16:51:50 UTC (rev 768)
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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 distribution; if not, write to:
- ~ Free Software Foundation, Inc.
- ~ 51 Franklin Street, Fifth Floor
- ~ Boston, MA 02110-1301 USA
- -->
-<testroot xmlns:jcr="http://www.jcp.org/jcr/1.0"
- xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
- xmlns:dna="http://www.jboss.org/dna/1.0"
- jcr:primaryType="nt:unstructured">
- <nt:unstructured jcr:name="node1" prop1="<foo&foo>" >
- <!-- This stanza checks for the jcr:xmltext special case for document export. DO NOT change this element. -->
- <dna:xmlText jcr:name="jcr:xmltext" jcr:xmlcharacters="This is my "XML" text!" />
- </nt:unstructured>
- <nt:unstructured jcr:name="node2 has a multi-word name" prop2="bar" />
- <nt:unstructured jcr:name="node3" />
- <nt:unstructured jcr:name="node4" />
-</testroot>
\ No newline at end of file
15 years, 1 month
DNA SVN: r767 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-10 12:37:29 -0400 (Tue, 10 Mar 2009)
New Revision: 767
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java
Log:
DNA-295 TCK Tests for Session.export* Methods Fail
Applied the "cache" patch that streamlined the conversion of DNA Name objects to strings containing the prefixed form of the Name.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java 2009-03-10 16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java 2009-03-10 16:37:29 UTC (rev 767)
@@ -74,6 +74,11 @@
private final Collection<String> restrictedPrefixes;
/**
+ * Cache from {@link Name}s to their rewritten version based on session uri mappings.
+ */
+ private final Map<Name, String> prefixedNames;
+
+ /**
* Creates the exporter
*
* @param session the session in which the exporter is created
@@ -83,9 +88,37 @@
Collection<String> restrictedPrefixes ) {
this.session = session;
this.restrictedPrefixes = restrictedPrefixes;
+ this.prefixedNames = new HashMap<Name, String>();
}
/**
+ * Returns the "prefixed" or rewritten version of <code>baseName</code> based on the URI mappings in the current
+ * session. For example:</p> If the namespace "http://www.example.com/JCR/example/1.0" is mapped to the prefix
+ * "foo" in the current session (or as a persistent mapping that has not been re-mapped in the current session),
+ * this method will return the string "foo:bar" when passed a {@link Name} with uri
+ * "http://www.example.com/JCR/example/1.0" and local name "bar".</p> This method does manage and utilize
+ * a {@link Name} to {@link String} cache at the instance scope.
+ *
+ * @param baseName the name to be re-mapped into its prefixed version
+ * @return the prefixed version of <code>baseName</code> based on the current session URI mappings (which include all
+ * persistent URI mappings by default).
+ * @see #prefixedNames
+ * @see javax.jcr.Session#setNamespacePrefix(String, String)
+ * @see javax.jcr.Session#getNamespacePrefix(String)
+ */
+ protected String getPrefixedName( Name baseName ) {
+ String prefixedName = prefixedNames.get(baseName);
+
+ if (prefixedName == null) {
+ prefixedName = baseName.getString(session.getExecutionContext().getNamespaceRegistry());
+
+ prefixedNames.put(baseName, prefixedName);
+ }
+
+ return prefixedName;
+ }
+
+ /**
* Exports <code>node</code> (or the subtree rooted at <code>node</code>) into an XML document by invoking SAX events on
* <code>contentHandler</code>.
*
@@ -188,7 +221,7 @@
Attributes atts ) throws SAXException {
contentHandler.startElement(name.getNamespaceUri(),
NAME_ENCODER.encode(name.getLocalName()),
- NAME_ENCODER.encode(name.getString(session.getExecutionContext().getNamespaceRegistry())),
+ NAME_ENCODER.encode(getPrefixedName(name)),
atts);
}
@@ -204,7 +237,7 @@
Name name ) throws SAXException {
contentHandler.endElement(name.getNamespaceUri(),
NAME_ENCODER.encode(name.getLocalName()),
- NAME_ENCODER.encode(name.getString(session.getExecutionContext().getNamespaceRegistry())));
+ NAME_ENCODER.encode(getPrefixedName(name)));
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java 2009-03-10 16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java 2009-03-10 16:37:29 UTC (rev 767)
@@ -139,7 +139,7 @@
/* Name of node type that holds xmltext from document view import (see JCR 1.0 spec section 7.3.2) */
JcrNodeType xmlText = new JcrNodeType(
session,
- DnaLexicon.XML_TEXT_TYPE,
+ DnaLexicon.XML_TEXT,
Arrays.asList(new NodeType[] {base}),
NO_PRIMARY_ITEM_NAME,
NO_CHILD_NODES,
@@ -166,13 +166,13 @@
Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
session,
null,
- DnaLexicon.XML_TEXT,
+ JcrLexicon.XMLTEXT,
OnParentVersionBehavior.VERSION.getJcrValue(),
false,
true,
false,
false,
- DnaLexicon.XML_TEXT_TYPE,
+ DnaLexicon.XML_TEXT,
new NodeType[] {xmlText})}),
NO_PROPERTIES, IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
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-03-10 16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-03-10 16:37:29 UTC (rev 767)
@@ -40,8 +40,8 @@
/**
* Mixin type that indicates the node contains an xmltext node which holds xmltext from document view import (see JCR 1.0
- * specification section 7.3.2). This node has a child node named {@link DnaLexicon#XML_TEXT} of type
- * {@link DnaLexicon#XML_TEXT_TYPE}.
+ * specification section 7.3.2). This node has a child node named {@link JcrLexicon#XMLTEXT} of type
+ * {@link DnaLexicon#XML_TEXT}.
*/
public static final Name XML_CONTENT = new BasicName(Namespace.URI, "xmlContent");
@@ -49,12 +49,6 @@
* Name of node type that holds xmltext from document view import (see JCR 1.0 specification section 7.3.2). It is defined in
* the node type named {@link DnaLexicon#XML_CONTENT}.
*/
- public static final Name XML_TEXT_TYPE = new BasicName(Namespace.URI, "xmlText");
+ public static final Name XML_TEXT = new BasicName(Namespace.URI, "xmlText");
- /**
- * Name of the child node that holds xmltext from document view import (see JCR 1.0 specification section 7.3.2). This is the
- * name of the child node of the {@link DnaLexicon#XML_CONTENT} mixin type. By definition, this node has a required primary
- * type of {@link DnaLexicon#XML_TEXT_TYPE}.
- */
- public static final Name XML_TEXT = new BasicName(Namespace.URI, "xmltext");
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java 2009-03-10 16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java 2009-03-10 16:37:29 UTC (rev 767)
@@ -97,7 +97,7 @@
Name propName = ((AbstractJcrProperty)prop).getDnaProperty().getName();
- String localPropName = propName.getString(executionContext.getNamespaceRegistry());
+ String localPropName = getPrefixedName(propName);
Value value;
if (prop instanceof JcrSingleValueProperty) {
@@ -151,8 +151,7 @@
private boolean isXmlTextNode( Node node ) throws RepositoryException {
// ./xmltext/xmlcharacters exception (see JSR-170 Spec 6.4.2.3)
- ExecutionContext executionContext = session.getExecutionContext();
- if (JcrLexicon.XMLTEXT.getString(executionContext.getNamespaceRegistry()).equals(node.getName())) {
+ if (getPrefixedName(JcrLexicon.XMLTEXT).equals(node.getName())) {
if (node.getNodes().getSize() == 0) {
PropertyIterator properties = node.getProperties();
@@ -161,11 +160,11 @@
while (properties.hasNext()) {
Property property = properties.nextProperty();
- if (JcrLexicon.PRIMARY_TYPE.getString(executionContext.getNamespaceRegistry()).equals(property.getName())) {
+ if (getPrefixedName(JcrLexicon.PRIMARY_TYPE).equals(property.getName())) {
continue;
}
- if (JcrLexicon.XMLCHARACTERS.getString(executionContext.getNamespaceRegistry()).equals(property.getName())) {
+ if (getPrefixedName(JcrLexicon.XMLCHARACTERS).equals(property.getName())) {
xmlCharactersFound = true;
continue;
}
@@ -195,8 +194,7 @@
assert isXmlTextNode(node);
- ExecutionContext executionContext = session.getExecutionContext();
- Property xmlCharacters = node.getProperty(JcrLexicon.XMLCHARACTERS.getString(executionContext.getNamespaceRegistry()));
+ Property xmlCharacters = node.getProperty(getPrefixedName(JcrLexicon.XMLCHARACTERS));
assert xmlCharacters != null;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java 2009-03-10 16:19:07 UTC (rev 766)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSystemViewExporter.java 2009-03-10 16:37:29 UTC (rev 767)
@@ -15,7 +15,6 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.Base64;
import org.jboss.dna.common.xml.XmlCharacters;
-import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.property.Name;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -65,13 +64,12 @@
ContentHandler contentHandler,
boolean skipBinary,
boolean noRecurse ) throws RepositoryException, SAXException {
- ExecutionContext executionContext = session.getExecutionContext();
// start the sv:node element for this JCR node
AttributesImpl atts = new AttributesImpl();
atts.addAttribute(JcrSvLexicon.NAME.getNamespaceUri(),
JcrSvLexicon.NAME.getLocalName(),
- JcrSvLexicon.NAME.getString(executionContext.getNamespaceRegistry()),
+ getPrefixedName(JcrSvLexicon.NAME),
PropertyType.nameFromValue(PropertyType.STRING),
node.getName());
@@ -141,21 +139,20 @@
assert property instanceof AbstractJcrProperty : "Illegal attempt to use " + getClass().getName()
+ " on non-DNA property";
- ExecutionContext executionContext = session.getExecutionContext();
AbstractJcrProperty prop = (AbstractJcrProperty)property;
// first set the property sv:name attribute
AttributesImpl propAtts = new AttributesImpl();
propAtts.addAttribute(JcrSvLexicon.NAME.getNamespaceUri(),
JcrSvLexicon.NAME.getLocalName(),
- JcrSvLexicon.NAME.getString(executionContext.getNamespaceRegistry()),
+ getPrefixedName(JcrSvLexicon.NAME),
PropertyType.nameFromValue(PropertyType.STRING),
prop.getName());
// and it's sv:type attribute
propAtts.addAttribute(JcrSvLexicon.TYPE.getNamespaceUri(),
JcrSvLexicon.TYPE.getLocalName(),
- JcrSvLexicon.TYPE.getString(executionContext.getNamespaceRegistry()),
+ getPrefixedName(JcrSvLexicon.TYPE),
PropertyType.nameFromValue(PropertyType.STRING),
PropertyType.nameFromValue(prop.getType()));
@@ -224,7 +221,7 @@
}
if (allCharsAreValidXml) {
-
+
startElement(contentHandler, JcrSvLexicon.VALUE, null);
contentHandler.characters(chars, 0, chars.length);
endElement(contentHandler, JcrSvLexicon.VALUE);
15 years, 1 month
DNA SVN: r766 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-10 12:19:07 -0400 (Tue, 10 Mar 2009)
New Revision: 766
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java
Log:
DNA-295 TCK Tests for Session.export* Methods Fail
Corrected a line to only print to System.out when debugging.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java 2009-03-10 16:18:31 UTC (rev 765)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrExporter.java 2009-03-10 16:19:07 UTC (rev 766)
@@ -47,10 +47,8 @@
/**
* Superclass of DNA JCR exporters, provides basic support for traversing through the nodes recursively (if needed), exception
* wrapping (since {@link ItemVisitor} does not allow checked exceptions to be thrown from its visit* methods, and the ability to
- * wrap an {@link OutputStream} with a {@link ContentHandler}.
- * <p />
- * Each exporter is only intended to be used once (by calling <code>exportView</code>) and discarded. This class is <b>NOT</b>
- * thread-safe.
+ * wrap an {@link OutputStream} with a {@link ContentHandler}. <p /> Each exporter is only intended to be used once (by calling
+ * <code>exportView</code>) and discarded. This class is <b>NOT</b> thread-safe.
*
* @see JcrSystemViewExporter
* @see JcrDocumentViewExporter
@@ -318,7 +316,7 @@
emit("</");
emit(name);
emit(">");
- System.out.println();
+ if (LOG_TO_CONSOLE) System.out.println();
}
15 years, 1 month