You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2006/08/17 18:02:25 UTC

svn commit: r432265 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype: DefinitionValidator.java EffectiveNodeTypeImpl.java NodeTypeRegistryImpl.java ValueConstraint.java

Author: angela
Date: Thu Aug 17 09:02:24 2006
New Revision: 432265

URL: http://svn.apache.org/viewvc?rev=432265&view=rev
Log:
work in progress

- javadoc
- remove some DIFF comments

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java?rev=432265&r1=432264&r2=432265&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java Thu Aug 17 09:02:24 2006
@@ -41,7 +41,6 @@
 /**
  * <code>DefinitionValidator</code>...
  */
-// DIFF JR: class added (methods extracted from NodeTypeRegistry)
 class DefinitionValidator {
 
     private static Logger log = LoggerFactory.getLogger(DefinitionValidator.class);

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java?rev=432265&r1=432264&r2=432265&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java Thu Aug 17 09:02:24 2006
@@ -44,8 +44,6 @@
  * <p/>
  * Instances of <code>EffectiveNodeType</code> are immutable.
  */
-// DIFF JR: extract interface
-// DIFF JR: rearrangement of methods
 public class EffectiveNodeTypeImpl implements Cloneable, EffectiveNodeType {
     private static Logger log = LoggerFactory.getLogger(EffectiveNodeTypeImpl.class);
 
@@ -75,8 +73,6 @@
         namedItemDefs = new HashMap();
         unnamedItemDefs = new ArrayList();
     }
-
-    // DIFF JR: remove create method that takes ntName instead of definition
 
     /**
      * Factory method: creates an effective node type

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java?rev=432265&r1=432264&r2=432265&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java Thu Aug 17 09:02:24 2006
@@ -62,18 +62,15 @@
     private final Set nodeDefs;
 
     /**
-     * DIFF JACKRABBIT: persisting nodetypes is delegated to a separate object
+     * Object used to persist new nodetypes and modified nodetype definitions.
      */
     private final NodeTypeStorage storage;
 
     /**
-     * DIFF JACKRABBIT: validation is delegated to extra class
+     * Class used to validate NodeType definitions
      */
     private final DefinitionValidator validator;
 
-
-    // DIFF JR: checkAutoCreatePropHasDefault is set directely on calling validator.validate
-
     /**
      * Listeners (soft references)
      */
@@ -194,7 +191,6 @@
         return getEffectiveNodeType(ntNames, entCache, ntdMap);
     }
 
-    // DIFF JR: method private: EffectiveNodeTypeCache must not be exposed in interface
     /**
      *
      * @param ntName
@@ -233,7 +229,6 @@
         }
     }
 
-    // DIFF JR: method private: EffectiveNodeTypeCache must not be exposed in interface
     /**
      * @param ntNames
      * @param anEntCache

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java?rev=432265&r1=432264&r2=432265&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java Thu Aug 17 09:02:24 2006
@@ -53,7 +53,7 @@
 
     public static final ValueConstraint[] EMPTY_ARRAY = new ValueConstraint[0];
 
-    final String qualifiedDefinition;
+    private final String qualifiedDefinition;
 
     protected ValueConstraint(String qualifiedDefinition) {
         this.qualifiedDefinition = qualifiedDefinition;
@@ -67,6 +67,9 @@
      * <code>NameConstraint</code>, <code>PathConstraint</code> and
      * <code>ReferenceConstraint</code>) use the given <code>nsResolver</code>
      * to reflect the current mapping in the returned value.
+     * In other words: subclasses, that need to make a conversion to JCR value
+     * must overwrite this and return a value that has all qualified names
+     * and path elements resolved.
      *
      * @return the definition of this constraint.
      * @see #getQualifiedDefinition()
@@ -75,8 +78,9 @@
         return qualifiedDefinition;
     }
 
-    // DIFF JACKRABBIT: added method
     /**
+     * By default the qualified definition is the same as the JCR definition.
+     *
      * @return the qualified definition String
      * @see #getDefinition(NamespaceResolver)
      */
@@ -93,7 +97,7 @@
     abstract void check(QValue value) throws ConstraintViolationException, RepositoryException;
 
 
-    //-------------------------------------------< java.lang.Object overrides >
+    //-----------------------------------------< java.lang.Object overrides >---
     public boolean equals(Object other) {
         if (other == this) {
             return true;
@@ -114,8 +118,7 @@
         return qualifiedDefinition.hashCode();
     }
 
-    //--------------------------------------------------------------------------
-    // DIFF JACKRABBIT: method added
+    //-----------------------------------< static factory and check methods >---
     /**
      * Create a new <code>ValueConstraint</code> from the String representation.
      * Note, that the definition must be in the qualified format in case the type
@@ -177,7 +180,7 @@
                                          NamespaceResolver nsResolver)
             throws InvalidConstraintException {
         if (definition == null) {
-            throw new IllegalArgumentException("illegal definition (null)");
+            throw new IllegalArgumentException("Illegal definition (null) for ValueConstraint.");
         }
         switch (type) {
             case PropertyType.STRING:
@@ -206,12 +209,10 @@
                 return new ReferenceConstraint(definition, nsResolver);
 
             default:
-                throw new IllegalArgumentException("unknown/unsupported target type for constraint: "
-                        + PropertyType.nameFromValue(type));
+                throw new IllegalArgumentException("Unknown/unsupported target type for constraint: " + PropertyType.nameFromValue(type));
         }
     }
 
-    // DIFF JACKRABBIT: moved from EffectiveNodeType
     /**
      * Tests if the value constraints defined in the property definition
      * <code>pd</code> are satisfied by the the specified <code>values</code>.
@@ -265,6 +266,7 @@
     }
 }
 
+//---------------------------------------------< Subclass BooleanConstraint >---
 /**
  * <code>BooleanConstraint</code> ...
  */
@@ -287,19 +289,19 @@
         }
     }
 
-    private void check(boolean bool) throws ConstraintViolationException {
-        if (bool != reqBool) {
-            throw new ConstraintViolationException("'" + bool + "' does not satisfy the constraint '" + qualifiedDefinition + "'");
-        }
-    }
-
+    /**
+     * @see ValueConstraint#check(QValue)
+     */
     void check(QValue value) throws ConstraintViolationException, RepositoryException {
         if (value == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '"  + qualifiedDefinition + "'");
+            throw new ConstraintViolationException("null value does not satisfy the constraint '"  + getQualifiedDefinition() + "'");
         }
         switch (value.getType()) {
             case PropertyType.BOOLEAN:
-                check(Boolean.valueOf(value.getString()).booleanValue());
+                boolean b = Boolean.valueOf(value.getString()).booleanValue();
+                if (b != reqBool) {
+                    throw new ConstraintViolationException("'" + b + "' does not satisfy the constraint '" + getQualifiedDefinition() + "'");
+                }
                 return;
 
             default:
@@ -311,6 +313,7 @@
     }
 }
 
+//----------------------------------------------< Subclass StringConstraint >---
 /**
  * <code>StringConstraint</code> ...
  */
@@ -330,23 +333,20 @@
         }
     }
 
-    private void check(String text) throws ConstraintViolationException {
-        if (text == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '" + qualifiedDefinition + "'");
-        }
-        Matcher matcher = pattern.matcher(text);
-        if (!matcher.matches()) {
-            throw new ConstraintViolationException("'" + text  + "' does not satisfy the constraint '" + qualifiedDefinition + "'");
-        }
-    }
-
+    /**
+     * @see ValueConstraint#check(QValue)
+     */
     void check(QValue value) throws ConstraintViolationException, RepositoryException {
         if (value == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '" + qualifiedDefinition + "'");
+            throw new ConstraintViolationException("null value does not satisfy the constraint '" + getQualifiedDefinition() + "'");
         }
         switch (value.getType()) {
             case PropertyType.STRING:
-                check(value.toString());
+                String text = value.toString();
+                Matcher matcher = pattern.matcher(text);
+                if (!matcher.matches()) {
+                    throw new ConstraintViolationException("'" + text  + "' does not satisfy the constraint '" + getQualifiedDefinition() + "'");
+                }
                 return;
 
             default:
@@ -357,6 +357,7 @@
     }
 }
 
+//---------------------------------------------< Subclass NumericConstraint >---
 /**
  * <code>NumericConstraint</code> ...
  */
@@ -422,35 +423,19 @@
         }
     }
 
-    private void check(Double number) throws ConstraintViolationException {
-        if (number == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '"
-                    + qualifiedDefinition + "'");
-        }
-        check(number.doubleValue());
-    }
-
-    private void check(Long number) throws ConstraintViolationException {
-        if (number == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '"
-                    + qualifiedDefinition + "'");
-        }
-        check(number.doubleValue());
-    }
-
     private void check(double number) throws ConstraintViolationException {
         if (lowerLimit != null) {
             if (lowerInclusive) {
                 if (number < lowerLimit.doubleValue()) {
                     throw new ConstraintViolationException(number
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             } else {
                 if (number <= lowerLimit.doubleValue()) {
                     throw new ConstraintViolationException(number
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             }
         }
@@ -459,22 +444,25 @@
                 if (number > upperLimit.doubleValue()) {
                     throw new ConstraintViolationException(number
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             } else {
                 if (number >= upperLimit.doubleValue()) {
                     throw new ConstraintViolationException(number
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             }
         }
     }
 
+    /**
+     * @see ValueConstraint#check(QValue)
+     */
     void check(QValue value) throws ConstraintViolationException, RepositoryException {
         if (value == null) {
             throw new ConstraintViolationException("null value does not satisfy the constraint '"
-                    + qualifiedDefinition + "'");
+                    + getQualifiedDefinition() + "'");
         }
         switch (value.getType()) {
             case PropertyType.LONG:
@@ -503,6 +491,7 @@
     }
 }
 
+//------------------------------------------------< Subclass DateConstraint >---
 /**
  * <code>DateConstraint</code> ...
  */
@@ -576,20 +565,20 @@
 
     private void check(Calendar cal) throws ConstraintViolationException {
         if (cal == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '" + qualifiedDefinition + "'");
+            throw new ConstraintViolationException("null value does not satisfy the constraint '" + getQualifiedDefinition() + "'");
         }
         if (lowerLimit != null) {
             if (lowerInclusive) {
                 if (cal.getTimeInMillis() < lowerLimit.getTimeInMillis()) {
                     throw new ConstraintViolationException(cal
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             } else {
                 if (cal.getTimeInMillis() <= lowerLimit.getTimeInMillis()) {
                     throw new ConstraintViolationException(cal
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             }
         }
@@ -598,21 +587,24 @@
                 if (cal.getTimeInMillis() > upperLimit.getTimeInMillis()) {
                     throw new ConstraintViolationException(cal
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             } else {
                 if (cal.getTimeInMillis() >= upperLimit.getTimeInMillis()) {
                     throw new ConstraintViolationException(cal
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
             }
         }
     }
 
+    /**
+     * @see ValueConstraint#check(QValue)
+     */
     void check(QValue value) throws ConstraintViolationException, RepositoryException {
         if (value == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '" + qualifiedDefinition + "'");
+            throw new ConstraintViolationException("null value does not satisfy the constraint '" + getQualifiedDefinition() + "'");
         }
         switch (value.getType()) {
             case PropertyType.DATE:
@@ -628,6 +620,7 @@
     }
 }
 
+//------------------------------------------------< Subclass PathConstraint >---
 /**
  * <code>PathConstraint</code> ...
  */
@@ -661,6 +654,12 @@
         }
     }
 
+    /**
+     * Uses {@link PathFormat#format(Path, NamespaceResolver)} to convert the
+     * qualified <code>Path</code> into a JCR path.
+     *
+     * @see ValueConstraint#getDefinition(NamespaceResolver)
+     */
     public String getDefinition(NamespaceResolver nsResolver) {
         try {
             String p = PathFormat.format(path, nsResolver);
@@ -673,7 +672,7 @@
             }
         } catch (NoPrefixDeclaredException npde) {
             // should never get here, return raw definition as fallback
-            return qualifiedDefinition;
+            return getQualifiedDefinition();
         }
     }
 
@@ -681,14 +680,18 @@
      * Returns the String representation of the path.
      *
      * @return String representation of the path.
+     * @see ValueConstraint#getQualifiedDefinition()
      */
     public String getQualifiedDefinition() {
         return path.toString();
     }
 
+    /**
+     * @see ValueConstraint#check(QValue)
+     */
     void check(QValue value) throws ConstraintViolationException, RepositoryException {
         if (value == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '" + qualifiedDefinition + "'");
+            throw new ConstraintViolationException("null value does not satisfy the constraint '" + getQualifiedDefinition() + "'");
         }
         switch (value.getType()) {
             case PropertyType.PATH:
@@ -706,20 +709,20 @@
                         if (!p0.isAncestorOf(p1)) {
                             throw new ConstraintViolationException(p
                                 + " does not satisfy the constraint '"
-                                + qualifiedDefinition + "'");
+                                + getQualifiedDefinition() + "'");
                         }
                     } catch (MalformedPathException e) {
                         // can't compare relative with absolute path
                         throw new ConstraintViolationException(p
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                     }
                 } else {
                     // exact match required
                     if (!p0.equals(p1)) {
                         throw new ConstraintViolationException(p
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                     }
                 }
                 return;
@@ -733,11 +736,13 @@
     }
 }
 
+//------------------------------------------------< Subclass NameConstraint >---
 /**
  * <code>NameConstraint</code> ...
  */
 class NameConstraint extends ValueConstraint {
-    final QName name;
+
+    private final QName name;
 
     NameConstraint(String qualifiedDefinition) {
         super(qualifiedDefinition);
@@ -765,12 +770,18 @@
         }
     }
 
+    /**
+     * Uses {@link NameFormat#format(QName, NamespaceResolver)} to convert the
+     * qualified <code>QName</code> into a JCR name.
+     *
+     * @see ValueConstraint#getDefinition(NamespaceResolver)
+     */
     public String getDefinition(NamespaceResolver nsResolver) {
         try {
             return NameFormat.format(name, nsResolver);
         } catch (NoPrefixDeclaredException npde) {
             // should never get here, return raw definition as fallback
-            return qualifiedDefinition;
+            return getQualifiedDefinition();
         }
     }
 
@@ -778,14 +789,18 @@
      * Returns the String representation of the qualified name
      *
      * @return String representation of the qualified name
+     * @see ValueConstraint#getQualifiedDefinition()
      */
     public String getQualifiedDefinition() {
         return name.toString();
     }
 
+    /**
+     * @see ValueConstraint#check(QValue)
+     */
     void check(QValue value) throws ConstraintViolationException, RepositoryException {
         if (value == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '" + qualifiedDefinition + "'");
+            throw new ConstraintViolationException("null value does not satisfy the constraint '" + getQualifiedDefinition() + "'");
         }
         switch (value.getType()) {
             case PropertyType.NAME:
@@ -793,7 +808,7 @@
                 if (!name.equals(n)) {
                     throw new ConstraintViolationException(n
                             + " does not satisfy the constraint '"
-                            + qualifiedDefinition + "'");
+                            + getQualifiedDefinition() + "'");
                 }
                 return;
 
@@ -806,11 +821,13 @@
     }
 }
 
+//-------------------------------------------< Subclass ReferenceConstraint >---
 /**
  * <code>ReferenceConstraint</code> ...
  */
 class ReferenceConstraint extends ValueConstraint {
-    final QName ntName;
+
+    private final QName ntName;
 
     ReferenceConstraint(String qualifiedDefinition) {
         super(qualifiedDefinition);
@@ -837,12 +854,18 @@
         }
     }
 
+    /**
+     * Uses {@link NameFormat#format(QName, NamespaceResolver)} to convert the
+     * qualified nodetype name into a JCR name.
+     *
+     * @see ValueConstraint#getDefinition(NamespaceResolver)
+     */
     public String getDefinition(NamespaceResolver nsResolver) {
         try {
             return NameFormat.format(ntName, nsResolver);
         } catch (NoPrefixDeclaredException npde) {
             // should never get here, return raw definition as fallback
-            return qualifiedDefinition;
+            return getQualifiedDefinition();
         }
     }
 
@@ -855,13 +878,16 @@
         return ntName.toString();
     }
 
+    /**
+     * @see ValueConstraint#check(QValue)
+     */
     void check(QValue value) throws ConstraintViolationException, RepositoryException {
         if (value == null) {
-            throw new ConstraintViolationException("null value does not satisfy the constraint '" + qualifiedDefinition + "'");
+            throw new ConstraintViolationException("Null value does not satisfy the constraint '" + getQualifiedDefinition() + "'");
         }
         switch (value.getType()) {
             case PropertyType.REFERENCE:
-                // @todo check REFERENCE value constraint (requires a session)
+                // TODO check REFERENCE value constraint (requires a session)
                 log.warn("validation of REFERENCE constraint is not yet implemented");
                 return;