Package javax.jcr.nodetype

Examples of javax.jcr.nodetype.ConstraintViolationException


      }

      // Check if node is not protected
      if (node.getDefinition().isProtected())
      {
         throw new ConstraintViolationException("Can't add protected node " + node.getName() + " to "
            + node.getParent().getPath());
      }

      // Check locking
      if (!node.checkLocking())
View Full Code Here


         def = ((PropertyImpl)this).getDefinition();
      }

      if (def.isMandatory() || def.isProtected())
      {
         throw new ConstraintViolationException("Can't remove mandatory or protected item " + getPath());
      }

      NodeImpl parentNode = parent();
      // Check if versionable ancestor is not checked-in
      if (!parentNode.checkedOut())
View Full Code Here

      }

      PropertyDefinitionData def = defs.getDefinition(isMultiValue);
      if (def != null && def.isProtected())
      {
         throw new ConstraintViolationException("Can not set protected property "
            + locationFactory.createJCRPath(qpath).getAsString(false));
      }

      if (multiValue && (def == null || (prevProp != null && !prevProp.isMultiValued())))
      {
         throw new ValueFormatException("Can not assign multiple-values Value to a single-valued property "
            + locationFactory.createJCRPath(qpath).getAsString(false));
      }

      if (!multiValue && (def == null || (prevProp != null && prevProp.isMultiValued())))
      {
         throw new ValueFormatException("Can not assign single-value Value to a multiple-valued property "
            + locationFactory.createJCRPath(qpath).getAsString(false));
      }

      // Check if checked-in (versionable)
      if (!parentNode.checkedOut())
      {
         throw new VersionException("Node " + parentNode.getPath() + " or its nearest ancestor is checked-in");
      }

      // Check is locked
      if (!parentNode.checkLocking())
      {
         throw new LockException("Node " + parentNode.getPath() + " is locked ");
      }

      List<ValueData> valueDataList = new ArrayList<ValueData>();

      // cast to required type if neccessary
      int requiredType = def.getRequiredType();

      int propType = requiredType;
      // if list of values not null
      if (propertyValues != null)
      {
         // All Value objects in the array must be of the same type, otherwise a
         // ValueFormatException is thrown.
         if (propertyValues.length > 1)
         {
            if (propertyValues[0] != null)
            {
               int vType = propertyValues[0].getType();
               for (Value val : propertyValues)
               {
                  if (val != null && vType != val.getType())
                  {
                     throw new ValueFormatException("All Value objects in the array must be of the same type");
                  }
               }
            }
         }

         // if value count >0 and original type not UNDEFINED
         if (propertyValues.length > 0 && requiredType == PropertyType.UNDEFINED)
         {
            // if type what we expected to be UNDEFINED
            // set destination type = type of values else type expectedType
            if (expectedType == PropertyType.UNDEFINED)
            {
               for (Value val : propertyValues)
               {
                  if (val != null)
                  {
                     expectedType = val.getType();
                     break;
                  }
               }
            }
            propType = expectedType;
         }
         // fill datas and also remove null values and reorder values
         for (Value value : propertyValues)
         {
            if (value != null)
            {
               valueDataList.add(valueData(value, propType));
            }
            else
            {
               if (log.isDebugEnabled())
               {
                  log.debug("Set null value (" + getPath() + ", multivalued: " + multiValue + ")");
               }
            }
         }
      }

      // Check value constraints
      checkValueConstraints(def, valueDataList, propType);

      if (requiredType != PropertyType.UNDEFINED && expectedType != PropertyType.UNDEFINED
         && requiredType != expectedType)
      {
         throw new ConstraintViolationException(" the type parameter "
            + ExtendedPropertyType.nameFromValue(expectedType) + " and the "
            + "type of the property do not match required type" + ExtendedPropertyType.nameFromValue(requiredType));
      }

      PropertyImpl prop;
      if (state != ItemState.DELETED)
      {
         // add or update      
         TransientPropertyData newData =
            new TransientPropertyData(qpath, identifier, version, propType, parentNode.getInternalIdentifier(),
               multiValue, valueDataList);

         ItemState itemState = new ItemState(newData, state, true, qpath, false);
         prop = (PropertyImpl)dataManager.update(itemState, true);

         // launch event: post-set
         session.getActionHandler().postSetProperty(prevProperty, prop, state);
      }
      else
      {
         if (def.isMandatory())
         {
            throw new ConstraintViolationException("Can not remove (by setting null value) mandatory property "
               + locationFactory.createJCRPath(qpath).getAsString(false));
         }

         TransientPropertyData newData =
            new TransientPropertyData(qpath, identifier, version, propType, parentNode.getInternalIdentifier(),
View Full Code Here

               validateMandatoryItem(itemState);
            }

            if (path.isDescendantOf(itemState.getAncestorToSave()))
            {
               throw new ConstraintViolationException(path.getAsString()
                  + " is the same or descendant of either Session.move()'s destination or source node only "
                  + path.getAsString());
            }
         }
      }
View Full Code Here

            .getManadatoryItemDefs(nData.getPrimaryTypeName(), nData.getMixinTypeNames());
      for (ItemDefinitionData itemDefinitionData : mandatoryItemDefs)
      {
         if (getItemData(nData, new QPathEntry(itemDefinitionData.getName(), 0), ItemType.UNKNOWN) == null)
         {
            throw new ConstraintViolationException("Mandatory item " + itemDefinitionData.getName()
               + " not found. Node [" + nData.getQPath().getAsString() + " primary type: "
               + nData.getPrimaryTypeName().getAsString() + "]");
         }

      }
View Full Code Here

               validateMandatoryItem(itemState);
            }

            if (path.isDescendantOf(itemState.getAncestorToSave()))
            {
               throw new ConstraintViolationException(path.getAsString()
                  + " is the same or descendant of either Session.move()'s destination or source node only "
                  + path.getAsString());
            }
         }
      }
View Full Code Here

            .getManadatoryItemDefs(nData.getPrimaryTypeName(), nData.getMixinTypeNames());
      for (ItemDefinitionData itemDefinitionData : mandatoryItemDefs)
      {
         if (getItemData(nData, new QPathEntry(itemDefinitionData.getName(), 0), ItemType.UNKNOWN) == null)
         {
            throw new ConstraintViolationException("Mandatory item " + itemDefinitionData.getName()
               + " not found. Node [" + nData.getQPath().getAsString() + " primary type: "
               + nData.getPrimaryTypeName().getAsString() + "]");
         }

      }
View Full Code Here

            InternalQName childName =
               locationFactory.parseJCRName(propertiesMap.get(Constants.JCR_PRIMARYTYPE)).getInternalName();
            if (!nodeTypeDataManager.isChildNodePrimaryTypeAllowed(childName, parentNodeData.getPrimaryTypeName(),
               parentNodeData.getMixinTypeNames()))
            {
               throw new ConstraintViolationException("Can't add node " + nodeData.getQName().getAsString() + " to "
                  + parentNodeData.getQPath().getAsString() + " node type "
                  + propertiesMap.get(Constants.JCR_PRIMARYTYPE)
                  + " is not allowed as child's node type for parent node type "
                  + parentNodeData.getPrimaryTypeName().getAsString());
View Full Code Here

         {
            nodeType = nodeTypeDataManager.getNodeType(nodeNt.getName());
         }

         if (nodeType == null)
            throw new ConstraintViolationException("Can not define node-type for node " + nodeName.getAsString()
               + ", parent node type " + parent.getPrimaryTypeName().getAsString());

         nodeTypes.add(nodeType);
         props.put(Constants.JCR_PRIMARYTYPE, locationFactory.createJCRName(nodeType.getName()).getAsString());
      }

      if (atts != null)
      {
         for (String key : atts.keySet())
         {

            String attValue = atts.get(key);

            String propName = ISO9075.decode(key);
            if (log.isDebugEnabled())
            {
               log.debug(propName + ":" + attValue);
            }
            InternalQName propInternalQName = locationFactory.parseJCRName(propName).getInternalName();

            if (Constants.JCR_PRIMARYTYPE.equals(propInternalQName))
            {
               String primaryNodeType = StringConverter.denormalizeString(attValue);
               InternalQName ntName = locationFactory.parseJCRName(primaryNodeType).getInternalName();
               NodeTypeData nodeType = nodeTypeDataManager.getNodeType(ntName);
               if (nodeType == null)
                  throw new ConstraintViolationException("Can not find node type " + primaryNodeType);
               nodeTypes.add(nodeType);
               props.put(propInternalQName, primaryNodeType);
            }
            else if (Constants.JCR_MIXINTYPES.equals(propInternalQName))
            {
               String[] amTypes = attValue.split(" ");
               for (int mi = 0; mi < amTypes.length; mi++)
               {
                  amTypes[mi] = StringConverter.denormalizeString(amTypes[mi]);
                  InternalQName name = locationFactory.parseJCRName(amTypes[mi]).getInternalName();
                  mixinNodeTypes.add(name);
                  NodeTypeData nodeType = nodeTypeDataManager.getNodeType(name);
                  if (nodeType == null)
                     throw new ConstraintViolationException("Can not find node type " + amTypes[mi]);

                  nodeTypes.add(nodeType);
               }
               // value will not be used anywhere; for key only
               props.put(propInternalQName, null);
View Full Code Here

      QPath sameUuidPath = sameUuidItem.getQPath();

      if (ancestorToSave.isDescendantOf(sameUuidPath) || ancestorToSave.equals(sameUuidPath))
      {
         throw new ConstraintViolationException("The imported document contains a element"
            + " with jcr:uuid attribute the same as the  parent of the import target.");
      }

      setAncestorToSave(QPath.getCommonAncestorPath(ancestorToSave, sameUuidPath));
View Full Code Here

TOP

Related Classes of javax.jcr.nodetype.ConstraintViolationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.