Package org.exoplatform.services.jcr.core.nodetype

Examples of org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData


         InternalQName iname = locationFactory.parseJCRName(itemName).getInternalName();

         PropertyDefinitionDatas pdefs = nodeTypeDataManager.getPropertyDefinitions(iname, nodeTypeData.getName());
         if (pdefs != null)
         {
            PropertyDefinitionData pd = pdefs.getAnyDefinition();
            if (pd != null)
               return !(pd.isMandatory() || pd.isProtected());
         }
         NodeDefinitionData cndef = nodeTypeDataManager.findChildNodeDefinition(iname, nodeTypeData.getName());
         if (cndef != null)
            return !(cndef.isMandatory() || cndef.isProtected());
View Full Code Here


         InternalQName pname = locationFactory.parseJCRName(propertyName).getInternalName();

         PropertyDefinitionDatas pdefs = nodeTypeDataManager.getPropertyDefinitions(pname, nodeTypeData.getName());
         if (pdefs != null)
         {
            PropertyDefinitionData pd = pdefs.getDefinition(false);
            if (pd != null)
            {
               if (pd.isProtected())
                  // can set (edit)
                  return false;
               else if (value != null)
                  // can set (add or edit)
                  return canSetPropertyForType(pd.getRequiredType(), value, pd.getValueConstraints());
               else
                  // can remove
                  return !pd.isMandatory();
            }
         }
         return false;
      }
      catch (RepositoryException e)
View Full Code Here

      try
      {
         InternalQName pname = locationFactory.parseJCRName(propertyName).getInternalName();

         PropertyDefinitionDatas pdefs = nodeTypeDataManager.getPropertyDefinitions(pname, nodeTypeData.getName());
         PropertyDefinitionData pd = pdefs.getDefinition(true);
         if (pd != null)
         {
            if (pd.isProtected())
               // can set (edit)
               return false;
            else if (values != null)
            {
               // can set (add or edit)
               int res = 0;
               for (Value value : values)
               {
                  if (canSetPropertyForType(pd.getRequiredType(), value, pd.getValueConstraints()))
                     res++;
               }
               return res == values.length;
            }
            else
               // can remove
               return !pd.isMandatory();
         }
         else
            return false;
      }
      catch (RepositoryException e)
View Full Code Here

      for (int i = 0; i < pdefs.length; i++)
      {

         try
         {
            PropertyDefinitionData propertyDef = pdefs[i];
            String name =
                     locationFactory.createJCRName(
                              propertyDef.getName() != null ? propertyDef.getName() : Constants.JCR_ANY_NAME)
                              .getAsString();

            Value[] defaultValues = new Value[propertyDef.getDefaultValues().length];
            String[] propVal = propertyDef.getDefaultValues();
            // there can be null in definition but should not be null value
            if (propVal != null)
            {
               for (int j = 0; j < propVal.length; j++)
               {
                  if (propertyDef.getRequiredType() == PropertyType.UNDEFINED)
                     defaultValues[j] = valueFactory.createValue(propVal[j]);
                  else
                     defaultValues[j] = valueFactory.createValue(propVal[j], propertyDef.getRequiredType());
               }
            }

            propertyDefinitions[i] =
                     new PropertyDefinitionImpl(name, nodeTypeManager.findNodeType(propertyDef.getDeclaringNodeType()),
                              propertyDef.getRequiredType(), propertyDef.getValueConstraints(), defaultValues,
                              propertyDef.isAutoCreated(), propertyDef.isMandatory(), propertyDef.getOnParentVersion(),
                              propertyDef.isProtected(), propertyDef.isMultiple());
         }
         catch (ValueFormatException e)
         {
            e.printStackTrace();
         }
View Full Code Here

      }
      else
      {
         NodeData parent = (NodeData) dataManager.getItemData(property.getParentIdentifier());

         PropertyDefinitionData pdef =
                  ntManager.findPropertyDefinitions(qname, parent.getPrimaryTypeName(), parent.getMixinTypeNames())
                           .getAnyDefinition();

         int action = pdef.getOnParentVersion();

         if (action == OnParentVersionAction.IGNORE)
         {
            return;
         }
         else if (action == OnParentVersionAction.ABORT)
         {
            throw new VersionException("Property is aborted " + property.getQPath().getAsString());
         }
         else if (action == OnParentVersionAction.COPY || action == OnParentVersionAction.VERSION
                  || action == OnParentVersionAction.COMPUTE)
         {
            frozenProperty =
                     TransientPropertyData.createPropertyData(currentNode(), qname, property.getType(), mv, values);
         }
         else if (action == OnParentVersionAction.INITIALIZE)
         {
            // 8.2.11.3 INITIALIZE
            // On checkin of N, a new P will be created and placed in version
            // storage as a child of VN. The new P will be initialized just as it
            // would
            // be if created normally in a workspace
            if (pdef.isAutoCreated())
            {
               if (pdef.getDefaultValues() != null && pdef.getDefaultValues().length > 0)
               {
                  // to use default values
                  values.clear();
                  for (String defValue : pdef.getDefaultValues())
                  {
                     TransientValueData defData;
                     if (PropertyType.UNDEFINED == pdef.getRequiredType())
                     {
                        defData = ((BaseValue) valueFactory.createValue(defValue)).getInternalData();
                     }
                     else
                     {
                        defData =
                                 ((BaseValue) valueFactory.createValue(defValue, pdef.getRequiredType()))
                                          .getInternalData();
                     }
                     // TransientValueData defData = ((BaseValue)
                     // defValue).getInternalData();
                     // values.add(defData.createTransientCopy());
View Full Code Here

         }
      }
      if (defs == null || defs.getAnyDefinition() == null)
         throw new RepositoryException("Property definition '" + propertyName.getAsString() + "' is not found.");

      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 || (oldProp != null && !oldProp.isMultiValued())))
      {
         throw new ValueFormatException("Can not assign multiple-values Value to a single-valued property "
                  + locationFactory.createJCRPath(qpath).getAsString(false));
      }

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

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

      // Check locking
      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);

      TransientPropertyData newData =
               new TransientPropertyData(qpath, identifier, version, propType, parentNode.getInternalIdentifier(),
                        multiValue);

      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 = null;
      if (state != ItemState.DELETED)
      {
         newData.setValues(valueDataList);
         ItemState itemState = new ItemState(newData, state, true, qpath, false);
         prop = (PropertyImpl) dataManager.update(itemState, true);
         // launch event
         session.getActionHandler().postSetProperty(prop, state);

      }
      else
      {
         if (def.isMandatory())
         {
            throw new ConstraintViolationException("Can not remove (by setting null value) mandatory property "
                     + locationFactory.createJCRPath(qpath).getAsString(false));
         }
         // launch event
View Full Code Here

      if (curParent() == null)
      {
         NodeData existedParent = (NodeData) dataManager.getItemData(property.getParentIdentifier());

         PropertyDefinitionData pdef =
                  ntManager.findPropertyDefinitions(property.getQPath().getName(), existedParent.getPrimaryTypeName(),
                           existedParent.getMixinTypeNames()).getAnyDefinition();

         if (pdef.getOnParentVersion() == OnParentVersionAction.IGNORE)
         {
            // parent is not exists as this copy context current parent
            // i.e. it's a IGNOREd property elsewhere at a versionable node
            // descendant.
            // So, we have to know that this parent WILL exists after restore
View Full Code Here

         NodeTypeData nt = propReg.getNodeTypeDataManager().findNodeType(ntName[0]);

         PropertyDefinitionData[] propDefs = nt.getDeclaredPropertyDefinitions();
         for (int i = 0; i < propDefs.length; i++)
         {
            PropertyDefinitionData propDef = propDefs[i];
            if (!propDef.isResidualSet() && !propDef.isMultiple())
            {
               selectProps.add(propDef.getName());
            }
         }
      }

      // add jcr:path and jcr:score if not selected already
View Full Code Here

         {
            newProperty = endUuid(nodeData, propName);
         }
         else
         {
            PropertyDefinitionData pDef;
            PropertyDefinitionDatas defs;
            InternalQName[] nTypes = mixinNodeTypes.toArray(new InternalQName[mixinNodeTypes.size() + 1]);
            nTypes[nTypes.length - 1] = nodeData.getPrimaryTypeName();
            defs = nodeTypeDataManager.getPropertyDefinitions(propName, nTypes);
            if (defs == null || defs.getAnyDefinition() == null)
            {
               if (!((Boolean)context.get(ContentImporter.RESPECT_PROPERTY_DEFINITIONS_CONSTRAINTS)))
               {
                  log.warn("Property definition not found for " + propName.getAsString());
                  continue;
               }
               throw new RepositoryException("Property definition not found for " + propName.getAsString());
            }

            pDef = defs.getAnyDefinition();

            if ((pDef == null) || (defs == null))
            {
               throw new RepositoryException("no propertyDefinition found");
            }

            if (pDef.getRequiredType() == PropertyType.BINARY)
            {
               newProperty = endBinary(propertiesMap, newProperty, propName);
            }
            else
            {
               StringTokenizer spaceTokenizer = new StringTokenizer(propertiesMap.get(propName));

               List<ValueData> values = new ArrayList<ValueData>();
               int pType = pDef.getRequiredType() > 0 ? pDef.getRequiredType() : PropertyType.STRING;

               if ("".equals(propertiesMap.get(propName)))
               {
                  // Skip empty non string values
                  if (pType != PropertyType.STRING)
View Full Code Here

      if (curParent() == null)
      {
         NodeData existedParent = (NodeData)dataManager.getItemData(property.getParentIdentifier());

         PropertyDefinitionData pdef =
            ntManager.getPropertyDefinitions(property.getQPath().getName(), existedParent.getPrimaryTypeName(),
               existedParent.getMixinTypeNames()).getAnyDefinition();

         if (pdef.getOnParentVersion() == OnParentVersionAction.IGNORE)
         {
            // parent is not exists as this copy context current parent
            // i.e. it's a IGNOREd property elsewhere at a versionable node
            // descendant.
            // So, we have to know that this parent WILL exists after restore
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData

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.