DNA SVN: r408 - trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-10 14:38:48 -0400 (Sun, 10 Aug 2008)
New Revision: 408
Modified:
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java
Log:
enhance abstract meta data to support modifiers, return type and parameters of methods and more
Modified: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java 2008-08-09 15:43:34 UTC (rev 407)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java 2008-08-10 18:38:48 UTC (rev 408)
@@ -29,6 +29,7 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.IExtendedModifier;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.MethodDeclaration;
@@ -37,9 +38,9 @@
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.ParameterizedType;
import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.QualifiedType;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
@@ -52,10 +53,12 @@
import org.jboss.dna.sequencer.java.metadata.MarkerAnnotationMetadata;
import org.jboss.dna.sequencer.java.metadata.MethodMetadata;
import org.jboss.dna.sequencer.java.metadata.MethodTypeMemberMetadata;
+import org.jboss.dna.sequencer.java.metadata.ModifierMetadata;
import org.jboss.dna.sequencer.java.metadata.NormalAnnotationMetadata;
import org.jboss.dna.sequencer.java.metadata.PackageMetadata;
import org.jboss.dna.sequencer.java.metadata.ParameterizedFieldMetadata;
import org.jboss.dna.sequencer.java.metadata.PrimitiveFieldMetadata;
+import org.jboss.dna.sequencer.java.metadata.ReturnType;
import org.jboss.dna.sequencer.java.metadata.SimpleFieldMetadata;
import org.jboss.dna.sequencer.java.metadata.SingleImportMetadata;
import org.jboss.dna.sequencer.java.metadata.SingleMemberAnnotationMetadata;
@@ -168,22 +171,8 @@
} else {
// is a class top level type
ClassMetadata classMetadata = new ClassMetadata();
+ processModifiersOfTypDeclaration(typeDeclaration, classMetadata);
classMetadata.setName(JavaMetadataUtil.getName(typeDeclaration.getName()));
- List modifiers = typeDeclaration.modifiers();
- for (Object object : modifiers) {
- if (object instanceof Modifier) {
- Modifier modifier = (Modifier)object;
- if (modifier.isPublic()) {
- classMetadata.getModifiers().put(TypeMetadata.PUBLIC_MODIFIER, modifier.getKeyword().toString());
- }
- }
- if (object instanceof MarkerAnnotation) {
- MarkerAnnotation marker = (MarkerAnnotation)object;
- MarkerAnnotationMetadata markerAnnotationMetadata = new MarkerAnnotationMetadata();
- markerAnnotationMetadata.setName(JavaMetadataUtil.getName(marker.getTypeName()));
- classMetadata.getAnnotations().add(markerAnnotationMetadata);
- }
- }
// fields of the class top level type
FieldDeclaration[] fieldDeclarations = typeDeclaration.getFields();
for (FieldDeclaration fieldDeclaration : fieldDeclarations) {
@@ -216,6 +205,33 @@
}
/**
+ * @param typeDeclaration
+ * @param classMetadata
+ */
+ @SuppressWarnings( "unchecked" )
+ private void processModifiersOfTypDeclaration( TypeDeclaration typeDeclaration,
+ ClassMetadata classMetadata ) {
+ List<IExtendedModifier> modifiers = typeDeclaration.modifiers();
+
+ for (IExtendedModifier extendedModifier : modifiers) {
+ ModifierMetadata modifierMetadata = new ModifierMetadata();
+ if (extendedModifier.isAnnotation()) {
+ if (extendedModifier instanceof MarkerAnnotation) {
+ MarkerAnnotation marker = (MarkerAnnotation)extendedModifier;
+ MarkerAnnotationMetadata markerAnnotationMetadata = new MarkerAnnotationMetadata();
+ markerAnnotationMetadata.setName(JavaMetadataUtil.getName(marker.getTypeName()));
+ classMetadata.getAnnotations().add(markerAnnotationMetadata);
+ }
+ } else {
+
+ Modifier modifier = (Modifier)extendedModifier;
+ modifierMetadata.setName(modifier.getKeyword().toString());
+ classMetadata.getModifiers().add(modifierMetadata);
+ }
+ }
+ }
+
+ /**
* Gets a method meta data from {@link MethodDeclaration}.
*
* @param methodDeclaration - the MethodDeclaration.
@@ -238,13 +254,106 @@
* @param methodDeclaration
* @return methodTypeMemberMetadata
*/
+ @SuppressWarnings( "unchecked" )
private MethodMetadata getMethodTypeMemberMetadataFrom( MethodDeclaration methodDeclaration ) {
MethodTypeMemberMetadata methodTypeMemberMetadata = new MethodTypeMemberMetadata();
+ processReturnTypeOfMethodDeclaration(methodDeclaration, methodTypeMemberMetadata);
+ processModifiersOfMethodDeclaration(methodDeclaration, methodTypeMemberMetadata);
+ processParametersOfMethodDeclaration(methodDeclaration, methodTypeMemberMetadata);
methodTypeMemberMetadata.setName(JavaMetadataUtil.getName(methodDeclaration.getName()));
+ List<SingleVariableDeclaration> params = methodDeclaration.parameters();
+ for (SingleVariableDeclaration singleVariableDeclaration : params) {
+ singleVariableDeclaration.getName();
+ }
return methodTypeMemberMetadata;
}
/**
+ * @param methodDeclaration
+ * @param methodMetadata
+ */
+ private void processReturnTypeOfMethodDeclaration( MethodDeclaration methodDeclaration,
+ MethodMetadata methodMetadata ) {
+ Type type = methodDeclaration.getReturnType2();
+ ReturnType returnType = null;
+ if(type.isPrimitiveType()) {
+ returnType = new ReturnType();
+ returnType.setName(((PrimitiveType)type).getPrimitiveTypeCode().toString());
+ methodMetadata.setReturnType(returnType);
+ }
+ if(type.isSimpleType()) {
+ returnType = new ReturnType();
+ returnType.setName(JavaMetadataUtil.getName(((SimpleType)type).getName()));
+ methodMetadata.setReturnType(returnType);
+ }
+ }
+
+ /**
+ * @param methodDeclaration
+ * @param methodMetadata
+ */
+ @SuppressWarnings( "unchecked" )
+ private void processParametersOfMethodDeclaration( MethodDeclaration methodDeclaration,
+ MethodMetadata methodMetadata ) {
+ List<SingleVariableDeclaration> params = methodDeclaration.parameters();
+ for (SingleVariableDeclaration singleVariableDeclaration : params) {
+ Type type = singleVariableDeclaration.getType();
+ if (type.isPrimitiveType()) {
+ PrimitiveFieldMetadata primitiveFieldMetadata = new PrimitiveFieldMetadata();
+ primitiveFieldMetadata.setType(((PrimitiveType)type).getPrimitiveTypeCode().toString());
+ Variable variable = new Variable();
+ variable.setName(JavaMetadataUtil.getName(singleVariableDeclaration.getName()));
+ primitiveFieldMetadata.getVariables().add(variable);
+ List<IExtendedModifier> extendedModifiers = singleVariableDeclaration.modifiers();
+ for (IExtendedModifier extendedModifier : extendedModifiers) {
+ ModifierMetadata modifierMetadata = new ModifierMetadata();
+ if (extendedModifier.isAnnotation()) {
+ // TODO
+ } else {
+ Modifier modifier = (Modifier)extendedModifier;
+ modifierMetadata.setName(modifier.getKeyword().toString());
+ primitiveFieldMetadata.getModifiers().add(modifierMetadata);
+ }
+ }
+ methodMetadata.getParameters().add(primitiveFieldMetadata);
+ }
+ if (type.isParameterizedType()) {
+ // TODO
+ }
+ if (type.isQualifiedType()) {
+
+ }
+ if (type.isSimpleType()) {
+ SimpleType simpleType = (SimpleType)type;
+ SimpleFieldMetadata simpleFieldMetadata = new SimpleFieldMetadata();
+ simpleFieldMetadata.setType(JavaMetadataUtil.getName(simpleType.getName()));
+ Variable variable = new Variable();
+ variable.setName(JavaMetadataUtil.getName(singleVariableDeclaration.getName()));
+ simpleFieldMetadata.getVariables().add(variable);
+ List<IExtendedModifier> extendedModifiers = singleVariableDeclaration.modifiers();
+ for (IExtendedModifier extendedModifier2 : extendedModifiers) {
+ ModifierMetadata modifierMetadata = new ModifierMetadata();
+ if (extendedModifier2.isAnnotation()) {
+ // TODO
+ } else {
+ Modifier modifier = (Modifier)extendedModifier2;
+ modifierMetadata.setName(modifier.getKeyword().toString());
+ simpleFieldMetadata.getModifiers().add(modifierMetadata);
+ }
+ }
+ methodMetadata.getParameters().add(simpleFieldMetadata);
+ }
+ if (type.isArrayType()) {
+ // TODO
+ }
+ if (type.isWildcardType()) {
+ // TODO
+ }
+ }
+
+ }
+
+ /**
* Get {@link ConstructorMetadata}
*
* @param methodDeclaration
@@ -252,7 +361,11 @@
*/
private MethodMetadata getConstructorMetadataFrom( MethodDeclaration methodDeclaration ) {
ConstructorMetadata constructorMetadata = new ConstructorMetadata();
+ // modifiers
+ processModifiersOfMethodDeclaration(methodDeclaration, constructorMetadata);
+ processParametersOfMethodDeclaration(methodDeclaration, constructorMetadata);
constructorMetadata.setName(JavaMetadataUtil.getName(methodDeclaration.getName()));
+ // arguments list
return constructorMetadata;
}
@@ -265,60 +378,162 @@
@SuppressWarnings( "unchecked" )
private FieldMetadata getFieldMetadataFrom( FieldDeclaration fieldDeclaration ) {
if (fieldDeclaration != null && fieldDeclaration.getType() != null && (!fieldDeclaration.fragments().isEmpty())) {
- List<VariableDeclarationFragment> fragments = null;
// type
Type type = fieldDeclaration.getType();
// Primitive type
- if (type instanceof PrimitiveType) {
- PrimitiveType primitiveType = (PrimitiveType)type;
- PrimitiveFieldMetadata primitiveFieldMetadata = new PrimitiveFieldMetadata();
- primitiveFieldMetadata.setCode(primitiveType.getPrimitiveTypeCode().toString());
- // variables
- fragments = fieldDeclaration.fragments();
- getAllVariablesOf(fragments, primitiveFieldMetadata);
+ if (type.isPrimitiveType()) {
+ PrimitiveFieldMetadata primitiveFieldMetadata = processPrimitiveType(fieldDeclaration, type);
return primitiveFieldMetadata;
}
- if (type instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)type;
- ParameterizedFieldMetadata parameterizedFieldMetadata = new ParameterizedFieldMetadata();
- Type typeOfParameterizedType = parameterizedType.getType(); // type may be a simple type or a qualified type.
- if (typeOfParameterizedType instanceof SimpleType) {
- SimpleType simpleType = (SimpleType)typeOfParameterizedType;
- parameterizedFieldMetadata.setName(JavaMetadataUtil.getName(simpleType.getName()));
- }
- if (typeOfParameterizedType instanceof QualifiedType) {
- QualifiedType qualifiedType = (QualifiedType)typeOfParameterizedType;
- parameterizedFieldMetadata.setName(JavaMetadataUtil.getName(qualifiedType.getName()));
- Type qualifier = qualifiedType.getQualifier();
- if (qualifier instanceof ParameterizedType) {
- // TODO
- }
- }
- // variables
- fragments = fieldDeclaration.fragments();
- getAllVariablesOf(fragments, parameterizedFieldMetadata);
- return parameterizedFieldMetadata;
+ // ParameterizedType
+ if (type.isParameterizedType()) {
+ ParameterizedFieldMetadata referenceFieldMetadata = processParameterizedType(fieldDeclaration, type);
+ return referenceFieldMetadata;
}
- if (type instanceof SimpleType) {
- SimpleType simpleType = (SimpleType)type;
- SimpleFieldMetadata simpleFieldMetadata = new SimpleFieldMetadata();
- simpleFieldMetadata.setName(JavaMetadataUtil.getName(simpleType.getName()));
- fragments = fieldDeclaration.fragments();
- getAllVariablesOf(fragments, simpleFieldMetadata);
+ // SimpleType
+ if (type.isSimpleType()) {
+ SimpleFieldMetadata simpleFieldMetadata = processSimpleType(fieldDeclaration, type);
return simpleFieldMetadata;
}
+ // ArrayType
+ if (type.isArrayType()) {
+ // TODO
+ }
+ // QualifiedType
+ if (type.isQualifiedType()) {
+ // TODO
+
+ }
+ // WildcardType
+ if (type.isWildcardType()) {
+
+ }
}
return null;
}
/**
- * Get all variables of a fragment.
+ * @param fieldDeclaration
+ * @param type
+ * @return SimpleFieldMetadata
+ */
+ private SimpleFieldMetadata processSimpleType( FieldDeclaration fieldDeclaration,
+ Type type ) {
+ SimpleType simpleType = (SimpleType)type;
+ SimpleFieldMetadata simpleFieldMetadata = new SimpleFieldMetadata();
+ simpleFieldMetadata.setType(JavaMetadataUtil.getName(simpleType.getName()));
+ // modifiers
+ processModifiersOfFieldDeclaration(fieldDeclaration, simpleFieldMetadata);
+ processVariablesOfVariableDeclarationFragment(fieldDeclaration, simpleFieldMetadata);
+ return simpleFieldMetadata;
+ }
+
+ /**
+ * @param fieldDeclaration
+ * @param type
+ * @return ParameterizedFieldMetadata
+ */
+ private ParameterizedFieldMetadata processParameterizedType( FieldDeclaration fieldDeclaration,
+ Type type ) {
+ ParameterizedType parameterizedType = (ParameterizedType)type;
+ Type typeOfParameterizedType = parameterizedType.getType(); // type may be a simple type or a qualified type.
+ ParameterizedFieldMetadata referenceFieldMetadata = (ParameterizedFieldMetadata)createParameterizedFieldMetadataFrom(typeOfParameterizedType);
+ // modifiers
+ processModifiersOfFieldDeclaration(fieldDeclaration, referenceFieldMetadata);
+ // variables
+ processVariablesOfVariableDeclarationFragment(fieldDeclaration, referenceFieldMetadata);
+ return referenceFieldMetadata;
+ }
+
+ /**
+ * @param fieldDeclaration
+ * @param type
+ * @return PrimitiveFieldMetadata
+ */
+ private PrimitiveFieldMetadata processPrimitiveType( FieldDeclaration fieldDeclaration,
+ Type type ) {
+ PrimitiveType primitiveType = (PrimitiveType)type;
+ PrimitiveFieldMetadata primitiveFieldMetadata = new PrimitiveFieldMetadata();
+ primitiveFieldMetadata.setType(primitiveType.getPrimitiveTypeCode().toString());
+ // modifiers
+ processModifiersOfFieldDeclaration(fieldDeclaration, primitiveFieldMetadata);
+ // variables
+ processVariablesOfVariableDeclarationFragment(fieldDeclaration, primitiveFieldMetadata);
+ return primitiveFieldMetadata;
+ }
+
+ /**
+ * Process modifiers of a {@link FieldDeclaration}
*
- * @param fragments
+ * @param fieldDeclaration
* @param fieldMetadata
*/
- private void getAllVariablesOf( List<VariableDeclarationFragment> fragments,
- FieldMetadata fieldMetadata ) {
+ @SuppressWarnings( "unchecked" )
+ protected void processModifiersOfFieldDeclaration( FieldDeclaration fieldDeclaration,
+ FieldMetadata fieldMetadata ) {
+ List<IExtendedModifier> extendedModifiers = fieldDeclaration.modifiers();
+ for (IExtendedModifier extendedModifier : extendedModifiers) {
+ ModifierMetadata modifierMetadata = new ModifierMetadata();
+ if (extendedModifier.isAnnotation()) {
+ // TODO annotation modifiers
+ } else {
+ Modifier modifier = (Modifier)extendedModifier;
+ modifierMetadata.setName(modifier.getKeyword().toString());
+ fieldMetadata.getModifiers().add(modifierMetadata);
+ }
+ }
+
+ }
+
+ /**
+ * Process modifiers of a {@link MethodDeclaration}.
+ *
+ * @param methodDeclaration
+ * @param methodMetadata
+ */
+ @SuppressWarnings( "unchecked" )
+ private void processModifiersOfMethodDeclaration( MethodDeclaration methodDeclaration,
+ MethodMetadata methodMetadata ) {
+ List<IExtendedModifier> extendedModifiers = methodDeclaration.modifiers();
+ for (IExtendedModifier extendedModifier : extendedModifiers) {
+ ModifierMetadata modifierMetadata = new ModifierMetadata();
+ if (extendedModifier.isAnnotation()) {
+ // TODO
+ } else {
+ Modifier modifier = (Modifier)extendedModifier;
+ modifierMetadata.setName(modifier.getKeyword().toString());
+ methodMetadata.getModifiers().add(modifierMetadata);
+ }
+ }
+ }
+
+ /**
+ * Create a <code>FieldMetadata</code> from a {@link Type} instance.
+ *
+ * @param type - The {@link Type}
+ * @return the specific type of <code>FieldMetadata</code>
+ */
+ protected FieldMetadata createParameterizedFieldMetadataFrom( Type type ) {
+ ParameterizedFieldMetadata parameterizedFieldMetadata = null;
+ if (type.isSimpleType()) {
+ SimpleType simpleType = (SimpleType)type;
+ parameterizedFieldMetadata = new ParameterizedFieldMetadata();
+ parameterizedFieldMetadata.setType(JavaMetadataUtil.getName(simpleType.getName()));
+ }
+ // TODO also process QualifiedType
+ return parameterizedFieldMetadata;
+ }
+
+ /**
+ * Process variables of a {@link VariableDeclarationFragment}.
+ *
+ * @param fieldDeclaration - the {@link FieldDeclaration}
+ * @param fieldMetadata - where to transfer the meta data.
+ */
+ @SuppressWarnings( "unchecked" )
+ protected void processVariablesOfVariableDeclarationFragment( FieldDeclaration fieldDeclaration,
+ FieldMetadata fieldMetadata ) {
+ List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
for (VariableDeclarationFragment fragment : fragments) {
fieldMetadata.getVariables().add(new Variable(JavaMetadataUtil.getName(fragment.getName())));
}
15 years, 10 months
DNA SVN: r407 - trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-09 11:43:34 -0400 (Sat, 09 Aug 2008)
New Revision: 407
Added:
trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java
Log:
ReferenceFieldMeta
Copied: trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java (from rev 403, trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ParameterizedFieldMetadata.java)
===================================================================
--- trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java (rev 0)
+++ trunk/sequencers/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java 2008-08-09 15:43:34 UTC (rev 407)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.sequencer.java.metadata;
+
+
+/**
+ * Field meta data for parameterized type.
+ */
+public class ReferenceFieldMetadata extends FieldMetadata {
+}
15 years, 10 months
DNA SVN: r406 - trunk/dna-jcr/src/test/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-08 17:52:54 -0400 (Fri, 08 Aug 2008)
New Revision: 406
Modified:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
Log:
Added bogus test method to get builds to work.
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-08 21:11:12 UTC (rev 405)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-08 21:52:54 UTC (rev 406)
@@ -21,6 +21,7 @@
*/
package org.jboss.dna.jcr;
+import org.junit.Test;
/**
* @author jverhaeg
@@ -61,4 +62,9 @@
// public void shouldProvideName() throws Exception {
// assertThat(prop.getName(), is("name"));
// }
+
+ @Test
+ public void should() {
+
+ }
}
15 years, 10 months
DNA SVN: r405 - in trunk/dna-jcr: src/main/java/org/jboss/dna/jcr and 2 other directories.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-08 17:11:12 -0400 (Fri, 08 Aug 2008)
New Revision: 405
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.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/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Removed:
trunk/dna-jcr/.settings/
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaNamespaceRegistry.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaWorkspace.java
Modified:
trunk/dna-jcr/pom.xml
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
Log:
DNA-178: Completed basic functionality up to retrieving a skeleton root node.
Modified: trunk/dna-jcr/pom.xml
===================================================================
--- trunk/dna-jcr/pom.xml 2008-08-08 20:43:42 UTC (rev 404)
+++ trunk/dna-jcr/pom.xml 2008-08-08 21:11:12 UTC (rev 405)
@@ -46,12 +46,14 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
- <scope>test</scope>
</dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,717 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.lock.Lock;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+abstract class AbstractJcrNode implements Node {
+
+ private final Session session;
+ private final Set<Property> properties;
+
+ AbstractJcrNode( Session session,
+ Set<Property> properties ) {
+ assert session != null;
+ this.session = session;
+ this.properties = (properties == null ? new HashSet<Property>() : properties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
+ */
+ public void accept( ItemVisitor visitor ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#addMixin(java.lang.String)
+ */
+ public void addMixin( String mixinName ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#addNode(java.lang.String)
+ */
+ public Node addNode( String relPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#addNode(java.lang.String, java.lang.String)
+ */
+ public Node addNode( String relPath,
+ String primaryNodeTypeName ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#canAddMixin(java.lang.String)
+ */
+ public boolean canAddMixin( String mixinName ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#cancelMerge(javax.jcr.version.Version)
+ */
+ public void cancelMerge( Version version ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#checkin()
+ */
+ public Version checkin() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#checkout()
+ */
+ public void checkout() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#doneMerge(javax.jcr.version.Version)
+ */
+ public void doneMerge( Version version ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getAncestor(int)
+ */
+ public Item getAncestor( int depth ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getBaseVersion()
+ */
+ public Version getBaseVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getCorrespondingNodePath(java.lang.String)
+ */
+ public String getCorrespondingNodePath( String workspaceName ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getDefinition()
+ */
+ public NodeDefinition getDefinition() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getIndex()
+ */
+ public int getIndex() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getLock()
+ */
+ public Lock getLock() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getMixinNodeTypes()
+ */
+ public NodeType[] getMixinNodeTypes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getNode(java.lang.String)
+ */
+ public Node getNode( String relPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getNodes()
+ */
+ public NodeIterator getNodes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getNodes(java.lang.String)
+ */
+ public NodeIterator getNodes( String namePattern ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getPath()
+ */
+ public String getPath() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getPrimaryItem()
+ */
+ public Item getPrimaryItem() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getPrimaryNodeType()
+ */
+ public NodeType getPrimaryNodeType() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getProperties()
+ */
+ public PropertyIterator getProperties() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getProperties(java.lang.String)
+ */
+ public PropertyIterator getProperties( String namePattern ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getProperty(java.lang.String)
+ */
+ public Property getProperty( String relativePath ) throws RepositoryException {
+ ArgCheck.isNotEmpty(relativePath, "relativePath");
+ // TODO: Handle multi-segment paths
+ for (Property property : properties) {
+ if (relativePath.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getReferences()
+ */
+ public PropertyIterator getReferences() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getSession()
+ */
+ public Session getSession() {
+ return session;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getUUID()
+ */
+ public String getUUID() throws RepositoryException {
+ // TODO: Check if node is referenceable
+ Property prop = getProperty("jcr:uuid");
+ return (prop == null ? null : prop.getValue().getString());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#getVersionHistory()
+ */
+ public VersionHistory getVersionHistory() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#hasNode(java.lang.String)
+ */
+ public boolean hasNode( String relPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#hasNodes()
+ */
+ public boolean hasNodes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#hasProperties()
+ */
+ public boolean hasProperties() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#hasProperty(java.lang.String)
+ */
+ public boolean hasProperty( String relPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#holdsLock()
+ */
+ public boolean holdsLock() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#isCheckedOut()
+ */
+ public boolean isCheckedOut() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#isLocked()
+ */
+ public boolean isLocked() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isModified()
+ */
+ public boolean isModified() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNew()
+ */
+ public boolean isNew() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNode()
+ */
+ public boolean isNode() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#isNodeType(java.lang.String)
+ */
+ public boolean isNodeType( String nodeTypeName ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isSame(javax.jcr.Item)
+ */
+ public boolean isSame( Item otherItem ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#lock(boolean, boolean)
+ */
+ public Lock lock( boolean isDeep,
+ boolean isSessionScoped ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#merge(java.lang.String, boolean)
+ */
+ public NodeIterator merge( String srcWorkspace,
+ boolean bestEffort ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#orderBefore(java.lang.String, java.lang.String)
+ */
+ public void orderBefore( String srcChildRelPath,
+ String destChildRelPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#refresh(boolean)
+ */
+ public void refresh( boolean keepChanges ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#removeMixin(java.lang.String)
+ */
+ public void removeMixin( String mixinName ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#restore(java.lang.String, boolean)
+ */
+ public void restore( String versionName,
+ boolean removeExisting ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#restore(javax.jcr.version.Version, boolean)
+ */
+ public void restore( Version version,
+ boolean removeExisting ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#restore(javax.jcr.version.Version, java.lang.String, boolean)
+ */
+ public void restore( Version version,
+ String relPath,
+ boolean removeExisting ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#restoreByLabel(java.lang.String, boolean)
+ */
+ public void restoreByLabel( String versionLabel,
+ boolean removeExisting ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#save()
+ */
+ public void save() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, boolean)
+ */
+ public Property setProperty( String name,
+ boolean value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, java.util.Calendar)
+ */
+ public Property setProperty( String name,
+ Calendar value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, double)
+ */
+ public Property setProperty( String name,
+ double value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, java.io.InputStream)
+ */
+ public Property setProperty( String name,
+ InputStream value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, long)
+ */
+ public Property setProperty( String name,
+ long value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, javax.jcr.Node)
+ */
+ public Property setProperty( String name,
+ Node value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, java.lang.String)
+ */
+ public Property setProperty( String name,
+ String value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, java.lang.String, int)
+ */
+ public Property setProperty( String name,
+ String value,
+ int type ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, java.lang.String[])
+ */
+ public Property setProperty( String name,
+ String[] values ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, java.lang.String[], int)
+ */
+ public Property setProperty( String name,
+ String[] values,
+ int type ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, javax.jcr.Value)
+ */
+ public Property setProperty( String name,
+ Value value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, javax.jcr.Value, int)
+ */
+ public Property setProperty( String name,
+ Value value,
+ int type ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, javax.jcr.Value[])
+ */
+ public Property setProperty( String name,
+ Value[] values ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#setProperty(java.lang.String, javax.jcr.Value[], int)
+ */
+ public Property setProperty( String name,
+ Value[] values,
+ int type ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#unlock()
+ */
+ public void unlock() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Node#update(java.lang.String)
+ */
+ public void update( String srcWorkspaceName ) {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,375 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
+import net.jcip.annotations.NotThreadSafe;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+abstract class AbstractJcrProperty implements Property {
+
+ private final Session session;
+ private final String name;
+
+ AbstractJcrProperty( Session session,
+ String name ) {
+ assert session != null;
+ this.session = session;
+ assert name != null && name.length() > 0;
+ this.name = name;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDate()
+ */
+ public Calendar getDate() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDefinition()
+ */
+ public PropertyDefinition getDefinition() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDouble()
+ */
+ public double getDouble() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLength()
+ */
+ public long getLength() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLengths()
+ */
+ public long[] getLengths() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLong()
+ */
+ public long getLong() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getNode()
+ */
+ public Node getNode() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getStream()
+ */
+ public InputStream getStream() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getString()
+ */
+ public String getString() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getType()
+ */
+ public int getType() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValue()
+ */
+ public Value getValue() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValues()
+ */
+ public Value[] getValues() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(javax.jcr.Value)
+ */
+ public void setValue( Value value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(javax.jcr.Value[])
+ */
+ public void setValue( Value[] values ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(java.lang.String)
+ */
+ public void setValue( String value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(java.lang.String[])
+ */
+ public void setValue( String[] values ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(java.io.InputStream)
+ */
+ public void setValue( InputStream value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(long)
+ */
+ public void setValue( long value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(double)
+ */
+ public void setValue( double value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(java.util.Calendar)
+ */
+ public void setValue( Calendar value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(boolean)
+ */
+ public void setValue( boolean value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#setValue(javax.jcr.Node)
+ */
+ public void setValue( Node value ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
+ */
+ public void accept( ItemVisitor visitor ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getAncestor(int)
+ */
+ public Item getAncestor( int depth ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getParent()
+ */
+ public Node getParent() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getPath()
+ */
+ public String getPath() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getSession()
+ */
+ public Session getSession() {
+ return session;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isModified()
+ */
+ public boolean isModified() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNew()
+ */
+ public boolean isNew() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNode()
+ */
+ public boolean isNode() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isSame(javax.jcr.Item)
+ */
+ public boolean isSame( Item otherItem ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#refresh(boolean)
+ */
+ public void refresh( boolean keepChanges ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#save()
+ */
+ public void save() {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaNamespaceRegistry.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaNamespaceRegistry.java 2008-08-08 20:43:42 UTC (rev 404)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaNamespaceRegistry.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import javax.jcr.AccessDeniedException;
-import javax.jcr.NamespaceException;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-
-
-/**
- *
- * @author Randall Hauch
- */
-public class DnaNamespaceRegistry implements NamespaceRegistry {
-
- /**
- *
- */
- public DnaNamespaceRegistry() {
- }
-
- /**
- * {@inheritDoc}
- */
- public String getPrefix( String uri ) throws NamespaceException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getPrefixes() throws RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getURI( String prefix ) throws NamespaceException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getURIs() throws RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void registerNamespace( String prefix, String uri ) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void unregisterNamespace( String prefix ) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException {
- }
-
-}
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaRepository.java 2008-08-08 20:43:42 UTC (rev 404)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaRepository.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -1,91 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import javax.jcr.Credentials;
-import javax.jcr.LoginException;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-/**
- * @author Randall Hauch
- */
-public class DnaRepository implements Repository {
-
- /**
- *
- */
- public DnaRepository() {
- }
-
- /**
- * {@inheritDoc}
- */
- public String getDescriptor( String key ) {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getDescriptorKeys() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Session login() throws LoginException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Session login( Credentials credentials ) throws LoginException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Session login( String workspaceName ) throws LoginException, NoSuchWorkspaceException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Session login( Credentials credentials, String workspaceName ) throws LoginException, NoSuchWorkspaceException, RepositoryException {
- return null;
- }
-
- protected void logout( DnaSession session ) {
-
- }
-
- protected String[] getWorkspaceNamesAccessibleBy( String username, Credentials credentials ) throws RepositoryException {
- throw new UnsupportedOperationException();
- }
-}
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaSession.java 2008-08-08 20:43:42 UTC (rev 404)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaSession.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -1,312 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.security.AccessControlException;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import javax.jcr.AccessDeniedException;
-import javax.jcr.Credentials;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.InvalidSerializedDataException;
-import javax.jcr.Item;
-import javax.jcr.ItemExistsException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.LoginException;
-import javax.jcr.NamespaceException;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.ValueFactory;
-import javax.jcr.Workspace;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.version.VersionException;
-import net.jcip.annotations.GuardedBy;
-import net.jcip.annotations.ThreadSafe;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-/**
- * @author Randall Hauch
- */
-@ThreadSafe
-public class DnaSession implements Session {
-
- private final DnaWorkspace workspace;
- private final DnaRepository repository;
- private final String username;
- private final Credentials credentials;
- private final ReadWriteLock sessionLock = new ReentrantReadWriteLock();
- @GuardedBy( "sessionLock" )
- private boolean connected;
-
- /**
- * @param repository the {@link DnaRepository} that owns this session; may not be null
- * @param workspaceName the name of the workspace to which this session is connected; may not be null
- * @param credentials the credentials that were used to authentiate this session; may not be null
- * @param username the username used to create this session; may not be null
- */
- /* package */DnaSession( DnaRepository repository, String workspaceName, Credentials credentials, String username ) {
- assert repository != null;
- assert workspaceName != null;
- assert credentials != null;
- assert username != null;
- this.workspace = new DnaWorkspace(repository, workspaceName, this);
- this.repository = repository;
- this.credentials = credentials;
- this.username = username;
- this.connected = true;
- }
-
- /* package */Credentials getCredentials() {
- return this.credentials;
- }
-
- /**
- * {@inheritDoc}
- */
- public void addLockToken( String lt ) throws LockException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void checkPermission( String absPath, String actions ) throws AccessControlException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void exportDocumentView( String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse ) throws PathNotFoundException, SAXException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void exportDocumentView( String absPath, OutputStream out, boolean skipBinary, boolean noRecurse ) throws IOException, PathNotFoundException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void exportSystemView( String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse ) throws PathNotFoundException, SAXException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void exportSystemView( String absPath, OutputStream out, boolean skipBinary, boolean noRecurse ) throws IOException, PathNotFoundException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getAttribute( String name ) {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getAttributeNames() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public ContentHandler getImportContentHandler( String parentAbsPath, int uuidBehavior )
- throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Item getItem( String absPath ) throws PathNotFoundException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getLockTokens() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getNamespacePrefix( String uri ) throws NamespaceException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getNamespacePrefixes() throws RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getNamespaceURI( String prefix ) throws NamespaceException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Node getNodeByUUID( String uuid ) throws ItemNotFoundException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Repository getRepository() {
- return this.repository;
- }
-
- /**
- * {@inheritDoc}
- */
- public Node getRootNode() throws RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getUserID() {
- return this.username;
- }
-
- /**
- * {@inheritDoc}
- */
- public ValueFactory getValueFactory() throws UnsupportedRepositoryOperationException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Workspace getWorkspace() {
- return this.workspace;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasPendingChanges() throws RepositoryException {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Session impersonate( Credentials credentials ) throws LoginException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void importXML( String parentAbsPath, InputStream in, int uuidBehavior )
- throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException, InvalidSerializedDataException, LockException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isLive() {
- Lock lock = this.sessionLock.readLock();
- try {
- return connected;
- } finally {
- lock.unlock();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean itemExists( String absPath ) throws RepositoryException {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public void logout() {
- Lock lock = this.sessionLock.writeLock();
- try {
- repository.logout(this);
- connected = false;
- } finally {
- lock.unlock();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void move( String srcAbsPath, String destAbsPath ) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void refresh( boolean keepChanges ) throws RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeLockToken( String lt ) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void save()
- throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void setNamespacePrefix( String newPrefix, String existingUri ) throws NamespaceException, RepositoryException {
- }
-
-}
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaWorkspace.java 2008-08-08 20:43:42 UTC (rev 404)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaWorkspace.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -1,170 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import java.io.IOException;
-import java.io.InputStream;
-import javax.jcr.AccessDeniedException;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.InvalidSerializedDataException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Workspace;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-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.ThreadSafe;
-import org.xml.sax.ContentHandler;
-
-/**
- * @author Randall Hauch
- */
-@ThreadSafe
-public class DnaWorkspace implements Workspace {
-
- private final String name;
- private final DnaSession session;
- private final DnaRepository repository;
-
- /**
- * @param repository the repository instance that owns this workspace; may not be null
- * @param name the name of the workspace; may not be null
- * @param session the session that owns this workspace; may not be null
- */
- /* package */DnaWorkspace( DnaRepository repository, String name, DnaSession session ) {
- assert repository != null;
- assert session != null;
- assert name != null;
- this.repository = repository;
- this.session = session;
- this.name = name;
- }
-
- /**
- * {@inheritDoc}
- */
- public void clone( String srcWorkspace, String srcAbsPath, String destAbsPath, boolean removeExisting )
- throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void copy( String srcAbsPath, String destAbsPath )
- throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void copy( String srcWorkspace, String srcAbsPath, String destAbsPath )
- throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getAccessibleWorkspaceNames() throws RepositoryException {
- return repository.getWorkspaceNamesAccessibleBy(session.getUserID(), session.getCredentials());
- }
-
- /**
- * {@inheritDoc}
- */
- public ContentHandler getImportContentHandler( String parentAbsPath, int uuidBehavior )
- throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, AccessDeniedException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getName() {
- return name;
- }
-
- /**
- * {@inheritDoc}
- */
- public NamespaceRegistry getNamespaceRegistry() throws RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public NodeTypeManager getNodeTypeManager() throws RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public ObservationManager getObservationManager() throws UnsupportedRepositoryOperationException, RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public QueryManager getQueryManager() throws RepositoryException {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Session getSession() {
- return this.session;
- }
-
- /**
- * {@inheritDoc}
- */
- public void importXML( String parentAbsPath, InputStream in, int uuidBehavior )
- throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, InvalidSerializedDataException, LockException, AccessDeniedException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void move( String srcAbsPath, String destAbsPath )
- throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
- }
-
- /**
- * {@inheritDoc}
- */
- public void restore( Version[] versions, boolean removeExisting )
- throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException {
- }
-
-}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
+
+/**
+ * @author jverhaeg
+ */
+class GraphTools {
+
+ private final ExecutionContext executionContext;
+ private Session session;
+ private final RepositoryConnection connection;
+
+ GraphTools( ExecutionContext executionContext,
+ RepositoryConnection connection ) {
+ assert executionContext != null;
+ assert connection != null;
+ this.executionContext = executionContext;
+ this.connection = connection;
+ }
+
+ private void execute( GraphCommand... commands ) throws RepositoryException {
+ try {
+ connection.execute(executionContext, commands);
+ } catch (RuntimeException error) {
+ throw error;
+ } catch (Exception error) {
+ throw new RepositoryException(error);
+ }
+ }
+
+ /**
+ * @return connection
+ */
+ public RepositoryConnection getConnection() {
+ return connection;
+ }
+
+ NodeContent getNodeContent( Path path ) throws RepositoryException {
+ assert session != null;
+ assert path != null;
+ // Get root node from source
+ ValueFactories valueFactories = executionContext.getValueFactories();
+ PathFactory pathFactory = valueFactories.getPathFactory();
+ BasicGetNodeCommand getRootNodeCommand = new BasicGetNodeCommand(path);
+ execute(getRootNodeCommand);
+ // Get primary type
+ NameFactory nameFactory = valueFactories.getNameFactory();
+ org.jboss.dna.spi.graph.Property primaryTypeProp = getRootNodeCommand.getProperties().get(nameFactory.create("jcr:primaryType"));
+ org.jboss.dna.spi.graph.ValueFactory<String> stringFactory = valueFactories.getStringFactory();
+ String primaryType = stringFactory.create(primaryTypeProp.getValues()).next();
+ // Process node's properties
+ NodeContent content = new NodeContent();
+ org.jboss.dna.spi.graph.ValueFactory<Boolean> booleanFactory = valueFactories.getBooleanFactory();
+ for (org.jboss.dna.spi.graph.Property prop : getRootNodeCommand.getPropertyIterator()) {
+ // Get property definition from node's primary type
+ BasicGetNodeCommand getPropDefCommand = new BasicGetNodeCommand(pathFactory.create("/dna:system/dna:jcr/"
+ + primaryType + "/"
+ + prop.getName()));
+ execute(getPropDefCommand);
+ // Create either a single- or multiple-valued property, as defined by the property definition
+ org.jboss.dna.spi.graph.Property isMultipleProp = getPropDefCommand.getProperties().get(nameFactory.create("jcr:multiple"));
+ org.jboss.dna.spi.graph.Property requiredTypeProp = getPropDefCommand.getProperties().get(nameFactory.create("jcr:requiredType"));
+ String type = stringFactory.create(requiredTypeProp.getValues()).next();
+ if (booleanFactory.create(isMultipleProp.getValues()).next().booleanValue()) {
+ // jcrProps.add(new JcrMultiValuedProperty(dnaProp.getName(), type, dnaProp.getValues()));
+ } else {
+ Value jcrValue;
+ ValueFactory jcrValueFactory = session.getValueFactory();
+ if (PropertyType.BINARY.equals(type)) {
+ jcrValue = jcrValueFactory.createValue(valueFactories.getBinaryFactory().create(prop.getValues()).next().getStream());
+ } else {
+ assert PropertyType.UUID.equals(type);
+ jcrValue = jcrValueFactory.createValue(valueFactories.getStringFactory().create(prop.getValues()).next());
+ }
+ content.properties.add(new JcrProperty(session, prop.getName().toString(), jcrValue));
+ }
+ }
+ return content;
+ }
+
+ void setSession( Session session ) {
+ assert session != null;
+ this.session = session;
+ }
+
+ class NodeContent {
+
+ Set<Property> properties = new HashSet<Property>();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.security.AccessControlContext;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.PropertyFactory;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+class JcrExecutionContext implements ExecutionContext {
+
+ private final ExecutionContext delegate;
+ private final GraphTools tools;
+
+ JcrExecutionContext( ExecutionContext delegate,
+ RepositoryConnection connection ) {
+ assert delegate != null;
+ assert connection != null;
+ this.delegate = delegate;
+ tools = new GraphTools(delegate, connection);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getAccessControlContext()
+ */
+ public AccessControlContext getAccessControlContext() {
+ return delegate.getAccessControlContext();
+ }
+
+ GraphTools getGraphTools() {
+ return tools;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLoginContext()
+ */
+ public LoginContext getLoginContext() {
+ return delegate.getLoginContext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return delegate.getNamespaceRegistry();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getPropertyFactory()
+ */
+ public PropertyFactory getPropertyFactory() {
+ return delegate.getPropertyFactory();
+ }
+
+ RepositoryConnection getRepositoryConnection() {
+ return tools.getConnection();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getSubject()
+ */
+ public Subject getSubject() {
+ return delegate.getSubject();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getValueFactories()
+ */
+ public ValueFactories getValueFactories() {
+ return delegate.getValueFactories();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.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 2008-08-08 20:43:42 UTC (rev 404)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -26,12 +26,22 @@
import org.jboss.dna.common.i18n.I18n;
/**
+ * @author John Verhaeg
* @author Randall Hauch
*/
public final class JcrI18n {
- // public static I18n invalidStateString;
+ public static I18n credentialsMustProvideJaasMethod;
+ public static I18n credentialsMustReturnAccessControlContext;
+ public static I18n credentialsMustReturnLoginContext;
+ public static I18n defaultWorkspaceName;
+ public static I18n repositoryMustBeConfigured;
+ public static I18n sourceInUse;
+ public static I18n REP_NAME_DESC;
+ public static I18n REP_VENDOR_DESC;
+ public static I18n SPEC_NAME_DESC;
+
static {
try {
I18n.initialize(JcrI18n.class);
Copied: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java (from rev 375, trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaNamespaceRegistry.java)
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.ArgCheck;
+
+/**
+ * @author John Verhaeg
+ * @author Randall Hauch
+ */
+@Immutable
+class JcrNamespaceRegistry implements NamespaceRegistry {
+
+ private Map<String, String> prefix2UriMap = new HashMap<String, String>();
+
+ JcrNamespaceRegistry() {
+ prefix2UriMap.put("", "");
+ prefix2UriMap.put("dna", "http://www.jboss.org/dna/1.0");
+ prefix2UriMap.put("jcr", "http://www.jcp.org/jcr/1.0");
+ prefix2UriMap.put("mix", "http://www.jcp.org/jcr/mix/1.0");
+ prefix2UriMap.put("nt", "http://www.jcp.org/jcr/nt/1.0");
+ prefix2UriMap.put("xml", "http://www.w3.org/XML/1998/namespace");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPrefix( String uri ) throws NamespaceException {
+ ArgCheck.isNotNull(uri, "uri");
+ for (Entry<String, String> entry : prefix2UriMap.entrySet()) {
+ if (uri.equals(entry.getValue())) {
+ return entry.getKey();
+ }
+ }
+ throw new NamespaceException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getPrefixes() {
+ String[] prefixes = prefix2UriMap.keySet().toArray(new String[prefix2UriMap.size()]);
+ Arrays.sort(prefixes);
+ return prefixes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getURI( String prefix ) throws NamespaceException {
+ ArgCheck.isNotNull(prefix, "prefix");
+ String uri = prefix2UriMap.get(prefix);
+ if (uri == null) throw new NamespaceException();
+ return uri;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getURIs() {
+ String[] uris = prefix2UriMap.values().toArray(new String[prefix2UriMap.size()]);
+ Arrays.sort(uris);
+ return uris;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerNamespace( String prefix,
+ String uri ) throws UnsupportedRepositoryOperationException {
+ throw new UnsupportedRepositoryOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unregisterNamespace( String prefix ) throws UnsupportedRepositoryOperationException {
+ throw new UnsupportedRepositoryOperationException();
+ }
+}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.Set;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import net.jcip.annotations.NotThreadSafe;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+final class JcrNode extends AbstractJcrNode {
+
+ JcrNode( Session session,
+ Set<Property> properties ) {
+ super(session, properties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getName()
+ */
+ public String getName() throws RepositoryException {
+ Property prop = getProperty("jcr:name");
+ assert prop != null;
+ assert prop.getValue() != null;
+ return prop.getValue().getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getParent()
+ */
+ public Node getParent() {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+
+/**
+ * @author jverhaeg
+ */
+final class JcrProperty extends AbstractJcrProperty {
+
+ private Value value;
+
+ JcrProperty( Session session,
+ String name,
+ Value value ) {
+ super(session, name);
+ assert value != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getBoolean()
+ */
+ public boolean getBoolean() throws RepositoryException {
+ return value.getBoolean();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java (from rev 375, trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaRepository.java)
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,256 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.lang.reflect.Method;
+import java.security.AccessControlContext;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.security.auth.login.LoginContext;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+
+/**
+ * Creates JCR {@link Session sessions} to an underlying repository (which may be a federated repository).
+ * <p>
+ * This JCR repository must be configured with the ability to connect to a repository via a supplied
+ * {@link RepositoryConnectionFactory repository connection factory} and repository source name. An
+ * {@link ExecutionContextFactory execution context factory} must also be supplied to enable working with the underlying DNA graph
+ * implementation to which this JCR implementation delegates.
+ * </p>
+ * <p>
+ * If {@link Credentials} are used to login, implementations <em>must</em> also implement one of the following methods:
+ *
+ * <pre>
+ * public {@link AccessControlContext} getAccessControlContext();
+ * public {@link LoginContext} getLoginContext();
+ * </pre>
+ *
+ * </p>
+ *
+ * @author John Verhaeg
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class JcrRepository implements Repository {
+
+ private final Map<String, String> descriptors;
+ private final ExecutionContextFactory executionContextFactory;
+ private final RepositoryConnectionFactory connectionFactory;
+
+ /**
+ * Creates a JCR repository that uses the supplied {@link RepositoryConnectionFactory repository connection factory} to
+ * establish {@link Session sessions} to the underlying repository source upon {@link #login() login}.
+ *
+ * @param executionContextFactory An execution context factory.
+ * @param connectionFactory A repository connection factory.
+ * @throws IllegalArgumentException If <code>executionContextFactory</code> or <code>connectionFactory</code> is
+ * <code>null</code>.
+ */
+ public JcrRepository( ExecutionContextFactory executionContextFactory,
+ RepositoryConnectionFactory connectionFactory ) {
+ this(null, executionContextFactory, connectionFactory);
+ }
+
+ /**
+ * Creates a JCR repository that uses the supplied {@link RepositoryConnectionFactory repository connection factory} to
+ * establish {@link Session sessions} to the underlying repository source upon {@link #login() login}.
+ *
+ * @param descriptors The {@link #getDescriptorKeys() descriptors} for this repository; may be <code>null</code>.
+ * @param executionContextFactory An execution context factory.
+ * @param connectionFactory A repository connection factory.
+ * @throws IllegalArgumentException If <code>executionContextFactory</code> or <code>connectionFactory</code> is
+ * <code>null</code>.
+ */
+ public JcrRepository( Map<String, String> descriptors,
+ ExecutionContextFactory executionContextFactory,
+ RepositoryConnectionFactory connectionFactory ) {
+ ArgCheck.isNotNull(executionContextFactory, "executionContextFactory");
+ ArgCheck.isNotNull(connectionFactory, "connectionFactory");
+ this.executionContextFactory = executionContextFactory;
+ this.connectionFactory = connectionFactory;
+ Map<String, String> modifiableDescriptors;
+ if (descriptors == null) {
+ modifiableDescriptors = new HashMap<String, String>();
+ } else {
+ modifiableDescriptors = new HashMap<String, String>(descriptors);
+ }
+ // Initialize required JCR descriptors.
+ modifiableDescriptors.put(Repository.LEVEL_1_SUPPORTED, "true");
+ // TODO: Change to true once level 2 supported
+ modifiableDescriptors.put(Repository.LEVEL_2_SUPPORTED, "false");
+ // TODO: Change to true once locking supported
+ modifiableDescriptors.put(Repository.OPTION_LOCKING_SUPPORTED, "false");
+ // TODO: Change to true once observation supported
+ modifiableDescriptors.put(Repository.OPTION_OBSERVATION_SUPPORTED, "false");
+ // TODO: Change to true once query SQL supported
+ modifiableDescriptors.put(Repository.OPTION_QUERY_SQL_SUPPORTED, "false");
+ // TODO: Change to true once transactions supported
+ modifiableDescriptors.put(Repository.OPTION_TRANSACTIONS_SUPPORTED, "false");
+ // TODO: Change to true once versioning supported
+ modifiableDescriptors.put(Repository.OPTION_VERSIONING_SUPPORTED, "false");
+ modifiableDescriptors.put(Repository.QUERY_XPATH_DOC_ORDER, "true");
+ modifiableDescriptors.put(Repository.QUERY_XPATH_POS_INDEX, "true");
+ // Vendor-specific descriptors (REP_XXX) will only be initialized if not already present, allowing for customer branding.
+ // TODO: Should allow for branding via configuration
+ if (!modifiableDescriptors.containsKey(Repository.REP_NAME_DESC)) {
+ modifiableDescriptors.put(Repository.REP_NAME_DESC, JcrI18n.REP_NAME_DESC.text());
+ }
+ if (!modifiableDescriptors.containsKey(Repository.REP_VENDOR_DESC)) {
+ modifiableDescriptors.put(Repository.REP_VENDOR_DESC, JcrI18n.REP_VENDOR_DESC.text());
+ }
+ if (!modifiableDescriptors.containsKey(Repository.REP_VENDOR_URL_DESC)) {
+ modifiableDescriptors.put(Repository.REP_VENDOR_URL_DESC, "http://www.jboss.org/dna");
+ }
+ if (!modifiableDescriptors.containsKey(Repository.REP_VERSION_DESC)) {
+ // TODO: Permanent to-do to update the version for each release
+ modifiableDescriptors.put(Repository.REP_VERSION_DESC, "0.2");
+ }
+ modifiableDescriptors.put(Repository.SPEC_NAME_DESC, JcrI18n.SPEC_NAME_DESC.text());
+ modifiableDescriptors.put(Repository.SPEC_VERSION_DESC, "1.0");
+ this.descriptors = Collections.unmodifiableMap(modifiableDescriptors);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Repository#getDescriptor(java.lang.String)
+ */
+ public String getDescriptor( String key ) {
+ return descriptors.get(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Repository#getDescriptorKeys()
+ */
+ public String[] getDescriptorKeys() {
+ return descriptors.keySet().toArray(new String[descriptors.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Repository#login()
+ */
+ public synchronized Session login() throws RepositoryException {
+ return login(null, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Repository#login(javax.jcr.Credentials)
+ */
+ public synchronized Session login( Credentials credentials ) throws RepositoryException {
+ return login(credentials, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Repository#login(java.lang.String)
+ */
+ public synchronized Session login( String workspaceName ) throws RepositoryException {
+ return login(null, workspaceName);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Repository#login(javax.jcr.Credentials, java.lang.String)
+ */
+ public synchronized Session login( Credentials credentials,
+ String workspaceName ) throws RepositoryException {
+ // Ensure credentials are either null or provide a JAAS method
+ ExecutionContext execContext;
+ if (credentials == null) {
+ execContext = executionContextFactory.create();
+ } else {
+ try {
+ // Check if credentials provide a login context
+ try {
+ Method method = credentials.getClass().getMethod("getLoginContext");
+ if (method.getReturnType() != LoginContext.class) {
+ throw new IllegalArgumentException(JcrI18n.credentialsMustReturnLoginContext.text(credentials.getClass()));
+ }
+ LoginContext loginContext = (LoginContext)method.invoke(credentials);
+ if (loginContext == null) {
+ throw new IllegalArgumentException(JcrI18n.credentialsMustReturnLoginContext.text(credentials.getClass()));
+ }
+ execContext = executionContextFactory.create(loginContext);
+ } catch (NoSuchMethodException error) {
+ // Check if credentials provide an access control context
+ try {
+ Method method = credentials.getClass().getMethod("getAccessControlContext");
+ if (method.getReturnType() != AccessControlContext.class) {
+ throw new IllegalArgumentException(
+ JcrI18n.credentialsMustReturnAccessControlContext.text(credentials.getClass()));
+ }
+ AccessControlContext accessControlContext = (AccessControlContext)method.invoke(credentials);
+ if (accessControlContext == null) {
+ throw new IllegalArgumentException(
+ JcrI18n.credentialsMustReturnAccessControlContext.text(credentials.getClass()));
+ }
+ execContext = executionContextFactory.create(accessControlContext);
+ } catch (NoSuchMethodException error2) {
+ throw new IllegalArgumentException(JcrI18n.credentialsMustProvideJaasMethod.text(credentials.getClass()),
+ error2);
+ }
+ }
+ } catch (RuntimeException error) {
+ throw error;
+ } catch (Exception error) {
+ throw new RepositoryException(error);
+ }
+ }
+ // Authenticate
+ try {
+ assert execContext != null;
+ assert execContext.getLoginContext() != null;
+ execContext.getLoginContext().login();
+ } catch (javax.security.auth.login.LoginException error) {
+ throw new LoginException(error);
+ }
+ // Ensure valid workspace name
+ if (workspaceName == null) workspaceName = JcrI18n.defaultWorkspaceName.text();
+ // Create session
+ try {
+ RepositoryConnection connection = connectionFactory.createConnection(workspaceName);
+ assert connection != null;
+ return new JcrSession(this, new JcrExecutionContext(execContext, connection), workspaceName);
+ } catch (InterruptedException error) {
+ throw new RepositoryException(error);
+ }
+ }
+}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.Set;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import net.jcip.annotations.NotThreadSafe;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+final class JcrRootNode extends AbstractJcrNode {
+
+ JcrRootNode( Session session,
+ Set<Property> properties ) {
+ super(session, properties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getName()
+ */
+ public String getName() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getParent()
+ */
+ public Node getParent() throws ItemNotFoundException {
+ throw new ItemNotFoundException();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java (from rev 375, trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaSession.java)
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,392 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Principal;
+import java.util.Set;
+import javax.jcr.Credentials;
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
+import javax.jcr.Workspace;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginException;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.jcr.GraphTools.NodeContent;
+import org.xml.sax.ContentHandler;
+
+/**
+ * @author John Verhaeg
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+final class JcrSession implements Session {
+
+ private final JcrRepository repository;
+ private final JcrExecutionContext executionContext;
+ private boolean isLive;
+ private JcrWorkspace workspace;
+ private Node rootNode;
+
+ // private final Map<String, Node> uuid2NodeMap = new HashMap<String, Node>();
+
+ JcrSession( JcrRepository repository,
+ JcrExecutionContext executionContext,
+ String workspaceName ) throws RepositoryException {
+ assert repository != null;
+ assert executionContext != null;
+ assert workspaceName != null;
+ this.repository = repository;
+ this.executionContext = executionContext;
+ executionContext.getGraphTools().setSession(this);
+ this.isLive = true;
+ // Following must be initialized after session's state is initialized
+ this.workspace = new JcrWorkspace(this, workspaceName);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#addLockToken(java.lang.String)
+ */
+ public void addLockToken( String lt ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#checkPermission(java.lang.String, java.lang.String)
+ */
+ public void checkPermission( String absPath,
+ String actions ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#exportDocumentView(java.lang.String, org.xml.sax.ContentHandler, boolean, boolean)
+ */
+ public void exportDocumentView( String absPath,
+ ContentHandler contentHandler,
+ boolean skipBinary,
+ boolean noRecurse ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#exportDocumentView(java.lang.String, java.io.OutputStream, boolean, boolean)
+ */
+ public void exportDocumentView( String absPath,
+ OutputStream out,
+ boolean skipBinary,
+ boolean noRecurse ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#exportSystemView(java.lang.String, org.xml.sax.ContentHandler, boolean, boolean)
+ */
+ public void exportSystemView( String absPath,
+ ContentHandler contentHandler,
+ boolean skipBinary,
+ boolean noRecurse ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#exportSystemView(java.lang.String, java.io.OutputStream, boolean, boolean)
+ */
+ public void exportSystemView( String absPath,
+ OutputStream out,
+ boolean skipBinary,
+ boolean noRecurse ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getAttribute(java.lang.String)
+ */
+ public Object getAttribute( String name ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getAttributeNames()
+ */
+ public String[] getAttributeNames() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getImportContentHandler(java.lang.String, int)
+ */
+ public ContentHandler getImportContentHandler( String parentAbsPath,
+ int uuidBehavior ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getItem(java.lang.String)
+ */
+ public Item getItem( String absPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getLockTokens()
+ */
+ public String[] getLockTokens() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getNamespacePrefix(java.lang.String)
+ */
+ public String getNamespacePrefix( String uri ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getNamespacePrefixes()
+ */
+ public String[] getNamespacePrefixes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getNamespaceURI(java.lang.String)
+ */
+ public String getNamespaceURI( String prefix ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getNodeByUUID(java.lang.String)
+ */
+ public Node getNodeByUUID( String uuid ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getRepository()
+ */
+ public Repository getRepository() {
+ return this.repository;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getRootNode()
+ */
+ public Node getRootNode() throws RepositoryException {
+ // If root has no UUID, populate its contents from source
+ if (rootNode != null) {
+ return rootNode;
+ }
+ // Get root node from source
+ assert executionContext.getGraphTools() != null;
+ assert executionContext.getValueFactories() != null;
+ assert executionContext.getValueFactories().getPathFactory() != null;
+ NodeContent content = executionContext.getGraphTools().getNodeContent(executionContext.getValueFactories().getPathFactory().createRootPath());
+ rootNode = new JcrRootNode(this, content.properties);
+ return rootNode;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getUserID()
+ */
+ public String getUserID() {
+ Subject subject = executionContext.getSubject();
+ if (subject == null) return null;
+ Set<Principal> principals = subject.getPrincipals();
+ if (principals == null || principals.isEmpty()) return null;
+ return principals.iterator().next().getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getValueFactory()
+ */
+ public ValueFactory getValueFactory() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#getWorkspace()
+ */
+ public Workspace getWorkspace() {
+ return this.workspace;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#hasPendingChanges()
+ */
+ public boolean hasPendingChanges() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#impersonate(javax.jcr.Credentials)
+ */
+ public Session impersonate( Credentials credentials ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#importXML(java.lang.String, java.io.InputStream, int)
+ */
+ public void importXML( String parentAbsPath,
+ InputStream in,
+ int uuidBehavior ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#isLive()
+ */
+ public boolean isLive() {
+ return isLive;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#itemExists(java.lang.String)
+ */
+ public boolean itemExists( String absPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#logout()
+ */
+ public void logout() {
+ try {
+ if (executionContext.getRepositoryConnection() != null) {
+ executionContext.getRepositoryConnection().close();
+ }
+ assert executionContext.getLoginContext() != null;
+ executionContext.getLoginContext().logout();
+ isLive = false;
+ } catch (InterruptedException error) {
+ // TODO: Change to DnaException once DNA-180 is addressed
+ throw new RuntimeException(error);
+ } catch (LoginException error) {
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#move(java.lang.String, java.lang.String)
+ */
+ public void move( String srcAbsPath,
+ String destAbsPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#refresh(boolean)
+ */
+ public void refresh( boolean keepChanges ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#removeLockToken(java.lang.String)
+ */
+ public void removeLockToken( String lt ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#save()
+ */
+ public void save() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Session#setNamespacePrefix(java.lang.String, java.lang.String)
+ */
+ public void setNamespacePrefix( String newPrefix,
+ String existingUri ) {
+ throw new UnsupportedOperationException();
+ }
+}
Copied: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java (from rev 375, trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaWorkspace.java)
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.InputStream;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.observation.ObservationManager;
+import javax.jcr.query.QueryManager;
+import javax.jcr.version.Version;
+import org.xml.sax.ContentHandler;
+
+/**
+ * @author John Verhaeg
+ * @author Randall Hauch
+ */
+final class JcrWorkspace implements Workspace {
+
+ private final String name;
+ private final JcrSession session;
+
+ /**
+ * @param session the session that owns this workspace; may not be null
+ * @param name the name of the workspace; may not be null
+ * @throws RepositoryException
+ */
+ JcrWorkspace( JcrSession session,
+ String name ) throws RepositoryException {
+ assert session != null;
+ assert name != null;
+ this.session = session;
+ this.name = name;
+ // Ensure workspace with supplied name is accessible
+ // if (name == null) name = session.getDnaRepository().getSource(session.getSubject()).getName();
+ // String matchedName = null;
+ // for (String accessibleName : getAccessibleWorkspaceNames()) {
+ // if (name.equalsIgnoreCase(accessibleName)) {
+ // matchedName = name;
+ // break;
+ // }
+ // }
+ // if (matchedName == null) {
+ // throw new LoginException();
+ // }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void clone( String srcWorkspace,
+ String srcAbsPath,
+ String destAbsPath,
+ boolean removeExisting ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void copy( String srcAbsPath,
+ String destAbsPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void copy( String srcWorkspace,
+ String srcAbsPath,
+ String destAbsPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getAccessibleWorkspaceNames() {
+ // try {
+ // Node node = session.getRootNode().getNode("dna:jcr");
+ // if (node != null) {
+ // Property property = node.getProperty("dna:workspaceNames");
+ // if (property != null) {
+ // Value[] values = property.getValues();
+ // if (values.length > 0) {
+ // String[] names = new String[values.length];
+ // for (int ndx = values.length; --ndx >= 0;) {
+ // names[ndx] = values[ndx].getString();
+ // }
+ // return names;
+ // }
+ // }
+ // }
+ // } catch (PathNotFoundException meansOnlyDefaultWorkspaceNameAvailable) {
+ // // TODO: Check permissions and, if writable, create node & property and, if allowed, set to include this source's name
+ // }
+ // // Repository is read-only, so just return this source's name
+ // return new String[] {session.getDnaRepository().getSource(session.getSubject()).getName()};
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ContentHandler getImportContentHandler( String parentAbsPath,
+ int uuidBehavior ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeTypeManager getNodeTypeManager() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ObservationManager getObservationManager() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public QueryManager getQueryManager() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Session getSession() {
+ return this.session;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void importXML( String parentAbsPath,
+ InputStream in,
+ int uuidBehavior ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void move( String srcAbsPath,
+ String destAbsPath ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore( Version[] versions,
+ boolean removeExisting ) {
+ throw new UnsupportedOperationException();
+ }
+}
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 2008-08-08 20:43:42 UTC (rev 404)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2008-08-08 21:11:12 UTC (rev 405)
@@ -19,3 +19,13 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
#
+credentialsMustProvideJaasMethod = The Credentials class "{0}" must implement either "public LoginContext getLoginContext();" or "public AccessControlContext getAccessControlContext();".
+credentialsMustReturnAccessControlContext = The "getAccessControlContext()" method in Credentials class "{0}" must not return a null.
+credentialsMustReturnLoginContext = The "getLoginContext()" method in Credentials class "{0}" must not return a null.
+defaultWorkspaceName = Default
+repositoryMustBeConfigured = DNA repositories must be configured with either a repository source factory or a repository source.
+sourceInUse = All sessions must end before a new repository source can be set.
+
+REP_NAME_DESC = DNA Repository
+REP_VENDOR_DESC = JBoss - A division of Red Hat Middleware LLC
+SPEC_NAME_DESC = Content Repository for Java Technology API
\ No newline at end of file
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class AbstractJcrNodeTest {
+
+ private AbstractJcrNode node;
+ @Mock
+ private Session session;
+ private Set<Property> properties;
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ properties = new HashSet<Property>();
+ node = new AbstractJcrNode(session, properties) {
+
+ public String getName() {
+ return null;
+ }
+
+ public Node getParent() {
+ return null;
+ }
+ };
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoSession() throws Exception {
+ new AbstractJcrNode(null, properties) {
+
+ public String getName() {
+ return null;
+ }
+
+ public Node getParent() {
+ return null;
+ }
+ };
+ }
+
+ @Test
+ public void shouldProvideSession() throws Exception {
+ assertThat(node.getSession(), is(session));
+ }
+
+ @Test
+ public void shouldProvideUuid() throws Exception {
+ Property property = Mockito.mock(Property.class);
+ stub(property.getName()).toReturn("jcr:uuid");
+ Value value = Mockito.mock(Value.class);
+ stub(value.getString()).toReturn("uuid");
+ stub(property.getValue()).toReturn(value);
+ properties.add(property);
+ assertThat(node.getUUID(), is("uuid"));
+ }
+
+ @Test
+ public void shouldProvideNamedProperty() throws Exception {
+ Property property = Mockito.mock(Property.class);
+ stub(property.getName()).toReturn("test");
+ properties.add(property);
+ assertThat(node.getProperty("test"), is(property));
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import javax.jcr.Session;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class AbstractJcrPropertyTest {
+
+ private AbstractJcrProperty prop;
+ @Mock
+ private Session session;
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ prop = new AbstractJcrProperty(session, "name") {
+
+ public boolean getBoolean() {
+ return false;
+ }
+ };
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoSession() throws Exception {
+ new AbstractJcrProperty(null, "name") {
+
+ public boolean getBoolean() {
+ return false;
+ }
+ };
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoName() throws Exception {
+ new AbstractJcrProperty(session, null) {
+
+ public boolean getBoolean() {
+ return false;
+ }
+ };
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowEmptyName() throws Exception {
+ new AbstractJcrProperty(session, "") {
+
+ public boolean getBoolean() {
+ return false;
+ }
+ };
+ }
+
+ @Test
+ public void shouldProvideSession() throws Exception {
+ assertThat(prop.getSession(), is(session));
+ }
+
+ @Test
+ public void shouldProvideName() throws Exception {
+ assertThat(prop.getName(), is("name"));
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import javax.jcr.NamespaceException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrNamespaceRegistryTest {
+
+ private JcrNamespaceRegistry registry;
+
+ @Before
+ public void before() {
+ registry = new JcrNamespaceRegistry();
+ }
+
+ @Test
+ public void shouldProvidePrefixes() {
+ String[] prefixes = registry.getPrefixes();
+ assertThat(prefixes, notNullValue());
+ assertThat(prefixes.length, is(6));
+ assertThat(prefixes, hasItemInArray(""));
+ assertThat(prefixes, hasItemInArray("dna"));
+ assertThat(prefixes, hasItemInArray("jcr"));
+ assertThat(prefixes, hasItemInArray("mix"));
+ assertThat(prefixes, hasItemInArray("nt"));
+ assertThat(prefixes, hasItemInArray("xml"));
+ }
+
+ @Test
+ public void shouldProvideUris() {
+ String[] uris = registry.getURIs();
+ assertThat(uris, notNullValue());
+ assertThat(uris.length, is(6));
+ assertThat(uris, hasItemInArray(""));
+ assertThat(uris, hasItemInArray("http://www.jboss.org/dna/1.0"));
+ assertThat(uris, hasItemInArray("http://www.jcp.org/jcr/1.0"));
+ assertThat(uris, hasItemInArray("http://www.jcp.org/jcr/mix/1.0"));
+ assertThat(uris, hasItemInArray("http://www.jcp.org/jcr/nt/1.0"));
+ assertThat(uris, hasItemInArray("http://www.w3.org/XML/1998/namespace"));
+ }
+
+ @Test( expected = UnsupportedRepositoryOperationException.class )
+ public void shouldNotAllowRegisterNamespace() throws Exception {
+ registry.registerNamespace(null, null);
+ }
+
+ @Test( expected = UnsupportedRepositoryOperationException.class )
+ public void shouldNotAllowUnregisterNamespace() throws Exception {
+ registry.unregisterNamespace(null);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullPrefix() throws Exception {
+ registry.getURI(null);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullUri() throws Exception {
+ registry.getPrefix(null);
+ }
+
+ @Test
+ public void shouldProvideUriForRegisteredPrefix() throws Exception {
+ assertThat(registry.getPrefix(""), is(""));
+ assertThat(registry.getPrefix("http://www.jboss.org/dna/1.0"), is("dna"));
+ assertThat(registry.getPrefix("http://www.jcp.org/jcr/1.0"), is("jcr"));
+ assertThat(registry.getPrefix("http://www.jcp.org/jcr/mix/1.0"), is("mix"));
+ assertThat(registry.getPrefix("http://www.jcp.org/jcr/nt/1.0"), is("nt"));
+ assertThat(registry.getPrefix("http://www.w3.org/XML/1998/namespace"), is("xml"));
+ }
+
+ @Test
+ public void shouldProvidePrefixForRegisteredUri() throws Exception {
+ assertThat(registry.getURI(""), is(""));
+ assertThat(registry.getURI("dna"), is("http://www.jboss.org/dna/1.0"));
+ assertThat(registry.getURI("jcr"), is("http://www.jcp.org/jcr/1.0"));
+ assertThat(registry.getURI("mix"), is("http://www.jcp.org/jcr/mix/1.0"));
+ assertThat(registry.getURI("nt"), is("http://www.jcp.org/jcr/nt/1.0"));
+ assertThat(registry.getURI("xml"), is("http://www.w3.org/XML/1998/namespace"));
+ }
+
+ @Test( expected = NamespaceException.class )
+ public void shouldNotAllowUnregisteredPrefix() throws Exception {
+ registry.getURI("bogus");
+ }
+
+ @Test( expected = NamespaceException.class )
+ public void shouldNotAllowUnregisteredUri() throws Exception {
+ registry.getPrefix("bogus");
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrNodeTest {
+
+ private JcrNode node;
+ @Mock
+ private Session session;
+ private Set<Property> properties;
+
+ @Before
+ public void before() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ properties = new HashSet<Property>();
+ node = new JcrNode(session, properties);
+ }
+
+ @Test
+ public void shouldProvideName() throws Exception {
+ Property property = Mockito.mock(Property.class);
+ stub(property.getName()).toReturn("jcr:name");
+ Value value = Mockito.mock(Value.class);
+ stub(value.getString()).toReturn("name");
+ stub(property.getValue()).toReturn(value);
+ properties.add(property);
+ assertThat(node.getName(), is("name"));
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+
+/**
+ * @author jverhaeg
+ */
+public class JcrPropertyTest {
+ //
+ // private AbstractJcrProperty prop;
+ // @Mock
+ // private Session session;
+ //
+ // @Before
+ // public void before() {
+ // MockitoAnnotations.initMocks(this);
+ // prop = new AbstractJcrProperty(session, "name") {};
+ // }
+ //
+ // @Test( expected = AssertionError.class )
+ // public void shouldNotAllowNoSession() throws Exception {
+ // new AbstractJcrProperty(null, "name") {};
+ // }
+ //
+ // @Test( expected = AssertionError.class )
+ // public void shouldNotAllowNoName() throws Exception {
+ // new AbstractJcrProperty(session, null) {};
+ // }
+ //
+ // @Test( expected = AssertionError.class )
+ // public void shouldNotAllowEmptyName() throws Exception {
+ // new AbstractJcrProperty(session, "") {};
+ // }
+ //
+ // @Test
+ // public void shouldProvideSession() throws Exception {
+ // assertThat(prop.getSession(), is(session));
+ // }
+ //
+ // @Test
+ // public void shouldProvideName() throws Exception {
+ // assertThat(prop.getName(), is("name"));
+ // }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,235 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.util.HashMap;
+import java.util.Map;
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrRepositoryTest {
+
+ private Repository repository;
+ @Mock
+ private Map<String, String> descriptors;
+ @Mock
+ private ExecutionContextFactory executionContextFactory;
+ @Mock
+ private RepositoryConnectionFactory connectionFactory;
+ @Mock
+ private ExecutionContext executionContext;
+ @Mock
+ LoginContext loginContext;
+ @Mock
+ private RepositoryConnection connection;
+ AccessControlContext accessControlContext = AccessController.getContext();
+ private Credentials credentials = new Credentials() {
+
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public AccessControlContext getAccessControlContext() {
+ return accessControlContext;
+ }
+ };
+
+ @Before
+ public void before() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ stub(executionContext.getLoginContext()).toReturn(loginContext);
+ stub(executionContextFactory.create()).toReturn(executionContext);
+ stub(executionContextFactory.create(accessControlContext)).toReturn(executionContext);
+ stub(connectionFactory.createConnection(JcrI18n.defaultWorkspaceName.text())).toReturn(connection);
+ repository = new JcrRepository(descriptors, executionContextFactory, connectionFactory);
+ }
+
+ @Test
+ public void shouldAllowNoDescriptors() {
+ new JcrRepository(descriptors, executionContextFactory, connectionFactory);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNoExecutionContextFactory() throws Exception {
+ new JcrRepository(null, connectionFactory);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNoConnectionFactories() throws Exception {
+ new JcrRepository(executionContextFactory, null);
+ }
+
+ @Test
+ public void shouldProvideBuiltInDescriptorKeys() {
+ testDescriptorKeys(repository);
+ }
+
+ @Test
+ public void shouldProvideDescriptorValues() {
+ testDescriptorValues(repository);
+ }
+
+ @Test
+ public void shouldProvideBuiltInDescriptorsWhenNotSuppliedDescriptors() {
+ Repository repository = new JcrRepository(descriptors, executionContextFactory, connectionFactory);
+ testDescriptorKeys(repository);
+ testDescriptorValues(repository);
+ }
+
+ @Test
+ public void shouldProvideUserSuppliedDescriptors() {
+ Map<String, String> descriptors = new HashMap<String, String>();
+ descriptors.put("property", "value");
+ Repository repository = new JcrRepository(descriptors, executionContextFactory, connectionFactory);
+ testDescriptorKeys(repository);
+ testDescriptorValues(repository);
+ assertThat(repository.getDescriptor("property"), is("value"));
+ }
+
+ @Test
+ public void shouldAllowLoginWithNoCredentials() throws Exception {
+ Session session = repository.login();
+ assertThat(session, notNullValue());
+ session.logout();
+ session = repository.login((Credentials)null);
+ assertThat(session, notNullValue());
+ session.logout();
+ session = repository.login(null, JcrI18n.defaultWorkspaceName.text());
+ assertThat(session, notNullValue());
+ }
+
+ @Test
+ public void shouldAllowLoginWithProperCredentials() throws Exception {
+ repository.login(credentials);
+ stub(executionContextFactory.create(loginContext)).toReturn(executionContext);
+ repository.login(new Credentials() {
+
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public LoginContext getLoginContext() throws LoginException {
+ return loginContext;
+ }
+ });
+ }
+
+ @Test
+ public void shouldAllowLoginWithNoWorkspaceName() throws Exception {
+ Session session = repository.login((String)null);
+ assertThat(session, notNullValue());
+ session.logout();
+ session = repository.login(credentials, null);
+ assertThat(session, notNullValue());
+ session.logout();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowLoginIfCredentialsDoNotProvideJaasMethod() throws Exception {
+ repository.login(Mockito.mock(Credentials.class));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowLoginIfCredentialsReturnNoAccessControlContext() throws Exception {
+ repository.login(new Credentials() {
+
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public AccessControlContext getAccessControlContext() {
+ return null;
+ }
+ });
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowLoginIfCredentialsReturnNoLoginContext() throws Exception {
+ repository.login(new Credentials() {
+
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public LoginContext getLoginContext() {
+ return null;
+ }
+ });
+ }
+
+ private void testDescriptorKeys( Repository repository ) {
+ String[] keys = repository.getDescriptorKeys();
+ assertThat(keys, notNullValue());
+ assertThat(keys.length >= 15, is(true));
+ assertThat(keys, hasItemInArray(Repository.LEVEL_1_SUPPORTED));
+ assertThat(keys, hasItemInArray(Repository.LEVEL_2_SUPPORTED));
+ assertThat(keys, hasItemInArray(Repository.OPTION_LOCKING_SUPPORTED));
+ assertThat(keys, hasItemInArray(Repository.OPTION_OBSERVATION_SUPPORTED));
+ assertThat(keys, hasItemInArray(Repository.OPTION_QUERY_SQL_SUPPORTED));
+ assertThat(keys, hasItemInArray(Repository.OPTION_TRANSACTIONS_SUPPORTED));
+ assertThat(keys, hasItemInArray(Repository.OPTION_VERSIONING_SUPPORTED));
+ assertThat(keys, hasItemInArray(Repository.QUERY_XPATH_DOC_ORDER));
+ assertThat(keys, hasItemInArray(Repository.QUERY_XPATH_POS_INDEX));
+ assertThat(keys, hasItemInArray(Repository.REP_NAME_DESC));
+ assertThat(keys, hasItemInArray(Repository.REP_VENDOR_DESC));
+ assertThat(keys, hasItemInArray(Repository.REP_VENDOR_URL_DESC));
+ assertThat(keys, hasItemInArray(Repository.REP_VERSION_DESC));
+ assertThat(keys, hasItemInArray(Repository.SPEC_NAME_DESC));
+ assertThat(keys, hasItemInArray(Repository.SPEC_VERSION_DESC));
+ }
+
+ private void testDescriptorValues( Repository repository ) {
+ assertThat(repository.getDescriptor(Repository.LEVEL_1_SUPPORTED), is("true"));
+ assertThat(repository.getDescriptor(Repository.LEVEL_2_SUPPORTED), is("false"));
+ assertThat(repository.getDescriptor(Repository.OPTION_LOCKING_SUPPORTED), is("false"));
+ assertThat(repository.getDescriptor(Repository.OPTION_OBSERVATION_SUPPORTED), is("false"));
+ assertThat(repository.getDescriptor(Repository.OPTION_QUERY_SQL_SUPPORTED), is("false"));
+ assertThat(repository.getDescriptor(Repository.OPTION_TRANSACTIONS_SUPPORTED), is("false"));
+ assertThat(repository.getDescriptor(Repository.OPTION_VERSIONING_SUPPORTED), is("false"));
+ assertThat(repository.getDescriptor(Repository.QUERY_XPATH_DOC_ORDER), is("true"));
+ assertThat(repository.getDescriptor(Repository.QUERY_XPATH_POS_INDEX), is("true"));
+ assertThat(repository.getDescriptor(Repository.REP_NAME_DESC), is(JcrI18n.REP_NAME_DESC.text()));
+ assertThat(repository.getDescriptor(Repository.REP_VENDOR_DESC), is(JcrI18n.REP_VENDOR_DESC.text()));
+ assertThat(repository.getDescriptor(Repository.REP_VENDOR_URL_DESC), is("http://www.jboss.org/dna"));
+ assertThat(repository.getDescriptor(Repository.REP_VERSION_DESC), is("0.2"));
+ assertThat(repository.getDescriptor(Repository.SPEC_NAME_DESC), is(JcrI18n.SPEC_NAME_DESC.text()));
+ assertThat(repository.getDescriptor(Repository.SPEC_VERSION_DESC), is("1.0"));
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrRootNodeTest {
+
+ private JcrRootNode root;
+ @Mock
+ private Session session;
+ private Set<Property> properties;
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ properties = new HashSet<Property>();
+ root = new JcrRootNode(session, properties);
+ }
+
+ @Test
+ public void shouldHaveEmptyName() {
+ String name = root.getName();
+ assertThat(name, notNullValue());
+ assertThat(name.length(), is(0));
+ }
+
+ @Test( expected = ItemNotFoundException.class )
+ public void shouldHaveNoParent() throws Exception {
+ root.getParent();
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-08-08 21:11:12 UTC (rev 405)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.security.Principal;
+import java.util.Collections;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import org.jboss.dna.jcr.GraphTools.NodeContent;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.impl.BasicPath;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrSessionTest {
+
+ private JcrSession session;
+ @Mock
+ private JcrRepository repository;
+ @Mock
+ private JcrExecutionContext executionContext;
+ @Mock
+ private GraphTools tools;
+ @Mock
+ private LoginContext loginContext;
+
+ @Before
+ public void before() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ stub(executionContext.getLoginContext()).toReturn(loginContext);
+ stub(executionContext.getGraphTools()).toReturn(tools);
+ session = new JcrSession(repository, executionContext, JcrI18n.defaultWorkspaceName.text());
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoRepository() throws Exception {
+ new JcrSession(null, executionContext, JcrI18n.defaultWorkspaceName.text());
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoExecutionContext() throws Exception {
+ new JcrSession(repository, null, JcrI18n.defaultWorkspaceName.text());
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoWorkspaceName() throws Exception {
+ new JcrSession(repository, executionContext, null);
+ }
+
+ @Test
+ public void shouldProvideAccessToRepository() throws Exception {
+ assertThat((JcrRepository)session.getRepository(), is(repository));
+ }
+
+ @Test
+ public void shouldProvideAccessToWorkspace() throws Exception {
+ assertThat(session.getWorkspace(), notNullValue());
+ }
+
+ @Test
+ public void shouldBeLiveBeforeLogout() throws Exception {
+ assertThat(session.isLive(), is(true));
+ }
+
+ @Test
+ public void shouldAllowLogout() throws Exception {
+ session.logout();
+ }
+
+ @Test
+ public void shouldNotBeLiveAfterLogout() throws Exception {
+ session.logout();
+ assertThat(session.isLive(), is(false));
+ }
+
+ @Test
+ public void shouldProvideUserId() throws Exception {
+ assertThat(session.getUserID(), nullValue());
+ Principal principal = Mockito.mock(Principal.class);
+ stub(principal.getName()).toReturn("name");
+ Subject subject = new Subject(false, Collections.singleton(principal), Collections.EMPTY_SET, Collections.EMPTY_SET);
+ stub(executionContext.getSubject()).toReturn(subject);
+ assertThat(session.getUserID(), is("name"));
+ }
+
+ @Test
+ public void shouldProvideRootNode() throws Exception {
+ ValueFactories valueFactories = Mockito.mock(ValueFactories.class);
+ PathFactory pathFactory = Mockito.mock(PathFactory.class);
+ stub(pathFactory.createRootPath()).toReturn(BasicPath.ROOT);
+ stub(valueFactories.getPathFactory()).toReturn(pathFactory);
+ stub(executionContext.getValueFactories()).toReturn(valueFactories);
+ NodeContent content = tools.new NodeContent();
+ stub(tools.getNodeContent(BasicPath.ROOT)).toReturn(content);
+ assertThat(session.getRootNode(), notNullValue());
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r404 - in trunk: connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge and 8 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-08 16:43:42 -0400 (Fri, 08 Aug 2008)
New Revision: 404
Added:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java
Modified:
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added logic to handle same-name siblings. Also changed the structure of the "Lexicon" classes to be more easily used.
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -133,8 +133,8 @@
this.sourceProjections = sourceProjections;
this.connectionFactory = connectionFactory;
this.connectionsBySourceName = new HashMap<String, RepositoryConnection>();
- this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.UUID);
- this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.MERGE_PLAN);
+ this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.UUID);
+ this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.MERGE_PLAN);
this.sourceNames = new HashSet<String>();
for (Projection projection : this.sourceProjections) {
this.sourceNames.add(projection.getSourceName());
@@ -142,7 +142,7 @@
if (this.sourceProjections.size() == 1 && this.sourceProjections.get(0).isSimple()) {
this.mergingStrategy = new OneContributionMergeStrategy();
} else {
- this.mergingStrategy = new StandardMergeStrategy(DnaLexicon.PropertyNames.UUID);
+ this.mergingStrategy = new StandardMergeStrategy(DnaLexicon.UUID);
}
}
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -31,12 +31,11 @@
*/
public class StandardMergeStrategy implements MergeStrategy {
- private final String identityPropertyNameString;
+ private final Name identityPropertyName;
- public StandardMergeStrategy( String identityPropertyName ) {
+ public StandardMergeStrategy( Name identityPropertyName ) {
assert identityPropertyName != null;
- assert identityPropertyName.trim().length() != 0;
- this.identityPropertyNameString = identityPropertyName;
+ this.identityPropertyName = identityPropertyName;
}
/**
@@ -50,7 +49,6 @@
ExecutionContext context ) {
// Children whose identity properties are the same will be considered to be the same node ...
- Name identityPropertyName = context.getValueFactories().getNameFactory().create(this.identityPropertyNameString);
assert identityPropertyName != null;
}
}
Modified: trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -90,7 +90,7 @@
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
context = new BasicExecutionContext();
- context.getNamespaceRegistry().register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+ context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
executionContextFactoryJndiName = "context factory jndi name";
repositoryConnectionFactoryJndiName = "repository connection factory jndi name";
configurationSourceName = "configuration source name";
Modified: trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
===================================================================
--- trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -334,7 +334,7 @@
protected Executor( ExecutionContext context,
String sourceName ) {
super(context, sourceName);
- this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.UUID);
+ this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.UUID);
}
protected Property getUuidProperty( Node node ) {
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -24,6 +24,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.transaction.xa.XAResource;
@@ -73,7 +74,6 @@
}
};
- private boolean initializedUuidPropertyName = false;
private Name uuidPropertyName;
private final JBossCacheSource source;
private final Cache<Name, Object> cache;
@@ -166,10 +166,9 @@
* @return the name, or null if the UUID should not be stored
*/
protected Name getUuidPropertyName( ExecutionContext context ) {
- if (!initializedUuidPropertyName) {
+ if (uuidPropertyName == null) {
NameFactory nameFactory = context.getValueFactories().getNameFactory();
- this.uuidPropertyName = nameFactory.create(this.source.getUuidPropertyName());
- initializedUuidPropertyName = true;
+ uuidPropertyName = nameFactory.create(this.source.getUuidPropertyName());
}
return this.uuidPropertyName;
}
@@ -247,6 +246,127 @@
return numNodesCopied;
}
+ /**
+ * Update (or create) the array of {@link Path.Segment path segments} for the children of the supplied node. This array
+ * maintains the ordered list of children (since the {@link Cache} does not maintain the order). Invoking this method will
+ * change any existing children that a {@link Path.Segment#getName() name part} that matches the supplied
+ * <code>changedName</code> to have the appropriate {@link Path.Segment#getIndex() same-name sibling index}.
+ *
+ * @param parent the parent node; may not be null
+ * @param changedName the name that should be compared to the existing node siblings to determine whether the same-name
+ * sibling indexes should be updated; may not be null
+ * @param context the execution context; may not be null
+ */
+ @SuppressWarnings( "unchecked" )
+ protected void updateChildList( Node<Name, Object> parent,
+ Name changedName,
+ ExecutionContext context ) {
+ assert parent != null;
+ assert changedName != null;
+ assert context != null;
+ Set<Node<Name, Object>> children = parent.getChildren();
+ final int numChildren = children.size();
+ if (numChildren == 0) return;
+ // Go through the children, looking for any children with the same name as the 'changedName'
+ List<ChildInfo> childrenWithChangedName = new LinkedList<ChildInfo>();
+ Path.Segment[] childSegments = new Path.Segment[children.size()];
+ int index = 0;
+ for (Node<Name, Object> child : children) {
+ Path.Segment childSegment = (Path.Segment)child.getFqn().getLastElement();
+ Name childName = childSegment.getName();
+ if (childName.equals(changedName)) {
+ ChildInfo info = new ChildInfo(child.getFqn(), index);
+ childrenWithChangedName.add(info);
+ }
+ childSegments[index++] = childSegment;
+ }
+ // Go through the children with the same name as the 'changedName', making sure their indexes are correct ...
+ assert childrenWithChangedName.isEmpty() == false;
+ if (childrenWithChangedName.size() == 1) {
+ // The child should have no indexes ...
+ ChildInfo child = childrenWithChangedName.get(0);
+ Fqn<Path.Segment> fqn = child.getFqn();
+ Path.Segment segment = fqn.getLastElement();
+ if (segment.hasIndex()) {
+ // Determine the new name and index ...
+ Path.Segment newSegment = context.getValueFactories().getPathFactory().createSegment(changedName);
+ // Replace the child with the correct FQN ...
+ changeNodeName(parent, fqn, newSegment, context);
+ // Change the segment in the child list ...
+ childSegments[child.getChildIndex()] = newSegment;
+ }
+ } else {
+ // There is more than one child with the same name ...
+ int i = 0;
+ for (ChildInfo child : childrenWithChangedName) {
+ Fqn<Path.Segment> fqn = child.getFqn();
+ Path.Segment childSegment = fqn.getLastElement();
+ if (childSegment.getIndex() != i) {
+ // Determine the new name and index ...
+ Path.Segment newSegment = context.getValueFactories().getPathFactory().createSegment(changedName, i);
+ // Replace the child with the correct FQN ...
+ changeNodeName(parent, fqn, newSegment, context);
+ // Change the segment in the child list ...
+ childSegments[child.getChildIndex()] = newSegment;
+ }
+ ++i;
+ }
+ }
+ // Record the list of children as a property on the parent ...
+ // (Do this last, as it doesn't need to be done if there's an exception in the above logic)
+ parent.put(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST, childSegments); // replaces any existing value
+ }
+
+ /**
+ * Utility class used by the {@link JBossCacheConnection#updateChildList(Node, Name, ExecutionContext)} method.
+ *
+ * @author Randall Hauch
+ */
+ private static class ChildInfo {
+ private final Fqn<Path.Segment> fqn;
+ private final int childIndex;
+
+ protected ChildInfo( Fqn<Path.Segment> fqn,
+ int childIndex ) {
+ assert fqn != null;
+ this.fqn = fqn;
+ this.childIndex = childIndex;
+ }
+
+ public int getChildIndex() {
+ return childIndex;
+ }
+
+ public Fqn<Path.Segment> getFqn() {
+ return fqn;
+ }
+ }
+
+ /**
+ * Changes the name of the node in the cache (but does not update the list of child segments stored on the parent).
+ *
+ * @param parent
+ * @param existing
+ * @param newSegment
+ * @param context
+ */
+ protected void changeNodeName( Node<Name, Object> parent,
+ Fqn<Path.Segment> existing,
+ Path.Segment newSegment,
+ ExecutionContext context ) {
+ assert parent != null;
+ assert existing != null;
+ assert newSegment != null;
+ assert context != null;
+ parent.removeChild(existing);
+ List<Path.Segment> elements = existing.peekElements();
+ assert elements.size() > 0;
+ elements.set(elements.size() - 1, newSegment);
+ existing = Fqn.fromList(elements);
+ parent.addChild(existing);
+
+ }
+
protected class Executor extends AbstractCommandExecutor {
private final PropertyFactory propertyFactory;
@@ -267,6 +387,12 @@
// Look up the parent node, which must exist ...
Node<Name, Object> parentNode = getNode(parent);
Node<Name, Object> node = parentNode.addChild(childFqn);
+
+ // Update the children to account for same-name siblings.
+ // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+ // the array of Path.Segment for the children (since the cache doesn't maintain order).
+ updateChildList(parentNode, path.getLastSegment().getName(), getExecutionContext());
+
// Add the UUID property (if required), which may be overwritten by a supplied property ...
Name uuidPropertyName = getUuidPropertyName(getExecutionContext());
if (uuidPropertyName != null) {
@@ -286,22 +412,29 @@
}
}
+ @SuppressWarnings( "unchecked" )
@Override
public void execute( GetChildrenCommand command ) {
Node<Name, Object> node = getNode(command.getPath());
Name uuidPropertyName = getUuidPropertyName(getExecutionContext());
- // Get the names of the children ...
- for (Node<Name, Object> child : node.getChildren()) {
- Segment segment = (Segment)child.getFqn().getLastElement();
- Object uuid = node.getData().get(uuidPropertyName);
+ List<Path.Segment> segments = node.getFqn().peekElements();
+ segments.add(null);
+ // Get the names of the children, using the child list ...
+ Path.Segment[] childList = (Path.Segment[])node.get(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST);
+ for (Path.Segment child : childList) {
+ // We have the child segment, but we need the UUID property ...
+ segments.set(segments.size() - 1, child); // each iteration sets this last list element ...
+ Fqn<Path.Segment> fqn = Fqn.fromList(segments);
+ Node<Name, Object> childNode = node.getChild(fqn);
+ Object uuid = childNode.getData().get(uuidPropertyName);
if (uuid == null) {
uuid = generateUuid();
- node.getData().put(uuidPropertyName, uuid);
+ childNode.getData().put(uuidPropertyName, uuid);
} else {
uuid = uuidFactory.create(uuid);
}
Property uuidProperty = propertyFactory.create(uuidPropertyName, uuid);
- command.addChild(segment, uuidProperty);
+ command.addChild(child, uuidProperty);
}
}
@@ -311,6 +444,8 @@
Map<Name, Object> dataMap = node.getData();
for (Map.Entry<Name, Object> data : dataMap.entrySet()) {
Name propertyName = data.getKey();
+ // Don't allow the child list property to be accessed
+ if (propertyName.equals(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST)) continue;
Object values = data.getValue();
Property property = propertyFactory.create(propertyName, values);
command.setProperty(property);
@@ -323,6 +458,8 @@
// Now set (or remove) the properties to the supplied node ...
for (Property property : command.getPropertyIterator()) {
Name propName = property.getName();
+ // Don't allow the child list property to be removed or changed
+ if (propName.equals(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST)) continue;
if (property.size() == 0) {
node.remove(propName);
continue;
@@ -350,6 +487,10 @@
Path newPath = command.getNewPath();
Node<Name, Object> newParent = getNode(newPath.getAncestor());
copyNode(node, newParent, false, null);
+ // Update the children to account for same-name siblings.
+ // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+ // the array of Path.Segment for the children (since the cache doesn't maintain order).
+ updateChildList(newParent, newPath.getLastSegment().getName(), getExecutionContext());
}
@Override
@@ -359,6 +500,10 @@
Path newPath = command.getNewPath();
Node<Name, Object> newParent = getNode(newPath.getAncestor());
copyNode(node, newParent, true, null);
+ // Update the children to account for same-name siblings.
+ // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+ // the array of Path.Segment for the children (since the cache doesn't maintain order).
+ updateChildList(newParent, newPath.getLastSegment().getName(), getExecutionContext());
}
@Override
@@ -370,6 +515,10 @@
Path newPath = command.getNewPath();
Node<Name, Object> newParent = getNode(newPath.getAncestor());
copyNode(node, newParent, recursive, uuidProperty);
+ // Update the children to account for same-name siblings.
+ // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+ // the array of Path.Segment for the children (since the cache doesn't maintain order).
+ updateChildList(newParent, newPath.getLastSegment().getName(), getExecutionContext());
// Now delete the old node ...
Node<Name, Object> oldParent = node.getParent();
boolean removed = oldParent.removeChild(node.getFqn().getLastElement());
Added: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java (rev 0)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.jbosscache;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.impl.BasicName;
+
+/**
+ * The namespace and property names used within a {@link JBossCacheSource} to store internal information.
+ *
+ * @author Randall Hauch
+ */
+public class JBossCacheLexicon {
+
+ public static class Namespace {
+ public static final String URI = "http://www.jboss.org/dna/connector/jbosscache";
+ public static final String PREFIX = "dnajbcc";
+ }
+
+ public static final Name CHILD_PATH_SEGMENT_LIST = new BasicName(Namespace.URI, "orderedChildNames");
+
+}
Property changes on: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -78,7 +78,7 @@
* The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
*/
public static final int DEFAULT_RETRY_LIMIT = 0;
- public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
+ public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.UUID.getString();
protected static final String ROOT_NODE_UUID = "rootNodeUuid";
protected static final String SOURCE_NAME = "sourceName";
Modified: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -70,7 +70,7 @@
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
context = new BasicExecutionContext();
- context.getNamespaceRegistry().register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+ context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
pathFactory = context.getValueFactories().getPathFactory();
cacheFactory = new DefaultCacheFactory<Name, Object>();
cache = cacheFactory.createCache();
@@ -141,11 +141,11 @@
@Test
public void shouldGetUuidPropertyNameFromSouceAndShouldNotChangeDuringLifetimeOfConnection() {
- stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
Name name = connection.getUuidPropertyName(context);
verify(source).getUuidPropertyName();
assertThat(name.getLocalName(), is("uuid"));
- assertThat(name.getNamespaceUri(), is(DnaLexicon.NAMESPACE_URI));
+ assertThat(name.getNamespaceUri(), is(DnaLexicon.Namespace.URI));
stub(source.getUuidPropertyName()).toReturn("something else");
for (int i = 0; i != 10; ++i) {
Name name2 = connection.getUuidPropertyName(context);
@@ -216,7 +216,7 @@
@Test
public void shouldGetNodeIfItExistsInCache() {
// Set up the cache with data ...
- stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
Name uuidProperty = connection.getUuidPropertyName(context);
Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
Path nonExistantPath = pathFactory.create("/a/d");
@@ -241,7 +241,7 @@
@Test
public void shouldThrowExceptionWithLowestExistingNodeFromGetNodeIfTheNodeDoesNotExist() {
// Set up the cache with data ...
- stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
Name uuidProperty = connection.getUuidPropertyName(context);
Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
Path nonExistantPath = pathFactory.create("/a/d");
@@ -268,7 +268,7 @@
@Test
public void shouldCopyNode() {
// Set up the cache with data ...
- stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
Name uuidProperty = connection.getUuidPropertyName(context);
Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c"),
pathFactory.create("/a/d")};
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -87,7 +87,7 @@
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
NamespaceRegistry registry = new BasicNamespaceRegistry();
- registry.register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+ registry.register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
valueFactories = new StandardValueFactories(registry);
pathFactory = valueFactories.getPathFactory();
propertyFactory = new BasicPropertyFactory(valueFactories);
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -21,16 +21,19 @@
*/
package org.jboss.dna.spi;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.impl.BasicName;
+
/**
* @author Randall Hauch
*/
public class DnaLexicon {
- public static final String NAMESPACE_URI = "http://www.jboss.org/dna";
- public static final String NAMESPACE_PREFIX = "dna";
+ public static class Namespace {
+ public static final String URI = "http://www.jboss.org/dna";
+ public static final String PREFIX = "dna";
+ }
- public static class PropertyNames {
- public static final String UUID = "dna:uuid";
- public static final String MERGE_PLAN = "dna:mergePlan";
- }
+ public static final Name UUID = new BasicName(Namespace.URI, "uuid");
+ public static final Name MERGE_PLAN = new BasicName(Namespace.URI, "mergePlan");
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -52,7 +52,7 @@
@ThreadSafe
public class SimpleRepository {
- public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
+ public static final Name DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.UUID;
private static final ConcurrentMap<String, SimpleRepository> repositoriesByName = new ConcurrentHashMap<String, SimpleRepository>();
@@ -68,7 +68,7 @@
private ConcurrentMap<Path, Map<Name, Property>> data = new ConcurrentHashMap<Path, Map<Name, Property>>();
private final String repositoryName;
- private String uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
+ private Name uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
private boolean shutdown = false;
public SimpleRepository( String repositoryName ) {
@@ -88,15 +88,15 @@
/**
* @return uuidPropertyName
*/
- public String getUuidPropertyName() {
+ public Name getUuidPropertyName() {
return uuidPropertyName;
}
/**
* @param uuidPropertyName Sets uuidPropertyName to the specified value.
*/
- public void setUuidPropertyName( String uuidPropertyName ) {
- if (uuidPropertyName == null || uuidPropertyName.trim().length() == 0) uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
+ public void setUuidPropertyName( Name uuidPropertyName ) {
+ if (uuidPropertyName == null) uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
this.uuidPropertyName = uuidPropertyName;
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -46,8 +46,8 @@
@Before
public void beforeEach() {
- this.validNamespacePrefix = DnaLexicon.NAMESPACE_PREFIX;
- this.validNamespaceUri = DnaLexicon.NAMESPACE_URI;
+ this.validNamespacePrefix = DnaLexicon.Namespace.PREFIX;
+ this.validNamespaceUri = DnaLexicon.Namespace.URI;
this.validLocalName = "localPart";
this.name = new BasicName(validNamespaceUri, validLocalName);
this.encoder = Path.URL_ENCODER;
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -49,7 +49,7 @@
@Before
public void beforeEach() {
this.registry = new BasicNamespaceRegistry();
- this.registry.register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+ this.registry.register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
this.stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
this.nameFactory = new NameValueFactory(registry, Path.DEFAULT_DECODER, stringValueFactory);
this.validName = nameFactory.create("dna:something");
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-08 20:43:42 UTC (rev 404)
@@ -60,8 +60,8 @@
@Before
public void beforeEach() {
- validNamespacePrefix = DnaLexicon.NAMESPACE_PREFIX;
- validNamespaceUri = DnaLexicon.NAMESPACE_URI;
+ validNamespacePrefix = DnaLexicon.Namespace.PREFIX;
+ validNamespaceUri = DnaLexicon.Namespace.URI;
validSegmentNames = new Name[] {new BasicName(validNamespaceUri, "a"), new BasicName(validNamespaceUri, "b"),
new BasicName(validNamespaceUri, "c")};
validSegments = new Path.Segment[] {new BasicPathSegment(validSegmentNames[0]),
15 years, 10 months
DNA SVN: r403 - in trunk: connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor and 8 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-07 18:37:39 -0400 (Thu, 07 Aug 2008)
New Revision: 403
Added:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java
Removed:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/AbstractRepositorySource.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceRegistry.java
Modified:
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepository.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java
trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java
trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionPool.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/RepositoryConnectionPoolTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java
Log:
DNA-192 - Clean up the repository connector SPI
http://jira.jboss.com/jira/browse/DNA-192
Refactored the classes again, since the RepositorySource needs to be serializable and able to be turned into a JNDI reference. In other words, the RepositorySource needs to be a factory for creating connections to a specific repository, but it shouldn't manage the pool of connections (since the pool and any live connections cannot be serialized).
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepository.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepository.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepository.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -32,15 +32,15 @@
import org.jboss.dna.connector.federation.executor.FederatingCommandExecutor;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceListener;
-import org.jboss.dna.spi.connector.RepositorySourceRegistry;
import org.jboss.dna.spi.graph.commands.executor.CommandExecutor;
/**
* The component that represents a single federated repository. The federated repository uses a set of {@link RepositorySource
- * federated sources} as designated by name through the {@link #getConfiguration() configuration}, and provides the logic of
- * interacting with those sources and presenting a single unified graph.
+ * federated connectionFactory} as designated by name through the {@link #getConfiguration() configuration}, and provides the
+ * logic of interacting with those connectionFactory and presenting a single unified graph.
*
* @author Randall Hauch
*/
@@ -48,7 +48,7 @@
public class FederatedRepository {
private final ExecutionContext context;
- private final RepositorySourceRegistry sources;
+ private final RepositoryConnectionFactory connectionFactory;
private FederatedRepositoryConfig config;
private final AtomicInteger openExecutors = new AtomicInteger(0);
private final CountDownLatch shutdownLatch = new CountDownLatch(1);
@@ -59,18 +59,18 @@
* Create a federated repository instance.
*
* @param context the execution context
- * @param sources the registry of {@link RepositorySource} instances that should be used
+ * @param connectionFactory the factory for {@link RepositoryConnection} instances that should be used
* @param config the configuration for this repository
* @throws IllegalArgumentException if any of the parameters are null, or if the name is blank
*/
public FederatedRepository( ExecutionContext context,
- RepositorySourceRegistry sources,
+ RepositoryConnectionFactory connectionFactory,
FederatedRepositoryConfig config ) {
- ArgCheck.isNotNull(sources, "sources");
+ ArgCheck.isNotNull(connectionFactory, "connectionFactory");
ArgCheck.isNotNull(context, "context");
ArgCheck.isNotNull(config, "config");
this.context = context;
- this.sources = sources;
+ this.connectionFactory = connectionFactory;
this.config = config;
}
@@ -91,17 +91,17 @@
}
/**
- * @return the sources
+ * @return the connectionFactory
*/
- protected RepositorySourceRegistry getRepositorySourceRegistry() {
- return sources;
+ protected RepositoryConnectionFactory getConnectionFactory() {
+ return connectionFactory;
}
/**
* Utility method called by the administrator.
*/
public synchronized void start() {
- // Do not establish connections to the sources; these will be established as needed
+ // Do not establish connections to the connectionFactory; these will be established as needed
}
/**
@@ -232,7 +232,7 @@
String sourceName ) {
FederatedRepositoryConfig config = this.getConfiguration();
return new FederatingCommandExecutor(context, sourceName, config.getCacheProjection(), config.getDefaultCachePolicy(),
- config.getSourceProjections(), getRepositorySourceRegistry());
+ config.getSourceProjections(), getConnectionFactory());
}
/**
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -28,6 +28,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.RefAddr;
@@ -52,12 +53,11 @@
import org.jboss.dna.spi.ExecutionContextFactory;
import org.jboss.dna.spi.cache.BasicCachePolicy;
import org.jboss.dna.spi.cache.CachePolicy;
-import org.jboss.dna.spi.connector.AbstractRepositorySource;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
import org.jboss.dna.spi.connector.RepositorySourceException;
-import org.jboss.dna.spi.connector.RepositorySourceRegistry;
import org.jboss.dna.spi.graph.InvalidPathException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
@@ -78,12 +78,17 @@
* @author Randall Hauch
*/
@ThreadSafe
-public class FederatedRepositorySource extends AbstractRepositorySource implements ObjectFactory {
+public class FederatedRepositorySource implements RepositorySource, ObjectFactory {
/**
*/
private static final long serialVersionUID = 7587346948013486977L;
+ /**
+ * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ */
+ public static final int DEFAULT_RETRY_LIMIT = 0;
+
public static final String[] DEFAULT_CONFIGURATION_SOURCE_PROJECTION_RULES = {"/dna:system => /"};
protected static final String REPOSITORY_NAME = "repositoryName";
@@ -92,7 +97,7 @@
protected static final String PASSWORD = "password";
protected static final String CONFIGURATION_SOURCE_NAME = "configurationSourceName";
protected static final String CONFIGURATION_SOURCE_PROJECTION_RULES = "configurationSourceProjectionRules";
- protected static final String REPOSITORY_SOURCE_REGISTRY_JNDI_NAME = "repositorySourceRegistryJndiName";
+ protected static final String REPOSITORY_CONNECTION_FACTORY_JNDI_NAME = "repositoryConnectionFactoryJndiName";
protected static final String EXECUTION_CONTEXT_FACTORY_JNDI_NAME = "executionContextFacotryJndiName";
protected static final String REPOSITORY_JNDI_NAME = "repositoryJndiName";
protected static final String SECURITY_DOMAIN = "securityDomain";
@@ -107,10 +112,11 @@
private String password;
private String configurationSourceName;
private String[] configurationSourceProjectionRules = DEFAULT_CONFIGURATION_SOURCE_PROJECTION_RULES;
- private String repositorySourceRegistryJndiName;
+ private String repositoryConnectionFactoryJndiName;
private String executionContextFactoryJndiName;
private String securityDomain;
private String repositoryJndiName;
+ private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private transient FederatedRepository repository;
private transient Context jndiContext;
@@ -149,7 +155,7 @@
*
* @param sourceName the name of this repository source
* @see #setConfigurationSourceName(String)
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setConfigurationSourceProjectionRules(String[])
* @see #setPassword(String)
* @see #setUsername(String)
@@ -166,6 +172,24 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#setRetryLimit(int)
+ */
+ public void setRetryLimit( int limit ) {
+ retryLimit.set(limit < 0 ? 0 : limit);
+ }
+
+ /**
* Get the name in JNDI of a {@link FederatedRepository} instance that should be used. If this is set (and an instance can be
* found at that location), few of the remaining properties on this instance may not be used (basically just
* {@link #getUsername() username}, {@link #getPassword() password}, and {@link #getName() source name}).
@@ -219,8 +243,8 @@
/**
* Get the name of a {@link RepositorySource} instance that should be used by the {@link FederatedRepository federated
- * repository} as the configuration repository. The instance will be retrieved from the {@link RepositorySourceRegistry}
- * instance {@link #getRepositorySourceRegistryJndiName() found in JDNI}.
+ * repository} as the configuration repository. The instance will be retrieved from the {@link RepositoryConnectionFactory}
+ * instance {@link #getRepositoryConnectionFactoryJndiName() found in JDNI}.
* <p>
* This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
* </p>
@@ -228,7 +252,7 @@
* @param sourceName the name of the {@link RepositorySource} instance that should be used for the configuration, or null if
* the federated repository instance is to be found in JNDI
* @see #getConfigurationSourceName()
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setConfigurationSourceProjectionRules(String[])
* @see #setPassword(String)
* @see #setUsername(String)
@@ -270,7 +294,7 @@
* @param projectionRules the string array of projection rules, or null if the projection rules haven't yet been set or if the
* federated repository instance is to be found in JNDI
* @see #setConfigurationSourceProjectionRules(String[])
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setConfigurationSourceName(String)
* @see #setPassword(String)
* @see #setUsername(String)
@@ -316,7 +340,7 @@
* @see #getExecutionContextFactoryJndiName()
* @see #setConfigurationSourceName(String)
* @see #setConfigurationSourceProjectionRules(String[])
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
@@ -329,32 +353,32 @@
}
/**
- * Get the name in JNDI where the {@link RepositorySourceRegistry} instance that can be used by the
+ * Get the name in JNDI where the {@link RepositoryConnectionFactory} instance that can be used by the
* {@link FederatedRepository federated repository} can find any {@link RepositorySource} sources it needs, including those
* used for {@link Projection sources} and that used for it's {@link #getConfigurationSourceName() configuration}.
* <p>
* This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
* </p>
*
- * @return the JNDI name where the {@link RepositorySourceRegistry} instance can be found, or null if the federated repository
- * instance is to be found in JNDI
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @return the JNDI name where the {@link RepositoryConnectionFactory} instance can be found, or null if the federated
+ * repository instance is to be found in JNDI
+ * @see #setRepositoryConnectionFactoryJndiName(String)
*/
- public String getRepositorySourceRegistryJndiName() {
- return repositorySourceRegistryJndiName;
+ public String getRepositoryConnectionFactoryJndiName() {
+ return repositoryConnectionFactoryJndiName;
}
/**
- * Set the name in JNDI where the {@link RepositorySourceRegistry} instance that can be used by the
+ * Set the name in JNDI where the {@link RepositoryConnectionFactory} instance that can be used by the
* {@link FederatedRepository federated repository} can find any {@link RepositorySource} sources it needs, including those
* used for {@link Projection sources} and that used for it's {@link #getConfigurationSourceName() configuration}.
* <p>
* This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
* </p>
*
- * @param jndiName the JNDI name where the {@link RepositorySourceRegistry} instance can be found, or null if the federated
+ * @param jndiName the JNDI name where the {@link RepositoryConnectionFactory} instance can be found, or null if the federated
* repository instance is to be found in JNDI
- * @see #getRepositorySourceRegistryJndiName()
+ * @see #getRepositoryConnectionFactoryJndiName()
* @see #setConfigurationSourceName(String)
* @see #setConfigurationSourceProjectionRules(String[])
* @see #setPassword(String)
@@ -363,10 +387,10 @@
* @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
- public synchronized void setRepositorySourceRegistryJndiName( String jndiName ) {
- if (this.repositorySourceRegistryJndiName == jndiName || this.repositorySourceRegistryJndiName != null
- && this.repositorySourceRegistryJndiName.equals(jndiName)) return; // unchanged
- this.repositorySourceRegistryJndiName = jndiName;
+ public synchronized void setRepositoryConnectionFactoryJndiName( String jndiName ) {
+ if (this.repositoryConnectionFactoryJndiName == jndiName || this.repositoryConnectionFactoryJndiName != null
+ && this.repositoryConnectionFactoryJndiName.equals(jndiName)) return; // unchanged
+ this.repositoryConnectionFactoryJndiName = jndiName;
changeRepositoryConfig();
}
@@ -418,7 +442,7 @@
* @see #setConfigurationSourceProjectionRules(String[])
* @see #setPassword(String)
* @see #setUsername(String)
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
@@ -455,7 +479,7 @@
* @see #setConfigurationSourceProjectionRules(String[])
* @see #setPassword(String)
* @see #setRepositoryName(String)
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
@@ -490,7 +514,7 @@
* @see #setConfigurationSourceProjectionRules(String[])
* @see #setUsername(String)
* @see #setRepositoryName(String)
- * @see #setRepositorySourceRegistryJndiName(String)
+ * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
@@ -503,16 +527,16 @@
/**
* This method is called to signal that some aspect of the configuration has changed. If a {@link #getRepository() repository}
* instance has been created, it's configuration is
- * {@link #getRepositoryConfiguration(ExecutionContext, RepositorySourceRegistry) rebuilt} and updated. Nothing is done,
+ * {@link #getRepositoryConfiguration(ExecutionContext, RepositoryConnectionFactory) rebuilt} and updated. Nothing is done,
* however, if there is currently no {@link #getRepository() repository}.
*/
protected synchronized void changeRepositoryConfig() {
if (this.repository != null) {
// Find in JNDI the repository source registry and the environment ...
ExecutionContext context = getExecutionContext();
- RepositorySourceRegistry registry = getRepositorySourceRegistry();
+ RepositoryConnectionFactory factory = getConnectionFactory();
// Compute a new repository config and set it on the repository ...
- FederatedRepositoryConfig newConfig = getRepositoryConfiguration(context, registry);
+ FederatedRepositoryConfig newConfig = getRepositoryConfiguration(context, factory);
this.repository.setConfiguration(newConfig);
}
}
@@ -520,10 +544,9 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.connector.AbstractRepositorySource#createConnection()
+ * @see org.jboss.dna.spi.connector.RepositorySource#getConnection()
*/
- @Override
- protected synchronized RepositoryConnection createConnection() throws RepositorySourceException {
+ public RepositoryConnection getConnection() throws RepositorySourceException {
if (getName() == null) {
I18n msg = FederationI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("name"));
@@ -536,7 +559,7 @@
I18n msg = FederationI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("security domain"));
}
- if (getRepositorySourceRegistryJndiName() == null) {
+ if (getRepositoryConnectionFactoryJndiName() == null) {
I18n msg = FederationI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("repository source registry JNDI name"));
}
@@ -559,7 +582,7 @@
* <ol>
* <li>If a {@link FederatedRepository} already was obtained from a prior call, the same instance is returned.</li>
* <li>A {@link FederatedRepository} is created using a {@link FederatedRepositoryConfig} is created from this instance's
- * properties and {@link ExecutionContext} and {@link RepositorySourceRegistry} instances obtained from JNDI.</li>
+ * properties and {@link ExecutionContext} and {@link RepositoryConnectionFactory} instances obtained from JNDI.</li>
* <li></li>
* <li></li>
* </ol>
@@ -594,10 +617,10 @@
if (repository == null) {
// Find in JNDI the repository source registry and the environment ...
ExecutionContext context = getExecutionContext();
- RepositorySourceRegistry registry = getRepositorySourceRegistry();
+ RepositoryConnectionFactory connectionFactory = getConnectionFactory();
// And create the configuration and the repository ...
- FederatedRepositoryConfig config = getRepositoryConfiguration(context, registry);
- repository = new FederatedRepository(context, registry, config);
+ FederatedRepositoryConfig config = getRepositoryConfiguration(context, connectionFactory);
+ repository = new FederatedRepository(context, connectionFactory, config);
}
}
return repository;
@@ -639,22 +662,22 @@
}
}
- protected RepositorySourceRegistry getRepositorySourceRegistry() {
- RepositorySourceRegistry factories = null;
+ protected RepositoryConnectionFactory getConnectionFactory() {
+ RepositoryConnectionFactory factories = null;
Context context = getContext();
- String jndiName = getRepositorySourceRegistryJndiName();
+ String jndiName = getRepositoryConnectionFactoryJndiName();
if (jndiName != null && jndiName.trim().length() != 0) {
Object object = null;
try {
if (context == null) context = new InitialContext();
object = context.lookup(jndiName);
- if (object != null) factories = (RepositorySourceRegistry)object;
+ if (object != null) factories = (RepositoryConnectionFactory)object;
} catch (ClassCastException err) {
I18n msg = FederationI18n.objectFoundInJndiWasNotOfExpectedType;
String className = object != null ? object.getClass().getName() : "null";
throw new RepositorySourceException(getName(), msg.text(jndiName,
this.getName(),
- RepositorySourceRegistry.class.getName(),
+ RepositoryConnectionFactory.class.getName(),
className), err);
} catch (Throwable err) {
I18n msg = FederationI18n.unableToFindRepositoryConnectionFactoriesInJndi;
@@ -698,11 +721,11 @@
* <i>not</i> modify the state of this instance.
*
* @param context the execution context that should be used to read the configuration; may not be null
- * @param registry the registry from which {@link RepositorySource} instances can be obtained; may not be null
+ * @param connectionFactory the factory for {@link RepositoryConnection}s can be obtained; may not be null
* @return a configuration reflecting the current state of this instance
*/
protected synchronized FederatedRepositoryConfig getRepositoryConfiguration( ExecutionContext context,
- RepositorySourceRegistry registry ) {
+ RepositoryConnectionFactory connectionFactory ) {
Problems problems = new SimpleProblems();
ValueFactories valueFactories = context.getValueFactories();
PathFactory pathFactory = valueFactories.getPathFactory();
@@ -725,10 +748,11 @@
} else if (configurationProjection.isSimple()) {
// There is just a single projection for the configuration repository, so just use an executor that
// translates the paths using the projection
- executor = new SingleProjectionCommandExecutor(context, configurationSourceName, configurationProjection, registry);
+ executor = new SingleProjectionCommandExecutor(context, configurationSourceName, configurationProjection,
+ connectionFactory);
} else {
// The configuration repository has more than one projection, so we need to merge the results
- executor = new FederatingCommandExecutor(context, configurationSourceName, projections, registry);
+ executor = new FederatingCommandExecutor(context, configurationSourceName, projections, connectionFactory);
}
// Wrap the executor with a logging executor ...
executor = new LoggingCommandExecutor(executor, Logger.getLogger(getClass()), Logger.Level.INFO);
@@ -884,8 +908,8 @@
}
ref.add(new StringRefAddr(CONFIGURATION_SOURCE_PROJECTION_RULES, sb.toString()));
}
- if (getRepositorySourceRegistryJndiName() != null) {
- ref.add(new StringRefAddr(REPOSITORY_SOURCE_REGISTRY_JNDI_NAME, getRepositorySourceRegistryJndiName()));
+ if (getRepositoryConnectionFactoryJndiName() != null) {
+ ref.add(new StringRefAddr(REPOSITORY_CONNECTION_FACTORY_JNDI_NAME, getRepositoryConnectionFactoryJndiName()));
}
if (getExecutionContextFactoryJndiName() != null) {
ref.add(new StringRefAddr(EXECUTION_CONTEXT_FACTORY_JNDI_NAME, getExecutionContextFactoryJndiName()));
@@ -925,7 +949,7 @@
String password = values.get(FederatedRepositorySource.PASSWORD);
String configurationSourceName = values.get(FederatedRepositorySource.CONFIGURATION_SOURCE_NAME);
String projectionRules = values.get(FederatedRepositorySource.CONFIGURATION_SOURCE_PROJECTION_RULES);
- String connectionFactoriesJndiName = values.get(FederatedRepositorySource.REPOSITORY_SOURCE_REGISTRY_JNDI_NAME);
+ String connectionFactoriesJndiName = values.get(FederatedRepositorySource.REPOSITORY_CONNECTION_FACTORY_JNDI_NAME);
String environmentJndiName = values.get(FederatedRepositorySource.EXECUTION_CONTEXT_FACTORY_JNDI_NAME);
String repositoryJndiName = values.get(FederatedRepositorySource.REPOSITORY_JNDI_NAME);
String securityDomain = values.get(FederatedRepositorySource.SECURITY_DOMAIN);
@@ -942,7 +966,7 @@
List<String> rules = StringUtil.splitLines(projectionRules);
source.setConfigurationSourceProjectionRules(rules.toArray(new String[rules.size()]));
}
- if (connectionFactoriesJndiName != null) source.setRepositorySourceRegistryJndiName(connectionFactoriesJndiName);
+ if (connectionFactoriesJndiName != null) source.setRepositoryConnectionFactoryJndiName(connectionFactoriesJndiName);
if (environmentJndiName != null) source.setExecutionContextFactoryJndiName(environmentJndiName);
if (repositoryJndiName != null) source.setRepositoryJndiName(repositoryJndiName);
if (securityDomain != null) source.setSecurityDomain(securityDomain);
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -43,9 +43,9 @@
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceException;
-import org.jboss.dna.spi.connector.RepositorySourceRegistry;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.DateTimeFactory;
import org.jboss.dna.spi.graph.Name;
@@ -77,7 +77,7 @@
private final Projection cacheProjection;
private final List<Projection> sourceProjections;
private final Set<String> sourceNames;
- private final RepositorySourceRegistry sourceRegistry;
+ private final RepositoryConnectionFactory connectionFactory;
private final MergeStrategy mergingStrategy;
/** The set of all connections, including the cache connection */
private final Map<String, RepositoryConnection> connectionsBySourceName;
@@ -88,19 +88,19 @@
* Create a command executor that federates (merges) the information from multiple sources described by the source
* projections. The resulting command executor does not first consult a cache for the merged information; if a cache is
* desired, see
- * {@link #FederatingCommandExecutor(ExecutionContext, String, Projection, CachePolicy, List, RepositorySourceRegistry)
+ * {@link #FederatingCommandExecutor(ExecutionContext, String, Projection, CachePolicy, List, RepositoryConnectionFactory)
* constructor} that takes a {@link Projection cache projection}.
*
* @param context the execution context in which the executor will be run; may not be null
* @param sourceName the name of the {@link RepositorySource} that is making use of this executor; may not be null or empty
* @param sourceProjections the source projections; may not be null
- * @param sourceRegistry the registry of {@link RepositorySource} instances
+ * @param connectionFactory the factory for {@link RepositoryConnection} instances
*/
public FederatingCommandExecutor( ExecutionContext context,
String sourceName,
List<Projection> sourceProjections,
- RepositorySourceRegistry sourceRegistry ) {
- this(context, sourceName, null, null, sourceProjections, sourceRegistry);
+ RepositoryConnectionFactory connectionFactory ) {
+ this(context, sourceName, null, null, sourceProjections, connectionFactory);
}
/**
@@ -116,22 +116,22 @@
* @param defaultCachePolicy the default caching policy that outlines the length of time that information should be cached, or
* null if there is no cache or no specific cache policy
* @param sourceProjections the source projections; may not be null
- * @param sourceRegistry the registry of {@link RepositorySource} instances
+ * @param connectionFactory the factory for {@link RepositoryConnection} instances
*/
public FederatingCommandExecutor( ExecutionContext context,
String sourceName,
Projection cacheProjection,
CachePolicy defaultCachePolicy,
List<Projection> sourceProjections,
- RepositorySourceRegistry sourceRegistry ) {
+ RepositoryConnectionFactory connectionFactory ) {
super(context, sourceName);
assert sourceProjections != null;
- assert sourceRegistry != null;
+ assert connectionFactory != null;
assert cacheProjection != null ? defaultCachePolicy != null : defaultCachePolicy == null;
this.cacheProjection = cacheProjection;
this.defaultCachePolicy = defaultCachePolicy;
this.sourceProjections = sourceProjections;
- this.sourceRegistry = sourceRegistry;
+ this.connectionFactory = connectionFactory;
this.connectionsBySourceName = new HashMap<String, RepositoryConnection>();
this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.UUID);
this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.MERGE_PLAN);
@@ -181,10 +181,7 @@
String sourceName = projection.getSourceName();
RepositoryConnection connection = connectionsBySourceName.get(sourceName);
if (connection == null) {
- RepositorySource source = sourceRegistry.getRepositorySource(sourceName);
- if (source != null) {
- connection = source.getConnection();
- }
+ connection = connectionFactory.createConnection(sourceName);
connectionsBySourceName.put(sourceName, connection);
}
return connection;
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -26,9 +26,9 @@
import org.jboss.dna.connector.federation.Projection;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceException;
-import org.jboss.dna.spi.connector.RepositorySourceRegistry;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
@@ -52,7 +52,7 @@
private final Projection projection;
private final PathFactory pathFactory;
- private final RepositorySourceRegistry registry;
+ private final RepositoryConnectionFactory connectionFactory;
private RepositoryConnection connection;
/**
@@ -60,13 +60,13 @@
* @param sourceName the name of the {@link RepositorySource} that is making use of this executor; may not be null or empty
* @param projection the projection used for the cached information; may not be null and must have exactly one
* {@link Projection#getRules() rule}
- * @param sourceRegistry the registry of {@link RepositorySource} instances
+ * @param connectionFactory the factory for {@link RepositoryConnection} instances
*/
public SingleProjectionCommandExecutor( ExecutionContext context,
String sourceName,
Projection projection,
- RepositorySourceRegistry sourceRegistry ) {
- this(context, sourceName, null, projection, sourceRegistry);
+ RepositoryConnectionFactory connectionFactory ) {
+ this(context, sourceName, null, projection, connectionFactory);
}
/**
@@ -75,19 +75,19 @@
* @param now the current time; may be null if the system time is to be used
* @param projection the projection used for the cached information; may not be null and must have exactly one
* {@link Projection#getRules() rule}
- * @param sourceRegistry the registry of {@link RepositorySource} instances
+ * @param connectionFactory the factory for {@link RepositoryConnection} instances
*/
public SingleProjectionCommandExecutor( ExecutionContext context,
String sourceName,
DateTime now,
Projection projection,
- RepositorySourceRegistry sourceRegistry ) {
+ RepositoryConnectionFactory connectionFactory ) {
super(context, sourceName, now);
- assert sourceRegistry != null;
+ assert connectionFactory != null;
assert projection != null;
assert projection.getRules().size() == 1;
this.projection = projection;
- this.registry = sourceRegistry;
+ this.connectionFactory = connectionFactory;
this.pathFactory = context.getValueFactories().getPathFactory();
assert this.pathFactory != null;
}
@@ -95,8 +95,7 @@
protected RepositoryConnection getConnection() throws RepositorySourceException, InterruptedException {
if (connection == null) {
// Create a connection ...
- RepositorySource source = this.registry.getRepositorySource(this.projection.getSourceName());
- connection = source.getConnection();
+ connection = this.connectionFactory.createConnection(this.projection.getSourceName());
}
return connection;
}
Modified: trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -45,8 +45,8 @@
import org.jboss.dna.spi.ExecutionContextFactory;
import org.jboss.dna.spi.connector.BasicExecutionContext;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
import org.jboss.dna.spi.connector.RepositorySourceException;
-import org.jboss.dna.spi.connector.RepositorySourceRegistry;
import org.jboss.dna.spi.connector.SimpleRepository;
import org.jboss.dna.spi.connector.SimpleRepositorySource;
import org.junit.After;
@@ -67,18 +67,19 @@
private String username;
private String credentials;
private String executionContextFactoryJndiName;
- private String repositorySourceRegistryJndiName;
+ private String repositoryConnectionFactoryJndiName;
private String configurationSourceName;
private String securityDomain;
private SimpleRepository configRepository;
private SimpleRepositorySource configRepositorySource;
+ private RepositoryConnection configRepositoryConnection;
private ExecutionContext context;
@Mock
private RepositoryConnection connection;
@Mock
private Context jndiContext;
@Mock
- private RepositorySourceRegistry sourceRegistry;
+ private RepositoryConnectionFactory connectionFactory;
@Mock
private ExecutionContextFactory executionContextFactory;
@@ -91,7 +92,7 @@
context = new BasicExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
executionContextFactoryJndiName = "context factory jndi name";
- repositorySourceRegistryJndiName = "repository source registry jndi name";
+ repositoryConnectionFactoryJndiName = "repository connection factory jndi name";
configurationSourceName = "configuration source name";
repositoryName = "Test Repository";
securityDomain = "security domain";
@@ -104,7 +105,7 @@
source.setPassword(credentials);
source.setConfigurationSourceName(configurationSourceName);
source.setConfigurationSourceProjectionRules(new String[] {"/dna:system/dna:federation/ => /dna:repositories/Test Repository"});
- source.setRepositorySourceRegistryJndiName(repositorySourceRegistryJndiName);
+ source.setRepositoryConnectionFactoryJndiName(repositoryConnectionFactoryJndiName);
source.setExecutionContextFactoryJndiName(executionContextFactoryJndiName);
source.setContext(jndiContext);
source.setSecurityDomain(securityDomain);
@@ -123,9 +124,10 @@
configRepositorySource = new SimpleRepositorySource();
configRepositorySource.setRepositoryName(configRepository.getRepositoryName());
configRepositorySource.setName(configurationSourceName);
- stub(sourceRegistry.getRepositorySource(configurationSourceName)).toReturn(configRepositorySource);
+ configRepositoryConnection = configRepositorySource.getConnection();
+ stub(connectionFactory.createConnection(configurationSourceName)).toReturn(configRepositoryConnection);
stub(jndiContext.lookup(executionContextFactoryJndiName)).toReturn(executionContextFactory);
- stub(jndiContext.lookup(repositorySourceRegistryJndiName)).toReturn(sourceRegistry);
+ stub(jndiContext.lookup(repositoryConnectionFactoryJndiName)).toReturn(connectionFactory);
stub(executionContextFactory.create(eq(securityDomain), anyCallbackHandler())).toReturn(context);
}
@@ -267,7 +269,7 @@
source.setName("Some source");
source.setConfigurationSourceName("config source");
source.setConfigurationSourceProjectionRules(new String[] {"/dna:system => /a/b/c"});
- source.setRepositorySourceRegistryJndiName("repository source registry jndi name");
+ source.setRepositoryConnectionFactoryJndiName("repository connection factory jndi name");
source.setRepositoryJndiName("repository jndi name");
source.setExecutionContextFactoryJndiName("env jndi name");
@@ -291,8 +293,8 @@
is(source.getConfigurationSourceName()));
assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_SOURCE_PROJECTION_RULES),
is("/dna:system => /a/b/c"));
- assertThat((String)refAttributes.remove(FederatedRepositorySource.REPOSITORY_SOURCE_REGISTRY_JNDI_NAME),
- is(source.getRepositorySourceRegistryJndiName()));
+ assertThat((String)refAttributes.remove(FederatedRepositorySource.REPOSITORY_CONNECTION_FACTORY_JNDI_NAME),
+ is(source.getRepositoryConnectionFactoryJndiName()));
assertThat((String)refAttributes.remove(FederatedRepositorySource.EXECUTION_CONTEXT_FACTORY_JNDI_NAME),
is(source.getExecutionContextFactoryJndiName()));
assertThat((String)refAttributes.remove(FederatedRepositorySource.REPOSITORY_JNDI_NAME),
@@ -315,7 +317,7 @@
assertThat(recoveredSource.getRetryLimit(), is(source.getRetryLimit()));
assertThat(recoveredSource.getConfigurationSourceName(), is(source.getConfigurationSourceName()));
assertThat(recoveredSource.getConfigurationSourceProjectionRules(), is(source.getConfigurationSourceProjectionRules()));
- assertThat(recoveredSource.getRepositorySourceRegistryJndiName(), is(source.getRepositorySourceRegistryJndiName()));
+ assertThat(recoveredSource.getRepositoryConnectionFactoryJndiName(), is(source.getRepositoryConnectionFactoryJndiName()));
assertThat(recoveredSource.getExecutionContextFactoryJndiName(), is(source.getExecutionContextFactoryJndiName()));
assertThat(recoveredSource.getRepositoryJndiName(), is(source.getRepositoryJndiName()));
assertThat(recoveredSource.getSecurityDomain(), is(source.getSecurityDomain()));
Modified: trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -29,8 +29,8 @@
import static org.junit.matchers.JUnitMatchers.hasItems;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
import org.jboss.dna.spi.connector.RepositorySourceListener;
-import org.jboss.dna.spi.connector.RepositorySourceRegistry;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@@ -50,13 +50,13 @@
@Mock
private RepositorySourceListener listener2;
@Mock
- private RepositorySourceRegistry registry;
+ private RepositoryConnectionFactory connectionFactory;
@Before
public void beforeEach() {
MockitoAnnotations.initMocks(this);
context = new BasicExecutionContext();
- repository = new FederatedRepository(context, registry, config);
+ repository = new FederatedRepository(context, connectionFactory, config);
}
@Test
Modified: trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
===================================================================
--- trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -27,6 +27,7 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -40,21 +41,26 @@
import net.jcip.annotations.GuardedBy;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.cache.CachePolicy;
-import org.jboss.dna.spi.connector.AbstractRepositorySource;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
import org.jboss.dna.spi.connector.RepositorySourceException;
/**
* @author Randall Hauch
*/
-public class InMemoryRepositorySource extends AbstractRepositorySource implements ObjectFactory {
+public class InMemoryRepositorySource implements RepositorySource, ObjectFactory {
/**
* The initial version is 1
*/
private static final long serialVersionUID = 1L;
+ /**
+ * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ */
+ public static final int DEFAULT_RETRY_LIMIT = 0;
+
private static final ConcurrentMap<String, InMemoryRepositorySource> sources = new ConcurrentHashMap<String, InMemoryRepositorySource>();
private static final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
@@ -95,6 +101,7 @@
private String jndiName;
private UUID rootNodeUuid = UUID.randomUUID();
private CachePolicy defaultCachePolicy;
+ private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private transient InMemoryRepository repository;
/**
@@ -105,6 +112,24 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#setRetryLimit(int)
+ */
+ public void setRetryLimit( int limit ) {
+ retryLimit.set(limit < 0 ? 0 : limit);
+ }
+
+ /**
* Get the default cache policy for this source, or null if the global default cache policy should be used
*
* @return the default cache policy, or null if this source has no explicit default cache policy
@@ -223,10 +248,9 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.connector.AbstractRepositorySource#createConnection()
+ * @see org.jboss.dna.spi.connector.RepositorySource#getConnection()
*/
- @Override
- protected synchronized RepositoryConnection createConnection() throws RepositorySourceException {
+ public RepositoryConnection getConnection() throws RepositorySourceException {
if (repository == null) {
repository = new InMemoryRepository(name, rootNodeUuid);
}
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -31,6 +31,7 @@
import java.util.Hashtable;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.BinaryRefAddr;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -46,7 +47,6 @@
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.cache.CachePolicy;
-import org.jboss.dna.spi.connector.AbstractRepositorySource;
import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
@@ -71,9 +71,13 @@
* @author Randall Hauch
*/
@ThreadSafe
-public class JBossCacheSource extends AbstractRepositorySource implements ObjectFactory {
+public class JBossCacheSource implements RepositorySource, ObjectFactory {
private static final long serialVersionUID = 1L;
+ /**
+ * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ */
+ public static final int DEFAULT_RETRY_LIMIT = 0;
public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
protected static final String ROOT_NODE_UUID = "rootNodeUuid";
@@ -92,6 +96,7 @@
private String cacheFactoryJndiName;
private String cacheJndiName;
private String uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
+ private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private transient Cache<Name, Object> cache;
private transient Context jndiContext;
@@ -109,6 +114,24 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#setRetryLimit(int)
+ */
+ public void setRetryLimit( int limit ) {
+ retryLimit.set(limit < 0 ? 0 : limit);
+ }
+
+ /**
* Set the name of this source
*
* @param name the name for this source
@@ -317,10 +340,11 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#getConnection()
*/
@SuppressWarnings( "unchecked" )
- @Override
- protected synchronized RepositoryConnection createConnection() {
+ public RepositoryConnection getConnection() throws RepositorySourceException {
if (getName() == null) {
I18n msg = JBossCacheConnectorI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("name"));
Modified: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -32,7 +32,6 @@
import java.util.Hashtable;
import java.util.Map;
import java.util.UUID;
-import java.util.concurrent.TimeUnit;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
@@ -90,9 +89,6 @@
if (connection != null) {
connection.close();
}
- source.shutdownNow();
- source.awaitTermination(4, TimeUnit.SECONDS);
- // assertThat(source.isTerminated(), is(true));
}
@Test
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -196,9 +196,6 @@
NameFactory nameFactory = valueFactories.getNameFactory();
final String configurationSourceName = configurationProjection.getSourceName();
- if (sources.getRepositorySource(configurationSourceName) == null) {
- throw new FederationException(RepositoryI18n.unableToFindRepositorySourceWithName.text(configurationSourceName));
- }
// Create a federating command executor to execute the commands and merge the results into a single set of
// commands.
@@ -242,7 +239,7 @@
RepositorySource source = createRepositorySource(getSourceCommand.getPath(),
getSourceCommand.getProperties(),
problems);
- if (source != null) sources.addSource(source, true);
+ if (source != null) sources.addSource(source);
}
}
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -23,20 +23,30 @@
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.repository.services.AbstractServiceAdministrator;
import org.jboss.dna.repository.services.ServiceAdministrator;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositoryConnectionPool;
import org.jboss.dna.spi.connector.RepositorySource;
-import org.jboss.dna.spi.connector.RepositorySourceRegistry;
/**
+ * A manager of {@link RepositorySource} instances and the {@link RepositoryConnectionPool} used to manage the connections for
+ * each.
+ *
* @author Randall Hauch
*/
-public class RepositorySourceManager implements RepositorySourceRegistry {
+@ThreadSafe
+public class RepositorySourceManager implements RepositoryConnectionFactory {
/**
* The administrative component for this service.
@@ -87,36 +97,36 @@
private final ServiceAdministrator administrator = new Administrator();
private final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
- private final CopyOnWriteArrayList<RepositorySource> sources = new CopyOnWriteArrayList<RepositorySource>();
- private RepositorySourceRegistry delegate;
+ private final CopyOnWriteArrayList<RepositoryConnectionPool> pools = new CopyOnWriteArrayList<RepositoryConnectionPool>();
+ private RepositoryConnectionFactory delegate;
/**
* Create a new manager instance.
*
- * @param delegate the registry to which this instance should delegate in the event that a source is not found in this
- * manager; may be null if there is no delegate
+ * @param delegate the connection factory to which this instance should delegate in the event that a source is not found in
+ * this manager; may be null if there is no delegate
*/
- public RepositorySourceManager( RepositorySourceRegistry delegate ) {
+ public RepositorySourceManager( RepositoryConnectionFactory delegate ) {
this.delegate = delegate;
}
/**
- * Get the delegate registry.
+ * Get the delegate connection factory.
*
- * @return the registry to which this instance should delegate in the event that a source is not found in this manager, or
- * null if there is no delegate
+ * @return the connection factory to which this instance should delegate in the event that a source is not found in this
+ * manager, or null if there is no delegate
*/
- public RepositorySourceRegistry getDelegate() {
+ public RepositoryConnectionFactory getDelegate() {
return delegate;
}
/**
- * Set the delegate registry.
+ * Set the delegate connection factory.
*
- * @param delegate the registry to which this instance should delegate in the event that a source is not found in this
- * manager; may be null if there is no delegate
+ * @param delegate the connection factory to which this instance should delegate in the event that a source is not found in
+ * this manager; may be null if there is no delegate
*/
- public void setDelegate( RepositorySourceRegistry delegate ) {
+ public void setDelegate( RepositoryConnectionFactory delegate ) {
this.delegate = delegate;
}
@@ -131,7 +141,7 @@
* Utility method called by the administrator.
*/
protected void start() {
- // Do not establish connections to the sources; these will be established as needed
+ // Do not establish connections to the pools; these will be established as needed
}
@@ -139,11 +149,11 @@
* Utility method called by the administrator.
*/
protected void shutdown() {
- // Close all connections to the sources. This is done inside the sources write lock.
+ // Close all connections to the pools. This is done inside the pools write lock.
try {
this.sourcesLock.readLock().lock();
- for (RepositorySource source : this.sources) {
- source.shutdown();
+ for (RepositoryConnectionPool pool : this.pools) {
+ pool.shutdown();
}
} finally {
this.sourcesLock.readLock().unlock();
@@ -161,11 +171,11 @@
*/
protected boolean awaitTermination( long timeout,
TimeUnit unit ) throws InterruptedException {
- // Check whether all source pools are shut down. This is done inside the sources write lock.
+ // Check whether all source pools are shut down. This is done inside the pools write lock.
try {
this.sourcesLock.readLock().lock();
- for (RepositorySource source : this.sources) {
- if (!source.awaitTermination(timeout, unit)) return false;
+ for (RepositoryConnectionPool pool : this.pools) {
+ if (!pool.awaitTermination(timeout, unit)) return false;
}
return true;
} finally {
@@ -186,8 +196,8 @@
public boolean isTerminating() {
try {
this.sourcesLock.readLock().lock();
- for (RepositorySource source : this.sources) {
- if (source.isTerminating()) return true;
+ for (RepositoryConnectionPool pool : this.pools) {
+ if (pool.isTerminating()) return true;
}
return false;
} finally {
@@ -204,8 +214,8 @@
public boolean isTerminated() {
try {
this.sourcesLock.readLock().lock();
- for (RepositorySource source : this.sources) {
- if (!source.isTerminated()) return false;
+ for (RepositoryConnectionPool pool : this.pools) {
+ if (!pool.isTerminated()) return false;
}
return true;
} finally {
@@ -214,37 +224,86 @@
}
/**
- * Get an unmodifiable collection of {@link RepositorySource federated sources}.
- * <p>
- * This method can safely be called while the federation repository is in use.
- * </p>
+ * Get an unmodifiable collection of {@link RepositorySource} names.
*
- * @return the sources
+ * @return the pools
*/
+ public Collection<String> getSourceNames() {
+ Set<String> sourceNames = new HashSet<String>();
+ for (RepositoryConnectionPool pool : this.pools) {
+ sourceNames.add(pool.getRepositorySource().getName());
+ }
+ return Collections.unmodifiableCollection(sourceNames);
+ }
+
+ /**
+ * Get an unmodifiable collection of {@link RepositorySource} instances managed by this instance.
+ *
+ * @return the pools
+ */
public Collection<RepositorySource> getSources() {
- return Collections.unmodifiableCollection(this.sources);
+ List<RepositorySource> sources = new LinkedList<RepositorySource>();
+ for (RepositoryConnectionPool pool : this.pools) {
+ sources.add(pool.getRepositorySource());
+ }
+ return Collections.unmodifiableCollection(sources);
}
/**
+ * Get the RepositorySource with the specified name managed by this instance.
+ *
+ * @param sourceName the name of the source
+ * @return the source, or null if no such source exists in this instance
+ */
+ public RepositorySource getSource( String sourceName ) {
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ RepositorySource source = existingPool.getRepositorySource();
+ if (source.getName().equals(sourceName)) return source;
+ }
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ return null;
+ }
+
+ /**
+ * Get the connection pool managing the {@link RepositorySource} with the specified name managed by this instance.
+ *
+ * @param sourceName the name of the source
+ * @return the pool, or null if no such pool exists in this instance
+ */
+ public RepositoryConnectionPool getConnectionPool( String sourceName ) {
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ RepositorySource source = existingPool.getRepositorySource();
+ if (source.getName().equals(sourceName)) return existingPool;
+ }
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ return null;
+ }
+
+ /**
* Add the supplied federated source. This method returns false if the source is null.
- * <p>
- * This method can safely be called while the federation repository is in use.
- * </p>
*
* @param source the source to add
- * @param force true if the valid source should be added even if there is an existing source with the supplied name
* @return true if the source is added, or false if the reference is null or if there is already an existing source with the
* supplied name.
*/
- public boolean addSource( RepositorySource source,
- boolean force ) {
+ public boolean addSource( RepositorySource source ) {
if (source == null) return false;
try {
this.sourcesLock.writeLock().lock();
- for (RepositorySource existingSource : this.sources) {
- if (existingSource.getName().equals(source.getName())) return false;
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ if (existingPool.getRepositorySource().getName().equals(source.getName())) return false;
}
- return force ? this.sources.add(source) : this.sources.addIfAbsent(source);
+ RepositoryConnectionPool pool = new RepositoryConnectionPool(source);
+ this.pools.add(pool);
+ return true;
} finally {
this.sourcesLock.writeLock().unlock();
}
@@ -276,9 +335,6 @@
* Remove from this federated repository the source with the supplied name. This call shuts down the connections in the source
* in an orderly fashion, allowing those connection currently in use to be used and closed normally, but preventing further
* connections from being used.
- * <p>
- * This method can safely be called while the federation repository is in use.
- * </p>
*
* @param name the name of the source to be removed
* @param timeToAwait the amount of time to wait while all of the source's connections are closed, or non-positive if the call
@@ -293,13 +349,13 @@
TimeUnit unit ) throws InterruptedException {
try {
this.sourcesLock.writeLock().lock();
- for (RepositorySource existingSource : this.sources) {
- if (existingSource.getName().equals(name)) {
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ if (existingPool.getRepositorySource().getName().equals(name)) {
// Shut down the source ...
- existingSource.shutdown();
- if (timeToAwait > 0l) existingSource.awaitTermination(timeToAwait, unit);
+ existingPool.shutdown();
+ if (timeToAwait > 0L) existingPool.awaitTermination(timeToAwait, unit);
}
- return existingSource;
+ return existingPool.getRepositorySource();
}
} finally {
this.sourcesLock.writeLock().unlock();
@@ -310,22 +366,22 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.connector.RepositorySourceRegistry#getRepositorySource(java.lang.String)
+ * @see org.jboss.dna.spi.connector.RepositoryConnectionFactory#createConnection(java.lang.String)
*/
- public RepositorySource getRepositorySource( String sourceName ) {
+ public RepositoryConnection createConnection( String sourceName ) throws InterruptedException {
try {
this.sourcesLock.readLock().lock();
- for (RepositorySource existingSource : this.sources) {
- if (existingSource.getName().equals(sourceName)) return existingSource;
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ RepositorySource source = existingPool.getRepositorySource();
+ if (source.getName().equals(sourceName)) return existingPool.getConnection();
}
- RepositorySourceRegistry delegate = this.delegate;
+ RepositoryConnectionFactory delegate = this.delegate;
if (delegate != null) {
- return delegate.getRepositorySource(sourceName);
+ return delegate.createConnection(sourceName);
}
} finally {
this.sourcesLock.readLock().unlock();
}
return null;
}
-
}
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -41,6 +41,7 @@
import org.jboss.dna.repository.services.ServiceAdministrator;
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.SimpleRepository;
import org.jboss.dna.spi.connector.SimpleRepositorySource;
@@ -76,6 +77,7 @@
private String configSourceName;
private SimpleRepository configRepository;
private SimpleRepositorySource configRepositorySource;
+ private RepositoryConnection configRepositoryConnection;
@Mock
private ExecutionContext context;
@Mock
@@ -98,7 +100,8 @@
configRepositorySource = new SimpleRepositorySource();
configRepositorySource.setRepositoryName(configRepository.getRepositoryName());
configRepositorySource.setName(configSourceName);
- stub(sources.getRepositorySource(configSourceName)).toReturn(configRepositorySource);
+ configRepositoryConnection = configRepositorySource.getConnection();
+ stub(sources.createConnection(configSourceName)).toReturn(configRepositoryConnection);
stub(context.getValueFactories()).toReturn(valueFactories);
stub(context.getPropertyFactory()).toReturn(propertyFactory);
stub(context.getNamespaceRegistry()).toReturn(registry);
@@ -157,32 +160,28 @@
}
@Test( expected = FederationException.class )
- public void shouldFailToStartUpIfConfigurationRepositorySourceIsNotFound() {
- stub(sources.getRepositorySource(configSourceName)).toReturn(null);
+ public void shouldFailToStartUpIfConfigurationRepositorySourceIsNotFound() throws Exception {
+ stub(sources.createConnection(configSourceName)).toReturn(null);
service.getAdministrator().start();
}
@Test( expected = FederationException.class )
public void shouldFailToStartUpIfUnableToConnectToConfigurationRepository() throws Exception {
- RepositorySource mockSource = mock(RepositorySource.class);
- stub(sources.getRepositorySource(configSourceName)).toReturn(mockSource);
- stub(mockSource.getConnection()).toThrow(new UnsupportedOperationException());
+ stub(sources.createConnection(configSourceName)).toThrow(new UnsupportedOperationException());
service.getAdministrator().start();
}
@Test( expected = FederationException.class )
public void shouldFailToStartUpIfInterruptedWhileConnectingToConfigurationRepository() throws Exception {
- RepositorySource mockSource = mock(RepositorySource.class);
- stub(sources.getRepositorySource(configSourceName)).toReturn(mockSource);
- stub(mockSource.getConnection()).toThrow(new InterruptedException());
+ stub(sources.createConnection(configSourceName)).toThrow(new InterruptedException());
service.getAdministrator().start();
}
@Test
- public void shouldStartUpUsingConfigurationRepositoryThatContainsSomeSources() {
+ public void shouldStartUpUsingConfigurationRepositoryThatContainsSomeSources() throws Exception {
// Use a real source manager for this test ...
sources = new RepositorySourceManager(sources);
- sources.addSource(configRepositorySource, true);
+ sources.addSource(configRepositorySource);
assertThat(sources.getSources(), hasItems((RepositorySource)configRepositorySource));
assertThat(sources.getSources().size(), is(1));
service = new RepositoryService(sources, configProjection, context, null);
@@ -207,28 +206,28 @@
// and verify that the sources were added to the manager...
assertThat(sources.getSources().size(), is(4));
- assertThat(sources.getRepositorySource("source A"), is(instanceOf(SimpleRepositorySource.class)));
- assertThat(sources.getRepositorySource("source B"), is(instanceOf(SimpleRepositorySource.class)));
- assertThat(sources.getRepositorySource("source C"), is(instanceOf(SimpleRepositorySource.class)));
+ assertThat(sources.getSource("source A"), is(instanceOf(SimpleRepositorySource.class)));
+ assertThat(sources.getSource("source B"), is(instanceOf(SimpleRepositorySource.class)));
+ assertThat(sources.getSource("source C"), is(instanceOf(SimpleRepositorySource.class)));
- SimpleRepositorySource sourceA = (SimpleRepositorySource)sources.getRepositorySource("source A");
+ SimpleRepositorySource sourceA = (SimpleRepositorySource)sources.getSource("source A");
assertThat(sourceA.getName(), is("source A"));
assertThat(sourceA.getRepositoryName(), is("sourceReposA"));
assertThat(sourceA.getRetryLimit(), is(3));
- SimpleRepositorySource sourceB = (SimpleRepositorySource)sources.getRepositorySource("source B");
+ SimpleRepositorySource sourceB = (SimpleRepositorySource)sources.getSource("source B");
assertThat(sourceB.getName(), is("source B"));
assertThat(sourceB.getRepositoryName(), is("sourceReposB"));
assertThat(sourceB.getRetryLimit(), is(SimpleRepositorySource.DEFAULT_RETRY_LIMIT));
- SimpleRepositorySource sourceC = (SimpleRepositorySource)sources.getRepositorySource("source C");
+ SimpleRepositorySource sourceC = (SimpleRepositorySource)sources.getSource("source C");
assertThat(sourceC.getName(), is("source C"));
assertThat(sourceC.getRepositoryName(), is("sourceReposC"));
assertThat(sourceC.getRetryLimit(), is(SimpleRepositorySource.DEFAULT_RETRY_LIMIT));
}
@Test
- public void shouldStartUpUsingConfigurationRepositoryThatContainsNoSources() {
+ public void shouldStartUpUsingConfigurationRepositoryThatContainsNoSources() throws Exception {
// Set up the configuration repository to contain NO sources ...
configRepository.create(context, "/reposX/dna:sources");
@@ -236,7 +235,7 @@
service.getAdministrator().start();
// and verify that the configuration source was obtained from the manager ...
- verify(sources, times(2)).getRepositorySource(configSourceName); // once for checking source, second for getting
+ verify(sources, times(1)).createConnection(configSourceName); // once for checking source, second for getting
// and verify that the sources were never added to the manager...
verifyNoMoreInteractions(sources);
Deleted: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/AbstractRepositorySource.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/AbstractRepositorySource.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/AbstractRepositorySource.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -1,221 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.connector;
-
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import net.jcip.annotations.ThreadSafe;
-
-/**
- * An abstract implementation of {@link RepositorySource} that may serve as a foundation for most implementations, since it
- * automatically manages the {@link RepositoryConnection connections} using an internal {@link RepositoryConnectionPool pool}.
- *
- * @author Randall Hauch
- */
-@ThreadSafe
-public abstract class AbstractRepositorySource implements RepositorySource {
-
- /**
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
- */
- public static final int DEFAULT_RETRY_LIMIT = 0;
-
- private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
- private RepositoryConnectionPool.ConnectionFactory connectionFactory;
- private transient RepositoryConnectionPool connections;
-
- /**
- * Create a new instance of the repository source. This constructor calls relying upon the {@link #createConnectionFactory()}
- * method, which creation of the {@link RepositoryConnection connections}.
- */
- protected AbstractRepositorySource() {
- this.connectionFactory = createConnectionFactory();
- assert this.connectionFactory != null;
- this.connections = new RepositoryConnectionPool(this.connectionFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#getRetryLimit()
- */
- public int getRetryLimit() {
- return retryLimit.get();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#setRetryLimit(int)
- */
- public void setRetryLimit( int limit ) {
- retryLimit.set(limit < 0 ? 0 : limit);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#isRunning()
- */
- public boolean isRunning() {
- return this.connections.isRunning();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#isShutdown()
- */
- public boolean isShutdown() {
- return this.connections.isShutdown();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#getConnection()
- */
- public RepositoryConnection getConnection() throws RepositorySourceException, InterruptedException {
- return this.connections.getConnection();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#shutdown()
- */
- public void shutdown() {
- this.connections.shutdown();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#shutdownNow()
- */
- public void shutdownNow() {
- this.connections.shutdownNow();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#isTerminated()
- */
- public boolean isTerminated() {
- return this.connections.isTerminated();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#isTerminating()
- */
- public boolean isTerminating() {
- return this.connections.isTerminating();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositorySource#awaitTermination(long, java.util.concurrent.TimeUnit)
- */
- public boolean awaitTermination( long timeout,
- TimeUnit unit ) throws InterruptedException {
- return this.connections.awaitTermination(timeout, unit);
- }
-
- private void writeObject( java.io.ObjectOutputStream out ) throws IOException {
- out.writeInt(this.getRetryLimit());
- // Write out the pool's state, since the pool is not serializable ...
- out.writeLong(connections.getKeepAliveTime(TimeUnit.NANOSECONDS));
- out.writeInt(connections.getCorePoolSize());
- out.writeInt(connections.getMaximumPoolSize());
- out.writeInt(connections.getMaxFailedAttemptsBeforeError());
- out.writeBoolean(connections.getValidateConnectionBeforeUse());
- out.writeLong(connections.getPingTimeoutInNanos());
- }
-
- private void readObject( java.io.ObjectInputStream in ) throws IOException {
- setRetryLimit(in.readInt());
- connectionFactory = createConnectionFactory();
- // Read the pool state parameters ...
- final long keepAliveTimeInNanos = in.readLong();
- final int corePoolSize = in.readInt();
- final int maxPoolSize = in.readInt();
- final int maxFailedAttemptsBeforeError = in.readInt();
- final boolean validateConnections = in.readBoolean();
- final long pingTimeoutInNanos = in.readLong();
- // Create a new pool and set it's parameters ...
- connections = new RepositoryConnectionPool(connectionFactory, corePoolSize, maxPoolSize, keepAliveTimeInNanos,
- TimeUnit.NANOSECONDS);
- connections.setMaxFailedAttemptsBeforeError(maxFailedAttemptsBeforeError);
- connections.setValidateConnectionBeforeUse(validateConnections);
- connections.setPingTimeout(pingTimeoutInNanos, TimeUnit.NANOSECONDS);
- }
-
- /**
- * Create a connection factory that should be used. The default implementation returns a factory that delegates to the
- * {@link #createConnection()} method, which should be overridden.
- *
- * @return the connection factory; never null
- */
- protected RepositoryConnectionPool.ConnectionFactory createConnectionFactory() {
- return new RepositoryConnectionPool.ConnectionFactory() {
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositoryConnectionPool.ConnectionFactory#createConnection()
- */
- public RepositoryConnection createConnection() throws RepositorySourceException, InterruptedException {
- return AbstractRepositorySource.this.createConnection();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.connector.RepositoryConnectionPool#getSourceName()
- */
- public String getSourceName() {
- return AbstractRepositorySource.this.getName();
- }
- };
- }
-
- /**
- * Method to create a new {@link RepositoryConnection} instance. This method is called by the
- * {@link RepositoryConnectionPool.ConnectionFactory} returned by the default implementation of
- * {@link #createConnectionFactory()}. If the {@link #createConnectionFactory()} method is overridden, this method will not be
- * called.
- *
- * @return the new connection
- * @throws RepositorySourceException
- * @throws InterruptedException
- */
- protected abstract RepositoryConnection createConnection() throws RepositorySourceException, InterruptedException;
-
-}
Copied: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java (from rev 401, trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceRegistry.java)
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.connector;
+
+/**
+ * An interface for a factory of {@link RepositoryConnection}s using the names of the {@link RepositorySource} from which the
+ * connections are to be obtained.
+ *
+ * @author Randall Hauch
+ */
+public interface RepositoryConnectionFactory {
+
+ /**
+ * Create a {@link RepositoryConnection} using the given {@link RepositorySource} name.
+ *
+ * @param sourceName the name of the source from which a connection should be obtained
+ * @return the source, or null if no such source could be found (or created)
+ * @throws RepositorySourceException if there was an error obtaining the new connection
+ * @throws InterruptedException if the thread was interrupted during the operation
+ */
+ RepositoryConnection createConnection( String sourceName ) throws RepositorySourceException, InterruptedException;
+
+}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionPool.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionPool.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionPool.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -52,30 +52,6 @@
public class RepositoryConnectionPool {
/**
- * A factory that is used by the connection pool to create new connections.
- *
- * @author Randall Hauch
- */
- public interface ConnectionFactory {
-
- /**
- * Get the name for the source that owns the pool.
- *
- * @return the name; never null or empty
- */
- String getSourceName();
-
- /**
- * Create a new connection to the underlying source.
- *
- * @return the new connection
- * @throws RepositorySourceException if there is a problem obtaining a connection
- * @throws InterruptedException if the thread is interrupted while attempting to get a connection
- */
- RepositoryConnection createConnection() throws RepositorySourceException, InterruptedException;
- }
-
- /**
* The core pool size for default-constructed pools is {@value} .
*/
public static final int DEFAULT_CORE_POOL_SIZE = 1;
@@ -96,9 +72,9 @@
private static final RuntimePermission shutdownPerm = new RuntimePermission("modifyThread");
/**
- * The factory that this pool uses to create new connections.
+ * The source that this pool uses to create new connections.
*/
- private final ConnectionFactory connectionFactory;
+ private final RepositorySource source;
/**
* Lock held on updates to poolSize, corePoolSize, maximumPoolSize, and workers set.
@@ -189,18 +165,17 @@
* uses the {@link #DEFAULT_CORE_POOL_SIZE default core pool size}, {@link #DEFAULT_MAXIMUM_POOL_SIZE default maximum pool
* size}, and {@link #DEFAULT_KEEP_ALIVE_TIME_IN_SECONDS default keep-alive time (in seconds)}.
*
- * @param connectionFactory the factory for connections
+ * @param source the source for connections
* @throws IllegalArgumentException if the connection factory is null or any of the supplied arguments are invalid
*/
- public RepositoryConnectionPool( ConnectionFactory connectionFactory ) {
- this(connectionFactory, DEFAULT_CORE_POOL_SIZE, DEFAULT_MAXIMUM_POOL_SIZE, DEFAULT_KEEP_ALIVE_TIME_IN_SECONDS,
- TimeUnit.SECONDS);
+ public RepositoryConnectionPool( RepositorySource source ) {
+ this(source, DEFAULT_CORE_POOL_SIZE, DEFAULT_MAXIMUM_POOL_SIZE, DEFAULT_KEEP_ALIVE_TIME_IN_SECONDS, TimeUnit.SECONDS);
}
/**
* Create the pool to use the supplied connection factory, which is typically a {@link RepositorySource}.
*
- * @param connectionFactory the factory for connections
+ * @param source the source for connections
* @param corePoolSize the number of connections to keep in the pool, even if they are idle.
* @param maximumPoolSize the maximum number of connections to allow in the pool.
* @param keepAliveTime when the number of connection is greater than the core, this is the maximum time that excess idle
@@ -208,7 +183,7 @@
* @param unit the time unit for the keepAliveTime argument.
* @throws IllegalArgumentException if the connection factory is null or any of the supplied arguments are invalid
*/
- public RepositoryConnectionPool( ConnectionFactory connectionFactory,
+ public RepositoryConnectionPool( RepositorySource source,
int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
@@ -216,11 +191,11 @@
ArgCheck.isNonNegative(corePoolSize, "corePoolSize");
ArgCheck.isPositive(maximumPoolSize, "maximumPoolSize");
ArgCheck.isNonNegative(keepAliveTime, "keepAliveTime");
- ArgCheck.isNotNull(connectionFactory, "repository connection factory");
+ ArgCheck.isNotNull(source, "source");
if (maximumPoolSize < corePoolSize) {
throw new IllegalArgumentException(SpiI18n.maximumPoolSizeMayNotBeSmallerThanCorePoolSize.text());
}
- this.connectionFactory = connectionFactory;
+ this.source = source;
this.corePoolSize = corePoolSize;
this.maximumPoolSize = maximumPoolSize;
this.keepAliveTime = unit.toNanos(keepAliveTime);
@@ -228,12 +203,21 @@
}
/**
+ * Get the {@link RepositorySource} that's used by this pool.
+ *
+ * @return the repository source; never null
+ */
+ public final RepositorySource getRepositorySource() {
+ return source;
+ }
+
+ /**
* Get the name of this pool, which delegates to the connection factory.
*
* @return the name of the source
*/
protected String getSourceName() {
- return connectionFactory.getSourceName();
+ return source.getName();
}
// -------------------------------------------------
@@ -847,7 +831,7 @@
*/
@GuardedBy( "mainLock" )
protected ConnectionWrapper newWrappedConnection() throws RepositorySourceException, InterruptedException {
- RepositoryConnection connection = this.connectionFactory.createConnection();
+ RepositoryConnection connection = this.source.getConnection();
++this.poolSize;
this.totalConnectionsCreated.incrementAndGet();
return new ConnectionWrapper(connection);
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -22,7 +22,6 @@
package org.jboss.dna.spi.connector;
import java.io.Serializable;
-import java.util.concurrent.TimeUnit;
import javax.naming.Referenceable;
/**
@@ -44,10 +43,7 @@
* {@link Serializable} so that such objects can be stored in any JNDI naming context and enable proper system recovery,
* </p>
* <p>
- * Pooling connections is not done above or outside of the RepositorySource implementations. Therefore, if an implementation would
- * benefit from pooling connections, it should use a pool within the implementation (and expose any pool parameters as desired).
- * If this is the case, the implementation class may benefit from subclassing {@link AbstractRepositorySource} (which manages a
- * pool of connections).
+ * If the connections to a source are to be pooled, see {@link RepositoryConnectionPool}.
* </p>
*
* @author Randall Hauch
@@ -72,85 +68,6 @@
RepositoryConnection getConnection() throws RepositorySourceException, InterruptedException;
/**
- * Initiates an orderly shutdown in which connections that are currently in use are allowed to be used and closed as normal,
- * but no new connections will be created. Invocation has no additional effect if already shut down.
- * <p>
- * Once the source has been shutdown, it may not be used to {@link #getConnection() get connections}.
- * </p>
- *
- * @throws SecurityException if a security manager exists and shutting down this pool may manipulate threads that the caller
- * is not permitted to modify because it does not hold {@link java.lang.RuntimePermission}<tt>("modifyThread")</tt>,
- * or the security manager's <tt>checkAccess</tt> method denies access.
- * @see #shutdownNow()
- */
- void shutdown();
-
- /**
- * Attempts to close all connections, including those connections currently in use, and prevent the use of other connections.
- *
- * @throws SecurityException if a security manager exists and shutting down this pool may manipulate threads that the caller
- * is not permitted to modify because it does not hold {@link java.lang.RuntimePermission}<tt>("modifyThread")</tt>,
- * or the security manager's <tt>checkAccess</tt> method denies access.
- * @see #shutdown()
- */
- void shutdownNow();
-
- /**
- * Return whether this source is running and is able to {@link #getConnection() provide connections}. Note that this method is
- * effectively <code>!isShutdown()</code>.
- *
- * @return true if this source is running, or false otherwise
- * @see #isShutdown()
- * @see #isTerminated()
- * @see #isTerminating()
- */
- boolean isRunning();
-
- /**
- * Return whether this source is in the process of shutting down or has already been shut down. A result of <code>true</code>
- * signals that the pool may no longer be used. Note that this method is effectively <code>!isRunning()</code>.
- *
- * @return true if this source has been shut down, or false otherwise
- * @see #isShutdown()
- * @see #isTerminated()
- * @see #isTerminating()
- */
- boolean isShutdown();
-
- /**
- * Returns true if this source is in the process of terminating after {@link #shutdown()} or {@link #shutdownNow()} has been
- * called but has not completely terminated. This method may be useful for debugging. A return of <tt>true</tt> reported a
- * sufficient period after shutdown may indicate that submitted tasks have ignored or suppressed interruption, causing this
- * executor not to properly terminate.
- *
- * @return true if terminating but not yet terminated, or false otherwise
- * @see #isTerminated()
- */
- boolean isTerminating();
-
- /**
- * Return true if this pool has completed its termination and no longer has any open connections.
- *
- * @return true if terminated, or false otherwise
- * @see #isTerminating()
- */
- boolean isTerminated();
-
- /**
- * Method that can be called after {@link #shutdown()} or {@link #shutdownNow()} to wait until all connections in use at the
- * time those methods were called have been closed normally. This method accepts a maximum time duration, after which it will
- * return even if all connections have not been closed.
- *
- * @param timeout the maximum time to wait for all connections to be closed and returned to the pool
- * @param unit the time unit for <code>timeout</code>
- * @return true if the pool was terminated in the supplied time (or was already terminated), or false if the timeout occurred
- * before all the connections were closed
- * @throws InterruptedException if the thread was interrupted
- */
- boolean awaitTermination( long timeout,
- TimeUnit unit ) throws InterruptedException;
-
- /**
* Get the maximum number of retries that may be performed on a given operation when using {@link #getConnection()
* connections} created by this source. This value does not constitute a minimum number of retries; in fact, the connection
* user is not required to retry any operations.
Deleted: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceRegistry.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceRegistry.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceRegistry.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -1,39 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.connector;
-
-/**
- * An interface for any collection of {@link RepositorySource} instances that are accessed by their name.
- *
- * @author Randall Hauch
- */
-public interface RepositorySourceRegistry {
-
- /**
- * Obtain a {@link RepositorySource} given its name.
- *
- * @param sourceName the name of the source to obtain
- * @return the source, or null if no such source could be found (or created)
- */
- RepositorySource getRepositorySource( String sourceName );
-
-}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/RepositoryConnectionPoolTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/RepositoryConnectionPoolTest.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/RepositoryConnectionPoolTest.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -21,18 +21,14 @@
*/
package org.jboss.dna.spi.connector;
-import static org.jboss.dna.spi.connector.RepositorySourceLoadHarness.runLoadTest;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
+import static org.jboss.dna.spi.connector.RepositorySourceLoadHarness.runLoadTest;
import static org.junit.Assert.assertThat;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.connector.RepositoryConnectionPool;
-import org.jboss.dna.spi.connector.RepositorySource;
-import org.jboss.dna.spi.connector.RepositorySourceException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -44,23 +40,14 @@
public class RepositoryConnectionPoolTest {
private RepositoryConnectionPool pool;
- private RepositoryConnectionPool.ConnectionFactory connectionFactory;
+ private RepositorySource source;
private ExecutionContext context;
@Before
public void beforeEach() {
- final RepositorySource repositorySource = new TimeDelayingRepositorySource("source 1");
- this.connectionFactory = new RepositoryConnectionPool.ConnectionFactory() {
- public RepositoryConnection createConnection() throws RepositorySourceException, InterruptedException {
- return repositorySource.getConnection();
- }
-
- public String getSourceName() {
- return repositorySource.getName();
- }
- };
- this.pool = new RepositoryConnectionPool(this.connectionFactory, 1, 1, 100, TimeUnit.SECONDS);
- this.context = null;
+ source = new TimeDelayingRepositorySource("source 1");
+ pool = new RepositoryConnectionPool(source, 1, 1, 100, TimeUnit.SECONDS);
+ context = null;
}
@After
@@ -174,7 +161,7 @@
public void shouldBlockClientsWhenNotEnoughConnections() throws Exception {
int numConnectionsInPool = 1;
int numClients = 2;
- RepositoryConnectionPool pool = new RepositoryConnectionPool(connectionFactory);
+ RepositoryConnectionPool pool = new RepositoryConnectionPool(source);
pool.setCorePoolSize(numConnectionsInPool);
pool.setMaximumPoolSize(numConnectionsInPool);
RepositoryOperation.Factory<Integer> operationFactory = RepositorySourceLoadHarness.createMultipleLoadOperationFactory(10);
@@ -187,7 +174,7 @@
public void shouldLimitClientsToRunSequentiallyWithOneConnectionInPool() throws Exception {
int numConnectionsInPool = 1;
int numClients = 3;
- RepositoryConnectionPool pool = new RepositoryConnectionPool(connectionFactory);
+ RepositoryConnectionPool pool = new RepositoryConnectionPool(source);
pool.setCorePoolSize(numConnectionsInPool);
pool.setMaximumPoolSize(numConnectionsInPool);
RepositoryOperation.Factory<Integer> operationFactory = RepositorySourceLoadHarness.createMultipleLoadOperationFactory(10);
@@ -200,7 +187,7 @@
public void shouldClientsToRunConncurrentlyWithTwoConnectionsInPool() throws Exception {
int numConnectionsInPool = 2;
int numClients = 10;
- RepositoryConnectionPool pool = new RepositoryConnectionPool(connectionFactory);
+ RepositoryConnectionPool pool = new RepositoryConnectionPool(source);
pool.setCorePoolSize(numConnectionsInPool);
pool.setMaximumPoolSize(numConnectionsInPool);
RepositoryOperation.Factory<Integer> operationFactory = RepositorySourceLoadHarness.createMultipleLoadOperationFactory(10);
@@ -214,7 +201,7 @@
public void shouldClientsToRunConncurrentlyWithMultipleConnectionInPool() throws Exception {
int numConnectionsInPool = 10;
int numClients = 50;
- RepositoryConnectionPool pool = new RepositoryConnectionPool(connectionFactory);
+ RepositoryConnectionPool pool = new RepositoryConnectionPool(source);
pool.setCorePoolSize(numConnectionsInPool);
pool.setMaximumPoolSize(numConnectionsInPool);
RepositoryOperation.Factory<Integer> operationFactory = RepositorySourceLoadHarness.createMultipleLoadOperationFactory(20);
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -26,17 +26,12 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.Reference;
import javax.transaction.xa.XAResource;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
-import org.jboss.dna.spi.connector.AbstractRepositorySource;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.connector.RepositorySource;
-import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
-import org.jboss.dna.spi.connector.RepositorySourceException;
-import org.jboss.dna.spi.connector.RepositorySourceListener;
import org.jboss.dna.spi.graph.InvalidPathException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -53,12 +48,17 @@
* @author Randall Hauch
*/
@ThreadSafe
-public class SimpleRepositorySource extends AbstractRepositorySource {
+public class SimpleRepositorySource implements RepositorySource {
private static final long serialVersionUID = 1L;
+ /**
+ * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ */
+ public static final int DEFAULT_RETRY_LIMIT = 0;
private String repositoryName;
private String name;
+ private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
public SimpleRepositorySource() {
super();
@@ -97,6 +97,24 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.connector.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#setRetryLimit(int)
+ */
+ public void setRetryLimit( int limit ) {
+ retryLimit.set(limit < 0 ? 0 : limit);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.naming.Referenceable#getReference()
*/
public Reference getReference() {
@@ -152,10 +170,9 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.connector.AbstractRepositorySource#createConnection()
+ * @see org.jboss.dna.spi.connector.RepositorySource#getConnection()
*/
- @Override
- protected synchronized RepositoryConnection createConnection() throws RepositorySourceException {
+ public RepositoryConnection getConnection() throws RepositorySourceException {
String reposName = this.getRepositoryName();
SimpleRepository repository = SimpleRepository.get(reposName);
if (repository == null) {
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java 2008-08-07 19:56:15 UTC (rev 402)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java 2008-08-07 22:37:39 UTC (rev 403)
@@ -34,12 +34,6 @@
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
-import org.jboss.dna.spi.connector.AbstractRepositorySource;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.connector.RepositorySource;
-import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
-import org.jboss.dna.spi.connector.RepositorySourceException;
-import org.jboss.dna.spi.connector.RepositorySourceListener;
import org.jboss.dna.spi.graph.commands.GraphCommand;
/**
@@ -48,11 +42,16 @@
* @author Randall Hauch
*/
@ThreadSafe
-public class TimeDelayingRepositorySource extends AbstractRepositorySource {
+public class TimeDelayingRepositorySource implements RepositorySource {
/**
*/
private static final long serialVersionUID = -2756725117087437347L;
+ /**
+ * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ */
+ public static final int DEFAULT_RETRY_LIMIT = 0;
+
private String name;
private final AtomicInteger connectionsOpenedCount = new AtomicInteger(0);
private final AtomicInteger connectionsClosedCount = new AtomicInteger(0);
@@ -61,6 +60,7 @@
private final AtomicLong loadDelay = new AtomicLong(0);
private final AtomicLong pingCount = new AtomicLong(0);
private final AtomicLong pingDelay = new AtomicLong(0);
+ private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private CachePolicy defaultCachePolicy;
public TimeDelayingRepositorySource( String identifier ) {
@@ -82,6 +82,24 @@
this.name = name;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.connector.RepositorySource#setRetryLimit(int)
+ */
+ public void setRetryLimit( int limit ) {
+ retryLimit.set(limit < 0 ? 0 : limit);
+ }
+
public CachePolicy getDefaultCachePolicy() {
return defaultCachePolicy;
}
@@ -131,10 +149,9 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.connector.AbstractRepositorySource#createConnection()
+ * @see org.jboss.dna.spi.connector.RepositorySource#getConnection()
*/
- @Override
- protected RepositoryConnection createConnection() throws RepositorySourceException {
+ public RepositoryConnection getConnection() throws RepositorySourceException {
int connectionNumber = this.connectionsOpenedCount.incrementAndGet();
String connectionName = "Connection " + connectionNumber;
XAResource xaResource = newXaResource(connectionName);
15 years, 10 months
DNA SVN: r402 - in trunk: connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-07 15:56:15 -0400 (Thu, 07 Aug 2008)
New Revision: 402
Modified:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added more tests.
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-07 16:37:58 UTC (rev 401)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-07 19:56:15 UTC (rev 402)
@@ -88,6 +88,13 @@
}
/**
+ * @return cache
+ */
+ /*package*/Cache<Name, Object> getCache() {
+ return cache;
+ }
+
+ /**
* {@inheritDoc}
*/
public String getSourceName() {
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-07 16:37:58 UTC (rev 401)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-07 19:56:15 UTC (rev 402)
@@ -390,6 +390,24 @@
/**
* {@inheritDoc}
*/
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof JBossCacheSource) {
+ JBossCacheSource that = (JBossCacheSource)obj;
+ if (this.getName() == null) {
+ if (that.getName() != null) return false;
+ } else {
+ if (!this.getName().equals(that.getName())) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public synchronized Reference getReference() {
String className = getClass().getName();
String factoryClassName = this.getClass().getName();
Modified: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-07 16:37:58 UTC (rev 401)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-07 19:56:15 UTC (rev 402)
@@ -25,8 +25,28 @@
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.dna.spi.cache.BasicCachePolicy;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author Randall Hauch
@@ -34,12 +54,47 @@
public class JBossCacheSourceTest {
private JBossCacheSource source;
+ private RepositoryConnection connection;
+ private String validName;
+ private String validUuidPropertyName;
+ private String validCacheConfigurationName;
+ private String validCacheFactoryJndiName;
+ private String validCacheJndiName;
+ private UUID validRootNodeUuid;
+ @Mock
+ private Context jndiContext;
+ @Mock
+ private CacheFactory<Name, Object> cacheFactory;
+ @Mock
+ private Cache<Name, Object> cache;
@Before
public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ validName = "cache source";
+ validUuidPropertyName = "dna:uuid";
+ validCacheConfigurationName = "cache config name";
+ validCacheFactoryJndiName = "cache factory jndi name";
+ validCacheJndiName = "cache jndi name";
+ validRootNodeUuid = UUID.randomUUID();
source = new JBossCacheSource();
+
+ // Set up the fake JNDI context ...
+ source.setContext(jndiContext);
+ stub(jndiContext.lookup(validCacheFactoryJndiName)).toReturn(cacheFactory);
+ stub(jndiContext.lookup(validCacheJndiName)).toReturn(cache);
}
+ @After
+ public void afterEach() throws Exception {
+ if (connection != null) {
+ connection.close();
+ }
+ source.shutdownNow();
+ source.awaitTermination(4, TimeUnit.SECONDS);
+ // assertThat(source.isTerminated(), is(true));
+ }
+
@Test
public void shouldReturnNonNullCapabilities() {
assertThat(source.getCapabilities(), is(notNullValue()));
@@ -75,4 +130,139 @@
source.setName(null);
assertThat(source.getName(), is(nullValue()));
}
+
+ @Test
+ public void shouldHaveDefaultRetryLimit() {
+ assertThat(source.getRetryLimit(), is(JBossCacheSource.DEFAULT_RETRY_LIMIT));
+ }
+
+ @Test
+ public void shouldSetRetryLimitToZeroWhenSetWithNonPositiveValue() {
+ source.setRetryLimit(0);
+ assertThat(source.getRetryLimit(), is(0));
+ source.setRetryLimit(-1);
+ assertThat(source.getRetryLimit(), is(0));
+ source.setRetryLimit(-100);
+ assertThat(source.getRetryLimit(), is(0));
+ }
+
+ @Test
+ public void shouldAllowRetryLimitToBeSet() {
+ for (int i = 0; i != 100; ++i) {
+ source.setRetryLimit(i);
+ assertThat(source.getRetryLimit(), is(i));
+ }
+ }
+
+ @Test
+ public void shouldCreateJndiReferenceAndRecreatedObjectFromReference() throws Exception {
+ BasicCachePolicy cachePolicy = new BasicCachePolicy();
+ cachePolicy.setTimeToLive(1000L);
+ convertToAndFromJndiReference(validName,
+ validRootNodeUuid,
+ validCacheConfigurationName,
+ validCacheJndiName,
+ validCacheFactoryJndiName,
+ validUuidPropertyName,
+ cachePolicy,
+ 100);
+ }
+
+ @Test
+ public void shouldCreateJndiReferenceAndRecreatedObjectFromReferenceWithNullProperties() throws Exception {
+ BasicCachePolicy cachePolicy = new BasicCachePolicy();
+ cachePolicy.setTimeToLive(1000L);
+ convertToAndFromJndiReference("some source", null, null, null, null, null, null, 100);
+ convertToAndFromJndiReference(null, null, null, null, null, null, null, 100);
+ }
+
+ private void convertToAndFromJndiReference( String sourceName,
+ UUID rootNodeUuid,
+ String cacheConfigName,
+ String cacheJndiName,
+ String cacheFactoryJndiName,
+ String uuidPropertyName,
+ BasicCachePolicy cachePolicy,
+ int retryLimit ) throws Exception {
+ source.setRetryLimit(retryLimit);
+ source.setName(sourceName);
+ source.setCacheConfigurationName(cacheConfigName);
+ source.setCacheFactoryJndiName(cacheFactoryJndiName);
+ source.setCacheJndiName(cacheJndiName);
+ source.setDefaultCachePolicy(cachePolicy);
+ source.setRootNodeUuid(rootNodeUuid != null ? rootNodeUuid.toString() : null);
+ source.setUuidPropertyName(uuidPropertyName);
+
+ Reference ref = source.getReference();
+ assertThat(ref.getClassName(), is(JBossCacheSource.class.getName()));
+ assertThat(ref.getFactoryClassName(), is(JBossCacheSource.class.getName()));
+
+ Map<String, Object> refAttributes = new HashMap<String, Object>();
+ Enumeration<RefAddr> enumeration = ref.getAll();
+ while (enumeration.hasMoreElements()) {
+ RefAddr addr = enumeration.nextElement();
+ refAttributes.put(addr.getType(), addr.getContent());
+ }
+
+ assertThat((String)refAttributes.remove(JBossCacheSource.SOURCE_NAME), is(source.getName()));
+ assertThat((String)refAttributes.remove(JBossCacheSource.ROOT_NODE_UUID), is(source.getRootNodeUuid()));
+ assertThat((String)refAttributes.remove(JBossCacheSource.UUID_PROPERTY_NAME), is(source.getUuidPropertyName()));
+ assertThat((String)refAttributes.remove(JBossCacheSource.CACHE_JNDI_NAME), is(source.getCacheJndiName()));
+ assertThat((String)refAttributes.remove(JBossCacheSource.CACHE_FACTORY_JNDI_NAME), is(source.getCacheFactoryJndiName()));
+ assertThat((String)refAttributes.remove(JBossCacheSource.CACHE_CONFIGURATION_NAME),
+ is(source.getCacheConfigurationName()));
+ assertThat((String)refAttributes.remove(JBossCacheSource.RETRY_LIMIT), is(Integer.toString(source.getRetryLimit())));
+ refAttributes.remove(JBossCacheSource.DEFAULT_CACHE_POLICY);
+ assertThat(refAttributes.isEmpty(), is(true));
+
+ // Recreate the object, use a newly constructed source ...
+ ObjectFactory factory = new JBossCacheSource();
+ Name name = mock(Name.class);
+ Context context = mock(Context.class);
+ Hashtable<?, ?> env = new Hashtable<Object, Object>();
+ JBossCacheSource recoveredSource = (JBossCacheSource)factory.getObjectInstance(ref, name, context, env);
+ assertThat(recoveredSource, is(notNullValue()));
+
+ assertThat(recoveredSource.getName(), is(source.getName()));
+ assertThat(recoveredSource.getRootNodeUuid(), is(source.getRootNodeUuid()));
+ assertThat(recoveredSource.getUuidPropertyName(), is(source.getUuidPropertyName()));
+ assertThat(recoveredSource.getCacheJndiName(), is(source.getCacheJndiName()));
+ assertThat(recoveredSource.getRetryLimit(), is(source.getRetryLimit()));
+ assertThat(recoveredSource.getCacheFactoryJndiName(), is(source.getCacheFactoryJndiName()));
+ assertThat(recoveredSource.getCacheConfigurationName(), is(source.getCacheConfigurationName()));
+ assertThat(recoveredSource.getDefaultCachePolicy(), is(source.getDefaultCachePolicy()));
+
+ assertThat(recoveredSource.equals(source), is(true));
+ assertThat(source.equals(recoveredSource), is(true));
+ }
+
+ @Test
+ public void shouldCreateCacheUsingDefaultCacheFactoryWhenNoCacheOrCacheFactoryOrCacheConfigurationNameIsFound()
+ throws Exception {
+ source.setName(validName);
+ connection = source.getConnection();
+ assertThat(connection, is(notNullValue()));
+ // assertThat(connection.getCache(), is(notNullValue()));
+ }
+
+ @Test
+ public void shouldCreateCacheUsingDefaultCacheFactoryWithConfigurationNameWhenNoCacheOrCacheFactoryIsFound() throws Exception {
+
+ }
+
+ @Test
+ public void shouldCreateCacheUsingCacheFactoryAndDefaultConfigurationWhenNoCacheOrCacheConfigurationNameIsFound()
+ throws Exception {
+
+ }
+
+ @Test
+ public void shouldCreateCacheUsingCacheFactoryAndConfigurationWhenNoCacheIsFound() throws Exception {
+
+ }
+
+ @Test
+ public void shouldUseCacheIfFoundInJndi() throws Exception {
+
+ }
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java 2008-08-07 16:37:58 UTC (rev 401)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java 2008-08-07 19:56:15 UTC (rev 402)
@@ -60,4 +60,30 @@
return new ImmutableCachePolicy(this.getTimeToLive());
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof CachePolicy) {
+ CachePolicy that = (CachePolicy)obj;
+ if (this.getTimeToLive() != that.getTimeToLive()) return false;
+ if (obj instanceof BasicCachePolicy) return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "{ TTL=" + this.timeToLive + " }";
+ }
+
}
15 years, 10 months
DNA SVN: r401 - trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-07 12:37:58 -0400 (Thu, 07 Aug 2008)
New Revision: 401
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
Log:
DNA-196 - Add methods to ValueFactory that takes Iterator<?> and returns Iterator<T>
http://jira.jboss.com/jira/browse/DNA-196
Added more documentation to better explain how the ValueFactory should be used to get at the Property's values.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-08-07 16:17:48 UTC (rev 400)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-08-07 16:37:58 UTC (rev 401)
@@ -27,7 +27,32 @@
/**
* Representation of a property consisting of a name and value(s). Note that this property is immutable, meaning that the property
* values may not be changed through this interface.
+ * <p>
+ * This class is designed to be used with the {@link ValueFactories} interface and the particular {@link ValueFactory} that
+ * corresponds to the type of value you'd like to use. The <code>ValueFactory</code> will then return the values (if no type
+ * conversion is required) or will convert the values using the appropriate conversion algorithm.
+ * </p>
+ * <p>
+ * The following example shows how to obtain the {@link String} representations of the {@link #getValues() property values}:
*
+ * <pre>
+ * ValueFactories valueFactories = ...
+ * Property property = ...
+ * Iterator<String> iter = valueFactories.getStringFactory().create(property.getValues());
+ * while ( iter.hasNext() ) {
+ * System.out.println(iter.next());
+ * }
+ * </pre>
+ *
+ * Meanwhile, the {@link ValueFactories#getLongFactory() long value factory} converts the values to <code>long</code>, the
+ * {@link ValueFactories#getDateFactory() date value factory} converts the values to {@link DateTime} instances, and so on.
+ * </p>
+ * <p>
+ * This technique is much better and far safer than casting the values. It is possible that some Property instances contain
+ * heterogeneous values, so casting may not always work. Also, this technique guarantees that the values are properly converted if
+ * the type is not what you expected.
+ * </p>
+ *
* @author Randall Hauch
*/
@Immutable
@@ -43,8 +68,8 @@
/**
* Get the number of actual values in this property. If the property allows {@link #isMultiple() multiple values}, then this
* method may return a value greater than 1. If the property only allows a {@link #isSingle() single value}, then this method
- * will return either 0 or 1. This method may return 0 regardless of whether the property allows a
- * {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
+ * will return either 0 or 1. This method may return 0 regardless of whether the property allows a {@link #isSingle() single
+ * value}, or {@link #isMultiple() multiple values}.
*
* @return the number of actual values in this property; always non-negative
*/
@@ -93,6 +118,7 @@
* @return an iterator over the values; never null
* @see Iterable#iterator()
* @see #getValuesAsArray()
+ * @see ValueFactory#create(Iterator)
*/
Iterator<?> getValues();
@@ -109,6 +135,7 @@
* @return the array of values
* @see Iterable#iterator()
* @see #getValues()
+ * @see ValueFactory#create(Object[])
*/
Object[] getValuesAsArray();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-07 16:37:58 UTC (rev 401)
@@ -401,10 +401,14 @@
/**
* Create an iterator over the values (of an unknown type). The factory converts any values as required. Note that this method
* will not consider {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ * <p>
+ * This is useful to use when iterating over the {@link Property#getValues() values} of a {@link Property}.
+ * </p>
*
* @param values the values
* @return the iterator of type <code>T</code> over the values, or null if the supplied parameter is null
* @throws IoException If an unexpected problem occurs during the conversion.
+ * @see Property#getValues()
*/
Iterator<T> create( Iterator<?> values ) throws IoException;
15 years, 10 months
DNA SVN: r400 - in trunk/dna-spi/src: main/java/org/jboss/dna/spi/graph/impl and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-07 12:17:48 -0400 (Thu, 07 Aug 2008)
New Revision: 400
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java
Log:
DNA-196 - Add methods to ValueFactory that takes Iterator<?> and returns Iterator<T>
http://jira.jboss.com/jira/browse/DNA-196
Added a single "create(Iterator<?> values):Iterator<T>" to the ValueFactory interface, and added implementation methods to all concrete classes. The AbstractValueFactory class defines a ConvertingIterator<T> that wraps an Iterator<?> and simply calls "create(Object):T" on the value factory that is using it. Thus, this method is actually quite efficient, since the only cost is the wrapped iterator instance.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -28,6 +28,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
@@ -397,4 +398,14 @@
*/
T[] create( Object[] values ) throws IoException;
+ /**
+ * Create an iterator over the values (of an unknown type). The factory converts any values as required. Note that this method
+ * will not consider {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ *
+ * @param values the values
+ * @return the iterator of type <code>T</code> over the values, or null if the supplied parameter is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ Iterator<T> create( Iterator<?> values ) throws IoException;
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -344,4 +345,44 @@
return result;
}
+ protected static class ConvertingIterator<ValueType> implements Iterator<ValueType> {
+ private final Iterator<?> delegate;
+ private final ValueFactory<ValueType> factory;
+
+ protected ConvertingIterator( Iterator<?> delegate,
+ ValueFactory<ValueType> factory ) {
+ assert delegate != null;
+ assert factory != null;
+ this.delegate = delegate;
+ this.factory = factory;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return this.delegate.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public ValueType next() {
+ return factory.create(this.delegate.next());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ this.delegate.remove();
+ }
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -214,7 +215,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<Boolean> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Boolean>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected Boolean[] createEmptyArray( int length ) {
return new Boolean[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -210,7 +211,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<BigDecimal> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<BigDecimal>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected BigDecimal[] createEmptyArray( int length ) {
return new BigDecimal[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -217,7 +218,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<Double> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Double>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected Double[] createEmptyArray( int length ) {
return new Double[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -29,6 +29,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -227,7 +228,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<Binary> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Binary>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected Binary[] createEmptyArray( int length ) {
return new Binary[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -286,7 +287,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<DateTime> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<DateTime>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected DateTime[] createEmptyArray( int length ) {
return new DateTime[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -211,7 +212,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<Long> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Long>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected Long[] createEmptyArray( int length ) {
return new Long[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -301,6 +302,15 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
+ */
+ public Iterator<Name> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Name>(values, this);
+ }
+
+ /**
* <p>
* {@inheritDoc}
* </p>
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,11 +27,13 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -197,7 +199,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<Object> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Object>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected Object[] createEmptyArray( int length ) {
return new Object[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
@@ -599,7 +600,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<Path> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Path>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected Path[] createEmptyArray( int length ) {
return new Path[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -29,6 +29,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -244,7 +245,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<String> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<String>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected String[] createEmptyArray( int length ) {
return new String[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -28,6 +28,7 @@
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -229,7 +230,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<URI> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<URI>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected URI[] createEmptyArray( int length ) {
return new URI[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -219,7 +220,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<Reference> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<Reference>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected Reference[] createEmptyArray( int length ) {
return new Reference[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -235,7 +236,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<UUID> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<UUID>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected UUID[] createEmptyArray( int length ) {
return new UUID[length];
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -32,9 +32,11 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.UUID;
import org.jboss.dna.common.text.NoOpEncoder;
import org.jboss.dna.common.text.TextDecoder;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -134,7 +136,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
+ public Iterator<String> create( Iterator<?> values ) throws IoException {
+ return new ConvertingIterator<String>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
protected String[] createEmptyArray( int length ) {
return new String[length];
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -27,8 +27,11 @@
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -164,4 +167,16 @@
assertThat(factory.create(new StringReader("FALSE")), is(false));
assertThat(factory.create(new StringReader("something else")), is(false));
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i)
+ values.add((i % 2 == 0 ? "true" : "false"));
+ Iterator<Boolean> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -28,8 +28,11 @@
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -167,4 +170,16 @@
public void shouldNotCreateDecimalFromReaderContainingStringWithContentsOtherThanDecimal() {
factory.create(new StringReader("something"));
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i)
+ values.add("" + i);
+ Iterator<BigDecimal> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -28,8 +28,11 @@
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -169,4 +172,16 @@
public void shouldNotCreateDoubleFromReaderContainingStringWithContentsOtherThanDouble() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i)
+ values.add("" + i);
+ Iterator<Double> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -21,6 +21,7 @@
*/
package org.jboss.dna.spi.graph.impl;
+import static org.hamcrest.core.Is.is;
import static org.jboss.dna.spi.graph.impl.BinaryContains.hasContent;
import static org.junit.Assert.assertThat;
import java.io.ByteArrayInputStream;
@@ -28,10 +29,14 @@
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
import java.util.UUID;
import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.Binary;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -135,13 +140,15 @@
@Test
public void shouldCreateBinaryFromName() throws UnsupportedEncodingException {
Name value = nameFactory.create("jboss:localName");
- assertThat(factory.create(value), hasContent("{" + encoder.encode("http://www.jboss.org") + "}" + encoder.encode("localName")));
+ assertThat(factory.create(value), hasContent("{" + encoder.encode("http://www.jboss.org") + "}"
+ + encoder.encode("localName")));
}
@Test
public void shouldCreateBinaryFromPath() throws UnsupportedEncodingException {
Path value = pathFactory.create("/a/b/c/jboss:localName");
- assertThat(factory.create(value), hasContent("/{}a/{}b/{}c/{" + encoder.encode("http://www.jboss.org") + "}" + encoder.encode("localName")));
+ assertThat(factory.create(value), hasContent("/{}a/{}b/{}c/{" + encoder.encode("http://www.jboss.org") + "}"
+ + encoder.encode("localName")));
}
@Test
@@ -174,4 +181,16 @@
String value = "Some test string";
assertThat(factory.create(new StringReader(value)), hasContent(value));
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i)
+ values.add("some string" + i);
+ Iterator<Binary> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -28,7 +28,10 @@
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -177,4 +180,17 @@
public void shouldNotCreateDateFromReaderContainingStringWithContentThatIsNotWellFormedDate() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i) {
+ values.add(new JodaDateTime(10000 + i).toString());
+ }
+ Iterator<DateTime> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -28,8 +28,11 @@
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -171,4 +174,16 @@
public void shouldNotCreateLongFromReaderContainingStringWithContentsOtherThanLong() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i)
+ values.add(" " + i);
+ Iterator<Long> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -23,6 +23,9 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.Name;
@@ -120,4 +123,17 @@
public void shouldNotAllowEmptyLocalNameWithEncoder() {
factory.create("a", "", decoder);
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i) {
+ values.add("dna:something" + i);
+ }
+ Iterator<Name> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -25,6 +25,7 @@
import static org.jboss.dna.spi.graph.impl.IsPathContaining.hasSegments;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.Name;
@@ -116,4 +117,17 @@
assertThat(path.compareTo(path2), is(0));
}
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i) {
+ values.add("/a/b/c/d/dna:e/dna:f" + i);
+ }
+ Iterator<Path> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
+
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java 2008-08-07 15:42:07 UTC (rev 399)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java 2008-08-07 16:17:48 UTC (rev 400)
@@ -29,7 +29,10 @@
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
import java.util.UUID;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -161,4 +164,17 @@
public void shouldNotCreateUuuidFromReaderContainingStringWithContentsOtherThanUuuid() throws Exception {
factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
}
+
+ @Test
+ public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i != 10; ++i) {
+ values.add(" " + UUID.randomUUID());
+ }
+ Iterator<UUID> iter = factory.create(values.iterator());
+ Iterator<String> valueIter = values.iterator();
+ while (iter.hasNext()) {
+ assertThat(iter.next(), is(factory.create(valueIter.next())));
+ }
+ }
}
15 years, 10 months
DNA SVN: r399 - in trunk/connectors/dna-connector-jbosscache/src: main/resources/org/jboss/dna/connector/jbosscache and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-07 11:42:07 -0400 (Thu, 07 Aug 2008)
New Revision: 399
Modified:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Changed how the JBossCacheSource is turned into a JNDI Reference, removing all static references to the instances.
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java 2008-08-07 15:38:59 UTC (rev 398)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.java 2008-08-07 15:42:07 UTC (rev 399)
@@ -32,6 +32,10 @@
public static I18n connectorName;
public static I18n nodeDoesNotExist;
+ public static I18n propertyIsRequired;
+ public static I18n errorSerializingCachePolicyInSource;
+ public static I18n objectFoundInJndiWasNotCache;
+ public static I18n objectFoundInJndiWasNotCacheFactory;
static {
try {
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-07 15:38:59 UTC (rev 398)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-07 15:42:07 UTC (rev 399)
@@ -21,36 +21,53 @@
*/
package org.jboss.dna.connector.jbosscache;
-import java.util.Collections;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Hashtable;
-import java.util.Set;
+import java.util.Map;
import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import javax.naming.BinaryRefAddr;
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NamingException;
import javax.naming.RefAddr;
import javax.naming.Reference;
+import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
-import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.connector.AbstractRepositorySource;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
+import org.jboss.dna.spi.connector.RepositorySourceException;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
/**
+ * A repository source that uses a JBoss Cache instance to manage the content. This source is capable of using an existing
+ * {@link Cache} instance or creating a new instance. This process is controlled entirely by the JavaBean properties of the
+ * JBossCacheSource instance.
+ * <p>
+ * This source first attempts to find an existing cache in {@link #getCacheJndiName() JNDI}. If none is found, then it attempts to
+ * create a cache instance using the {@link CacheFactory} found in {@link #getCacheFactoryJndiName() JNDI} (or the
+ * {@link DefaultCacheFactory} if no such factory is available) and the {@link #getCacheConfigurationName() cache configuration
+ * name} if supplied or the default configuration if not set.
+ * </p>
+ * <p>
+ * Like other {@link RepositorySource} classes, instances of JBossCacheSource can be placed into JNDI and do support the creation
+ * of {@link Referenceable JNDI referenceable} objects and resolution of references into JBossCacheSource.
+ *
* @author Randall Hauch
*/
@ThreadSafe
@@ -59,49 +76,24 @@
private static final long serialVersionUID = 1L;
public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
- private static final ConcurrentMap<String, JBossCacheSource> sources = new ConcurrentHashMap<String, JBossCacheSource>();
- private static final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
+ protected static final String ROOT_NODE_UUID = "rootNodeUuid";
+ protected static final String SOURCE_NAME = "sourceName";
+ protected static final String DEFAULT_CACHE_POLICY = "defaultCachePolicy";
+ protected static final String CACHE_CONFIGURATION_NAME = "cacheConfigurationName";
+ protected static final String CACHE_FACTORY_JNDI_NAME = "cacheFactoryJndiName";
+ protected static final String CACHE_JNDI_NAME = "cacheJndiName";
+ protected static final String UUID_PROPERTY_NAME = "uuidPropertyName";
+ protected static final String RETRY_LIMIT = "retryLimit";
- /**
- * Get the names of the in-memory repository sources that are currently registered
- *
- * @return the unmodifiable set of names
- */
- public static Set<String> getSourceNames() {
- Lock lock = sourcesLock.readLock();
- try {
- lock.lock();
- return Collections.unmodifiableSet(sources.keySet());
- } finally {
- lock.unlock();
- }
- }
-
- /**
- * Get the source with the supplied name.
- *
- * @param name the name
- * @return the source, or null if there is no source with the supplied name
- */
- public static JBossCacheSource getSource( String name ) {
- Lock lock = sourcesLock.readLock();
- try {
- lock.lock();
- return sources.get(name);
- } finally {
- lock.unlock();
- }
- }
-
- @GuardedBy( "sourcesLock" )
private String name;
- @GuardedBy( "this" )
- private String jndiName;
private UUID rootNodeUuid = UUID.randomUUID();
private CachePolicy defaultCachePolicy;
private String cacheConfigurationName;
+ private String cacheFactoryJndiName;
+ private String cacheJndiName;
private String uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
private transient Cache<Name, Object> cache;
+ private transient Context jndiContext;
/**
* Create a repository source instance.
@@ -110,6 +102,23 @@
}
/**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Set the name of this source
+ *
+ * @param name the name for this source
+ */
+ public synchronized void setName( String name ) {
+ if (this.name == name || this.name != null && this.name.equals(name)) return; // unchanged
+ this.name = name;
+ }
+
+ /**
* Get the default cache policy for this source, or null if the global default cache policy should be used
*
* @return the default cache policy, or null if this source has no explicit default cache policy
@@ -121,145 +130,303 @@
/**
* @param defaultCachePolicy Sets defaultCachePolicy to the specified value.
*/
- public void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
+ public synchronized void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
+ if (this.defaultCachePolicy == defaultCachePolicy || this.defaultCachePolicy != null
+ && this.defaultCachePolicy.equals(defaultCachePolicy)) return; // unchanged
this.defaultCachePolicy = defaultCachePolicy;
}
/**
- * @return rootNodeUuid
+ * Get the name in JNDI of a {@link Cache} instance that should be used by this source.
+ * <p>
+ * This source first attempts to find an existing cache in {@link #getCacheJndiName() JNDI}. If none is found, then it
+ * attempts to create a cache instance using the {@link CacheFactory} found in {@link #getCacheFactoryJndiName() JNDI} (or the
+ * {@link DefaultCacheFactory} if no such factory is available) and the {@link #getCacheConfigurationName() cache
+ * configuration name} if supplied or the default configuration if not set.
+ * </p>
+ *
+ * @return the JNDI name of the {@link Cache} instance that should be used, or null if the cache is to be created with a cache
+ * factory {@link #getCacheFactoryJndiName() found in JNDI} using the specified {@link #getCacheConfigurationName()
+ * cache configuration name}.
+ * @see #setCacheJndiName(String)
+ * @see #getCacheConfigurationName()
+ * @see #getCacheFactoryJndiName()
*/
- public UUID getRootNodeUuid() {
- return this.rootNodeUuid;
+ public String getCacheJndiName() {
+ return cacheJndiName;
}
/**
- * @param rootNodeUuid Sets rootNodeUuid to the specified value.
+ * Set the name in JNDI of a {@link Cache} instance that should be used by this source.
+ * <p>
+ * This source first attempts to find an existing cache in {@link #getCacheJndiName() JNDI}. If none is found, then it
+ * attempts to create a cache instance using the {@link CacheFactory} found in {@link #getCacheFactoryJndiName() JNDI} (or the
+ * {@link DefaultCacheFactory} if no such factory is available) and the {@link #getCacheConfigurationName() cache
+ * configuration name} if supplied or the default configuration if not set.
+ * </p>
+ *
+ * @param cacheJndiName the JNDI name of the {@link Cache} instance that should be used, or null if the cache is to be created
+ * with a cache factory {@link #getCacheFactoryJndiName() found in JNDI} using the specified
+ * {@link #getCacheConfigurationName() cache configuration name}.
+ * @see #getCacheJndiName()
+ * @see #getCacheConfigurationName()
+ * @see #getCacheFactoryJndiName()
*/
- public void setRootNodeUuid( UUID rootNodeUuid ) {
- this.rootNodeUuid = rootNodeUuid != null ? rootNodeUuid : UUID.randomUUID();
+ public synchronized void setCacheJndiName( String cacheJndiName ) {
+ if (this.cacheJndiName == cacheJndiName || this.cacheJndiName != null && this.cacheJndiName.equals(cacheJndiName)) return; // unchanged
+ this.cacheJndiName = cacheJndiName;
}
/**
- * @return uuidPropertyName
+ * Get the name in JNDI of a {@link CacheFactory} instance that should be used to create the cache for this source.
+ * <p>
+ * This source first attempts to find an existing cache in {@link #getCacheJndiName() JNDI}. If none is found, then it
+ * attempts to create a cache instance using the {@link CacheFactory} found in {@link #getCacheFactoryJndiName() JNDI} (or the
+ * {@link DefaultCacheFactory} if no such factory is available) and the {@link #getCacheConfigurationName() cache
+ * configuration name} if supplied or the default configuration if not set.
+ * </p>
+ *
+ * @return the JNDI name of the {@link CacheFactory} instance that should be used, or null if the {@link DefaultCacheFactory}
+ * should be used if a cache is to be created
+ * @see #setCacheFactoryJndiName(String)
+ * @see #getCacheConfigurationName()
+ * @see #getCacheJndiName()
*/
- public String getUuidPropertyName() {
- return this.uuidPropertyName;
+ public String getCacheFactoryJndiName() {
+ return cacheFactoryJndiName;
}
/**
- * @param uuidPropertyName Sets uuidPropertyName to the specified value.
+ * Set the name in JNDI of a {@link CacheFactory} instance that should be used to obtain the {@link Cache} instance used by
+ * this source.
+ * <p>
+ * This source first attempts to find an existing cache in {@link #getCacheJndiName() JNDI}. If none is found, then it
+ * attempts to create a cache instance using the {@link CacheFactory} found in {@link #getCacheFactoryJndiName() JNDI} (or the
+ * {@link DefaultCacheFactory} if no such factory is available) and the {@link #getCacheConfigurationName() cache
+ * configuration name} if supplied or the default configuration if not set.
+ * </p>
+ *
+ * @param jndiName the JNDI name of the {@link CacheFactory} instance that should be used, or null if the
+ * {@link DefaultCacheFactory} should be used if a cache is to be created
+ * @see #setCacheFactoryJndiName(String)
+ * @see #getCacheConfigurationName()
+ * @see #getCacheJndiName()
*/
- public synchronized void setUuidPropertyName( String uuidPropertyName ) {
- this.uuidPropertyName = uuidPropertyName != null ? uuidPropertyName.trim() : DEFAULT_UUID_PROPERTY_NAME;
+ public synchronized void setCacheFactoryJndiName( String jndiName ) {
+ if (this.cacheFactoryJndiName == jndiName || this.cacheFactoryJndiName != null
+ && this.cacheFactoryJndiName.equals(jndiName)) return; // unchanged
+ this.cacheFactoryJndiName = jndiName;
}
/**
- * If you use this to set a JNDI name, this source will be bound to that name using the default {@link InitialContext}. You
- * can also do this manually if you have additional requirements.
+ * Get the name of the configuration that should be used if a {@link Cache cache} is to be created using the
+ * {@link CacheFactory} found in JNDI or the {@link DefaultCacheFactory} if needed.
+ * <p>
+ * This source first attempts to find an existing cache in {@link #getCacheJndiName() JNDI}. If none is found, then it
+ * attempts to create a cache instance using the {@link CacheFactory} found in {@link #getCacheFactoryJndiName() JNDI} (or the
+ * {@link DefaultCacheFactory} if no such factory is available) and the {@link #getCacheConfigurationName() cache
+ * configuration name} if supplied or the default configuration if not set.
+ * </p>
*
- * @param name the JNDI name
- * @throws NamingException if there is a problem registering this object
- * @see #getJndiName()
+ * @return the name of the configuration that should be passed to the {@link CacheFactory}, or null if the default
+ * configuration should be used
+ * @see #setCacheConfigurationName(String)
+ * @see #getCacheFactoryJndiName()
+ * @see #getCacheJndiName()
*/
- public void setJndiName( String name ) throws NamingException {
- setJndiName(name, null);
+ public String getCacheConfigurationName() {
+ return cacheConfigurationName;
}
/**
- * Register this source in JNDI under the supplied name using the supplied context. to set a JNDI name, this source will be
- * bound to that name using the default {@link InitialContext}. You can also do this manually if you have additional
- * requirements.
+ * Get the name of the configuration that should be used if a {@link Cache cache} is to be created using the
+ * {@link CacheFactory} found in JNDI or the {@link DefaultCacheFactory} if needed.
+ * <p>
+ * This source first attempts to find an existing cache in {@link #getCacheJndiName() JNDI}. If none is found, then it
+ * attempts to create a cache instance using the {@link CacheFactory} found in {@link #getCacheFactoryJndiName() JNDI} (or the
+ * {@link DefaultCacheFactory} if no such factory is available) and the {@link #getCacheConfigurationName() cache
+ * configuration name} if supplied or the default configuration if not set.
+ * </p>
*
- * @param name the JNDI name, or null if this object is to no longer be registered
- * @param context the JNDI context, or null if the {@link InitialContext} should be used
- * @throws NamingException if there is a problem registering this object
- * @see #getJndiName()
+ * @param cacheConfigurationName the name of the configuration that should be passed to the {@link CacheFactory}, or null if
+ * the default configuration should be used
+ * @see #getCacheConfigurationName()
+ * @see #getCacheFactoryJndiName()
+ * @see #getCacheJndiName()
*/
- public synchronized void setJndiName( String name,
- Context context ) throws NamingException {
- ArgCheck.isNotNull(name, "name");
- if (context == null) context = new InitialContext();
+ public synchronized void setCacheConfigurationName( String cacheConfigurationName ) {
+ if (this.cacheConfigurationName == cacheConfigurationName || this.cacheConfigurationName != null
+ && this.cacheConfigurationName.equals(cacheConfigurationName)) return; // unchanged
+ this.cacheConfigurationName = cacheConfigurationName;
+ }
- // First register in JNDI under the new name ...
- if (name != null) {
- context.bind(name, this);
- }
- // Second, unregister from JNDI if there is already a name ...
- if (jndiName != null && !jndiName.equals(name)) {
- context.unbind(jndiName);
- }
- // Record the new name ...
- this.jndiName = name;
+ /**
+ * Get the UUID of the root node for the cache. If the cache exists, this UUID is not used but is instead set to the UUID of
+ * the existing root node.
+ *
+ * @return the UUID of the root node for the cache.
+ */
+ public String getRootNodeUuid() {
+ return this.rootNodeUuid.toString();
}
/**
- * Gets the JNDI name this source is bound to. Only valid if you used setJNDIName to bind it.
+ * Get the UUID of the root node for the cache. If the cache exists, this UUID is not used but is instead set to the UUID of
+ * the existing root node.
*
- * @return the JNDI name, or null if it is not bound in JNDI
- * @see #setJndiName(String)
+ * @return the UUID of the root node for the cache.
*/
- public synchronized String getJndiName() {
- return jndiName;
+ public UUID getRootNodeUuidObject() {
+ return this.rootNodeUuid;
}
/**
- * {@inheritDoc}
+ * Set the UUID of the root node in this repository. If the cache exists, this UUID is not used but is instead set to the UUID
+ * of the existing root node.
+ *
+ * @param rootNodeUuid the UUID of the root node for the cache, or null if the UUID should be randomly generated
*/
- public String getName() {
- Lock lock = sourcesLock.readLock();
- try {
- lock.lock();
- return this.name;
- } finally {
- lock.unlock();
- }
+ public synchronized void setRootNodeUuid( String rootNodeUuid ) {
+ UUID uuid = null;
+ if (rootNodeUuid == null) uuid = UUID.randomUUID();
+ else uuid = UUID.fromString(rootNodeUuid);
+ if (this.rootNodeUuid.equals(uuid)) return; // unchanged
+ this.rootNodeUuid = uuid;
}
/**
- * @param name Sets name to the specified value.
- * @return true if the name was changed, or false if an existing instance already exists with that name
+ * Get the {@link Property#getName() property name} where the UUID is stored for each node.
+ *
+ * @return the name of the UUID property; never null
*/
- public boolean setName( String name ) {
- Lock lock = sourcesLock.writeLock();
- try {
- lock.lock();
- // Determine if this name is allowed ...
- if (name != null && sources.containsKey(name)) return false;
+ public String getUuidPropertyName() {
+ return this.uuidPropertyName;
+ }
- // Remove this object under its current name
- if (this.name != null) {
- sources.remove(this.name);
- }
- // Register this object under the new name
- this.name = name;
- if (this.name != null) {
- sources.put(this.name, this);
- }
- return true;
- } finally {
- lock.unlock();
- }
+ /**
+ * Set the {@link Property#getName() property name} where the UUID is stored for each node.
+ *
+ * @param uuidPropertyName the name of the UUID property, or null if the {@link #DEFAULT_UUID_PROPERTY_NAME default name}
+ * should be used
+ */
+ public synchronized void setUuidPropertyName( String uuidPropertyName ) {
+ if (uuidPropertyName == null || uuidPropertyName.trim().length() == 0) uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
+ if (this.uuidPropertyName.equals(uuidPropertyName)) return; // unchanged
+ this.uuidPropertyName = uuidPropertyName;
}
/**
* {@inheritDoc}
*/
+ @SuppressWarnings( "unchecked" )
@Override
protected synchronized RepositoryConnection createConnection() {
+ if (getName() == null) {
+ I18n msg = JBossCacheConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getName(), msg.text("name"));
+ }
+ if (getUuidPropertyName() == null) {
+ I18n msg = JBossCacheConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getName(), msg.text("uuidPropertyName"));
+ }
if (this.cache == null) {
- CacheFactory<Name, Object> factory = new DefaultCacheFactory<Name, Object>();
- cache = factory.createCache(cacheConfigurationName);
+ // First look for an existing cache instance in JNDI ...
+ Context context = getContext();
+ String jndiName = this.getCacheJndiName();
+ if (jndiName != null && jndiName.trim().length() != 0) {
+ Object object = null;
+ try {
+ if (context == null) context = new InitialContext();
+ object = context.lookup(jndiName);
+ if (object != null) cache = (Cache<Name, Object>)object;
+ } catch (ClassCastException err) {
+ I18n msg = JBossCacheConnectorI18n.objectFoundInJndiWasNotCache;
+ String className = object != null ? object.getClass().getName() : "null";
+ throw new RepositorySourceException(getName(), msg.text(jndiName, this.getName(), className), err);
+ } catch (Throwable err) {
+ // try loading
+ }
+ }
+ if (cache == null) {
+ // Then look for a cache factory in JNDI ...
+ CacheFactory<Name, Object> cacheFactory = null;
+ jndiName = getCacheFactoryJndiName();
+ if (jndiName != null && jndiName.trim().length() != 0) {
+ Object object = null;
+ try {
+ if (context == null) context = new InitialContext();
+ object = context.lookup(jndiName);
+ if (object != null) cacheFactory = (CacheFactory<Name, Object>)object;
+ } catch (ClassCastException err) {
+ I18n msg = JBossCacheConnectorI18n.objectFoundInJndiWasNotCacheFactory;
+ String className = object != null ? object.getClass().getName() : "null";
+ throw new RepositorySourceException(getName(), msg.text(jndiName, this.getName(), className), err);
+ } catch (Throwable err) {
+ // try loading
+ }
+ }
+ if (cacheFactory == null) cacheFactory = new DefaultCacheFactory<Name, Object>();
+
+ // Now, get the configuration name ...
+ String configName = this.getCacheConfigurationName();
+ if (configName != null) {
+ cache = cacheFactory.createCache(configName);
+ } else {
+ cache = cacheFactory.createCache();
+ }
+ }
}
return new JBossCacheConnection(this, this.cache);
}
+ protected Context getContext() {
+ return this.jndiContext;
+ }
+
+ protected synchronized void setContext( Context context ) {
+ this.jndiContext = context;
+ }
+
/**
* {@inheritDoc}
*/
- public Reference getReference() {
+ public synchronized Reference getReference() {
String className = getClass().getName();
- String factoryClassName = className;
- return new Reference(className, new StringRefAddr("DnaConnectorJBossCacheSource", getName()), factoryClassName, null);
+ String factoryClassName = this.getClass().getName();
+ Reference ref = new Reference(className, factoryClassName, null);
+
+ if (getName() != null) {
+ ref.add(new StringRefAddr(SOURCE_NAME, getName()));
+ }
+ if (getRootNodeUuid() != null) {
+ ref.add(new StringRefAddr(ROOT_NODE_UUID, getRootNodeUuid().toString()));
+ }
+ if (getUuidPropertyName() != null) {
+ ref.add(new StringRefAddr(UUID_PROPERTY_NAME, getUuidPropertyName()));
+ }
+ if (getCacheJndiName() != null) {
+ ref.add(new StringRefAddr(CACHE_JNDI_NAME, getCacheJndiName()));
+ }
+ if (getCacheFactoryJndiName() != null) {
+ ref.add(new StringRefAddr(CACHE_FACTORY_JNDI_NAME, getCacheFactoryJndiName()));
+ }
+ if (getCacheConfigurationName() != null) {
+ ref.add(new StringRefAddr(CACHE_CONFIGURATION_NAME, getCacheConfigurationName()));
+ }
+ if (getDefaultCachePolicy() != null) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ CachePolicy policy = getDefaultCachePolicy();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(policy);
+ ref.add(new BinaryRefAddr(DEFAULT_CACHE_POLICY, baos.toByteArray()));
+ } catch (IOException e) {
+ I18n msg = JBossCacheConnectorI18n.errorSerializingCachePolicyInSource;
+ throw new RepositorySourceException(getName(), msg.text(policy.getClass().getName(), getName()), e);
+ }
+ }
+ ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
+ return ref;
}
/**
@@ -268,13 +435,51 @@
public Object getObjectInstance( Object obj,
javax.naming.Name name,
Context nameCtx,
- Hashtable<?, ?> environment ) {
+ Hashtable<?, ?> environment ) throws Exception {
if (obj instanceof Reference) {
+ Map<String, Object> values = new HashMap<String, Object>();
Reference ref = (Reference)obj;
- if (ref.getClassName().equals(getClass().getName())) {
- RefAddr addr = ref.get("DnaConnectorJBossCacheSource");
- return JBossCacheSource.getSource((String)addr.getContent());
+ Enumeration<?> en = ref.getAll();
+ while (en.hasMoreElements()) {
+ RefAddr subref = (RefAddr)en.nextElement();
+ if (subref instanceof StringRefAddr) {
+ String key = subref.getType();
+ Object value = subref.getContent();
+ if (value != null) values.put(key, value.toString());
+ } else if (subref instanceof BinaryRefAddr) {
+ String key = subref.getType();
+ Object value = subref.getContent();
+ if (value instanceof byte[]) {
+ // Deserialize ...
+ ByteArrayInputStream bais = new ByteArrayInputStream((byte[])value);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ value = ois.readObject();
+ values.put(key, value);
+ }
+ }
}
+ String sourceName = (String)values.get(SOURCE_NAME);
+ String rootNodeUuidString = (String)values.get(ROOT_NODE_UUID);
+ String uuidPropertyName = (String)values.get(UUID_PROPERTY_NAME);
+ String cacheJndiName = (String)values.get(CACHE_JNDI_NAME);
+ String cacheFactoryJndiName = (String)values.get(CACHE_FACTORY_JNDI_NAME);
+ String cacheConfigurationName = (String)values.get(CACHE_CONFIGURATION_NAME);
+ Object defaultCachePolicy = values.get(DEFAULT_CACHE_POLICY);
+ String retryLimit = (String)values.get(RETRY_LIMIT);
+
+ // Create the source instance ...
+ JBossCacheSource source = new JBossCacheSource();
+ if (sourceName != null) source.setName(sourceName);
+ if (rootNodeUuidString != null) source.setRootNodeUuid(rootNodeUuidString);
+ if (uuidPropertyName != null) source.setUuidPropertyName(uuidPropertyName);
+ if (cacheJndiName != null) source.setCacheJndiName(cacheJndiName);
+ if (cacheFactoryJndiName != null) source.setCacheFactoryJndiName(cacheFactoryJndiName);
+ if (cacheConfigurationName != null) source.setCacheConfigurationName(cacheConfigurationName);
+ if (defaultCachePolicy instanceof CachePolicy) {
+ source.setDefaultCachePolicy((CachePolicy)defaultCachePolicy);
+ }
+ if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+ return source;
}
return null;
}
Modified: trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties 2008-08-07 15:38:59 UTC (rev 398)
+++ trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties 2008-08-07 15:42:07 UTC (rev 399)
@@ -21,4 +21,8 @@
#
connectorName = JBoss Cache Connector
-nodeDoesNotExist = Could not find an existing node at {0}
\ No newline at end of file
+nodeDoesNotExist = Could not find an existing node at {0}
+propertyIsRequired = The {0} property is required but has no value
+errorSerializingCachePolicyInSource = Error serializing a {0} instance owned by the {1} JBossCacheSource
+objectFoundInJndiWasNotCache = Object in JNDI at {0} found by JBossCacheSource {1} was expected to be a org.jboss.cache.Cache<org.jboss.dna.spi.graph.Name,Object> but instead was {2}
+objectFoundInJndiWasNotCacheFactory = Object in JNDI at {0} found by JBossCacheSource {1} was expected to be a org.jboss.cache.CacheFactory<org.jboss.dna.spi.graph.Name,Object> but instead was {2}
\ No newline at end of file
Modified: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-07 15:38:59 UTC (rev 398)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-07 15:42:07 UTC (rev 399)
@@ -63,16 +63,16 @@
@Test
public void shouldAllowSettingName() {
- assertThat(source.setName("Something"), is(true));
+ source.setName("Something");
assertThat(source.getName(), is("Something"));
- assertThat(source.setName("another name"), is(true));
+ source.setName("another name");
assertThat(source.getName(), is("another name"));
}
@Test
- public void shouldNotAllowSettingNameToNull() {
- assertThat(source.setName("some name"), is(true));
- assertThat(source.setName(null), is(true));
+ public void shouldAllowSettingNameToNull() {
+ source.setName("some name");
+ source.setName(null);
assertThat(source.getName(), is(nullValue()));
}
}
15 years, 10 months