コード例 #1
0
 /**
  * creates a node state for the given property def
  *
  * @param parent
  * @param propDef
  * @return
  * @throws RepositoryException
  */
 private VirtualNodeState createPropertyDefState(
     VirtualNodeState parent, QPropertyDefinition propDef, QNodeTypeDefinition ntDef, int n)
     throws RepositoryException {
   NodeId id =
       calculateStableId(
           ntDef.getName().toString()
               + "/"
               + NameConstants.JCR_PROPERTYDEFINITION.toString()
               + "/"
               + n);
   VirtualNodeState pState =
       createNodeState(
           parent, NameConstants.JCR_PROPERTYDEFINITION, id, NameConstants.NT_PROPERTYDEFINITION);
   // add properties
   if (!propDef.definesResidual()) {
     pState.setPropertyValue(NameConstants.JCR_NAME, InternalValue.create(propDef.getName()));
   }
   pState.setPropertyValue(
       NameConstants.JCR_AUTOCREATED, InternalValue.create(propDef.isAutoCreated()));
   pState.setPropertyValue(
       NameConstants.JCR_MANDATORY, InternalValue.create(propDef.isMandatory()));
   pState.setPropertyValue(
       NameConstants.JCR_ONPARENTVERSION,
       InternalValue.create(OnParentVersionAction.nameFromValue(propDef.getOnParentVersion())));
   pState.setPropertyValue(
       NameConstants.JCR_PROTECTED, InternalValue.create(propDef.isProtected()));
   pState.setPropertyValue(NameConstants.JCR_MULTIPLE, InternalValue.create(propDef.isMultiple()));
   pState.setPropertyValue(
       NameConstants.JCR_REQUIREDTYPE,
       InternalValue.create(PropertyType.nameFromValue(propDef.getRequiredType()).toUpperCase()));
   InternalValue[] defVals = InternalValue.create(propDef.getDefaultValues());
   // retrieve the property type from the first default value present with
   // the property definition. in case no default values are defined,
   // fallback to PropertyType.STRING in order to avoid creating a property
   // with type UNDEFINED which is illegal.
   int defValsType = PropertyType.STRING;
   if (defVals != null && defVals.length > 0) {
     defValsType = defVals[0].getType();
   }
   if (defVals != null) {
     pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, defValsType, defVals);
   }
   QValueConstraint[] vc = propDef.getValueConstraints();
   InternalValue[] vals = new InternalValue[vc.length];
   for (int i = 0; i < vc.length; i++) {
     vals[i] = InternalValue.create(vc[i].getString());
   }
   pState.setPropertyValues(NameConstants.JCR_VALUECONSTRAINTS, PropertyType.STRING, vals);
   return pState;
 }
コード例 #2
0
 /**
  * Create a new JCR property definition from the given <code>QPropertyDefinition</code>.
  *
  * @param qPd A SPI property definition.
  * @return the corresponding JCR property definition.
  * @throws RepositoryException if an error occurs.
  */
 public PropertyDefinition create(QPropertyDefinition qPd) throws RepositoryException {
   PropertyDefinitionTemplate pt = ntMgr.createPropertyDefinitionTemplate();
   pt.setName(getJCRName(qPd.getName()));
   pt.setAutoCreated(qPd.isAutoCreated());
   pt.setMandatory(qPd.isMandatory());
   pt.setOnParentVersion(qPd.getOnParentVersion());
   pt.setProtected(qPd.isProtected());
   pt.setRequiredType(qPd.getRequiredType());
   pt.setMultiple(qPd.isMultiple());
   pt.setFullTextSearchable(qPd.isFullTextSearchable());
   pt.setValueConstraints(
       createValueConstraints(qPd.getRequiredType(), qPd.getValueConstraints()));
   pt.setAvailableQueryOperators(qPd.getAvailableQueryOperators());
   pt.setQueryOrderable(qPd.isQueryOrderable());
   pt.setDefaultValues(createValues(qPd.getDefaultValues()));
   return pt;
 }