Index: b/modeshape-cnd/src/main/java/org/modeshape/cnd/CndImporter.java =================================================================== --- a/modeshape-cnd/src/main/java/org/modeshape/cnd/CndImporter.java (revision ) +++ b/modeshape-cnd/src/main/java/org/modeshape/cnd/CndImporter.java (working copy) @@ -337,6 +337,9 @@ public class CndImporter { } else if (tokens.canConsumeAnyOf("NOQUERY", "NOQ")) { tokens.canConsume('?'); isQueryable = false; + } else if (tokens.canConsumeAnyOf("QUERY", "Q")) { + tokens.canConsume('?'); + isQueryable = true; } else if (tokens.canConsumeAnyOf("PRIMARYITEM", "!")) { primaryItem = parseName(tokens); tokens.canConsume('?'); Index: b/modeshape-graph/src/main/java/org/modeshape/graph/xml/XmlHandler.java =================================================================== --- a/modeshape-graph/src/main/java/org/modeshape/graph/xml/XmlHandler.java (revision ) +++ b/modeshape-graph/src/main/java/org/modeshape/graph/xml/XmlHandler.java (working copy) @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import javax.xml.parsers.SAXParser; import net.jcip.annotations.NotThreadSafe; import org.modeshape.common.text.TextDecoder; @@ -328,12 +329,12 @@ public class XmlHandler extends DefaultHandler2 { Name nodeName = null; ElementEntry element; - if (!elementStack.isEmpty()) { + if (elementStack.isEmpty()) { + element = new ElementEntry(null, currentPath, null); + } else { // Add the parent elementStack.peek().addAsNode(); element = new ElementEntry(elementStack.peek(), currentPath, null); - } else { - element = new ElementEntry(null, currentPath, null); } elementStack.addFirst(element); @@ -505,6 +506,7 @@ public class XmlHandler extends DefaultHandler2 { private Name name; private Multimap properties; private ElementEntryState state; + private Map childSnsIndexes = new HashMap(); protected ElementEntry( ElementEntry parent, Path pathToParent, @@ -516,9 +518,22 @@ public class XmlHandler extends DefaultHandler2 { properties = LinkedHashMultimap.create(); } + private int getNextSnsForChildNamed( Name childName ) { + AtomicInteger snsIndex = childSnsIndexes.get(childName); + if (snsIndex == null) { + snsIndex = new AtomicInteger(0); + childSnsIndexes.put(childName, snsIndex); + } + return snsIndex.addAndGet(1); + } + protected void setName( Name name ) { this.name = name; - pathToThisNode = pathFactory.create(pathToParent, name); + int snsIndex = 1; + if (parent != null) { + snsIndex = parent.getNextSnsForChildNamed(name); + } + pathToThisNode = pathFactory.create(pathToParent, name, snsIndex); } protected void addProperty( Name propertyName, @@ -532,7 +547,7 @@ public class XmlHandler extends DefaultHandler2 { if (state == ElementEntryState.NODE) return; state = ElementEntryState.NODE; - destination.create(pathFactory.create(pathToParent, name), Collections.emptyList()); + destination.create(pathToThisNode, Collections.emptyList()); } protected void addAsPropertySetTo( Object value ) { Index: b/modeshape-graph/src/test/java/org/modeshape/graph/xml/XmlHandlerTest.java =================================================================== --- a/modeshape-graph/src/test/java/org/modeshape/graph/xml/XmlHandlerTest.java (revision ) +++ b/modeshape-graph/src/test/java/org/modeshape/graph/xml/XmlHandlerTest.java (working copy) @@ -35,6 +35,8 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.junit.Before; +import org.junit.Test; import org.modeshape.common.text.Jsr283Encoder; import org.modeshape.common.text.TextDecoder; import org.modeshape.graph.ExecutionContext; @@ -47,8 +49,6 @@ import org.modeshape.graph.property.Path; import org.modeshape.graph.property.PathFactory; import org.modeshape.graph.property.Property; import org.modeshape.graph.request.CreateNodeRequest; -import org.junit.Before; -import org.junit.Test; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; @@ -365,7 +365,7 @@ public class XmlHandlerTest { assertNode("Cars/Sports/car", unstructPrimaryType, "name=Infiniti G37", "maker=Infiniti", "model=G37"); assertProperties("Cars/Sports", unstructPrimaryType); assertProperties("Cars", unstructPrimaryType); - + } @Test @@ -402,17 +402,21 @@ public class XmlHandlerTest { assertNode("Cars"); assertNode("Cars/Hybrid"); assertNode("Cars/Hybrid/car", "name=Toyota Prius", "maker=Toyota", "model=Prius"); - assertNode("Cars/Hybrid/car", "name=Toyota Highlander", "maker=Toyota", "model=Highlander"); - assertNode("Cars/Hybrid/car"); - assertProperties("Cars/Hybrid/car", "name=Nissan Altima", "maker=Nissan", "model=Altima"); + assertNode("Cars/Hybrid/car[2]", "name=Toyota Highlander", "maker=Toyota", "model=Highlander"); + assertNode("Cars/Hybrid/car[3]"); + assertProperties("Cars/Hybrid/car[3]", "name=Nissan Altima", "maker=Nissan", "model=Altima"); assertNode("Cars/Sports"); assertNode("Cars/Sports/car", "name=Aston Martin DB9", "maker=Aston Martin", "model=DB9"); assertNode("Cars/Sports/car"); - assertNode("Cars/Sports/car/driver", "name=Tony Stewart"); - assertProperties("Cars/Sports/car", "name=Infiniti G37", "maker=Infiniti", "model=G37", "category=Turbocharged=My Sedan"); - assertNode("Cars/Sports/car"); - assertNode("Cars/Sports/car/jcr:xmltext", "jcr:xmlcharacters=This is my text "); - assertNode("Cars/Sports/car/jcr:xmltext", "jcr:xmlcharacters=that should be merged"); + assertNode("Cars/Sports/car[2]/driver", "name=Tony Stewart"); + assertProperties("Cars/Sports/car[2]", + "name=Infiniti G37", + "maker=Infiniti", + "model=G37", + "category=Turbocharged=My Sedan"); + assertNode("Cars/Sports/car[3]"); + assertNode("Cars/Sports/car[3]/jcr:xmltext", "jcr:xmlcharacters=This is my text "); + assertNode("Cars/Sports/car[3]/jcr:xmltext", "jcr:xmlcharacters=that should be merged"); assertProperties("Cars/Sports/car", "name=Infiniti G37", "maker=Infiniti", "model=G37"); } @@ -463,7 +467,7 @@ public class XmlHandlerTest { } protected void assertProperties( String path, - String... properties ) { + String... properties ) { // Create the expected path ... PathFactory factory = context.getValueFactories().getPathFactory(); Path expectedPath = parentPath != null ? factory.create(parentPath, path) : factory.create("/" + path); @@ -565,21 +569,19 @@ public class XmlHandlerTest { } } - public void setProperties( Path path, + public void setProperties( Path path, Property... properties ) { if (properties.length == 0) { return; - } - else if (properties.length == 1) { + } else if (properties.length == 1) { create(path, properties[0]); + } else { + Property[] additionalProperties = new Property[properties.length - 1]; + System.arraycopy(properties, 1, additionalProperties, 0, properties.length - 1); + create(path, properties[0], additionalProperties); } - else { - Property[] additionalProperties = new Property[properties.length - 1]; - System.arraycopy(properties, 1, additionalProperties, 0, properties.length - 1); - create(path, properties[0], additionalProperties); - } - } - + } + @SuppressWarnings( "synthetic-access" ) public ExecutionContext getExecutionContext() { return XmlHandlerTest.this.context;