DNA SVN: r745 - trunk/dna-jcr/src/test/resources.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-02 20:30:03 -0500 (Mon, 02 Mar 2009)
New Revision: 745
Added:
trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml
Log:
Corrected name of file to have the same case as in the JackrabbitTckTest.java.
Added: trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml (rev 0)
+++ trunk/dna-jcr/src/test/resources/repositoryJackrabbitTck.xml 2009-03-03 01:30:03 UTC (rev 745)
@@ -0,0 +1,34 @@
+<?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"
+ jcr:primaryType="nt:unstructured">
+ <nt:unstructured jcr:name="node1" jcr:primaryType="nt:unstructured" prop1="foo" />
+ <nt:unstructured jcr:name="node2" jcr:primaryType="nt:unstructured" prop2="bar" />
+ <nt:unstructured jcr:name="node3" jcr:primaryType="nt:unstructured" />
+ <nt:unstructured jcr:name="node4" jcr:primaryType="nt:unstructured" />
+</testroot>
\ No newline at end of file
15 years, 2 months
DNA SVN: r744 - trunk.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-02 15:11:29 -0500 (Mon, 02 Mar 2009)
New Revision: 744
Modified:
trunk/pom.xml
Log:
Added 'dna-jcr' back into the build.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-03-02 20:03:51 UTC (rev 743)
+++ trunk/pom.xml 2009-03-02 20:11:29 UTC (rev 744)
@@ -114,7 +114,7 @@
<module>dna-common</module>
<module>dna-graph</module>
<module>dna-repository</module>
- <!--module>dna-jcr</module-->
+ <module>dna-jcr</module>
<module>extensions/dna-classloader-maven</module>
<module>extensions/dna-sequencer-images</module>
<module>extensions/dna-sequencer-mp3</module>
15 years, 2 months
DNA SVN: r743 - in trunk: dna-graph/src/test/java/org/jboss/dna/graph and 4 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-02 15:03:51 -0500 (Mon, 02 Mar 2009)
New Revision: 743
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StandardValueFactories.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StringValueFactory.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.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/BooleanValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DecimalValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DoubleValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/InMemoryBinaryValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/JodaDateTimeValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/LongValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/NameValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/PathValueFactoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/UuidValueFactoryTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
Log:
DNA-286 Implement namespace management
This change corrects the behavior of the Session's namespace-related methods, which are not the same as those in the NamespaceRegistry implementation associated with the workspace. This also corrected several of the TCK tests associated with namespaces.
Note that the StringValueFactory in 'dna-graph' was changed to use a DNA namespace registry to convert a Name and Path to a string using the namespace prefixes. (This change affected a number of unit tests.) The result is that any Name and Path property values are treated correctly and properly converted to a string using the current namespace prefixes in the namespace registry. However, the BinaryValueFactory implementations should not use this StringValueFactory, since they need to convert values using the non-prefixed form (that is, the namespace URI).
In the case of our JCR implementation, the above change to the Graph factories means that property values are properly mapped to strings using the Session's local mappings (which fall back on the Workspace's mappings). This corrected at least one TCK test.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StandardValueFactories.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StandardValueFactories.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StandardValueFactories.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -105,9 +105,12 @@
}
// Now assign the members, using the factories in the map or (if null) the supplied default ...
- this.stringFactory = getFactory(factories, new StringValueFactory(this.decoder, this.encoder));
- this.binaryFactory = (BinaryFactory)getFactory(factories,
- new InMemoryBinaryValueFactory(this.decoder, this.stringFactory));
+ this.stringFactory = getFactory(factories, new StringValueFactory(this.namespaceRegistry, this.decoder, this.encoder));
+
+ // The binary factory should NOT use the string factory that converts namespaces to prefixes ...
+ StringValueFactory stringFactoryWithoutNamespaces = new StringValueFactory(this.decoder, this.encoder);
+ this.binaryFactory = (BinaryFactory)getFactory(factories, new InMemoryBinaryValueFactory(this.decoder,
+ stringFactoryWithoutNamespaces));
this.booleanFactory = getFactory(factories, new BooleanValueFactory(this.decoder, this.stringFactory));
this.dateFactory = (DateTimeFactory)getFactory(factories, new JodaDateTimeValueFactory(this.decoder, this.stringFactory));
this.decimalFactory = getFactory(factories, new DecimalValueFactory(this.decoder, this.stringFactory));
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StringValueFactory.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StringValueFactory.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/StringValueFactory.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -43,6 +43,7 @@
import org.jboss.dna.graph.property.DateTime;
import org.jboss.dna.graph.property.IoException;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PropertyType;
import org.jboss.dna.graph.property.Reference;
@@ -59,14 +60,26 @@
public class StringValueFactory extends AbstractValueFactory<String> {
private final TextEncoder encoder;
+ private final NamespaceRegistry namespaceRegistry;
public StringValueFactory( TextDecoder decoder,
TextEncoder encoder ) {
super(PropertyType.STRING, decoder, null);
CheckArg.isNotNull(encoder, "encoder");
this.encoder = encoder;
+ this.namespaceRegistry = null;
}
+ public StringValueFactory( NamespaceRegistry namespaceRegistry,
+ TextDecoder decoder,
+ TextEncoder encoder ) {
+ super(PropertyType.STRING, decoder, null);
+ CheckArg.isNotNull(encoder, "encoder");
+ CheckArg.isNotNull(namespaceRegistry, "namespaceRegistry");
+ this.encoder = encoder;
+ this.namespaceRegistry = namespaceRegistry;
+ }
+
/**
* @return encoder
*/
@@ -173,6 +186,9 @@
*/
public String create( Name value ) {
if (value == null) return null;
+ if (this.namespaceRegistry != null) {
+ return value.getString(this.namespaceRegistry, getEncoder());
+ }
return value.getString(getEncoder());
}
@@ -181,6 +197,9 @@
*/
public String create( Path value ) {
if (value == null) return null;
+ if (this.namespaceRegistry != null) {
+ return value.getString(this.namespaceRegistry, getEncoder());
+ }
return value.getString(getEncoder());
}
@@ -220,8 +239,8 @@
} catch (UnsupportedEncodingException err) {
throw new ValueFormatException(value, getPropertyType(),
GraphI18n.errorConvertingType.text(byte[].class.getSimpleName(),
- String.class.getSimpleName(),
- value), err);
+ String.class.getSimpleName(),
+ value), err);
}
}
@@ -262,12 +281,11 @@
} catch (UnsupportedEncodingException err) {
throw new ValueFormatException(value, getPropertyType(),
GraphI18n.errorConvertingType.text(InputStream.class.getSimpleName(),
- String.class.getSimpleName(),
- value), err);
+ String.class.getSimpleName(),
+ value), err);
} catch (IOException err) {
- throw new IoException(
- GraphI18n.errorConvertingIo.text(InputStream.class.getSimpleName(), String.class.getSimpleName()),
- err);
+ throw new IoException(GraphI18n.errorConvertingIo.text(InputStream.class.getSimpleName(),
+ String.class.getSimpleName()), err);
}
}
@@ -280,7 +298,8 @@
try {
return IoUtil.read(reader);
} catch (IOException err) {
- throw new IoException(GraphI18n.errorConvertingIo.text(Reader.class.getSimpleName(), String.class.getSimpleName()), err);
+ throw new IoException(GraphI18n.errorConvertingIo.text(Reader.class.getSimpleName(), String.class.getSimpleName()),
+ err);
}
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -30,6 +30,7 @@
import java.util.List;
import java.util.UUID;
import org.jboss.dna.common.text.NoOpEncoder;
+import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.Property;
@@ -47,11 +48,11 @@
public class LocationTest {
private static final NoOpEncoder NO_OP_ENCODER = new NoOpEncoder();
- private static final StringValueFactory STRING_VALUE_FACTORY = new StringValueFactory(NO_OP_ENCODER, NO_OP_ENCODER);
- private static final NameValueFactory NAME_VALUE_FACTORY = new NameValueFactory(
- new SimpleNamespaceRegistry(
- "http://www.jboss.org/dna/1.0"),
- NO_OP_ENCODER, STRING_VALUE_FACTORY);
+ private static final NamespaceRegistry NAMESPACE_REGISTRY = new SimpleNamespaceRegistry("http://www.jboss.org/dna/1.0");
+ private static final StringValueFactory STRING_VALUE_FACTORY = new StringValueFactory(NAMESPACE_REGISTRY, NO_OP_ENCODER,
+ NO_OP_ENCODER);
+ private static final NameValueFactory NAME_VALUE_FACTORY = new NameValueFactory(NAMESPACE_REGISTRY, NO_OP_ENCODER,
+ STRING_VALUE_FACTORY);
private PathFactory pathFactory = new PathValueFactory(NO_OP_ENCODER, STRING_VALUE_FACTORY, NAME_VALUE_FACTORY);
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -78,7 +78,8 @@
path = new BasicPath(validSegmentsList, true);
namespaceRegistry = new SimpleNamespaceRegistry();
namespaceRegistry.register(validNamespacePrefix, validNamespaceUri);
- StringValueFactory stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
+ StringValueFactory stringValueFactory = new StringValueFactory(namespaceRegistry, Path.DEFAULT_DECODER,
+ Path.DEFAULT_ENCODER);
NameValueFactory nameValueFactory = new NameValueFactory(namespaceRegistry, Path.DEFAULT_DECODER, stringValueFactory);
pathFactory = new PathValueFactory(Path.DEFAULT_DECODER, stringValueFactory, nameValueFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -55,7 +55,7 @@
public void beforeEach() {
this.registry = new SimpleNamespaceRegistry();
this.registry.register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
- this.stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
+ this.stringValueFactory = new StringValueFactory(registry, Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
this.nameFactory = new NameValueFactory(registry, Path.DEFAULT_DECODER, stringValueFactory);
this.validName = nameFactory.create("dna:something");
this.factory = new PathValueFactory(Path.DEFAULT_DECODER, stringValueFactory, nameFactory);
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-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -77,7 +77,8 @@
super.path = new BasicPath(validSegmentsList, true);
namespaceRegistry = new SimpleNamespaceRegistry();
namespaceRegistry.register(validNamespacePrefix, validNamespaceUri);
- StringValueFactory stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
+ StringValueFactory stringValueFactory = new StringValueFactory(namespaceRegistry, Path.DEFAULT_DECODER,
+ Path.DEFAULT_ENCODER);
NameValueFactory nameValueFactory = new NameValueFactory(namespaceRegistry, Path.DEFAULT_DECODER, stringValueFactory);
pathFactory = new PathValueFactory(Path.DEFAULT_DECODER, stringValueFactory, nameValueFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BooleanValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BooleanValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BooleanValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -35,11 +35,10 @@
import java.util.Iterator;
import java.util.List;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Reference;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.BooleanValueFactory;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -49,6 +48,7 @@
*/
public class BooleanValueFactoryTest {
+ private NamespaceRegistry registry;
private BooleanValueFactory factory;
private StringValueFactory stringFactory;
@@ -57,7 +57,8 @@
*/
@Before
public void setUp() throws Exception {
- stringFactory = new StringValueFactory(Path.URL_DECODER, Path.DEFAULT_ENCODER);
+ registry = new SimpleNamespaceRegistry();
+ stringFactory = new StringValueFactory(registry, Path.URL_DECODER, Path.DEFAULT_ENCODER);
factory = new BooleanValueFactory(Path.URL_DECODER, stringFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DecimalValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DecimalValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DecimalValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -36,11 +36,10 @@
import java.util.Iterator;
import java.util.List;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Reference;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.DecimalValueFactory;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -50,6 +49,7 @@
*/
public class DecimalValueFactoryTest {
+ private NamespaceRegistry registry;
private DecimalValueFactory factory;
private StringValueFactory stringFactory;
@@ -58,7 +58,8 @@
*/
@Before
public void setUp() throws Exception {
- stringFactory = new StringValueFactory(Path.URL_DECODER, Path.DEFAULT_ENCODER);
+ registry = new SimpleNamespaceRegistry();
+ stringFactory = new StringValueFactory(registry, Path.URL_DECODER, Path.DEFAULT_ENCODER);
factory = new DecimalValueFactory(Path.URL_DECODER, stringFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DoubleValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DoubleValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/DoubleValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -36,11 +36,10 @@
import java.util.Iterator;
import java.util.List;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Reference;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.DoubleValueFactory;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -50,6 +49,7 @@
*/
public class DoubleValueFactoryTest {
+ private NamespaceRegistry registry;
private DoubleValueFactory factory;
private StringValueFactory stringFactory;
@@ -58,7 +58,8 @@
*/
@Before
public void setUp() throws Exception {
- stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ registry = new SimpleNamespaceRegistry();
+ stringFactory = new StringValueFactory(registry, Path.URL_DECODER, Path.URL_ENCODER);
factory = new DoubleValueFactory(Path.URL_DECODER, stringFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/InMemoryBinaryValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/InMemoryBinaryValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/InMemoryBinaryValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -64,13 +64,16 @@
@Before
public void setUp() throws Exception {
encoder = Path.URL_ENCODER;
- stringFactory = new StringValueFactory(Path.URL_DECODER, encoder);
- factory = new InMemoryBinaryValueFactory(Path.URL_DECODER, stringFactory);
namespaceRegistry = new SimpleNamespaceRegistry();
namespaceRegistry.register("jboss", "http://www.jboss.org");
namespaceRegistry.register("dna", "http://www.jboss.org/dna");
+ stringFactory = new StringValueFactory(namespaceRegistry, Path.URL_DECODER, encoder);
nameFactory = new NameValueFactory(namespaceRegistry, Path.URL_DECODER, stringFactory);
pathFactory = new PathValueFactory(Path.URL_DECODER, stringFactory, nameFactory);
+
+ // The binary factory should convert between names and paths without using prefixes ...
+ StringValueFactory noNamespaceStringFactory = new StringValueFactory(Path.URL_DECODER, encoder);
+ factory = new InMemoryBinaryValueFactory(Path.URL_DECODER, noNamespaceStringFactory);
}
@Test
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/JodaDateTimeValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/JodaDateTimeValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/JodaDateTimeValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -39,9 +39,6 @@
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Reference;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.JodaDateTime;
-import org.jboss.dna.graph.property.basic.JodaDateTimeValueFactory;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -68,7 +65,7 @@
*/
@Before
public void setUp() throws Exception {
- stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ stringFactory = new StringValueFactory(new SimpleNamespaceRegistry(), Path.URL_DECODER, Path.URL_ENCODER);
factory = new JodaDateTimeValueFactory(Path.URL_DECODER, stringFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/LongValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/LongValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/LongValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -39,8 +39,6 @@
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Reference;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.LongValueFactory;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -58,7 +56,7 @@
*/
@Before
public void setUp() throws Exception {
- stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ stringFactory = new StringValueFactory(new SimpleNamespaceRegistry(), Path.URL_DECODER, Path.URL_ENCODER);
factory = new LongValueFactory(Path.URL_DECODER, stringFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/NameValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/NameValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/NameValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -58,7 +58,7 @@
this.registry.register("dna", "http://www.jboss.org/dna/namespace");
this.encoder = Path.DEFAULT_ENCODER;
this.decoder = Path.DEFAULT_DECODER;
- this.stringValueFactory = new StringValueFactory(decoder, encoder);
+ this.stringValueFactory = new StringValueFactory(registry, decoder, encoder);
this.factory = new NameValueFactory(registry, decoder, stringValueFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/PathValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/PathValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/PathValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -54,7 +54,7 @@
public void beforeEach() {
this.registry = new SimpleNamespaceRegistry();
this.registry.register("dna", "http://www.jboss.org/dna/namespace");
- this.stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
+ this.stringValueFactory = new StringValueFactory(registry, Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
this.nameFactory = new NameValueFactory(registry, Path.DEFAULT_DECODER, stringValueFactory);
this.factory = new PathValueFactory(Path.DEFAULT_DECODER, stringValueFactory, nameFactory);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/UuidValueFactoryTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/UuidValueFactoryTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/UuidValueFactoryTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -39,9 +39,6 @@
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
-import org.jboss.dna.graph.property.basic.UuidReference;
-import org.jboss.dna.graph.property.basic.UuidValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -60,7 +57,7 @@
*/
@Before
public void setUp() throws Exception {
- stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ stringFactory = new StringValueFactory(new SimpleNamespaceRegistry(), Path.URL_DECODER, Path.URL_ENCODER);
factory = new UuidValueFactory(Path.URL_DECODER, stringFactory);
uuid = UUID.randomUUID();
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -54,12 +54,14 @@
public static I18n unableToUnregisterReservedNamespacePrefix;
public static I18n unableToUnregisterReservedNamespaceUri;
public static I18n unableToUnregisterPrefixForNamespaceThatIsNotRegistered;
+ public static I18n unableToRemapUriNotRegisteredInNamespaceRegistry;
+ public static I18n unableToRemapUriUsingPrefixUsedInNamespaceRegistry;
public static I18n errorWhileInitializingTheNamespaceRegistry;
public static I18n invalidPathParameter;
-
+
public static I18n typeNotFound;
-
+
public static I18n REP_NAME_DESC;
public static I18n REP_VENDOR_DESC;
public static I18n SPEC_NAME_DESC;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -32,7 +32,7 @@
import javax.jcr.NamespaceException;
import javax.jcr.RepositoryException;
import javax.xml.XMLConstants;
-import net.jcip.annotations.ThreadSafe;
+import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.xml.XmlCharacters;
import org.jboss.dna.graph.JcrLexicon;
@@ -40,17 +40,25 @@
import org.jboss.dna.graph.JcrNtLexicon;
import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.NamespaceRegistry.Namespace;
-import org.jboss.dna.graph.property.basic.SimpleNamespaceRegistry;
-import org.jboss.dna.graph.property.basic.ThreadSafeNamespaceRegistry;
/**
* A thread-safe JCR {@link javax.jcr.NamespaceRegistry} implementation that has the standard JCR namespaces pre-registered and
* enforces the JCR semantics for {@link #registerNamespace(String, String) registering} and {@link #unregisterNamespace(String)
* unregistering} namespaces.
+ * <p>
+ * Note that this implementation is {@link NotThreadSafe not thread safe}, since it is used within a single {@link JcrWorkspace}
+ * and single {@link JcrSession}, and according to the JCR specification these interfaces are not thread safe.
+ * </p>
*/
-@ThreadSafe
+@NotThreadSafe
class JcrNamespaceRegistry implements javax.jcr.NamespaceRegistry {
+ public static enum Behavior {
+ JSR170_SESSION,
+ JSR283_SESSION,
+ WORKSPACE;
+ }
+
static final String DEFAULT_NAMESPACE_PREFIX = "";
static final String DEFAULT_NAMESPACE_URI = "";
@@ -89,18 +97,27 @@
STANDARD_BUILT_IN_URIS = Collections.unmodifiableSet(new HashSet<String>(namespaces.values()));
}
+ private final Behavior behavior;
private final NamespaceRegistry registry;
+ private final NamespaceRegistry workspaceRegistry;
- JcrNamespaceRegistry() {
- this(new ThreadSafeNamespaceRegistry(new SimpleNamespaceRegistry())); // thread-safe implementation
+ JcrNamespaceRegistry( NamespaceRegistry workspaceRegistry ) {
+ this(Behavior.WORKSPACE, null, workspaceRegistry);
}
- JcrNamespaceRegistry( NamespaceRegistry dnaRegistry ) {
- this.registry = dnaRegistry;
+ JcrNamespaceRegistry( Behavior behavior,
+ NamespaceRegistry localRegistry,
+ NamespaceRegistry workspaceRegistry ) {
+ this.behavior = behavior;
+ this.registry = localRegistry != null ? localRegistry : workspaceRegistry;
+ this.workspaceRegistry = workspaceRegistry;
// Add the built-ins, ensuring we overwrite any badly-initialized values ...
for (Map.Entry<String, String> builtIn : STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
this.registry.register(builtIn.getKey(), builtIn.getValue());
}
+ assert this.behavior != null;
+ assert this.registry != null;
+ assert this.workspaceRegistry != null;
}
/**
@@ -109,11 +126,13 @@
* @see javax.jcr.NamespaceRegistry#getPrefix(java.lang.String)
*/
public String getPrefix( String uri ) throws NamespaceException, RepositoryException {
- // Check the standard ones first, ensuring that invalid changes to the persistent storage don't matter ...
- String prefix = STANDARD_BUILT_IN_PREFIXES_BY_NAMESPACE.get(uri);
- if (prefix != null) return prefix;
+ if (behavior == Behavior.WORKSPACE) {
+ // Check the standard ones first, ensuring that invalid changes to the persistent storage don't matter ...
+ String prefix = STANDARD_BUILT_IN_PREFIXES_BY_NAMESPACE.get(uri);
+ if (prefix != null) return prefix;
+ }
// Now check the underlying registry ...
- prefix = registry.getPrefixForNamespaceUri(uri, false);
+ String prefix = registry.getPrefixForNamespaceUri(uri, false);
if (prefix == null) {
throw new NamespaceException(JcrI18n.noNamespaceWithUri.text(uri));
}
@@ -141,11 +160,13 @@
* @see javax.jcr.NamespaceRegistry#getURI(java.lang.String)
*/
public String getURI( String prefix ) throws NamespaceException, RepositoryException {
- // Check the standard ones first, ensuring that invalid changes to the persistent storage don't matter ...
- String uri = STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.get(prefix);
- if (uri != null) return uri;
+ if (behavior == Behavior.WORKSPACE) {
+ // Check the standard ones first, ensuring that invalid changes to the persistent storage don't matter ...
+ String uri = STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.get(prefix);
+ if (uri != null) return uri;
+ }
// Now check the underlying registry ...
- uri = registry.getNamespaceForPrefix(prefix);
+ String uri = registry.getNamespaceForPrefix(prefix);
if (uri == null) {
throw new NamespaceException(JcrI18n.noNamespaceWithPrefix.text(prefix));
}
@@ -176,17 +197,94 @@
String uri ) throws NamespaceException, RepositoryException {
CheckArg.isNotNull(prefix, "prefix");
CheckArg.isNotNull(uri, "uri");
+
+ switch (behavior) {
+ case JSR170_SESSION:
+ // ----------------------------------------------------------
+ // JSR-170 Session remapping behavior (see Section 6.3.3) ...
+ // ----------------------------------------------------------
+ // Section 6.3.3:
+ // "If existingUri is not registered in the NamespaceRegistry a NamespaceException will be thrown.
+ //
+ // If newPrefix is already locally mapped to existingUri (i.e., within this Session, by virtue
+ // of an earlier setNamespaceRegistry call) then this method returns silently and has no effect.
+ //
+ // If newPrefix is already locally mapped to a URI other than existingUri, then that URI reverts to its
+ // globally mapped prefix (as set in the NamespaceRegistry) and newPrefix is locally mapped to existingUri.
+ //
+ // If newPrefix is already assigned in the global NamespaceRegistry to otheruri (which differs from
+ // existingUri) and otherUri has not been locally mapped to another prefix which differs from newPrefix,
+ // then a NamespaceException will be thrown. In order to successfully locally map newPrefix to existingUri,
+ // otherUri must first be locally mapped to another prefix."
+
+ // The URI must already be registered ...
+ String existingPrefix = registry.getPrefixForNamespaceUri(uri, false);
+ if (existingPrefix == null) {
+ // Paragraph 1 ...
+ throw new NamespaceException(JcrI18n.unableToRemapUriNotRegisteredInNamespaceRegistry.text(prefix, uri));
+ }
+ if (existingPrefix.equals(prefix)) return; // Paragraph 2
+
+ // Is the prefix already used in a mapping ...
+ String existingUri = registry.getNamespaceForPrefix(prefix);
+ if (existingUri != null) {
+ // Is this existing mapping local, or is it in the global (workspace) registry?
+ String globalPrefix = workspaceRegistry.getPrefixForNamespaceUri(existingUri, false);
+ if (!prefix.equals(globalPrefix)) {
+ // Paragraph 3: The mapping is local to the session, so this local mapping should just be reverted ...
+ registry.unregister(existingUri);
+ }
+
+ // Paragraph 4: The mapping is global, so this is not allowed; the existing ...
+ String msg = JcrI18n.unableToRemapUriUsingPrefixUsedInNamespaceRegistry.text(prefix, uri, existingUri);
+ throw new NamespaceException(msg);
+ }
+
+ // Otherwise, the prefix is not already used in a mapping, so we can continue ...
+
+ break;
+
+ case JSR283_SESSION:
+ // --------------------------------------
+ // JSR-283 Session remapping behavior ...
+ // --------------------------------------
+ // Section 4.3.3 (of the Draft specification):
+ // "All local mappings already present in the Session that include either the specified prefix
+ // or the specified uri are removed and the new mapping is added."
+ String existingUriForPrefix = registry.getNamespaceForPrefix(prefix);
+ if (existingUriForPrefix != null) {
+ registry.unregister(existingUriForPrefix);
+ }
+ registry.unregister(uri);
+
+ break;
+
+ case WORKSPACE:
+ // --------------------------------------------------
+ // JSR-170 & JSR-283 Workspace namespace registry ...
+ // --------------------------------------------------
+
+ // Check the zero-length prefix and zero-length URI ...
+ if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) {
+ throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text());
+ }
+ // Check whether the prefix or URI are reserved (case-sensitive) ...
+ if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) {
+ throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespacePrefix.text(prefix, uri));
+ }
+ if (STANDARD_BUILT_IN_URIS.contains(uri)) {
+ throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespaceUri.text(prefix, uri));
+ }
+ break;
+ default:
+ assert false; // should never happen
+ }
+
// Check the zero-length prefix and zero-length URI ...
if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) {
throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text());
}
- // Check whether the prefix or URI are reserved (case-sensitive) ...
- if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) {
- throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespacePrefix.text(prefix, uri));
- }
- if (STANDARD_BUILT_IN_URIS.contains(uri)) {
- throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespaceUri.text(prefix, uri));
- }
+
// Check whether the prefix begins with 'xml' (in any case) ...
if (prefix.toLowerCase().startsWith(XML_NAMESPACE_PREFIX)) {
throw new NamespaceException(JcrI18n.unableToRegisterNamespaceUsingXmlPrefix.text(prefix, uri));
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -131,7 +131,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see javax.jcr.Property#getString()
*/
public String getString() throws RepositoryException {
@@ -163,8 +163,7 @@
* @see javax.jcr.Property#getValues()
*/
public Value[] getValues() throws ValueFormatException {
-
- return new Value[] {jcrValue};
+ throw new ValueFormatException();
}
/*
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-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -61,6 +61,7 @@
import org.jboss.dna.graph.property.UuidFactory;
import org.jboss.dna.graph.property.ValueFactories;
import org.jboss.dna.graph.property.basic.LocalNamespaceRegistry;
+import org.jboss.dna.jcr.JcrNamespaceRegistry.Behavior;
import org.xml.sax.ContentHandler;
import com.google.common.base.ReferenceType;
import com.google.common.collect.ReferenceMap;
@@ -93,7 +94,7 @@
/**
* The execution context for this session, which uses the {@link #sessionRegistry session's namespace registry}
*/
- private final ExecutionContext executionContext;
+ protected final ExecutionContext executionContext;
/**
* The graph representing this session, which uses the {@link #graph session's graph}.
@@ -123,9 +124,10 @@
this.workspace = workspace;
// Create an execution context for this session, which should use the local namespace registry ...
- NamespaceRegistry local = new LocalNamespaceRegistry(workspaceContext.getNamespaceRegistry());
+ NamespaceRegistry workspaceRegistry = workspaceContext.getNamespaceRegistry();
+ NamespaceRegistry local = new LocalNamespaceRegistry(workspaceRegistry);
this.executionContext = workspaceContext.with(local);
- this.sessionRegistry = new JcrNamespaceRegistry(local);
+ this.sessionRegistry = new JcrNamespaceRegistry(Behavior.JSR170_SESSION, local, workspaceRegistry);
// Set up the graph to use for this session (which uses the session's namespace registry and context) ...
this.graph = Graph.create(this.repository.getRepositorySourceName(),
@@ -425,10 +427,7 @@
populateNode(rootNode, graph.getNodeAt(executionContext.getValueFactories().getPathFactory().createRootPath()));
// Root nodes need to have a type in JCR land
- // JcrProperty primaryType = new JcrProperty(rootNode, getExecutionContext(), JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.BASE);
- String typeValue = JcrNtLexicon.BASE.getString(executionContext.getNamespaceRegistry());
- JcrProperty primaryType = new JcrProperty(rootNode, executionContext, JcrLexicon.PRIMARY_TYPE, typeValue);
-
+ JcrProperty primaryType = new JcrProperty(rootNode, executionContext, JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.BASE);
// TODO: Not liking the hard-code
rootNode.properties.add(primaryType);
@@ -603,7 +602,8 @@
if (uuid == null && DnaLexicon.UUID.equals(name)) uuid = uuidFactory.create(dnaProp.getValues()).next();
else if (jcrUuidName.equals(name)) dnaUuidProp = dnaProp;
else if (jcrMixinTypesName.equals(name)) {
- org.jboss.dna.graph.property.ValueFactory<String> stringFactory = executionContext.getValueFactories().getStringFactory();
+ org.jboss.dna.graph.property.ValueFactory<String> stringFactory = executionContext.getValueFactories()
+ .getStringFactory();
for (String mixin : stringFactory.create(dnaProp)) {
if ("mix:referenceable".equals(mixin)) referenceable = true;
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -65,7 +65,6 @@
import org.jboss.dna.graph.property.PropertyFactory;
import org.jboss.dna.graph.property.ValueFormatException;
import org.jboss.dna.graph.property.basic.GraphNamespaceRegistry;
-import org.jboss.dna.graph.property.basic.ThreadSafeNamespaceRegistry;
import org.xml.sax.ContentHandler;
/**
@@ -144,10 +143,9 @@
org.jboss.dna.graph.property.NamespaceRegistry persistentRegistry = new GraphNamespaceRegistry(namespaceGraph,
namespacesPath,
uriProperty, namespaceType);
- persistentRegistry = new ThreadSafeNamespaceRegistry(persistentRegistry);
this.context = context.with(persistentRegistry);
- // Set up and initialize the persistent (and thread-safe) JCR namespace registry ...
+ // Set up and initialize the persistent JCR namespace registry ...
this.workspaceRegistry = new JcrNamespaceRegistry(persistentRegistry);
// Now create a graph with this new execution context ...
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-02 20:03:51 UTC (rev 743)
@@ -44,6 +44,8 @@
unableToUnregisterReservedNamespacePrefix = Unable to unregister the namespace "{1}" with prefix "{0}" because this prefix is reserved
unableToUnregisterReservedNamespaceUri = Unable to unregister the namespace "{1}" with prefix "{0}" because this URI is reserved
unableToUnregisterPrefixForNamespaceThatIsNotRegistered = The namespace with prefix "{0}" is not registered and cannot be unregistered
+unableToRemapUriNotRegisteredInNamespaceRegistry = Unable to remap the namespace "{1}" to prefix "{0}" because the URI is not already registered in the workspace's namespace registry
+unableToRemapUriUsingPrefixUsedInNamespaceRegistry = Unable to remap the namespace "{1}" to prefix "{0}" because the prefix is already used as the prefix for the namespace "{2}" in the workspace's namespace registry
errorWhileInitializingTheNamespaceRegistry = Error while initializing the namespace registry for workspace "{0}"
invalidPathParameter = The "{1}" parameter value "{0}" was not a valid path
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -87,7 +87,7 @@
// addTestSuite(org.apache.jackrabbit.test.api.StringPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.UndefinedPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NamespaceRegistryReadMethodsTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.NamespaceRemappingTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.NamespaceRemappingTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NodeIteratorTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.PropertyReadMethodsTest.class);
addTestSuite(org.apache.jackrabbit.test.api.RepositoryDescriptorTest.class);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-03-02 17:40:37 UTC (rev 742)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-03-02 20:03:51 UTC (rev 743)
@@ -150,9 +150,9 @@
assertThat(registry.getURI(JcrLexicon.Namespace.PREFIX), is(JcrLexicon.Namespace.URI));
}
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowGetNodeTypeManager() throws Exception {
- workspace.getNodeTypeManager();
+ @Test
+ public void shouldGetNodeTypeManager() throws Exception {
+ assertThat(workspace.getNodeTypeManager(), is(notNullValue()));
}
@Test( expected = UnsupportedOperationException.class )
15 years, 2 months
DNA SVN: r742 - in trunk/dna-jcr/src: main/resources/org/jboss/dna/jcr and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-02 12:40:37 -0500 (Mon, 02 Mar 2009)
New Revision: 742
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrItemDefinition.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMixLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/OnParentVersionBehavior.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSvLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml
Log:
DNA-91 Implement node type management
Applied the patch, which is a good design for node type management.
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-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -26,6 +26,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -48,6 +49,7 @@
import javax.jcr.version.VersionHistory;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path.Segment;
@@ -225,8 +227,20 @@
* @throws UnsupportedOperationException always
* @see javax.jcr.Node#getMixinNodeTypes()
*/
- public NodeType[] getMixinNodeTypes() {
- throw new UnsupportedOperationException();
+ public NodeType[] getMixinNodeTypes() throws RepositoryException {
+ PropertyIterator mixinProperties = getProperties(JcrLexicon.MIXIN_TYPES.getString(session.getExecutionContext().getNamespaceRegistry()));
+ List<NodeType> mixinNodeTypes = new ArrayList<NodeType>((int)mixinProperties.getSize());
+
+ while (mixinProperties.hasNext()) {
+ Property property = mixinProperties.nextProperty();
+
+ String nodeTypeName = property.getValue().getString();
+ NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(nodeTypeName);
+
+ mixinNodeTypes.add(nodeType);
+ }
+
+ return mixinNodeTypes.toArray(new NodeType[mixinNodeTypes.size()]);
}
/**
@@ -308,8 +322,16 @@
* @throws UnsupportedOperationException always
* @see javax.jcr.Node#getPrimaryNodeType()
*/
- public NodeType getPrimaryNodeType() {
- throw new UnsupportedOperationException();
+ public NodeType getPrimaryNodeType() throws RepositoryException {
+ String primaryTypeName = JcrLexicon.PRIMARY_TYPE.getString(session.getExecutionContext().getNamespaceRegistry());
+ Property primaryNodeTypeProperty = getProperty(primaryTypeName);
+ Value nodeValue = primaryNodeTypeProperty.getValue();
+
+ ExecutionContext context = session.getExecutionContext();
+ Name nodeValueAsName = context.getValueFactories().getNameFactory().create(nodeValue.getString());
+
+ String nodeTypeName = nodeValueAsName.getString(context.getNamespaceRegistry());
+ return session.getWorkspace().getNodeTypeManager().getNodeType(nodeTypeName);
}
/**
@@ -324,12 +346,19 @@
/**
* {@inheritDoc}
*
- * @throws UnsupportedOperationException always
* @see javax.jcr.Node#getProperties(java.lang.String)
*/
- public PropertyIterator getProperties( String namePattern ) {
+ public PropertyIterator getProperties( String namePattern ) throws RepositoryException {
// TODO: Implement after changing impl to delegate to Graph API
- throw new UnsupportedOperationException();
+
+ // Implementing exact-matching only for now to prototype types as properties
+ Set<Property> matchingProps = new HashSet<Property>();
+ for (Property prop : properties) {
+ String propName = prop.getName();
+ if (propName.equals(namePattern)) matchingProps.add(prop);
+ }
+
+ return new JcrPropertyIterator(matchingProps);
}
/**
@@ -522,7 +551,20 @@
* @return <code>false</code>
* @see javax.jcr.Node#isNodeType(java.lang.String)
*/
- public boolean isNodeType( String nodeTypeName ) {
+ public boolean isNodeType( String nodeTypeName ) throws RepositoryException {
+ NodeType nodeType = getPrimaryNodeType();
+
+ if (nodeType.isNodeType(nodeTypeName)) {
+ return true;
+ }
+
+ NodeType[] mixinNodeTypes = getMixinNodeTypes();
+ for (int i = 0; i < mixinNodeTypes.length; i++) {
+ if (mixinNodeTypes[i].isNodeType(nodeTypeName)) {
+ return true;
+ }
+ }
+
return false;
}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,638 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.basic.BasicName;
+
+/**
+ * {@link JcrNodeTypeSource} that provides built-in node types per the 1.0 specification.
+ */
+@Immutable
+class JcrBuiltinNodeTypeSource implements JcrNodeTypeSource {
+
+ // Convenience constants to help improve readability
+ private static final Value[] NO_DEFAULT_VALUES = new Value[0];
+ private static final String[] NO_CONSTRAINTS = new String[0];
+ private static final List<NodeType> NO_SUPERTYPES = Collections.<NodeType>emptyList();
+ private static final List<JcrNodeDefinition> NO_CHILD_NODES = Collections.<JcrNodeDefinition>emptyList();
+ private static final List<JcrPropertyDefinition> NO_PROPERTIES = Collections.<JcrPropertyDefinition>emptyList();
+
+ // Indicates that the node type has no primary item name - added for readability
+ private static final Name NO_PRIMARY_ITEM_NAME = null;
+ // Indicates that the definition should apply to all property definition or child node definitions - added for readability
+ private static final Name ALL_NODES = null;
+
+ // Indicates whether or not the node type is a mixin - added for readability
+ private static final boolean IS_A_MIXIN = true;
+ private static final boolean NOT_MIXIN = false;
+
+ // Indicates whether or not the node type has orderable children - added for readability
+ private static final boolean ORDERABLE_CHILD_NODES = true;
+ private static final boolean UNORDERABLE_CHILD_NODES = false;
+
+ /** The list of primary node types. */
+ private final List<JcrNodeType> primaryNodeTypes;
+ /** The list of mixin node types. */
+ private final List<JcrNodeType> mixinNodeTypes;
+
+ JcrBuiltinNodeTypeSource( JcrSession session ) {
+ primaryNodeTypes = new ArrayList<JcrNodeType>();
+
+ Value trueValue = new JcrValue<Boolean>(session.getExecutionContext().getValueFactories(), PropertyType.BOOLEAN,
+ Boolean.TRUE);
+ Value ntBaseValue = new JcrValue<Name>(session.getExecutionContext().getValueFactories(), PropertyType.NAME,
+ JcrNtLexicon.BASE);
+
+ // Stubbing in child node and property definitions for now
+ JcrNodeType base = new JcrNodeType(session, JcrNtLexicon.BASE, NO_SUPERTYPES, NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.PRIMARY_TYPE,
+ OnParentVersionBehavior.COMPUTE.getJcrValue(), true,
+ true, true, NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.MIXIN_TYPES,
+ OnParentVersionBehavior.COMPUTE.getJcrValue(), false,
+ false, true, NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, true)}), NOT_MIXIN,
+ UNORDERABLE_CHILD_NODES);
+
+ // This needs to be declared early, as some of the primary types reference it
+ JcrNodeType referenceable = new JcrNodeType(
+ session,
+ JcrMixLexicon.REFERENCEABLE,
+ NO_SUPERTYPES,
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.UUID,
+ OnParentVersionBehavior.INITIALIZE.getJcrValue(),
+ true,
+ true,
+ true,
+ NO_DEFAULT_VALUES,
+ PropertyType.STRING,
+ NO_CONSTRAINTS,
+ false),}),
+ IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType childNodeDefinition = new JcrNodeType(
+ session,
+ JcrNtLexicon.CHILD_NODE_DEFINITION,
+ Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.AUTO_CREATED,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.DEFAULT_PRIMARY_TYPE,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false, NO_DEFAULT_VALUES,
+ PropertyType.NAME, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.MANDATORY,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.NAME,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false, NO_DEFAULT_VALUES,
+ PropertyType.NAME, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.ON_PARENT_VERSION,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.PROTECTED,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.REQUIRED_PRIMARY_TYPES,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false,
+ new Value[] {ntBaseValue},
+ PropertyType.NAME, NO_CONSTRAINTS, true),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.SAME_NAME_SIBLINGS,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false)}), NOT_MIXIN,
+ UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType hierarchyNode = new JcrNodeType(
+ session,
+ JcrNtLexicon.HIERARCHY_NODE,
+ Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.CREATED,
+ OnParentVersionBehavior.INITIALIZE.getJcrValue(),
+ true,
+ false,
+ true,
+ NO_DEFAULT_VALUES,
+ PropertyType.DATE,
+ NO_CONSTRAINTS,
+ false),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType file = new JcrNodeType(
+ session,
+ JcrNtLexicon.FILE,
+ Arrays.asList(new NodeType[] {hierarchyNode}),
+ JcrLexicon.CONTENT,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ session,
+ null,
+ JcrLexicon.CONTENT,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false,
+ false, null,
+ new NodeType[] {base})}),
+ NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType folder = new JcrNodeType(
+ session,
+ JcrNtLexicon.FOLDER,
+ Arrays.asList(new NodeType[] {hierarchyNode}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ session,
+ null,
+ null,
+ OnParentVersionBehavior.VERSION.getJcrValue(),
+ false,
+ false,
+ false,
+ false,
+ null,
+ new NodeType[] {hierarchyNode})}),
+ NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType frozenNode = new JcrNodeType(
+ session,
+ JcrNtLexicon.FROZEN_NODE,
+ Arrays.asList(new NodeType[] {base, referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ session,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false,
+ false,
+ true,
+ true,
+ null,
+ new NodeType[] {base})}),
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.FROZEN_MIXIN_TYPES,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false, false, true, NO_DEFAULT_VALUES,
+ PropertyType.NAME, NO_CONSTRAINTS, true),
+ new JcrPropertyDefinition(session, null, JcrLexicon.FROZEN_PRIMARY_TYPE,
+ OnParentVersionBehavior.ABORT.getJcrValue(), true,
+ true, true, NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.FROZEN_UUID,
+ OnParentVersionBehavior.ABORT.getJcrValue(), true,
+ true, true, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, ALL_NODES,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false, false, true, NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, ALL_NODES,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false, false, true, NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED, NO_CONSTRAINTS, true),}),
+ NOT_MIXIN, ORDERABLE_CHILD_NODES);
+
+ JcrNodeType linkedFile = new JcrNodeType(
+ session,
+ JcrNtLexicon.LINKED_FILE,
+ Arrays.asList(new NodeType[] {hierarchyNode}),
+ JcrLexicon.CONTENT,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.CONTENT,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false,
+ true,
+ false,
+ NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE,
+ NO_CONSTRAINTS,
+ false),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ // Had to be moved above nodeType due to dependency
+ JcrNodeType propertyDefinition = new JcrNodeType(
+ session,
+ JcrNtLexicon.PROPERTY_DEFINITION,
+ Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.AUTO_CREATED,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.DEFAULT_VALUES,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false, NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED, NO_CONSTRAINTS,
+ true),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.MANDATORY,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.MULTIPLE,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.NAME,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false, NO_DEFAULT_VALUES,
+ PropertyType.NAME, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.ON_PARENT_VERSION,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.PROTECTED,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS,
+ false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.REQUIRED_TYPE,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, false, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.VALUE_CONSTRAINTS,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS, true)}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType nodeType = new JcrNodeType(session, JcrNtLexicon.NODE_TYPE, Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME, Arrays.asList(new JcrNodeDefinition[] {
+ new JcrNodeDefinition(session, null, JcrLexicon.CHILD_NODE_DEFINITION,
+ OnParentVersionBehavior.VERSION.getJcrValue(), false,
+ false, false, true, JcrNtLexicon.CHILD_NODE_DEFINITION,
+ new NodeType[] {childNodeDefinition}),
+ new JcrNodeDefinition(session, null, JcrLexicon.PROPERTY_DEFINITION,
+ OnParentVersionBehavior.VERSION.getJcrValue(), false,
+ false, false, true, JcrNtLexicon.PROPERTY_DEFINITION,
+ new NodeType[] {propertyDefinition})}),
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.HAS_ORDERABLE_CHILD_NODES,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.IS_MIXIN,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ true, false, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.NODE_TYPE_NAME,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ true, false, NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.PRIMARY_ITEM_NAME,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ false, false, NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.SUPERTYPES,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ false, false, NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, true),}), NOT_MIXIN,
+ UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType query = new JcrNodeType(session, JcrNtLexicon.QUERY, Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.LANGUAGE,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ false, false, NO_DEFAULT_VALUES, PropertyType.STRING,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.STATEMENT,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ false, false, NO_DEFAULT_VALUES, PropertyType.STRING,
+ NO_CONSTRAINTS, false),}), NOT_MIXIN,
+ UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType resource = new JcrNodeType(session, JcrNtLexicon.RESOURCE,
+ Arrays.asList(new NodeType[] {base, referenceable}), JcrLexicon.DATA,
+ NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.DATA,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ true, false, NO_DEFAULT_VALUES, PropertyType.BINARY,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.ENCODING,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ false, false, NO_DEFAULT_VALUES,
+ PropertyType.STRING, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.LAST_MODIFIED,
+ OnParentVersionBehavior.IGNORE.getJcrValue(), false,
+ true, false, NO_DEFAULT_VALUES, PropertyType.DATE,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.MIME_TYPE,
+ OnParentVersionBehavior.COPY.getJcrValue(), false,
+ true, false, NO_DEFAULT_VALUES, PropertyType.STRING,
+ NO_CONSTRAINTS, false),}), NOT_MIXIN,
+ UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType unstructured = new JcrNodeType(
+ session,
+ JcrNtLexicon.UNSTRUCTURED,
+ Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ session,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.VERSION.getJcrValue(),
+ false,
+ false,
+ false,
+ true,
+ JcrNtLexicon.UNSTRUCTURED,
+ new NodeType[] {base}),}),
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, ALL_NODES,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false, NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, ALL_NODES,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, false, false, NO_DEFAULT_VALUES,
+ PropertyType.UNDEFINED, NO_CONSTRAINTS, true),}),
+ NOT_MIXIN, ORDERABLE_CHILD_NODES);
+
+ JcrNodeType version = new JcrNodeType(
+ session,
+ JcrNtLexicon.VERSION,
+ Arrays.asList(new NodeType[] {base, referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ session,
+ null,
+ JcrLexicon.FROZEN_NODE,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false,
+ false,
+ true,
+ false,
+ null,
+ new NodeType[] {frozenNode}),}),
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.CREATED,
+ OnParentVersionBehavior.ABORT.getJcrValue(), true,
+ true, true, NO_DEFAULT_VALUES, PropertyType.DATE,
+ NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.PREDECESSORS,
+ OnParentVersionBehavior.ABORT.getJcrValue(), false,
+ false, true, NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE, NO_CONSTRAINTS, true),
+ new JcrPropertyDefinition(session, null, JcrLexicon.SUCCESSORS,
+ OnParentVersionBehavior.ABORT.getJcrValue(), false,
+ false, true, NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE, NO_CONSTRAINTS, true),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType versionLabels = new JcrNodeType(
+ session,
+ JcrNtLexicon.VERSION_LABELS,
+ Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ session,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false,
+ false,
+ true,
+ NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE,
+ NO_CONSTRAINTS,
+ false),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType versionHistory = new JcrNodeType(
+ session,
+ JcrNtLexicon.VERSION_HISTORY,
+ Arrays.asList(new NodeType[] {base, referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {
+ new JcrNodeDefinition(session, null, JcrLexicon.ROOT_VERSION,
+ OnParentVersionBehavior.ABORT.getJcrValue(), true,
+ true, true, false, JcrNtLexicon.VERSION,
+ new NodeType[] {version}),
+ new JcrNodeDefinition(session, null, JcrLexicon.VERSION_LABELS,
+ OnParentVersionBehavior.ABORT.getJcrValue(), true,
+ true, true, false, JcrNtLexicon.VERSION_LABELS,
+ new NodeType[] {versionLabels}),
+ new JcrNodeDefinition(session, null, ALL_NODES,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false, false, true, false, JcrNtLexicon.VERSION,
+ new NodeType[] {version}),}),
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ session,
+ null,
+ JcrLexicon.VERSIONABLE_UUID,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ true,
+ true,
+ true,
+ NO_DEFAULT_VALUES,
+ PropertyType.STRING,
+ NO_CONSTRAINTS,
+ false),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ Name CHILD_VERSION_HISTORY = new BasicName(JcrLexicon.Namespace.URI, "childVersionHistory");
+ JcrNodeType versionedChild = new JcrNodeType(
+ session,
+ JcrNtLexicon.VERSIONED_CHILD,
+ Arrays.asList(new NodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ session,
+ null,
+ CHILD_VERSION_HISTORY,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ true,
+ true,
+ true,
+ NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE,
+ NO_CONSTRAINTS,
+ false),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ primaryNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {base, unstructured, childNodeDefinition, file, folder,
+ frozenNode, hierarchyNode, linkedFile, nodeType, propertyDefinition, query, resource, nodeType, version,
+ versionHistory, versionLabels, versionedChild}));
+
+ mixinNodeTypes = new ArrayList<JcrNodeType>();
+
+ JcrNodeType lockable = new JcrNodeType(session, JcrMixLexicon.LOCKABLE, NO_SUPERTYPES, NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.LOCK_IS_DEEP,
+ OnParentVersionBehavior.IGNORE.getJcrValue(), false,
+ false, true, NO_DEFAULT_VALUES,
+ PropertyType.BOOLEAN, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.LOCK_OWNER,
+ OnParentVersionBehavior.IGNORE.getJcrValue(), false,
+ false, true, NO_DEFAULT_VALUES, PropertyType.STRING,
+ NO_CONSTRAINTS, false)}), IS_A_MIXIN,
+ UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType versionable = new JcrNodeType(
+ session,
+ JcrMixLexicon.VERSIONABLE,
+ Arrays.asList(new NodeType[] {referenceable}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(session, null, JcrLexicon.BASE_VERSION,
+ OnParentVersionBehavior.IGNORE.getJcrValue(),
+ false, true, true, NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.IS_CHECKED_OUT,
+ OnParentVersionBehavior.IGNORE.getJcrValue(),
+ true, true, true, new Value[] {trueValue},
+ PropertyType.BOOLEAN, NO_CONSTRAINTS, false),
+ new JcrPropertyDefinition(session, null, JcrLexicon.MERGE_FAILED,
+ OnParentVersionBehavior.ABORT.getJcrValue(),
+ false, false, true, NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE, NO_CONSTRAINTS, true),
+ new JcrPropertyDefinition(session, null, JcrLexicon.PREDECESSORS,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, true, NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE, NO_CONSTRAINTS, true),
+ new JcrPropertyDefinition(session, null, JcrLexicon.VERSION_HISTORY,
+ OnParentVersionBehavior.COPY.getJcrValue(),
+ false, true, true, NO_DEFAULT_VALUES,
+ PropertyType.REFERENCE, NO_CONSTRAINTS, false),}),
+ IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ mixinNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {lockable, referenceable, versionable}));
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrNodeTypeSource#getMixinNodeTypes()
+ */
+ public Collection<JcrNodeType> getMixinNodeTypes() {
+ return mixinNodeTypes;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrNodeTypeSource#getPrimaryNodeTypes()
+ */
+ public Collection<JcrNodeType> getPrimaryNodeTypes() {
+ return primaryNodeTypes;
+ }
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -57,7 +57,9 @@
public static I18n errorWhileInitializingTheNamespaceRegistry;
public static I18n invalidPathParameter;
-
+
+ public static I18n typeNotFound;
+
public static I18n REP_NAME_DESC;
public static I18n REP_VENDOR_DESC;
public static I18n SPEC_NAME_DESC;
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrItemDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrItemDefinition.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrItemDefinition.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,122 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.NodeType;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.graph.property.Name;
+
+/**
+ * DNA implementation of the {@link ItemDefinition} interface. This implementation is immutable and has all fields initialized
+ * through its constructor.
+ */
+@Immutable
+class JcrItemDefinition implements ItemDefinition {
+
+ protected final JcrSession session;
+
+ private final NodeType declaringNodeType;
+ protected final Name name;
+ private final int onParentVersion;
+ private final boolean autoCreated;
+ private final boolean mandatory;
+ private final boolean protectedItem;
+
+ JcrItemDefinition( JcrSession session,
+ NodeType declaringNodeType,
+ Name name,
+ int onParentVersion,
+ boolean autoCreated,
+ boolean mandatory,
+ boolean protectedItem ) {
+ super();
+ this.session = session;
+ this.declaringNodeType = declaringNodeType;
+ this.name = name;
+ this.onParentVersion = onParentVersion;
+ this.autoCreated = autoCreated;
+ this.mandatory = mandatory;
+ this.protectedItem = protectedItem;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
+ */
+ public NodeType getDeclaringNodeType() {
+ return declaringNodeType;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.ItemDefinition#getName()
+ */
+ public String getName() {
+ if (name == null) {
+ return "*";
+ }
+
+ return name.getString(session.getExecutionContext().getNamespaceRegistry());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
+ */
+ public int getOnParentVersion() {
+ return onParentVersion;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
+ */
+ public boolean isAutoCreated() {
+ return autoCreated;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.ItemDefinition#isMandatory()
+ */
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.ItemDefinition#isProtected()
+ */
+ public boolean isProtected() {
+ return protectedItem;
+ }
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrItemDefinition.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -31,6 +31,48 @@
*/
class JcrLexicon extends org.jboss.dna.graph.JcrLexicon {
+ public static final Name AUTO_CREATED = new BasicName(Namespace.URI, "autoCreated");
+ public static final Name BASE_VERSION = new BasicName(Namespace.URI, "baseVersion");
+ public static final Name CHILD_NODE_DEFINITION = new BasicName(Namespace.URI, "childNodeDefinition");
+ public static final Name CONTENT = new BasicName(Namespace.URI, "content");
+ public static final Name CREATED = new BasicName(Namespace.URI, "created");
+ public static final Name DATA = new BasicName(Namespace.URI, "data");
+ public static final Name DEFAULT_PRIMARY_TYPE = new BasicName(Namespace.URI, "defaultPrimaryType");
+ public static final Name DEFAULT_VALUES = new BasicName(Namespace.URI, "defaultValues");
+ public static final Name ENCODING = new BasicName(Namespace.URI, "encoding");
+ public static final Name FROZEN_MIXIN_TYPES = new BasicName(Namespace.URI, "frozenMixinTypes");
+ public static final Name FROZEN_NODE = new BasicName(Namespace.URI, "frozenNode");
+ public static final Name FROZEN_PRIMARY_TYPE = new BasicName(Namespace.URI, "frozenPrimaryType");
+ public static final Name FROZEN_UUID = new BasicName(Namespace.URI, "frozenUuid");
+ public static final Name HAS_ORDERABLE_CHILD_NODES = new BasicName(Namespace.URI, "hasOrderableChildNodes");
+ public static final Name IS_CHECKED_OUT = new BasicName(Namespace.URI, "isCheckedOut");
+ public static final Name IS_MIXIN = new BasicName(Namespace.URI, "isMixin");
+ public static final Name LANGUAGE = new BasicName(Namespace.URI, "language");
+ public static final Name LAST_MODIFIED = new BasicName(Namespace.URI, "lastModified");
+ public static final Name LOCK_IS_DEEP = new BasicName(Namespace.URI, "lockIsDeep");
+ public static final Name LOCK_OWNER = new BasicName(Namespace.URI, "lockOwner");
+ public static final Name MANDATORY = new BasicName(Namespace.URI, "mandatory");
+ public static final Name MERGE_FAILED = new BasicName(Namespace.URI, "mergeFailed");
+ public static final Name MIME_TYPE = new BasicName(Namespace.URI, "mimeType");
+ public static final Name MULTIPLE = new BasicName(Namespace.URI, "multiple");
+ public static final Name NAME = new BasicName(Namespace.URI, "name");
+ public static final Name NODE_TYPE_NAME = new BasicName(Namespace.URI, "nodeTypeName");
+ public static final Name ON_PARENT_VERSION = new BasicName(Namespace.URI, "onParentVersion");
+ public static final Name PREDECESSORS = new BasicName(Namespace.URI, "predecessors");
+ public static final Name PRIMARY_ITEM_NAME = new BasicName(Namespace.URI, "primaryItemName");
+ public static final Name PROPERTY_DEFINITION = new BasicName(Namespace.URI, "propertyDefinition");
+ public static final Name PROTECTED = new BasicName(Namespace.URI, "protected");
+ public static final Name REQUIRED_PRIMARY_TYPES = new BasicName(Namespace.URI, "requiredPrimaryTypes");
+ public static final Name REQUIRED_TYPE = new BasicName(Namespace.URI, "requiredType");
+ public static final Name ROOT_VERSION = new BasicName(Namespace.URI, "rootVersion");
+ public static final Name SAME_NAME_SIBLINGS = new BasicName(Namespace.URI, "sameNameSiblings");
+ public static final Name STATEMENT = new BasicName(Namespace.URI, "statement");
+ public static final Name SUCCESSORS = new BasicName(Namespace.URI, "successors");
+ public static final Name SUPERTYPES = new BasicName(Namespace.URI, "supertypes");
public static final Name SYSTEM = new BasicName(Namespace.URI, "system");
+ public static final Name VALUE_CONSTRAINTS = new BasicName(Namespace.URI, "valueConstraints");
+ public static final Name VERSIONABLE_UUID = new BasicName(Namespace.URI, "versionableUuid");
+ public static final Name VERSION_HISTORY = new BasicName(Namespace.URI, "versionHistory");
+ public static final Name VERSION_LABELS = new BasicName(Namespace.URI, "versionLabels");
}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMixLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMixLexicon.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMixLexicon.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,5 @@
+package org.jboss.dna.jcr;
+
+public class JcrMixLexicon extends org.jboss.dna.graph.JcrMixLexicon {
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMixLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,124 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.graph.property.Name;
+
+/**
+ * DNA implementation of the {@link NodeDefinition} class.
+ */
+@Immutable
+class JcrNodeDefinition extends JcrItemDefinition implements NodeDefinition {
+
+ /** @see NodeDefinition#allowsSameNameSiblings() */
+ private final boolean allowsSameNameSiblings;
+
+ /**
+ * The name of the default primary type (if any). The name is used instead of the raw node type to allow circular references a
+ * la <code>nt:unstructured</code>.
+ */
+ private final Name defaultPrimaryTypeName;
+
+ /** @see NodeDefinition#getRequiredPrimaryTypes() */
+ private final NodeType[] requiredPrimaryTypes;
+
+ JcrNodeDefinition( JcrSession session,
+ NodeType declaringNodeType,
+ Name name,
+ int onParentVersion,
+ boolean autoCreated,
+ boolean mandatory,
+ boolean protectedItem,
+ boolean allowsSameNameSiblings,
+ Name defaultPrimaryTypeName,
+ NodeType[] requiredPrimaryTypes ) {
+ super(session, declaringNodeType, name, onParentVersion, autoCreated, mandatory, protectedItem);
+ this.allowsSameNameSiblings = allowsSameNameSiblings;
+ this.defaultPrimaryTypeName = defaultPrimaryTypeName;
+ this.requiredPrimaryTypes = requiredPrimaryTypes;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeDefinition#allowsSameNameSiblings()
+ */
+ public boolean allowsSameNameSiblings() {
+ return allowsSameNameSiblings;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeDefinition#getDefaultPrimaryType()
+ */
+ public NodeType getDefaultPrimaryType() {
+ // It is valid for this field to be null.
+ if (defaultPrimaryTypeName == null) {
+ return null;
+ }
+
+ /*
+ * Translate the name to a prefixed type based on the current transient (session) and persistent (workspace)
+ * prefix to URI mappings.
+ */
+ String mappedTypeName = defaultPrimaryTypeName.getString(session.getExecutionContext().getNamespaceRegistry());
+
+ try {
+ return session.getWorkspace().getNodeTypeManager().getNodeType(mappedTypeName);
+ } catch (RepositoryException re) {
+ /*
+ * The spec doesn't allow us to throw a checked exception at this point, but a corrupted namespace mapping
+ * would be pretty severe.
+ */
+ throw new IllegalStateException(JcrI18n.typeNotFound.text(mappedTypeName));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeDefinition#getRequiredPrimaryTypes()
+ */
+ public NodeType[] getRequiredPrimaryTypes() {
+ return requiredPrimaryTypes;
+ }
+
+ /**
+ * Creates a new <code>JcrNodeDefinition</code> that is identical to the current object, but with the given
+ * <code>declaringNodeType</code>. Provided to support immutable pattern for this class.
+ *
+ * @param declaringNodeType the declaring node type for the new <code>JcrNodeDefinition</code>
+ * @return a new <code>JcrNodeDefinition</code> that is identical to the current object, but with the given
+ * <code>declaringNodeType</code>.
+ */
+ JcrNodeDefinition with( NodeType declaringNodeType ) {
+ return new JcrNodeDefinition(session, declaringNodeType, name, getOnParentVersion(), isAutoCreated(), isMandatory(),
+ isProtected(), allowsSameNameSiblings(), defaultPrimaryTypeName, requiredPrimaryTypes);
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,598 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+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;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+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.ValueFormatException;
+import org.jboss.dna.graph.property.Path.Segment;
+
+/**
+ * DNA implementation of JCR {@link NodeType}s.
+ */
+@Immutable
+class JcrNodeType implements NodeType {
+
+ /** The name of the node type (e.g., <code>{http://www.jcp.org/jcr/nt/1.0}base</code>) */
+ private final Name name;
+ /** The name of the node's primary item */
+ private final Name primaryItemName;
+
+ /** The set of child node definitions for nodes of this type (possibly empty). */
+ private final Set<JcrNodeDefinition> childNodeDefinitions;
+ /** The set of property definitions for nodes of this type (possibly empty). */
+ private final Set<JcrPropertyDefinition> propertyDefinitions;
+ /** The supertypes for this node. */
+ private final List<NodeType> declaredSupertypes;
+
+ /** Indicates whether this node type is a mixin type (as opposed to a primary type). */
+ private boolean mixin;
+ /** Indicates whether the child nodes of nodes of this type can be ordered. */
+ private boolean orderableChildNodes;
+
+ /**
+ * A reference to the session in which this node type exists, used to remap the internal names to their appropriate prefixed
+ * version (e.g., <code>{http://www.jcp.org/jcr/nt/1.0}base</code> to <code>"nt:base"</code>.).
+ */
+ private JcrSession session;
+
+ JcrNodeType( JcrSession session,
+ Name name,
+ List<NodeType> declaredSupertypes,
+ Name primaryItemName,
+ Collection<JcrNodeDefinition> childNodeDefinitions,
+ Collection<JcrPropertyDefinition> propertyDefinitions,
+ boolean mixin,
+ boolean orderableChildNodes ) {
+ this.session = session;
+ this.name = name;
+ this.primaryItemName = primaryItemName;
+ this.declaredSupertypes = declaredSupertypes != null ? declaredSupertypes : Collections.<NodeType>emptyList();
+ this.mixin = mixin;
+ this.orderableChildNodes = orderableChildNodes;
+ this.propertyDefinitions = new HashSet<JcrPropertyDefinition>(propertyDefinitions.size());
+ for (JcrPropertyDefinition property : propertyDefinitions) {
+ this.propertyDefinitions.add(property.with(this));
+ }
+
+ this.childNodeDefinitions = new HashSet<JcrNodeDefinition>(childNodeDefinitions.size());
+ for (JcrNodeDefinition childNode : childNodeDefinitions) {
+ this.childNodeDefinitions.add(childNode.with(this));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#canAddChildNode(java.lang.String)
+ */
+ public boolean canAddChildNode( String childNodeName ) {
+
+ CheckArg.isNotNull(childNodeName, "childNodeName");
+
+ JcrNodeDefinition residual = null;
+
+ // First, try to find a child node definition with the given name
+ for (JcrNodeDefinition childNode : childNodeDefinitions) {
+ if (childNodeName.equals(childNode.getName())) {
+ NodeType defaultType = childNode.getDefaultPrimaryType();
+ // If there's no default type, the child node can't be created
+ if (defaultType == null) {
+ return false;
+ }
+
+ // Check if the node can be added with the named child node definition
+ return checkTypeAgainstDefinition(defaultType, childNode);
+ // If we run into a residual (*) definition, save it just in case
+ } else if (childNode.name == null) {
+ residual = childNode;
+ }
+ }
+
+ // If there's no matching child node definition for the name and no residual definition, the node cannot be added
+ if (residual == null) {
+ return false;
+ }
+
+ NodeType defaultType = residual.getDefaultPrimaryType();
+
+ // If there's no default type, the child node can't be created
+ if (defaultType == null) {
+ return false;
+ }
+
+ // Check if the node can be added with the default type of the residual child node definition
+ return checkTypeAgainstDefinition(defaultType, residual);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#canAddChildNode(java.lang.String, java.lang.String)
+ */
+ public boolean canAddChildNode( String childNodeName,
+ String primaryNodeTypeName ) {
+
+ CheckArg.isNotNull(childNodeName, "childNodeName");
+ CheckArg.isNotNull(primaryNodeTypeName, "primaryNodeTypeName");
+
+ NodeType primaryNodeType;
+ try {
+ primaryNodeType = session.getWorkspace().getNodeTypeManager().getNodeType(primaryNodeTypeName);
+ } catch (RepositoryException re) {
+ // If the node type doesn't exist, you can't add a child node with that type
+ return false;
+ }
+
+ JcrNodeDefinition residual = null;
+
+ // First, try to find a child node definition with the given name
+ for (JcrNodeDefinition childNode : childNodeDefinitions) {
+ if (childNodeName.equals(childNode.getName())) {
+ return checkTypeAgainstDefinition(primaryNodeType, childNode);
+ // If we run into a residual (*) definition, save it just in case
+ } else if (childNode.name == null) {
+ residual = childNode;
+ }
+ }
+
+ // If there's no matching child node definition for the name and no residual definition, the node cannot be added
+ if (residual == null) {
+ return false;
+ }
+
+ return checkTypeAgainstDefinition(primaryNodeType, residual);
+ }
+
+ /**
+ * Checks whether the given type is the same type or a subtype of each of the required primary types for the given node
+ * definition.
+ *
+ * @param typeToCheck the type to check
+ * @param definition the node definition to check against
+ * @return <code>true</code> if and only if the given type is the same type or extends each of the required primary types in
+ * the given definition
+ */
+ private boolean checkTypeAgainstDefinition( NodeType typeToCheck,
+ NodeDefinition definition ) {
+ NodeType[] requiredPrimaryTypes = definition.getRequiredPrimaryTypes();
+ for (int i = 0; i < requiredPrimaryTypes.length; i++) {
+ // See if the given type for the node matches all of the required primary types
+ if (!typeToCheck.isNodeType(requiredPrimaryTypes[i].getName())) {
+ return false;
+ }
+ }
+ // The node can be added with the given type based on the given child node definition
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#canRemoveItem(java.lang.String)
+ */
+ public boolean canRemoveItem( String itemName ) {
+ CheckArg.isNotNull(itemName, "itemName");
+
+ for (PropertyDefinition item : propertyDefinitions) {
+ if (itemName.equals(item.getName())) {
+ return !item.isMandatory() && !item.isProtected();
+ }
+ }
+
+ for (NodeDefinition item : childNodeDefinitions) {
+ if (itemName.equals(item.getName())) {
+ return !item.isMandatory() && !item.isProtected();
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#canSetProperty(java.lang.String, javax.jcr.Value)
+ */
+ public boolean canSetProperty( String propertyName,
+ Value value ) {
+ CheckArg.isNotNull(propertyName, "propertyName");
+
+ JcrPropertyDefinition residual = null;
+
+ for (JcrPropertyDefinition property : propertyDefinitions) {
+ if (propertyName.equals(property.getName())) {
+ if (property.isMultiple()) {
+ return false;
+ }
+
+ return canSetProperty(property, value);
+ } else if (property.name == null && !property.isMultiple()) {
+ residual = property;
+ }
+ }
+
+ return canSetProperty(residual, value);
+ }
+
+ /**
+ * Internal method to validate that a value can be set on a given property. The values are set according to the following
+ * rules:
+ * <ol>
+ * <li>If <code>value</code> is <code>null</code>, return the value of {@link JcrNodeType#canRemoveItem(String)}</li>
+ * <li>If <code>property.isProtected()</code> is <code>true</code>, return <code>false</code></li>
+ * <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 property the property to be set
+ * @param value the value to set (may be <code>null</code>)
+ * @return whether the property can be set to the value based on the described rules
+ */
+ private boolean canSetProperty( JcrPropertyDefinition property,
+ Value value ) {
+ assert property != null;
+
+ if (value == null) {
+ return !property.isProtected() && !property.isMandatory();
+ }
+
+ if (property.isProtected()) {
+ return false;
+ }
+
+ int valueType = value.getType();
+
+ switch (property.getRequiredType()) {
+ case PropertyType.BINARY:
+ return true;
+ case PropertyType.BOOLEAN:
+ if (valueType == PropertyType.BOOLEAN || valueType == PropertyType.STRING) {
+ return true;
+ }
+
+ // If the binary can be converted to a UTF-8 string, it can be set onto a boolean property
+ if (valueType == PropertyType.BINARY) {
+ try {
+ value.getString();
+ return true;
+ } catch (RepositoryException re) {
+ return false;
+ }
+ }
+ return false;
+
+ case PropertyType.DATE:
+ if (valueType == PropertyType.DATE || valueType == PropertyType.DOUBLE || valueType == PropertyType.LONG) {
+ return true;
+ }
+
+ if (valueType == PropertyType.STRING || valueType == PropertyType.BINARY) {
+ try {
+ value.getDate();
+ return true;
+ } catch (RepositoryException re) {
+ return false;
+ }
+ }
+ return false;
+
+ case PropertyType.DOUBLE:
+ return value.getType() == PropertyType.DOUBLE;
+ case PropertyType.LONG:
+ return value.getType() == PropertyType.LONG;
+ case PropertyType.NAME:
+ if (value.getType() == PropertyType.NAME) {
+ return true;
+ }
+
+ try {
+ if (valueType == PropertyType.STRING || valueType == PropertyType.BINARY) {
+ session.getExecutionContext().getValueFactories().getNameFactory().create(value.getString());
+ return true;
+ }
+
+ if (valueType == PropertyType.PATH) {
+ Path path = session.getExecutionContext().getValueFactories().getPathFactory().create(value.getString());
+
+ Segment[] segments = path.getSegmentsArray();
+ return !path.isAbsolute() && segments.length == 1 && !segments[0].hasIndex();
+ }
+ } catch (ValueFormatException re) {
+ return false;
+ } catch (RepositoryException re) {
+ return false;
+ }
+
+ return false;
+
+ case PropertyType.PATH:
+ return value.getType() == PropertyType.PATH || value.getType() == PropertyType.STRING;
+ case PropertyType.REFERENCE:
+ return value.getType() == PropertyType.REFERENCE;
+
+ // Anything can be converted to these types
+ case PropertyType.STRING:
+ case PropertyType.UNDEFINED:
+ return true;
+ default:
+ throw new IllegalStateException("Invalid required property type " + property.getRequiredType() + " for property "
+ + property.getName());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#canSetProperty(java.lang.String, javax.jcr.Value[])
+ */
+ public boolean canSetProperty( String propertyName,
+ Value[] values ) {
+ CheckArg.isNotNull(propertyName, "propertyName");
+
+ JcrPropertyDefinition residual = null;
+
+ for (JcrPropertyDefinition property : propertyDefinitions) {
+ if (propertyName.equals(property.getName())) {
+ if (!property.isMultiple()) {
+ return false;
+ }
+
+ return canSetProperty(property, values);
+ } else if (property.name == null && property.isMultiple()) {
+ residual = property;
+ }
+ }
+
+ return canSetProperty(residual, values);
+ }
+
+ /**
+ * Internal method to validate that an array of values can be set on a given property. This method returns <code>true</code>
+ * if the following algorithm would return <code>true</code> when applied to each non-null value in <code>values</code>:
+ * <ol>
+ * <li>If the value is null, return the value of {@link JcrNodeType#canRemoveItem(String)}</li>
+ * <li>If the property definition has a no required type ({@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</li>
+ * </ol>
+ *
+ * @param property the property to be set
+ * @param values the array of values to set (may be <code>null</code>)
+ * @return whether the property can be set to the value based on the described rules
+ */
+ private boolean canSetProperty( JcrPropertyDefinition property,
+ Value[] values ) {
+ if (values != null) {
+ for (int i = 0; i < values.length; i++) {
+ if (values[i] != null) {
+ if (!canSetProperty(property, values[i])) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return !property.isProtected();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getDeclaredChildNodeDefinitions()
+ */
+ public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+ return childNodeDefinitions.toArray(new JcrNodeDefinition[childNodeDefinitions.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getChildNodeDefinitions()
+ */
+ public NodeDefinition[] getChildNodeDefinitions() {
+ Set<NodeDefinition> nodeDefs = new HashSet<NodeDefinition>();
+ NodeType[] supertypes = getSupertypes();
+
+ // TODO: This could be cached after being calculated once
+ for (int i = 0; i < supertypes.length; i++) {
+ NodeDefinition[] childNodeDefinitions = supertypes[i].getChildNodeDefinitions();
+ for (int j = 0; j < childNodeDefinitions.length; i++) {
+
+ // TODO: Could add sanity check here (assertion?) that definitions of the same child node in multiple supertypes
+ // are consistent
+ nodeDefs.add(childNodeDefinitions[j]);
+ }
+ }
+
+ nodeDefs.addAll(childNodeDefinitions);
+
+ return nodeDefs.toArray(new JcrNodeDefinition[nodeDefs.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getPropertyDefinitions()
+ */
+ public PropertyDefinition[] getPropertyDefinitions() {
+ Set<PropertyDefinition> propDefs = new HashSet<PropertyDefinition>();
+ NodeType[] supertypes = getSupertypes();
+
+ // TODO: This could be cached after being calculated once
+ for (int i = 0; i < supertypes.length; i++) {
+ PropertyDefinition[] childPropertyDefinitions = supertypes[i].getPropertyDefinitions();
+ for (int j = 0; j < childPropertyDefinitions.length; j++) {
+
+ // TODO: Could add sanity check here (assertion?) that definitions of the same child node in multiple supertypes
+ // are consistent
+ propDefs.add(childPropertyDefinitions[j]);
+ }
+ }
+ propDefs.addAll(propertyDefinitions);
+
+ return propDefs.toArray(new JcrPropertyDefinition[propDefs.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getDeclaredSupertypes()
+ */
+ public NodeType[] getDeclaredSupertypes() {
+ return declaredSupertypes.toArray(new NodeType[declaredSupertypes.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getName()
+ */
+ public String getName() {
+ // Translate the name to the correct prefix. Need to check the session to support url-remapping.
+ return name.getString(session.getExecutionContext().getNamespaceRegistry());
+ }
+
+ /**
+ * Returns the internal {@link Name} object for the note type. This method exists outside the JCR API and should not be
+ * exposed outside of the package.
+ *
+ * @return the internal {@link Name} object for the note type.
+ */
+ Name getInternalName() {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getPrimaryItemName()
+ */
+ public String getPrimaryItemName() {
+ if (primaryItemName == null) {
+ return null;
+ }
+
+ // Translate the name to the correct prefix. Need to check the session to support url-remapping.
+ return primaryItemName.getString(session.getExecutionContext().getNamespaceRegistry());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getDeclaredPropertyDefinitions()
+ */
+ public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+ return propertyDefinitions.toArray(new JcrPropertyDefinition[propertyDefinitions.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#getSupertypes()
+ */
+ public NodeType[] getSupertypes() {
+ Set<NodeType> supertypes = new HashSet<NodeType>();
+ Stack<NodeType> unvisitedSupertypes = new Stack<NodeType>();
+
+ assert declaredSupertypes != null;
+ unvisitedSupertypes.addAll(declaredSupertypes);
+
+ // TODO: If this ends up getting called frequently, it should probably be executed once in the constructor and have the
+ // results cached.
+ while (!unvisitedSupertypes.isEmpty()) {
+ NodeType nodeType = unvisitedSupertypes.pop();
+
+ /*
+ * If we haven't already visited this nodeType (which we can
+ * infer by whether or not it was already added to the return set),
+ * then add the supertypes of this new node to the unvisited set for
+ * further inspection.
+ */
+ if (!supertypes.contains(nodeType)) {
+ supertypes.add(nodeType);
+ // Violating encapsulation to avoid going from List to array back to List
+ unvisitedSupertypes.addAll(((JcrNodeType)nodeType).declaredSupertypes);
+ }
+ }
+
+ return supertypes.toArray(new NodeType[0]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#hasOrderableChildNodes()
+ */
+ public boolean hasOrderableChildNodes() {
+ return orderableChildNodes;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#isMixin()
+ */
+ public boolean isMixin() {
+ return mixin;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeType#isNodeType(java.lang.String)
+ */
+ public boolean isNodeType( String nodeTypeName ) {
+ if (this.getName().equals(nodeTypeName)) return true;
+
+ // TODO: This could be optimized
+ NodeType[] supertypes = getSupertypes();
+ for (int i = 0; i < supertypes.length; i++) {
+ if (supertypes[i].isNodeType(nodeTypeName)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeType.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeIterator.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeIterator.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,118 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
+import net.jcip.annotations.Immutable;
+
+/**
+ * Type-safe {@link Iterator} implementation for NodeTypes, as per the JCR specification.
+ */
+@Immutable
+final class JcrNodeTypeIterator implements NodeTypeIterator {
+
+ private int size;
+ private int position;
+ private Iterator<NodeType> iterator;
+
+ JcrNodeTypeIterator( Collection<? extends NodeType> values ) {
+ this.iterator = Collections.unmodifiableCollection(values).iterator();
+ this.size = values.size();
+ this.position = 0;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeTypeIterator#nextNodeType()
+ */
+ public NodeType nextNodeType() {
+ // TODO: Does this really need to return a copy of the node type to prevent manipulation?
+ position++;
+ return iterator.next();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return position;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long count ) {
+ position += count;
+ while (count-- > 0)
+ iterator.next();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ position++;
+ return iterator.next();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException("Node types cannot be removed through their iterator");
+ }
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,28 @@
+package org.jboss.dna.jcr;
+
+import java.util.Collection;
+import javax.jcr.nodetype.NodeType;
+
+/**
+ * Interface for any potential provider of {@link JcrNodeType} definitions, the DNA implementation of {@link NodeType}. Possible
+ * sources of node type definitions include CND files, repository metadata, and mock types for testing.
+ *
+ * @see JcrWorkspace#getNodeTypeManager()
+ */
+public interface JcrNodeTypeSource {
+
+ /**
+ * Returns the list of primary node types provided by this source
+ *
+ * @return the list of primary node types provided by this source
+ */
+ public Collection<JcrNodeType> getPrimaryNodeTypes();
+
+ /**
+ * Returns the list of mixin node types provided by this source
+ *
+ * @return the list of mixin node types provided by this source
+ */
+ public Collection<JcrNodeType> getMixinNodeTypes();
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,43 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.basic.BasicName;
+
+public class JcrNtLexicon extends org.jboss.dna.graph.JcrNtLexicon {
+
+ public static final Name CHILD_NODE_DEFINITION = new BasicName(Namespace.URI, "childNodeDefinition");
+ public static final Name FROZEN_NODE = new BasicName(Namespace.URI, "frozenNode");
+ public static final Name HIERARCHY_NODE = new BasicName(Namespace.URI, "hierarchyNode");
+ public static final Name LINKED_FILE = new BasicName(Namespace.URI, "linkedFile");
+ public static final Name NODE_TYPE = new BasicName(Namespace.URI, "nodeType");
+ public static final Name PROPERTY_DEFINITION = new BasicName(Namespace.URI, "propertyDefinition");
+ public static final Name QUERY = new BasicName(Namespace.URI, "query");
+ public static final Name VERSION = new BasicName(Namespace.URI, "version");
+ public static final Name VERSIONED_CHILD = new BasicName(Namespace.URI, "versionedChild");
+ public static final Name VERSION_HISTORY = new BasicName(Namespace.URI, "versionHistory");
+ public static final Name VERSION_LABELS = new BasicName(Namespace.URI, "versionLabels");
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -131,7 +131,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see javax.jcr.Property#getString()
*/
public String getString() throws RepositoryException {
@@ -163,7 +163,8 @@
* @see javax.jcr.Property#getValues()
*/
public Value[] getValues() throws ValueFormatException {
- throw new ValueFormatException();
+
+ return new Value[] {jcrValue};
}
/*
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,112 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.graph.property.Name;
+
+
+/**
+ * DNA implementation of the {@link PropertyDefinition} interface. This implementation is immutable and has all fields initialized
+ * through its constructor.
+ */
+@Immutable
+class JcrPropertyDefinition extends JcrItemDefinition implements PropertyDefinition {
+
+ private final Value[] defaultValues;
+ private final int requiredType;
+ private final String[] valueConstraints;
+ private final boolean multiple;
+
+ JcrPropertyDefinition( JcrSession session,
+ NodeType declaringNodeType,
+ Name name,
+ int onParentVersion,
+ boolean autoCreated,
+ boolean mandatory,
+ boolean protectedItem,
+ Value[] defaultValues,
+ int requiredType,
+ String[] valueConstraints,
+ boolean multiple ) {
+ super(session, declaringNodeType, name, onParentVersion, autoCreated, mandatory, protectedItem);
+ this.defaultValues = defaultValues;
+ this.requiredType = requiredType;
+ this.valueConstraints = valueConstraints;
+ this.multiple = multiple;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues()
+ */
+ public Value[] getDefaultValues() {
+ return defaultValues;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.PropertyDefinition#getRequiredType()
+ */
+ public int getRequiredType() {
+ return requiredType;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.PropertyDefinition#getValueConstraints()
+ */
+ public String[] getValueConstraints() {
+ return valueConstraints;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.PropertyDefinition#isMultiple()
+ */
+ public boolean isMultiple() {
+ return multiple;
+ }
+
+ /**
+ * Creates a new <code>JcrPropertyDefinition</code> that is identical to the current object, but with the given
+ * <code>declaringNodeType</code>. Provided to support immutable pattern for this class.
+ *
+ * @param declaringNodeType the declaring node type for the new <code>JcrPropertyDefinition</code>
+ * @return a new <code>JcrPropertyDefinition</code> that is identical to the current object, but with the given
+ * <code>declaringNodeType</code>.
+ */
+ JcrPropertyDefinition with( NodeType declaringNodeType ) {
+ return new JcrPropertyDefinition(this.session, declaringNodeType, this.name, this.getOnParentVersion(),
+ this.isAutoCreated(), this.isMandatory(), this.isProtected(), this.getDefaultValues(),
+ this.getRequiredType(), this.getValueConstraints(), this.isMultiple());
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -27,19 +27,23 @@
import java.util.Set;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
+import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
/**
* @author jverhaeg
*/
+@Immutable
final class JcrPropertyIterator implements PropertyIterator {
private final Iterator<Property> iterator;
private int ndx;
+ private int size;
JcrPropertyIterator( Set<Property> properties ) {
assert properties != null;
iterator = properties.iterator();
+ size = properties.size();
}
/**
@@ -54,11 +58,10 @@
/**
* {@inheritDoc}
*
- * @return -1L
* @see javax.jcr.RangeIterator#getSize()
*/
public long getSize() {
- return -1L;
+ return size;
}
/**
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-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -423,6 +423,15 @@
rootNode = new JcrRootNode(this);
// Get root node from source
populateNode(rootNode, graph.getNodeAt(executionContext.getValueFactories().getPathFactory().createRootPath()));
+
+ // Root nodes need to have a type in JCR land
+ // JcrProperty primaryType = new JcrProperty(rootNode, getExecutionContext(), JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.BASE);
+ String typeValue = JcrNtLexicon.BASE.getString(executionContext.getNamespaceRegistry());
+ JcrProperty primaryType = new JcrProperty(rootNode, executionContext, JcrLexicon.PRIMARY_TYPE, typeValue);
+
+ // TODO: Not liking the hard-code
+ rootNode.properties.add(primaryType);
+
return rootNode;
}
@@ -594,8 +603,7 @@
if (uuid == null && DnaLexicon.UUID.equals(name)) uuid = uuidFactory.create(dnaProp.getValues()).next();
else if (jcrUuidName.equals(name)) dnaUuidProp = dnaProp;
else if (jcrMixinTypesName.equals(name)) {
- org.jboss.dna.graph.property.ValueFactory<String> stringFactory = executionContext.getValueFactories()
- .getStringFactory();
+ org.jboss.dna.graph.property.ValueFactory<String> stringFactory = executionContext.getValueFactories().getStringFactory();
for (String mixin : stringFactory.create(dnaProp)) {
if ("mix:referenceable".equals(mixin)) referenceable = true;
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSvLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSvLexicon.java 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSvLexicon.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -4,13 +4,13 @@
* 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.
+ * 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
@@ -23,9 +23,11 @@
*/
package org.jboss.dna.jcr;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.basic.BasicName;
/**
- * @author Randall Hauch
+ *
*/
public class JcrSvLexicon {
@@ -34,4 +36,9 @@
public static final String PREFIX = "sv";
}
+ public static final Name NODE = new BasicName(Namespace.URI, "node");
+ public static final Name PROPERTY = new BasicName(Namespace.URI, "property");
+ public static final Name NAME = new BasicName(Namespace.URI, "name");
+ public static final Name TYPE = new BasicName(Namespace.URI, "type");
+ public static final Name VALUE = new BasicName(Namespace.URI, "value");
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -25,6 +25,10 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jcr.AccessDeniedException;
@@ -37,11 +41,15 @@
import javax.jcr.Workspace;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
import javax.jcr.nodetype.NodeTypeManager;
import javax.jcr.observation.ObservationManager;
import javax.jcr.query.QueryManager;
import javax.jcr.version.Version;
import javax.jcr.version.VersionException;
+import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -64,6 +72,7 @@
* @author John Verhaeg
* @author Randall Hauch
*/
+@NotThreadSafe
final class JcrWorkspace implements Workspace {
/**
@@ -101,10 +110,16 @@
private final JcrNamespaceRegistry workspaceRegistry;
/**
+ * Reference to the JCR type manager for this workspace.
+ */
+ private final NodeTypeManager nodeTypeManager;
+
+ /**
* The {@link Session} instance that this corresponds with this workspace.
*/
private final JcrSession session;
+ @SuppressWarnings( "synthetic-access" )
JcrWorkspace( JcrRepository repository,
String workspaceName,
ExecutionContext context,
@@ -141,6 +156,10 @@
// Set up the session for this workspace ...
this.session = new JcrSession(this.repository, this, this.context, sessionAttributes);
+
+ // This must be initialized after the session
+ this.nodeTypeManager = new JcrNodeTypeManager(new JcrBuiltinNodeTypeSource(this.session));
+
}
String getSourceName() {
@@ -186,7 +205,7 @@
* {@inheritDoc}
*/
public NodeTypeManager getNodeTypeManager() {
- throw new UnsupportedOperationException();
+ return nodeTypeManager;
}
/**
@@ -331,4 +350,96 @@
boolean removeExisting ) {
throw new UnsupportedOperationException();
}
+
+ /**
+ * Local implementation of @{link NodeTypeManager}. Initialized with {@link NodeType} source data when it is created (in the
+ * {@link JcrWorkspace} constructor.
+ */
+ @NotThreadSafe
+ private class JcrNodeTypeManager implements NodeTypeManager {
+
+ private final Map<Name, JcrNodeType> primaryNodeTypes;
+ private final Map<Name, JcrNodeType> mixinNodeTypes;
+
+ private JcrNodeTypeManager( JcrNodeTypeSource source ) {
+ Collection<JcrNodeType> primary = source.getPrimaryNodeTypes();
+ Collection<JcrNodeType> mixins = source.getMixinNodeTypes();
+
+ primaryNodeTypes = new HashMap<Name, JcrNodeType>(primary.size());
+ for (JcrNodeType nodeType : primary) {
+ primaryNodeTypes.put(nodeType.getInternalName(), nodeType);
+ }
+
+ mixinNodeTypes = new HashMap<Name, JcrNodeType>(mixins.size());
+ for (JcrNodeType nodeType : mixins) {
+ mixinNodeTypes.put(nodeType.getInternalName(), nodeType);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeTypeManager#getAllNodeTypes()
+ */
+ public NodeTypeIterator getAllNodeTypes() {
+
+ // TODO: Can revisit this approach later if it becomes a performance issue
+ /*
+ * Note also that this creates a subtle difference in behavior for concurrent modification
+ * between this method and the specific get*NodeTypes methods. That is, if a type is added
+ * while an iterator from the corresponding specific get*NodeType method is being traversed,
+ * a ConcurrentModificationException will be thrown. Because this iterator is based on a copy
+ * of the underlying maps, no exception would be thrown in the same case.
+ */
+
+ List<NodeType> allTypes = new ArrayList<NodeType>(primaryNodeTypes.size() + mixinNodeTypes.size());
+ allTypes.addAll(primaryNodeTypes.values());
+ allTypes.addAll(mixinNodeTypes.values());
+ return new JcrNodeTypeIterator(allTypes);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeTypeManager#getMixinNodeTypes()
+ */
+ public NodeTypeIterator getMixinNodeTypes() {
+ return new JcrNodeTypeIterator(mixinNodeTypes.values());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeTypeManager#getNodeType(java.lang.String)
+ */
+ @SuppressWarnings( "synthetic-access" )
+ public NodeType getNodeType( String nodeTypeName ) throws NoSuchNodeTypeException, RepositoryException {
+ Name ntName = session.getExecutionContext().getValueFactories().getNameFactory().create(nodeTypeName);
+
+ NodeType nodeType = primaryNodeTypes.get(ntName);
+
+ if (nodeType != null) {
+ return nodeType;
+ }
+
+ nodeType = mixinNodeTypes.get(ntName);
+
+ if (nodeType != null) {
+ return nodeType;
+ }
+
+ throw new NoSuchNodeTypeException(JcrI18n.typeNotFound.text(nodeTypeName));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.nodetype.NodeTypeManager#getPrimaryNodeTypes()
+ */
+ public NodeTypeIterator getPrimaryNodeTypes() {
+ return new JcrNodeTypeIterator(primaryNodeTypes.values());
+ }
+
+ }
+
}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/OnParentVersionBehavior.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/OnParentVersionBehavior.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/OnParentVersionBehavior.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -0,0 +1,71 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import javax.jcr.version.OnParentVersionAction;
+
+/**
+ * Enumeration of possible behaviors for on-parent-version setting of properties and child nodes in JCR specification.
+ */
+public enum OnParentVersionBehavior {
+ /** @see OnParentVersionAction#ABORT */
+ ABORT(OnParentVersionAction.ABORT, OnParentVersionAction.ACTIONNAME_ABORT),
+ /** @see OnParentVersionAction#COMPUTE */
+ COMPUTE(OnParentVersionAction.COMPUTE, OnParentVersionAction.ACTIONNAME_COMPUTE),
+ /** @see OnParentVersionAction#COPY */
+ COPY(OnParentVersionAction.COPY, OnParentVersionAction.ACTIONNAME_COPY),
+ /** @see OnParentVersionAction#IGNORE */
+ IGNORE(OnParentVersionAction.IGNORE, OnParentVersionAction.ACTIONNAME_IGNORE),
+ /** @see OnParentVersionAction#INITIALIZE */
+ INITIALIZE(OnParentVersionAction.INITIALIZE, OnParentVersionAction.ACTIONNAME_INITIALIZE),
+ /** @see OnParentVersionAction#VERSION */
+ VERSION(OnParentVersionAction.VERSION, OnParentVersionAction.ACTIONNAME_VERSION);
+
+ private final int jcrValue;
+ private final String name;
+
+ OnParentVersionBehavior( int jcrValue,
+ String name ) {
+ this.jcrValue = jcrValue;
+ this.name = name;
+ }
+
+ public int getJcrValue() {
+ return jcrValue;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static OnParentVersionBehavior fromValue( int onParentVersionAction ) {
+ for (OnParentVersionBehavior opvb : OnParentVersionBehavior.values()) {
+ if (opvb.jcrValue == onParentVersionAction) {
+ return opvb;
+ }
+ }
+
+ throw new IllegalStateException("No matching version for value: " + onParentVersionAction);
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/OnParentVersionBehavior.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-02 17:40:37 UTC (rev 742)
@@ -55,4 +55,5 @@
errorObtainingWorkspaceNames = Error while obtaining the workspace names for the "{0}" repository: {1}
errorObtainingDefaultWorkspaceName = Error while obtaining the default workspace names for the "{0}" repository: {1}
workspaceNameIsInvalid = "{1}" is not a valid workspace name for the "{0}" repository
-errorVerifyingWorkspaceName = Error validating the workspace name "{1}" for the "{0}" repository: {2}
\ No newline at end of file
+errorVerifyingWorkspaceName =Error validating the workspace name "{1}" for the "{0}" repository\: {2}
+typeNotFound=No type exists with name "{0}"
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java 2009-03-02 17:40:37 UTC (rev 742)
@@ -63,7 +63,7 @@
properties.add(Mockito.mock(Property.class));
PropertyIterator iter = node.getProperties();
assertThat(iter, notNullValue());
- assertThat(iter.getSize(), is(-1L));
+ assertThat(iter.getSize(), is(4L));
assertThat(iter.getPosition(), is(0L));
assertThat(iter.hasNext(), is(true));
assertThat(iter.next(), notNullValue());
Modified: trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml 2009-03-02 00:30:52 UTC (rev 741)
+++ trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml 2009-03-02 17:40:37 UTC (rev 742)
@@ -24,9 +24,11 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<testroot xmlns:jcr="http://www.jcp.org/jcr/1.0">
- <node jcr:name="node1" prop1="foo" />
- <node jcr:name="node2" prop2="bar" />
- <node jcr:name="node3" />
- <node jcr:name="node4" />
+<testroot xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:primaryType="nt:unstructured">
+ <nt:unstructured jcr:name="node1" jcr:primaryType="nt:unstructured" prop1="foo" />
+ <nt:unstructured jcr:name="node2" jcr:primaryType="nt:unstructured" prop2="bar" />
+ <nt:unstructured jcr:name="node3" jcr:primaryType="nt:unstructured" />
+ <nt:unstructured jcr:name="node4" jcr:primaryType="nt:unstructured" />
</testroot>
\ No newline at end of file
15 years, 2 months
DNA SVN: r741 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-03-01 19:30:52 -0500 (Sun, 01 Mar 2009)
New Revision: 741
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
CreateNodeRequest - add folder and file in a svn repos.
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-03-02 00:28:30 UTC (rev 740)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-03-02 00:30:52 UTC (rev 741)
@@ -158,7 +158,7 @@
request.setError(ex);
} else if (rootKind == SVNNodeKind.DIR) {
Collection<Property> childNodeProperties = request.properties();
- Object[] objs = organizeThings(childNodeProperties);
+ Object[] objs = values(childNodeProperties);
for (Object object : objs) {
if (object instanceof Name && ((Name)object).compareTo(JcrNtLexicon.FOLDER) == 0) {
// process folder creation
@@ -880,7 +880,7 @@
return content;
}
- private Object[] organizeThings( Collection<Property> childNodeProperties ) {
+ private Object[] values( Collection<Property> childNodeProperties ) {
Set<Object> result = new HashSet<Object>();
for (Property property : childNodeProperties) {
result.add(property.getFirstValue());
15 years, 2 months
DNA SVN: r740 - trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-03-01 19:28:30 -0500 (Sun, 01 Mar 2009)
New Revision: 740
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
Log:
CreateNodeRequest - add folder and file in a svn repos.
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-03-02 00:23:52 UTC (rev 739)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-03-02 00:28:30 UTC (rev 740)
@@ -284,6 +284,18 @@
SVNNodeKind nodeC1Kind = repository.checkPath("nodeC/nodeC_1", -1);
assertThat(nodeC1Kind, is(SVNNodeKind.DIR));
+ byte[] content1 = "My content".getBytes();
+ Property jcrDataProperty = propertyFactory().create(JcrLexicon.DATA, binaryFactory().create(content1));
+ graph.batch().create("/nodeC/nodeC_1/file1.txt").with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE)).and(propertyFactory().create(JcrLexicon.CREATED,
+ new Date())).and(jcrDataProperty).execute();
+
+ // Look up the file
+ Node nodeC1 = graph.getNodeAt("/nodeC/nodeC_1");
+ assertThat(nodeC1, is(notNullValue()));
+ assertThat(nodeC1.getChildren().size(), is(1));
+ SVNNodeKind fileKind = repository.checkPath("/nodeC/nodeC_1/file1.txt", -1);
+ assertThat(fileKind, is(SVNNodeKind.FILE));
+
}
protected Collection<String> containsPaths( Collection<Location> locations ) {
15 years, 2 months
DNA SVN: r739 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-03-01 19:23:52 -0500 (Sun, 01 Mar 2009)
New Revision: 739
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
CreateNodeRequest - add folder and file in a svn repos.
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-02-27 22:21:50 UTC (rev 738)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-03-02 00:23:52 UTC (rev 739)
@@ -23,11 +23,14 @@
*/
package org.jboss.dna.connector.svn;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.connector.scm.ScmAction;
@@ -73,6 +76,7 @@
import org.tmatesoft.svn.core.SVNProperty;
import org.tmatesoft.svn.core.io.ISVNEditor;
import org.tmatesoft.svn.core.io.SVNRepository;
+import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
/**
* The {@link RequestProcessor} implementation for the file subversion repository connector. This is the class that does the bulk
@@ -128,6 +132,7 @@
public void process( CreateNodeRequest request ) {
logger.trace(request.toString());
verifyUpdatesAllowed();
+ // get the parent location of the new node
Location myLocation = request.under();
Path parent = getPathFor(myLocation, request);
try {
@@ -152,18 +157,29 @@
SVNException ex = new SVNException(err);
request.setError(ex);
} else if (rootKind == SVNNodeKind.DIR) {
-
- // TODO if node is a file
-
- // if the node is a directory
- String childName = request.named().getString(getExecutionContext().getNamespaceRegistry());
- if (root.length() == 1 && root.charAt(0) == '/') {
- // test if so a directory does not exist.
- mkdir("", childName, request.toString());
- } else {
- if (root.length() > 1 && root.charAt(0) == '/') {
- // test if so a directory does not exist.
- mkdir(root.substring(1), childName, request.toString());
+ Collection<Property> childNodeProperties = request.properties();
+ Object[] objs = organizeThings(childNodeProperties);
+ for (Object object : objs) {
+ if (object instanceof Name && ((Name)object).compareTo(JcrNtLexicon.FOLDER) == 0) {
+ // process folder creation
+ // if the node is a directory
+ String folderName = request.named().getString(getExecutionContext().getNamespaceRegistry());
+ if (root.length() == 1 && root.charAt(0) == '/') {
+ // test if so a directory does not exist.
+ mkdir("", folderName, request.toString());
+ } else {
+ if (root.length() > 1 && root.charAt(0) == '/') {
+ // test if so a directory does not exist.
+ mkdir(root.substring(1), folderName, request.toString());
+ }
+ }
+ } else if (object instanceof Name && ((Name)object).compareTo(JcrNtLexicon.FILE) == 0) {
+ String fileName = request.named().getString(getExecutionContext().getNamespaceRegistry());
+ byte[] content = getContent(objs);
+ // TODO: what is with the created on
+ // Date createdOn = getCreatedOn(objs);
+ // commit in to the repository
+ newFile(root, fileName, content, request.toString());
}
}
}
@@ -710,6 +726,28 @@
}
/**
+ * Create a file.
+ * @param path
+ * @param file
+ * @param content
+ * @param message
+ * @throws SVNException
+ */
+ private void newFile( String path,
+ String file,
+ byte[] content, String message ) throws SVNException {
+ SVNNodeKind childKind = repository.checkPath(file, -1);
+ if (childKind == SVNNodeKind.NONE) {
+ ScmAction addFileNodeAction = addFile(path, file, content);
+ SVNActionExecutor executor = new SVNActionExecutor(repository);
+ executor.execute(addFileNodeAction,message);
+ } else {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "Item with name '{0}' can't be created (already exist)", file);
+ throw new SVNException(err);
+ }
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.connector.scm.ScmActionFactory#addDirectory(java.lang.String, java.lang.String)
@@ -726,8 +764,8 @@
*/
public ScmAction addFile( String path,
String file,
- byte[] content ) {
- return null;
+ byte[] content) {
+ return new AddFile(path, file, content);
}
/**
@@ -790,4 +828,63 @@
closeDirectories(editor, this.root);
}
}
+
+ public static class AddFile implements ScmAction {
+ private String path;
+ private String file;
+ private byte[] content;
+
+ public AddFile( String path,
+ String file,
+ byte[] content ) {
+ this.path = path;
+ this.file = file;
+ this.content = content;
+ }
+
+ public void applyAction( Object context ) throws Exception {
+ ISVNEditor editor = (ISVNEditor)context;
+ openDirectories(editor, path);
+
+ editor.addFile(path + "/" + file, null, -1);
+ editor.applyTextDelta(path + "/" + file, null);
+ SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
+ String checksum = deltaGenerator.sendDelta(path + "/" + file, new ByteArrayInputStream(this.content), editor, true);
+ editor.closeFile(path + "/" + file, checksum);
+
+ closeDirectories(editor, path);
+
+ }
+
+ }
+
+// private Date getCreatedOn( Object[] objs ) {
+// Date createdOn = null;
+// for (Object object : objs) {
+// if (object instanceof Date) {
+// createdOn = (Date)object;
+//
+// }
+// }
+// return createdOn;
+// }
+
+ private byte[] getContent( Object[] objs ) {
+ byte[] content = null;
+ for (Object object : objs) {
+ if (object != null && object instanceof Binary) {
+ Binary buf = (Binary)object;
+ content = buf.getBytes();
+ }
+ }
+ return content;
+ }
+
+ private Object[] organizeThings( Collection<Property> childNodeProperties ) {
+ Set<Object> result = new HashSet<Object>();
+ for (Property property : childNodeProperties) {
+ result.add(property.getFirstValue());
+ }
+ return result.toArray();
+ }
}
15 years, 2 months