/** * Copy constructor. * * @param propDef some other property definition. */ public QPropertyDefinitionImpl(QPropertyDefinition propDef) { this(propDef.getName(), propDef.getDeclaringNodeType(), propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(), propDef.isProtected(), propDef.getDefaultValues(), propDef.isMultiple(), propDef.getRequiredType(), propDef.getValueConstraints(), propDef.getAvailableQueryOperators(), propDef.isFullTextSearchable(), propDef.isQueryOrderable()); }
/** * Copy constructor. * * @param propDef some other property definition. */ public QPropertyDefinitionImpl(QPropertyDefinition propDef) { this(propDef.getName(), propDef.getDeclaringNodeType(), propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(), propDef.isProtected(), propDef.getDefaultValues(), propDef.isMultiple(), propDef.getRequiredType(), propDef.getValueConstraints()); }
private QPropertyDefinitionId(QPropertyDefinition def) { declaringNodeType = def.getDeclaringNodeType(); name = def.getName(); }
/** Test for the <code>binary</code> property definition type. */ public void testBinaryProperty() { QPropertyDefinition def = getPropDef("propertyNodeType", "binaryProperty"); assertEquals("binaryProperty requiredType", PropertyType.BINARY, def.getRequiredType()); assertEquals("binaryProperty valueConstraints", 1, def.getValueConstraints().length); assertEquals("binaryProperty valueConstraints[0]", "[0,)", (def.getValueConstraints())[0].getString()); assertNull("binaryProperty defaultValues", def.getDefaultValues()); }
/** * Compares two property definitions for equality. Returns <code>true</code> * if the given object is a property definition and has the same attributes * as this property definition. * * @param obj the object to compare this property definition with * @return <code>true</code> if the object is equal to this property definition, * <code>false</code> otherwise * @see Object#equals(Object) */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof QPropertyDefinition) { QPropertyDefinition other = (QPropertyDefinition) obj; return super.equals(obj) && requiredType == other.getRequiredType() && multiple == other.isMultiple() && fullTextSearchable == other.isFullTextSearchable() && queryOrderable == other.isQueryOrderable() && ((valueConstraints == null || other.getValueConstraints() == null) ? (valueConstraints == other.getValueConstraints()) : new HashSet(Arrays.asList(valueConstraints)).equals(new HashSet(Arrays.asList(other.getValueConstraints())))) && ((defaultValues == null || other.getDefaultValues() == null) ? (defaultValues == other.getDefaultValues()) : new HashSet(Arrays.asList(defaultValues)).equals(new HashSet(Arrays.asList(other.getDefaultValues())))) && new HashSet(Arrays.asList(availableQueryOperators)).equals(new HashSet(Arrays.asList(other.getAvailableQueryOperators()))); } return false; }
if (def.isProtected()) { return false; if (def.isMultiple()) { return false; if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) { targetType = def.getRequiredType(); } else {
/** * Compares two property definitions for equality. Returns <code>true</code> * if the given object is a property defintion and has the same attributes * as this property definition. * * @param obj the object to compare this property definition with * @return <code>true</code> if the object is equal to this property definition, * <code>false</code> otherwise * @see Object#equals(Object) */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof QPropertyDefinition) { QPropertyDefinition other = (QPropertyDefinition) obj; return super.equals(obj) && requiredType == other.getRequiredType() && Arrays.equals(valueConstraints, other.getValueConstraints()) && Arrays.equals(defaultValues, other.getDefaultValues()) && multiple == other.isMultiple(); } return false; }
public void nodeTypeRegistered(Name ntName) { try { QNodeTypeDefinition def = registry.getNodeTypeDef(ntName); QPropertyDefinition[] propDefs = def.getPropertyDefs(); synchronized (typeMapping) { for (QPropertyDefinition propDef : propDefs) { int type = propDef.getRequiredType(); if (!propDef.definesResidual() && type != PropertyType.UNDEFINED) { Name name = propDef.getName(); // only remember defined property types TypeMapping[] types = typeMapping.get(name); if (types == null) { types = new TypeMapping[1]; } else { TypeMapping[] tmp = new TypeMapping[types.length + 1]; System.arraycopy(types, 0, tmp, 0, types.length); types = tmp; } types[types.length - 1] = new TypeMapping(ntName, type, propDef.isMultiple()); typeMapping.put(name, types); } } } } catch (NoSuchNodeTypeException e) { log.error("Unable to get newly registered node type definition for name: " + ntName); } }
throws RepositoryException { QValue[] genValues = null; QValue[] qDefaultValues = def.getDefaultValues(); if (qDefaultValues != null && qDefaultValues.length > 0) { genValues = qDefaultValues; } else if (def.isAutoCreated()) { Name declaringNT = def.getDeclaringNodeType(); Name name = def.getName();
/** Test for the empty item definition. */ public void testEmptyItem() { QPropertyDefinition def = getPropDef("itemNodeType", "emptyItem"); assertEquals("emptyItem autoCreate", false, def.isAutoCreated()); assertEquals("emptyItem mandatory", false, def.isMandatory()); assertEquals("emptyItem onParentVersion", OnParentVersionAction.IGNORE, def.getOnParentVersion()); assertEquals("emptyItem protected", false, def.isProtected()); }
if (def.isProtected()) { return; } else { if (!def.isAutoCreated()) { log.warn("Property "+node.safeGetJCRPath()+"/"+name+" already exist"); Reference ref = new Reference(name, values, def.isMultiple()); if (derefNodes.containsKey(node.getNodeId())) { List<Reference> refs = derefNodes.get(node.getNodeId()); if (!def.isMandatory()) { return; if (multiple || def.isMultiple()) { node.setProperty(name, new Value[] {}, type); return; if (!multiple && values.length == 1 && !def.isMultiple()) { try {
prop = (PropertyState) itemOps.getItemState(idExisting); def = itemOps.findApplicablePropertyDefinition(prop.getName(), prop.getType(), prop.isMultiValued(), node); if (def.isProtected()) { return; if (!def.isAutoCreated() || (prop.getType() != type && type != PropertyType.UNDEFINED) || def.isMultiple() != prop.isMultiValued()) { throw new ItemExistsException(itemOps.safeGetJCRPath(prop.getPropertyId())); if (def.isProtected()) { if (values.length != 1 && !def.isMultiple()) { throw new ConstraintViolationException(itemOps.safeGetJCRPath(prop.getPropertyId()) + " is not multi-valued");
private void complete(AddProperty operation) throws RepositoryException { if (operation.getParentState().getHierarchyEntry() != this) { throw new IllegalArgumentException(); } PropertyEntry pe = getPropertyEntry(operation.getPropertyName()); if (pe != null && pe.getStatus() == Status.NEW) { switch (operation.getStatus()) { case Operation.STATUS_PERSISTED: // for autocreated/protected props, mark to be reloaded // upon next access. PropertyState addedState = (PropertyState) ((PropertyEntryImpl) pe).internalGetItemState(); addedState.setStatus(Status.EXISTING); QPropertyDefinition pd = addedState.getDefinition(); if (pd.isAutoCreated() || pd.isProtected()) { pe.invalidate(true); } // else: assume added property is up to date. break; case Operation.STATUS_UNDO: pe.revert(); break; default: // ignore } } // else: no such prop entry or entry has already been persisted // e.g due to external modifications merged into this NodeEntry. }
private QPropertyDefinition getMatchingPropDef(QPropertyDefinition[] defs, int type, boolean multiValued) { QPropertyDefinition match = null; for (QPropertyDefinition pd : defs) { int reqType = pd.getRequiredType(); // match type if (reqType == PropertyType.UNDEFINED || type == PropertyType.UNDEFINED || reqType == type) { // match multiValued flag if (multiValued == pd.isMultiple()) { // found match if (pd.getRequiredType() != PropertyType.UNDEFINED) { // found best possible match, get outta here return pd; } else { if (match == null) { match = pd; } } } } } return match; }
QPropertyDefinition pd = defProvider.getQPropertyDefinition(nState.getAllNodeTypeNames(), NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true); QValue[] mixinValue = getQValues(mixinNames, qValueFactory); addPropertyState(nState, pd.getName(), pd.getRequiredType(), mixinValue, pd, operation.getOptions());
private static boolean isAutoCreated(Name propertyName, EffectiveNodeType ent) { for (QPropertyDefinition def : ent.getAutoCreatePropDefs()) { if (def.getName().equals(propertyName)) { return true; } } return false; }
/** * {@inheritDoc} */ public boolean isMultiple() { return ((QPropertyDefinition) itemDef).isMultiple(); }
/** * {@inheritDoc} */ public String[] getValueConstraints() { QPropertyDefinition pd = (QPropertyDefinition) itemDef; QValueConstraint[] constraints = pd.getValueConstraints(); if (constraints == null || constraints.length == 0) { return new String[0]; } String[] vca = new String[constraints.length]; for (int i = 0; i < constraints.length; i++) { try { ValueConstraint vc = ValueConstraint.create(pd.getRequiredType(), constraints[i].getString()); vca[i] = vc.getDefinition(resolver); } catch (InvalidConstraintException e) { log.warn("Internal error during conversion of constraint.", e); vca[i] = constraints[i].getString(); } } return vca; }
/** * Computes the auto generated values and falls back to the default values * specified in the property definition * @param state parent state * @param def property definition * @param useDefaultValues if <code>true</code> the default values are respected * @return the values or <code>null</code> * @throws RepositoryException if the values cannot be computed. */ private InternalValue[] computeAutoValues(NodeStateEx state, QPropertyDefinition def, boolean useDefaultValues) throws RepositoryException { // compute system generated values if necessary InternalValue[] values = new NodeTypeInstanceHandler(session.getUserID()). computeSystemGeneratedPropertyValues(state.getState(), def); if (values == null && useDefaultValues) { values = InternalValue.create(def.getDefaultValues()); } // avoid empty value array for single value property if (values != null && values.length == 0 && !def.isMultiple()) { values = null; } return values; } }
/** * {@inheritDoc} */ public int getRequiredType() { return ((QPropertyDefinition) itemDef).getRequiredType(); }