[jbosstools-commits] JBoss Tools SVN: r39805 - in trunk/modeshape: plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes and 3 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Mar 23 17:03:35 EDT 2012


Author: elvisisking
Date: 2012-03-23 17:03:33 -0400 (Fri, 23 Mar 2012)
New Revision: 39805

Modified:
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CompactNodeTypeDefinition.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMapping.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java
   trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributes.java
   trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java
   trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java
   trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java
   trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java
   trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinitionTest.java
   trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributesTest.java
   trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/ValueConstraintsTest.java
Log:
JBIDE-10702 Editor for JCR Compact Node Definition (CND) files. CND editor now only shows a save is needed when something has changed in the CND. Added some equals/hashCode methods on business objects and more tests.

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -41,14 +41,28 @@
      */
     public static ChildNodeDefinition copy( final ChildNodeDefinition childNodeBeingCopied ) {
         final ChildNodeDefinition copy = new ChildNodeDefinition();
-        copy.setAutoCreated(childNodeBeingCopied.isAutoCreated());
-        copy.setMandatory(childNodeBeingCopied.isMandatory());
-        copy.setProtected(childNodeBeingCopied.isProtected());
-        copy.setOnParentVersion(childNodeBeingCopied.getOnParentVersion());
-        copy.setSameNameSiblings(childNodeBeingCopied.allowsSameNameSiblings());
+
+        // name
         copy.setName(childNodeBeingCopied.getName());
-        copy.setDefaultPrimaryTypeName(childNodeBeingCopied.getDefaultPrimaryTypeName());
-        copy.setRequiredPrimaryTypeNames(childNodeBeingCopied.getRequiredPrimaryTypeNames());
+
+        // attributes
+        copy.attributes.getAutocreated().set(childNodeBeingCopied.attributes.getAutocreated().get());
+        copy.attributes.getMandatory().set(childNodeBeingCopied.attributes.getMandatory().get());
+        copy.attributes.getProtected().set(childNodeBeingCopied.attributes.getProtected().get());
+        copy.attributes.getSameNameSiblings().set(childNodeBeingCopied.attributes.getSameNameSiblings().get());
+        copy.attributes.setOnParentVersion(childNodeBeingCopied.attributes.getOnParentVersion());
+
+        // default type
+        copy.defaultType.set(childNodeBeingCopied.defaultType.get());
+        copy.defaultType.setDefaultType(childNodeBeingCopied.getDefaultPrimaryTypeName());
+
+        // required types
+        copy.requiredTypes.set(childNodeBeingCopied.requiredTypes.get());
+
+        for (final String requiredTypeName : childNodeBeingCopied.getRequiredPrimaryTypeNames()) {
+            copy.addRequiredType(requiredTypeName);
+        }
+
         return copy;
     }
 
@@ -739,7 +753,7 @@
          */
         @Override
         public String toString() {
-            return (getClass().getSimpleName() + super.toString());
+            return (getClass().getName() + super.toString());
         }
     }
 }

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -297,64 +297,6 @@
     }
 
     /**
-     * @param childNodeDefinition the child node definition whose name is being validated (cannot be <code>null</code>)
-     * @param existingChildNodeNames the existing child node names used to check for a duplicate (can be <code>null</code> or empty)
-     * @param status the status to add the new status to (cannot be <code>null</code>)
-     */
-    public static void validateName( final ChildNodeDefinition childNodeDefinition,
-                                     final Collection<QualifiedName> existingChildNodeNames,
-                                     final MultiValidationStatus status ) {
-        // ERROR - Empty or invalid child node definition name
-        validateQualifiedName(childNodeDefinition.getQualifiedName(), Messages.childDefinitionName, status);
-
-        if (!Utils.isEmpty(existingChildNodeNames) && existingChildNodeNames.contains(childNodeDefinition.getQualifiedName())) {
-            status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateChildNodeDefinitionName,
-                                                                    childNodeDefinition.getName())));
-        }
-    }
-
-    /**
-     * @param childNodeDefinition the child node definition whose name is being validated (cannot be <code>null</code>)
-     * @param existingChildNodeNames the existing child node names used to check for a duplicate (can be <code>null</code> or empty)
-     * @return the status (never <code>null</code>)
-     */
-    public static MultiValidationStatus validateName( final ChildNodeDefinition childNodeDefinition,
-                                                      final Collection<QualifiedName> existingChildNodeNames ) {
-        final MultiValidationStatus status = new MultiValidationStatus();
-        validateName(childNodeDefinition, existingChildNodeNames, status);
-        return status;
-    }
-
-    /**
-     * @param propertyDefinition the property definition whose name is being validated (cannot be <code>null</code>)
-     * @param existingPropertyNames the existing property names used to check for a duplicate (can be <code>null</code> or empty)
-     * @param status the status to add the new status to (cannot be <code>null</code>)
-     */
-    public static void validateName( final PropertyDefinition propertyDefinition,
-                                     final Collection<QualifiedName> existingPropertyNames,
-                                     final MultiValidationStatus status ) {
-        // ERROR - Empty or invalid child node definition name
-        validateQualifiedName(propertyDefinition.getQualifiedName(), Messages.propertyDefinitionName, status);
-
-        if (!Utils.isEmpty(existingPropertyNames) && existingPropertyNames.contains(propertyDefinition.getQualifiedName())) {
-            status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateChildNodeDefinitionName,
-                                                                    propertyDefinition.getName())));
-        }
-    }
-
-    /**
-     * @param propertyDefinition the property definition whose name is being validated (cannot be <code>null</code>)
-     * @param existingPropertyNames the existing property names used to check for a duplicate (can be <code>null</code> or empty)
-     * @return the status (never <code>null</code>)
-     */
-    public static MultiValidationStatus validateName( final PropertyDefinition propertyDefinition,
-                                                      final Collection<QualifiedName> existingPropertyNames ) {
-        final MultiValidationStatus status = new MultiValidationStatus();
-        validateName(propertyDefinition, existingPropertyNames, status);
-        return status;
-    }
-
-    /**
      * @param childNodeDefinition the child node definition whose default type is being validated (cannot be <code>null</code>)
      * @return the status (never <code>null</code>)
      */
@@ -391,6 +333,70 @@
     }
 
     /**
+     * @param propertyDefinition the property definition whose default values are being validated (cannot be <code>null</code>)
+     * @return the status (never <code>null</code>)
+     */
+    public static MultiValidationStatus validateDefaultValues( final PropertyDefinition propertyDefinition ) {
+        final MultiValidationStatus status = new MultiValidationStatus();
+        validateDefaultValues(propertyDefinition, status);
+        return status;
+    }
+
+    /**
+     * @param propertyDefinition the property definition whose default values are being validated (cannot be <code>null</code>)
+     * @param status the status to add the new status to (cannot be <code>null</code>)
+     */
+    public static void validateDefaultValues( final PropertyDefinition propertyDefinition,
+                                              final MultiValidationStatus status ) {
+        Utils.verifyIsNotNull(propertyDefinition, "propertyDefinition"); //$NON-NLS-1$
+        Utils.verifyIsNotNull(status, "status"); //$NON-NLS-1$
+
+        String propertyName = propertyDefinition.getName();
+
+        if (Utils.isEmpty(propertyName)) {
+            propertyName = Messages.missingName;
+        }
+
+        final Collection<String> defaultValues = propertyDefinition.getDefaultValuesAsStrings();
+
+        if (Utils.isEmpty(defaultValues)) {
+            if (propertyDefinition.getState(PropertyDefinition.PropertyName.DEFAULT_VALUES) == Value.IS) {
+                status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.emptyDefaultValues, propertyName)));
+            }
+        } else {
+            // ERROR - Cannot have multiple default values when the property definition is single-valued
+            if ((defaultValues.size() > 1)
+                    && (propertyDefinition.getState(PropertyDefinition.PropertyName.MULTIPLE) == Value.IS_NOT)) {
+                status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.multipleDefaultValuesForSingleValuedProperty,
+                                                                        propertyName)));
+            }
+
+            final Collection<String> values = new ArrayList<String>(defaultValues.size());
+
+            for (final String defaultValue : defaultValues) {
+                // ERROR - Default value is not valid for the property definition type
+                isValid(defaultValue, propertyDefinition.getType(), Messages.defaultValue, status);
+
+                if (!Utils.isEmpty(defaultValue)) {
+                    // ERROR - Duplicate default value
+                    if (values.contains(defaultValue)) {
+                        status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateDefaultValue, propertyName,
+                                                                                defaultValue)));
+                    } else {
+                        values.add(defaultValue);
+                    }
+                }
+            }
+
+            // ERROR - Cannot have explicit default values when default values is marked as a variant
+            if (propertyDefinition.getState(PropertyDefinition.PropertyName.DEFAULT_VALUES) != Value.IS) {
+                status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.defaultValuesExistButMarkedAsVariant,
+                                                                        propertyDefinition)));
+            }
+        }
+    }
+
+    /**
      * @param localName the local name being validated (cannot be <code>null</code>)
      * @param propertyName the name to use in the validation message (cannot be <code>null</code>)
      * @return the status (never <code>null</code>)
@@ -442,6 +448,93 @@
     }
 
     /**
+     * @param childNodeDefinition the child node definition whose name is being validated (cannot be <code>null</code>)
+     * @param existingChildNodeNames the existing child node names used to check for a duplicate (can be <code>null</code> or empty)
+     * @return the status (never <code>null</code>)
+     */
+    public static MultiValidationStatus validateName( final ChildNodeDefinition childNodeDefinition,
+                                                      final Collection<QualifiedName> existingChildNodeNames ) {
+        final MultiValidationStatus status = new MultiValidationStatus();
+        validateName(childNodeDefinition, existingChildNodeNames, status);
+        return status;
+    }
+
+    /**
+     * @param childNodeDefinition the child node definition whose name is being validated (cannot be <code>null</code>)
+     * @param existingChildNodeNames the existing child node names used to check for a duplicate (can be <code>null</code> or empty)
+     * @param status the status to add the new status to (cannot be <code>null</code>)
+     */
+    public static void validateName( final ChildNodeDefinition childNodeDefinition,
+                                     final Collection<QualifiedName> existingChildNodeNames,
+                                     final MultiValidationStatus status ) {
+        // ERROR - Empty or invalid child node definition name
+        validateQualifiedName(childNodeDefinition.getQualifiedName(), Messages.childDefinitionName, status);
+
+        if (!Utils.isEmpty(existingChildNodeNames) && existingChildNodeNames.contains(childNodeDefinition.getQualifiedName())) {
+            status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateChildNodeDefinitionName,
+                                                                    childNodeDefinition.getName())));
+        }
+    }
+
+    /**
+     * @param nodeTypeDefinition the node type definition whose name is being validated (cannot be <code>null</code>)
+     * @param existingNodeTypeNames the existing node type names used to check for a duplicate (can be <code>null</code> or empty)
+     * @return the status (never <code>null</code>)
+     */
+    public static MultiValidationStatus validateName( final NodeTypeDefinition nodeTypeDefinition,
+                                                      final Collection<QualifiedName> existingNodeTypeNames ) {
+        final MultiValidationStatus status = new MultiValidationStatus();
+        validateName(nodeTypeDefinition, existingNodeTypeNames, status);
+        return status;
+    }
+
+    /**
+     * @param nodeTypeDefinition the node type definition whose name is being validated (cannot be <code>null</code>)
+     * @param existingNodeTypeNames the existing node type names used to check for a duplicate (can be <code>null</code> or empty)
+     * @param status the status to add the new status to (cannot be <code>null</code>)
+     */
+    public static void validateName( final NodeTypeDefinition nodeTypeDefinition,
+                                     final Collection<QualifiedName> existingNodeTypeNames,
+                                     final MultiValidationStatus status ) {
+        // ERROR - Empty or invalid node type definition name
+        validateQualifiedName(nodeTypeDefinition.getQualifiedName(), Messages.nodeTypeDefinitionName, status);
+
+        if (!Utils.isEmpty(existingNodeTypeNames) && existingNodeTypeNames.contains(nodeTypeDefinition.getQualifiedName())) {
+            status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateNodeTypeDefinitionName,
+                                                                    nodeTypeDefinition.getName())));
+        }
+    }
+
+    /**
+     * @param propertyDefinition the property definition whose name is being validated (cannot be <code>null</code>)
+     * @param existingPropertyNames the existing property names used to check for a duplicate (can be <code>null</code> or empty)
+     * @return the status (never <code>null</code>)
+     */
+    public static MultiValidationStatus validateName( final PropertyDefinition propertyDefinition,
+                                                      final Collection<QualifiedName> existingPropertyNames ) {
+        final MultiValidationStatus status = new MultiValidationStatus();
+        validateName(propertyDefinition, existingPropertyNames, status);
+        return status;
+    }
+
+    /**
+     * @param propertyDefinition the property definition whose name is being validated (cannot be <code>null</code>)
+     * @param existingPropertyNames the existing property names used to check for a duplicate (can be <code>null</code> or empty)
+     * @param status the status to add the new status to (cannot be <code>null</code>)
+     */
+    public static void validateName( final PropertyDefinition propertyDefinition,
+                                     final Collection<QualifiedName> existingPropertyNames,
+                                     final MultiValidationStatus status ) {
+        // ERROR - Empty or invalid child node definition name
+        validateQualifiedName(propertyDefinition.getQualifiedName(), Messages.propertyDefinitionName, status);
+
+        if (!Utils.isEmpty(existingPropertyNames) && existingPropertyNames.contains(propertyDefinition.getQualifiedName())) {
+            status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicatePropertyDefinitionName,
+                                                                    propertyDefinition.getName())));
+        }
+    }
+
+    /**
      * @param namespaceMapping the namespace mapping being validated (cannot be <code>null</code>)
      * @return the status (never <code>null</code>)
      */
@@ -609,9 +702,11 @@
 
     /**
      * @param nodeTypeDefinition the node type definition being validated (cannot be <code>null</code>)
+     * @param existingNodeTypeNames the existing node type names used to check for a duplicate (can be <code>null</code> or empty)
      * @return the status (never <code>null</code>)
      */
-    public static MultiValidationStatus validateNodeTypeDefinition( final NodeTypeDefinition nodeTypeDefinition ) {
+    public static MultiValidationStatus validateNodeTypeDefinition( final NodeTypeDefinition nodeTypeDefinition,
+                                                                    final Collection<QualifiedName> existingNodeTypeNames ) {
         Utils.verifyIsNotNull(nodeTypeDefinition, "nodeTypeDefinition"); //$NON-NLS-1$
 
         /**
@@ -637,7 +732,7 @@
 
         { // name
           // ERROR - Empty or invalid node type definition name
-            validateLocalName(nodeTypeDefinition.getName(), Messages.nodeTypeDefinitionName, status);
+            validateName(nodeTypeDefinition, existingNodeTypeNames, status);
         }
 
         { // super types
@@ -699,11 +794,13 @@
 
     /**
      * @param nodeTypeDefinition the node type definition being validated (cannot be <code>null</code>)
+     * @param existingNodeTypeNames the existing node type names used to check for a duplicate (can be <code>null</code> or empty)
      * @param status the status to add the new status to (never <code>null</code>)
      */
     public static void validateNodeTypeDefinition( final NodeTypeDefinition nodeTypeDefinition,
+                                                   final Collection<QualifiedName> existingNodeTypeNames,
                                                    final MultiValidationStatus status ) {
-        final ValidationStatus newStatus = validateNodeTypeDefinition(nodeTypeDefinition);
+        final ValidationStatus newStatus = validateNodeTypeDefinition(nodeTypeDefinition, existingNodeTypeNames);
 
         if (!newStatus.isOk()) {
             status.add(newStatus);
@@ -730,7 +827,7 @@
         final Collection<String> names = new ArrayList<String>(nodeTypeDefinitions.size());
 
         for (final NodeTypeDefinition nodeTypeDefinition : nodeTypeDefinitions) {
-            validateNodeTypeDefinition(nodeTypeDefinition, status);
+            validateNodeTypeDefinition(nodeTypeDefinition, null, status);
 
             { // ERROR - Duplicate node type definition names
                 final String name = nodeTypeDefinition.getName();
@@ -1123,70 +1220,6 @@
     }
 
     /**
-     * @param propertyDefinition the property definition whose default values are being validated (cannot be <code>null</code>)
-     * @return the status (never <code>null</code>)
-     */
-    public static MultiValidationStatus validateDefaultValues( final PropertyDefinition propertyDefinition ) {
-        final MultiValidationStatus status = new MultiValidationStatus();
-        validateDefaultValues(propertyDefinition, status);
-        return status;
-    }
-
-    /**
-     * @param propertyDefinition the property definition whose default values are being validated (cannot be <code>null</code>)
-     * @param status the status to add the new status to (cannot be <code>null</code>)
-     */
-    public static void validateDefaultValues( final PropertyDefinition propertyDefinition,
-                                              final MultiValidationStatus status ) {
-        Utils.verifyIsNotNull(propertyDefinition, "propertyDefinition"); //$NON-NLS-1$
-        Utils.verifyIsNotNull(status, "status"); //$NON-NLS-1$
-
-        String propertyName = propertyDefinition.getName();
-
-        if (Utils.isEmpty(propertyName)) {
-            propertyName = Messages.missingName;
-        }
-
-        final Collection<String> defaultValues = propertyDefinition.getDefaultValuesAsStrings();
-
-        if (Utils.isEmpty(defaultValues)) {
-            if (propertyDefinition.getState(PropertyDefinition.PropertyName.DEFAULT_VALUES) == Value.IS) {
-                status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.emptyDefaultValues, propertyName)));
-            }
-        } else {
-            // ERROR - Cannot have multiple default values when the property definition is single-valued
-            if ((defaultValues.size() > 1)
-                    && (propertyDefinition.getState(PropertyDefinition.PropertyName.MULTIPLE) == Value.IS_NOT)) {
-                status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.multipleDefaultValuesForSingleValuedProperty,
-                                                                        propertyName)));
-            }
-
-            final Collection<String> values = new ArrayList<String>(defaultValues.size());
-
-            for (final String defaultValue : defaultValues) {
-                // ERROR - Default value is not valid for the property definition type
-                isValid(defaultValue, propertyDefinition.getType(), Messages.defaultValue, status);
-
-                if (!Utils.isEmpty(defaultValue)) {
-                    // ERROR - Duplicate default value
-                    if (values.contains(defaultValue)) {
-                        status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateDefaultValue, propertyName,
-                                                                                defaultValue)));
-                    } else {
-                        values.add(defaultValue);
-                    }
-                }
-            }
-
-            // ERROR - Cannot have explicit default values when default values is marked as a variant
-            if (propertyDefinition.getState(PropertyDefinition.PropertyName.DEFAULT_VALUES) != Value.IS) {
-                status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.defaultValuesExistButMarkedAsVariant,
-                                                                        propertyDefinition)));
-            }
-        }
-    }
-
-    /**
      * @param nodeTypeDefinitionName the node type name whose supertypes are being checked (cannot be <code>null</code> or empty)
      * @param superTypesState the supertypes property state (cannot be <code>null</code>)
      * @param superTypeNames the collection of a node type definition's supertypes to validate (can be <code>null</code> or empty)
@@ -1342,8 +1375,8 @@
                 if (!Utils.isEmpty(constraint)) {
                     // ERROR - Duplicate value constraint
                     if (constraints.contains(constraint)) {
-                        status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateValueConstraint,
-                                                                                propertyName, constraint)));
+                        status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateValueConstraint, propertyName,
+                                                                                constraint)));
                     } else {
                         constraints.add(constraint);
                     }

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CompactNodeTypeDefinition.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CompactNodeTypeDefinition.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CompactNodeTypeDefinition.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -23,6 +23,28 @@
 public class CompactNodeTypeDefinition implements CndElement {
 
     /**
+     * @param cndToCopy the CND being copied (cannot be <code>null</code>)
+     * @return a CND exactly equals to the CND that was copied (never <code>null</code>)
+     */
+    public static CompactNodeTypeDefinition copy( final CompactNodeTypeDefinition cndToCopy ) {
+        Utils.verifyIsNotNull(cndToCopy, "cndToCopy"); //$NON-NLS-1$
+
+        final CompactNodeTypeDefinition copy = new CompactNodeTypeDefinition();
+
+        // namespace mappings
+        for (final NamespaceMapping namespaceMapping : cndToCopy.getNamespaceMappings()) {
+            copy.addNamespaceMapping(NamespaceMapping.copy(namespaceMapping));
+        }
+
+        // node type definitions
+        for (final NodeTypeDefinition nodeTypeDefinition : cndToCopy.getNodeTypeDefinitions()) {
+            copy.addNodeTypeDefinition(NodeTypeDefinition.copy(nodeTypeDefinition));
+        }
+
+        return copy;
+    }
+
+    /**
      * The registered property change listeners (never <code>null</code>).
      */
     private final CopyOnWriteArrayList<PropertyChangeListener> listeners;
@@ -145,6 +167,44 @@
         return wasCleared;
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals( final Object obj ) {
+        if (this == obj) {
+            return true;
+        }
+
+        if ((obj == null) || !getClass().equals(obj.getClass())) {
+            return false;
+        }
+
+        final CompactNodeTypeDefinition that = (CompactNodeTypeDefinition)obj;
+
+        { // compare namespace mappings
+            final List<NamespaceMapping> thisNamespaces = getNamespaceMappings();
+            final List<NamespaceMapping> thatNamespaces = that.getNamespaceMappings();
+
+            if (!Utils.equivalent(thisNamespaces, thatNamespaces)) {
+                return false;
+            }
+        }
+
+        { // compare node type definitions
+            final List<NodeTypeDefinition> thisNodeTypes = getNodeTypeDefinitions();
+            final List<NodeTypeDefinition> thatNodeTypes = that.getNodeTypeDefinitions();
+
+            if (!Utils.equivalent(thisNodeTypes, thatNodeTypes)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     private String getEndNamespaceMappingSectionDelimiter() {
         return CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.NAMESPACE_MAPPING_SECTION_END_DELIMITER);
     }
@@ -184,6 +244,18 @@
     }
 
     /**
+     * {@inheritDoc}
+     * 
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int result1 = Utils.hashCode(getNamespaceMappings().toArray());
+        final int result2 = Utils.hashCode(getNodeTypeDefinitions().toArray());
+        return Utils.hashCode(result1, result2);
+    }
+
+    /**
      * @param property the property that was changed (never <code>null</code>)
      * @param oldValue the old value (can be <code>null</code>)
      * @param newValue the new value (can be <code>null</code>)
@@ -323,7 +395,7 @@
          */
         @Override
         public String toString() {
-            return (getClass().getSimpleName() + super.toString());
+            return (getClass().getName() + super.toString());
         }
     }
 

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMapping.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMapping.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMapping.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -19,6 +19,14 @@
 public class NamespaceMapping implements CndElement, Comparable {
 
     /**
+     * @param namespaceMappingToCopy the namespace mapping being copied (cannot be <code>null</code>)
+     * @return a new namespace mapping exactly equal to the one that was copied (never <code>null</code>)
+     */
+    public static NamespaceMapping copy( NamespaceMapping namespaceMappingToCopy ) {
+        return new NamespaceMapping(namespaceMappingToCopy.getPrefix(), namespaceMappingToCopy.getUri());
+    }
+
+    /**
      * The delimeter used to separate the prefix from the URI.
      */
     public static final String NOTATION_DELIMITER = "="; //$NON-NLS-1$
@@ -262,7 +270,7 @@
          */
         @Override
         public String toString() {
-            return (getClass().getSimpleName() + super.toString());
+            return (getClass().getName() + super.toString());
         }
     }
 }

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -44,6 +44,46 @@
     public static final String NAME_NOTATION_SUFFIX = "]"; //$NON-NLS-1$
 
     /**
+     * @param nodeTypeToCopy the node type defition being copied (cannot be <code>null</code>)
+     * @return a new node type definition exactly equal to the one copied (never <code>null</code>)
+     */
+    public static NodeTypeDefinition copy( final NodeTypeDefinition nodeTypeToCopy ) {
+        Utils.verifyIsNotNull(nodeTypeToCopy, "nodeTypeToCopy"); //$NON-NLS-1$
+
+        final NodeTypeDefinition copy = new NodeTypeDefinition();
+
+        // name
+        copy.setName(nodeTypeToCopy.getName());
+
+        // attributes
+        copy.attributes.setAbstract(nodeTypeToCopy.attributes.getAbstract().get());
+        copy.attributes.setMixin(nodeTypeToCopy.attributes.getMixin().get());
+        copy.attributes.setOrderable(nodeTypeToCopy.attributes.getOrderable().get());
+        copy.attributes.setQueryable(nodeTypeToCopy.attributes.getQueryable().get());
+        copy.attributes.setPrimaryItem(nodeTypeToCopy.getPrimaryItemName());
+        copy.attributes.getPrimaryItem().set(nodeTypeToCopy.attributes.getPrimaryItem().get());
+
+        // child nodes
+        for (final ChildNodeDefinition childNode : nodeTypeToCopy.getChildNodeDefinitions()) {
+            copy.addChildNodeDefinition(ChildNodeDefinition.copy(childNode));
+        }
+
+        // properties
+        for (final PropertyDefinition property : nodeTypeToCopy.getPropertyDefinitions()) {
+            copy.addPropertyDefinition(PropertyDefinition.copy(property));
+        }
+
+        // supertypes
+        copy.superTypes.set(nodeTypeToCopy.superTypes.get());
+
+        for (final QualifiedName supertype : nodeTypeToCopy.getSupertypes()) {
+            copy.addSuperType(supertype.get());
+        }
+
+        return copy;
+    }
+
+    /**
      * The node type attributes (never <code>null</code>).
      */
     private final NodeTypeAttributes attributes;
@@ -283,6 +323,62 @@
         return thisName.compareTo(thatName);
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals( final Object obj ) {
+        if (this == obj) {
+            return true;
+        }
+
+        if ((obj == null) || !getClass().equals(obj.getClass())) {
+            return false;
+        }
+
+        final NodeTypeDefinition that = (NodeTypeDefinition)obj;
+
+        { // name
+            if (!this.name.equals(that.name)) {
+                return false;
+            }
+        }
+
+        { // attributes
+            if (!this.attributes.equals(that.attributes)) {
+                return false;
+            }
+        }
+
+        { // child nodes
+            final List<ChildNodeDefinition> thisChildNodes = getChildNodeDefinitions();
+            final List<ChildNodeDefinition> thatChildNodes = that.getChildNodeDefinitions();
+
+            if (!Utils.equivalent(thisChildNodes, thatChildNodes)) {
+                return false;
+            }
+        }
+
+        { // properties
+            final List<PropertyDefinition> thisProps = getPropertyDefinitions();
+            final List<PropertyDefinition> thatProps = that.getPropertyDefinitions();
+
+            if (!Utils.equivalent(thisProps, thatProps)) {
+                return false;
+            }
+        }
+
+        { // supertypes
+            if (!this.superTypes.equals(that.superTypes)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     private String getChildNodeDefinitionDelimiter() {
         return CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.CHILD_NODE_DEFINITION_DELIMITER);
     }
@@ -475,6 +571,20 @@
     /**
      * {@inheritDoc}
      * 
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int result1 = Utils.hashCode(this.name, this.attributes, this.superTypes);
+        final int result2 = Utils.hashCode(getChildNodeDefinitions().toArray());
+        final int result3 = Utils.hashCode(getPropertyDefinitions().toArray());
+
+        return Utils.hashCode(result1, result2, result3);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
      * @see javax.jcr.nodetype.NodeTypeDefinition#hasOrderableChildNodes()
      */
     @Override
@@ -830,7 +940,7 @@
          */
         @Override
         public String toString() {
-            return (getClass().getSimpleName() + super.toString());
+            return (getClass().getName() + super.toString());
         }
     }
 

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -51,18 +51,41 @@
      */
     public static final PropertyDefinition copy( final PropertyDefinition propertyBeingCopied ) {
         final PropertyDefinition copy = new PropertyDefinition();
+
+        // name
         copy.setName(propertyBeingCopied.getName());
-        copy.setAutoCreated(propertyBeingCopied.isAutoCreated());
-        copy.setAvailableQueryOperators(propertyBeingCopied.getAvailableQueryOperators());
-        copy.setDefaultValues(propertyBeingCopied.getDefaultValues());
-        copy.setFullTextSearchable(propertyBeingCopied.isFullTextSearchable());
-        copy.setMandatory(propertyBeingCopied.isMandatory());
-        copy.setMultiple(propertyBeingCopied.isMultiple());
-        copy.setOnParentVersion(propertyBeingCopied.getOnParentVersion());
-        copy.setProtected(propertyBeingCopied.isProtected());
-        copy.setQueryOrderable(propertyBeingCopied.isQueryOrderable());
-        copy.setRequiredType(propertyBeingCopied.getRequiredType());
-        copy.setValueConstraints(propertyBeingCopied.getValueConstraints());
+
+        // attributes
+        copy.attributes.getAutocreated().set(propertyBeingCopied.attributes.getAutocreated().get());
+        copy.attributes.getMandatory().set(propertyBeingCopied.attributes.getMandatory().get());
+        copy.attributes.getMultiple().set(propertyBeingCopied.attributes.getMultiple().get());
+        copy.attributes.getNoFullText().set(propertyBeingCopied.attributes.getNoFullText().get());
+        copy.attributes.getNoQueryOrder().set(propertyBeingCopied.attributes.getNoQueryOrder().get());
+        copy.attributes.getProtected().set(propertyBeingCopied.attributes.getProtected().get());
+        copy.attributes.setOnParentVersion(propertyBeingCopied.attributes.getOnParentVersion());
+        copy.attributes.getQueryOps().set(propertyBeingCopied.attributes.getQueryOps().get());
+
+        for (final QueryOperator operator : propertyBeingCopied.attributes.getQueryOps().getSupportedItems()) {
+            copy.attributes.getQueryOps().add(operator);
+        }
+
+        // default values
+        copy.defaultValues.set(propertyBeingCopied.defaultValues.get());
+
+        for (final String defaultValue : propertyBeingCopied.getDefaultValuesAsStrings()) {
+            copy.defaultValues.add(defaultValue);
+        }
+
+        // required type
+        copy.type = propertyBeingCopied.type;
+
+        // value constraints
+        copy.valueConstraints.set(propertyBeingCopied.valueConstraints.get());
+
+        for (final String constraint : propertyBeingCopied.getValueConstraints()) {
+            copy.valueConstraints.add(constraint);
+        }
+
         return copy;
     }
 
@@ -982,7 +1005,7 @@
          */
         @Override
         public String toString() {
-            return (getClass().getSimpleName() + super.toString());
+            return (getClass().getName() + super.toString());
         }
     }
 }

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributes.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributes.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributes.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -18,20 +18,6 @@
  */
 public class NodeAttributes implements CndElement {
 
-    /**
-     * @param attributesToCopy the attributes being copied (cannot be <code>null</code>)
-     * @return the copy (never <code>null</code>)
-     */
-    public static NodeAttributes copy( NodeAttributes attributesToCopy ) {
-        NodeAttributes copy = new NodeAttributes();
-        copy.autocreated.set(attributesToCopy.getAutocreated().get());
-        copy.mandatory.set(attributesToCopy.getMandatory().get());
-        copy.notDeletable.set(attributesToCopy.getProtected().get());
-        copy.opv = attributesToCopy.getOnParentVersion();
-        copy.sns.set(attributesToCopy.getSameNameSiblings().get());
-        return copy;
-    }
-
     private final Autocreated autocreated;
 
     private final Mandatory mandatory;

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -191,8 +191,17 @@
         // TODO implement createCnd
         CndImporter importer = new CndImporter();
         List<Throwable> errors = new ArrayList<Throwable>();
-        this.cndBeingEdited = importer.importFrom(getFile().getContents(), errors, getFile().getName());
-        // TODO implement
+        this.originalCnd = importer.importFrom(getFile().getContents(), errors, getFile().getName());
+
+        // TODO process parse errors here
+        
+        // unhook lstening to current CND being edited
+        if (this.cndBeingEdited != null)  {
+            this.cndBeingEdited.removeListener(this);
+        }
+
+        // copy over CND
+        this.cndBeingEdited = CompactNodeTypeDefinition.copy(this.originalCnd);
         this.cndBeingEdited.addListener(this);
     }
 

Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -10,6 +10,7 @@
 import static org.jboss.tools.modeshape.jcr.ui.JcrUiConstants.EditorIds.CND_FORMS_PAGE;
 
 import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -69,6 +70,7 @@
 import org.jboss.tools.modeshape.jcr.cnd.ChildNodeDefinition;
 import org.jboss.tools.modeshape.jcr.cnd.CndElement.NotationType;
 import org.jboss.tools.modeshape.jcr.cnd.CndValidator;
+import org.jboss.tools.modeshape.jcr.cnd.CompactNodeTypeDefinition;
 import org.jboss.tools.modeshape.jcr.cnd.NamespaceMapping;
 import org.jboss.tools.modeshape.jcr.cnd.NodeTypeDefinition;
 import org.jboss.tools.modeshape.jcr.cnd.NodeTypeDefinition.PropertyName;
@@ -86,7 +88,7 @@
 /**
  * The GUI part of the CND editor.
  */
-class CndFormsEditorPage extends CndEditorPage {
+class CndFormsEditorPage extends CndEditorPage implements PropertyChangeListener {
 
     private IAction addChildNode;
     private IAction addNamespace;
@@ -120,6 +122,7 @@
     private final ErrorMessage propertiesError;
     private Section propertiesSection;
     private TableViewer propertyViewer;
+    private NodeTypeDefinition selectedNodeType; // needed for property changes (can be null)
     private final ErrorMessage superTypesError;
     private TableViewer superTypesViewer;
 
@@ -1967,21 +1970,34 @@
     }
 
     void handleNodeTypeSelected() {
+        final NodeTypeDefinition prevNodeType = this.selectedNodeType;
+        this.selectedNodeType = getSelectedNodeType();
+
+        // unhook property change listening from previously selected node type
+        if (prevNodeType != null) {
+            prevNodeType.removeListener(this);
+        }
+
+        // hook property change listening to new selected node type
+        if (this.selectedNodeType != null) {
+            this.selectedNodeType.addListener(this);
+        }
+
         updateEnabledState();
 
         // update section descriptions
-        if (getSelectedNodeType() == null) {
+        if (this.selectedNodeType == null) {
             this.detailsSection.setDescription(CndMessages.cndEditorDetailsSectionDescription);
             this.propertiesSection.setDescription(CndMessages.cndEditorChildNodeSectionDescription);
             this.childNodeSection.setDescription(CndMessages.cndEditorPropertySectionDescription);
         } else {
-            String name = getSelectedNodeType().getName();
+            String name = this.selectedNodeType.getName();
 
             if (Utils.isEmpty(name)) {
                 name = Messages.missingName;
             }
 
-            this.nameEditor.setNameBeingEdited(getSelectedNodeType().getQualifiedName());
+            this.nameEditor.setNameBeingEdited(this.selectedNodeType.getQualifiedName());
             this.detailsSection.setDescription(NLS.bind(CndMessages.cndEditorChildNodeSectionDescriptionWithNodeTypeName, name));
             this.propertiesSection.setDescription(NLS.bind(CndMessages.cndEditorChildNodeSectionDescriptionWithNodeTypeName, name));
             this.childNodeSection.setDescription(NLS.bind(CndMessages.cndEditorPropertySectionDescriptionWithNodeTypeName, name));
@@ -2026,6 +2042,7 @@
                 this.childNodeViewer.refresh();
             } else if (NodeTypeDefinition.PropertyName.NAME.toString().equals(propName)) {
                 validateName();
+                this.nodeTypeViewer.refresh(source);
             } else if (NodeTypeDefinition.PropertyName.PROPERTY_DEFINITIONS.toString().equals(propName)) {
                 validateProperties();
                 this.propertyViewer.refresh();
@@ -2033,12 +2050,17 @@
                 validateSuperTypes();
                 this.superTypesViewer.refresh();
             }
+
+            // tell editor about node type definition change
+            getCndEditor().refreshDirtyState();
         } else if (source instanceof NamespaceMapping) {
             this.namespaceViewer.refresh(source);
-        } else if (source instanceof PropertyDefinition) {
-            this.propertyViewer.refresh(source);
-        } else if (source instanceof ChildNodeDefinition) {
-            this.childNodeViewer.refresh(source);
+        } else if (source instanceof CompactNodeTypeDefinition) {
+            if (CompactNodeTypeDefinition.PropertyName.NAMESPACE_MAPPINGS.toString().equals(propName)) {
+                this.namespaceViewer.refresh();
+            } else if (CompactNodeTypeDefinition.PropertyName.NODE_TYPE_DEFINITIONS.toString().equals(propName)) {
+                this.nodeTypeViewer.refresh();
+            }
         }
     }
 
@@ -2093,6 +2115,16 @@
         }
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+     */
+    @Override
+    public void propertyChange( final PropertyChangeEvent e ) {
+        handlePropertyChanged(e);
+    }
+
     private void refreshAttributeControls() {
         boolean notConcrete = false;
         boolean mixin = false;

Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -450,40 +450,49 @@
     }
 
     @Test
-    public void copiesShouldBeEqual() {
-        ChildNodeDefinition that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+    public void copiesShouldBeEqualAndHaveSameHashCode() {
+        ChildNodeDefinition thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
 
         this.childNodeDefinition.setName(Constants.QUALIFIED_NAME1.get());
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
 
         this.childNodeDefinition.setDefaultPrimaryTypeName(Constants.DEFAULT_TYPE);
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
         
         this.childNodeDefinition.setAutoCreated(!this.childNodeDefinition.isAutoCreated());
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
 
         this.childNodeDefinition.setMandatory(!this.childNodeDefinition.isMandatory());
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
 
         this.childNodeDefinition.setProtected(!this.childNodeDefinition.isProtected());
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
 
         this.childNodeDefinition.setSameNameSiblings(!this.childNodeDefinition.allowsSameNameSiblings());
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
 
         this.childNodeDefinition.setOnParentVersion(OnParentVersion.ABORT.asJcrValue());
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
 
         this.childNodeDefinition.setRequiredPrimaryTypeNames(Constants.Helper.getDefaultQualifiedNamesAsArray());
-        that = ChildNodeDefinition.copy(this.childNodeDefinition);
-        assertEquals(this.childNodeDefinition, that);
+        thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition);
+        assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+        assertEquals(this.childNodeDefinition.hashCode(), thatChildNodeDefinition.hashCode());
     }
 }

Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -147,7 +147,7 @@
         this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition);
         this.nodeTypeDefinition.addChildNodeDefinition(child2);
 
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isError());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isError());
     }
 
     @Test
@@ -162,22 +162,22 @@
         this.nodeTypeDefinition.addPropertyDefinition(this.propertyDefinition);
         this.nodeTypeDefinition.addPropertyDefinition(prop2);
 
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isError());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isError());
     }
 
     @Test
     public void nodeTypeDefinitionWithEmptyNameShouldAnError() {
         this.nodeTypeDefinition.setName(null);
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isError());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isError());
 
         this.nodeTypeDefinition.setName(Utils.EMPTY_STRING);
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isError());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isError());
     }
 
     @Test
     public void nodeTypeDefinitionWithInvalidNameShouldBeAnError() {
         this.nodeTypeDefinition.setName("invalid/name"); //$NON-NLS-1$
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isError());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isError());
     }
 
     @Test
@@ -185,7 +185,7 @@
         this.nodeTypeDefinition.setName("nodeTypeName"); //$NON-NLS-1$
         this.nodeTypeDefinition.setPrimaryItemName("invalid/name"); //$NON-NLS-1$
 
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isError());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isError());
     }
 
     @Test
@@ -193,13 +193,13 @@
         this.nodeTypeDefinition.setName("nodeTypeName"); //$NON-NLS-1$
         this.nodeTypeDefinition.addSuperType("invalid/name"); //$NON-NLS-1$
 
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isError());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isError());
     }
 
     @Test
     public void nodeTypeDefinitionWithoutPropertiesAndChildNodesShouldBeAWarning() {
         this.nodeTypeDefinition.setName("name"); //$NON-NLS-1$
-        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition).isWarning());
+        assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null).isWarning());
     }
 
     @Test

Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -196,4 +196,20 @@
         assertEquals(namespace1.hashCode(), namespace2.hashCode());
     }
 
+    @Test
+    public void copiesShouldBeEqualAndHaveSameHashCode() {
+        NamespaceMapping thatNamespaceMapping = NamespaceMapping.copy(this.namespaceMapping);
+        assertEquals(this.namespaceMapping, thatNamespaceMapping);
+        assertEquals(this.namespaceMapping.hashCode(), thatNamespaceMapping.hashCode());
+        
+        assertTrue(this.namespaceMapping.setPrefix(Constants.NAMESPACE_PREFIX1));
+        thatNamespaceMapping = NamespaceMapping.copy(this.namespaceMapping);
+        assertEquals(this.namespaceMapping, thatNamespaceMapping);
+        assertEquals(this.namespaceMapping.hashCode(), thatNamespaceMapping.hashCode());
+        
+        assertTrue(this.namespaceMapping.setUri(Constants.NAMESPACE_URI1));
+        thatNamespaceMapping = NamespaceMapping.copy(this.namespaceMapping);
+        assertEquals(this.namespaceMapping, thatNamespaceMapping);
+        assertEquals(this.namespaceMapping.hashCode(), thatNamespaceMapping.hashCode());
+    }
 }

Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -522,4 +522,56 @@
         assertEquals(SUPER_TYPE2, superTypeNames[1]);
         assertEquals(SUPER_TYPE3, superTypeNames[2]);
     }
+
+    @Test
+    public void copiesShouldBeEqualAndHaveSameHashCode() {
+        NodeTypeDefinition thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+        
+        this.nodeTypeDefinition.setName("newName"); //$NON-NLS-1$
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+        
+        this.nodeTypeDefinition.setAbstract(!this.nodeTypeDefinition.isAbstract());
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+        
+        this.nodeTypeDefinition.setMixin(!this.nodeTypeDefinition.isMixin());
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+        
+        this.nodeTypeDefinition.setOrderableChildNodes(!this.nodeTypeDefinition.hasOrderableChildNodes());
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+        
+        this.nodeTypeDefinition.setQueryable(!this.nodeTypeDefinition.isQueryable());
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+        
+        this.nodeTypeDefinition.setPrimaryItemName("newPrimaryItem"); //$NON-NLS-1$
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+
+        this.nodeTypeDefinition.addSuperType(Constants.QUALIFIED_NAME1.get());
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+
+        this.nodeTypeDefinition.addChildNodeDefinition(new ChildNodeDefinition());
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+
+        this.nodeTypeDefinition.addPropertyDefinition(new PropertyDefinition());
+        thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+        assertEquals(this.nodeTypeDefinition.hashCode(), thatNodeTypeDefinition.hashCode());
+    }
 }

Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinitionTest.java
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinitionTest.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinitionTest.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -39,57 +39,70 @@
     }
 
     @Test
-    public void copiesShouldBeEqual() {
+    public void copiesShouldBeEqualAndHaveSameHashCode() {
         PropertyDefinition thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setAvailableQueryOperators(Constants.Helper.getDefaultQueryOperators());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setAutoCreated(!this.propDefn.isAutoCreated());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setDefaultValues(Constants.Helper.getDefaultStringValues());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setFullTextSearchable(!this.propDefn.isFullTextSearchable());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setMandatory(!this.propDefn.isMandatory());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setMultiple(!this.propDefn.isMultiple());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setName(Constants.QUALIFIED_NAME1.get());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setOnParentVersion(OnParentVersion.COMPUTE.asJcrValue());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setProtected(!this.propDefn.isProtected());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setQueryOrderable(!this.propDefn.isQueryOrderable());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setRequiredType(PropertyType.BINARY.asJcrValue());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
 
         this.propDefn.setValueConstraints(Constants.Helper.getDefaultValueConstraints());
         thatPropDefn = PropertyDefinition.copy(this.propDefn);
         assertEquals(this.propDefn, thatPropDefn);
+        assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
     }
 
     @Test

Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributesTest.java
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributesTest.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/NodeAttributesTest.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -13,7 +13,6 @@
 
 import org.jboss.tools.modeshape.jcr.Utils;
 import org.jboss.tools.modeshape.jcr.cnd.CndElement.NotationType;
-import org.jboss.tools.modeshape.jcr.cnd.Constants;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -73,32 +72,6 @@
     }
 
     @Test
-    public void copiesShouldBeEqual() {
-        NodeAttributes copy = NodeAttributes.copy(this.attributes);
-        assertEquals(this.attributes, copy);
-
-        Constants.Helper.changeValue(this.attributes.getAutocreated());
-        copy.setAutocreated(this.attributes.getAutocreated().get());
-        assertEquals(this.attributes, copy);
-
-        Constants.Helper.changeValue(this.attributes.getMandatory());
-        copy.setMandatory(this.attributes.getMandatory().get());
-        assertEquals(this.attributes, copy);
-
-        Constants.Helper.changeValue(this.attributes.getProtected());
-        copy.setProtected(this.attributes.getProtected().get());
-        assertEquals(this.attributes, copy);
-
-        Constants.Helper.changeValue(this.attributes.getSameNameSiblings());
-        copy.setSameNameSibling(this.attributes.getSameNameSiblings().get());
-        assertEquals(this.attributes, copy);
-
-        this.attributes.setOnParentVersion(OnParentVersion.ABORT);
-        copy.setOnParentVersion(this.attributes.getOnParentVersion());
-        assertEquals(this.attributes, copy);
-    }
-
-    @Test
     public void equalInstancesShouldHaveSameHashCode() {
         NodeAttributes second = new NodeAttributes();
         assertEquals(this.attributes.hashCode(), second.hashCode());

Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/ValueConstraintsTest.java
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/ValueConstraintsTest.java	2012-03-23 19:35:45 UTC (rev 39804)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/ValueConstraintsTest.java	2012-03-23 21:03:33 UTC (rev 39805)
@@ -72,9 +72,9 @@
     @Test
     public void verifyMultipleElementsCndNotation() {
         // setup
-        add(ITEM_ONE);
-        add(ITEM_TWO);
-        add(ITEM_THREE);
+        add(VALUE_CONSTRAINT1);
+        add(VALUE_CONSTRAINT2);
+        add(VALUE_CONSTRAINT3);
 
         // tests
         assertEquals(VALUE_CONSTRAINTS_THREE_ITEM_FORM, this.attribute.toCndNotation(CndElement.NotationType.COMPACT));
@@ -85,7 +85,7 @@
     @Test
     public void verifyOneElementCndNotation() {
         // setup
-        add(ITEM_ONE);
+        add(VALUE_CONSTRAINT1);
 
         // tests
         assertEquals(VALUE_CONSTRAINTS_ONE_ITEM_FORM, this.attribute.toCndNotation(CndElement.NotationType.COMPACT));



More information about the jbosstools-commits mailing list