use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class ItemValidator method validate.
/**
* Checks whether the given property state satisfies the constraints
* specified by its definition. The following validations/checks are
* performed:
* <ul>
* <li>check if the type of the property values does comply with the
* requiredType specified in the property's definition</li>
* <li>check if the property values satisfy the value constraints
* specified in the property's definition</li>
* </ul>
*
* @param propState state of property to be validated
* @throws ConstraintViolationException if any of the validations fail
* @throws RepositoryException if another error occurs
*/
public void validate(PropertyState propState) throws ConstraintViolationException, RepositoryException {
QPropertyDefinition def = context.getItemManager().getDefinition(propState).unwrap();
InternalValue[] values = propState.getValues();
int type = PropertyType.UNDEFINED;
for (InternalValue value : values) {
if (type == PropertyType.UNDEFINED) {
type = value.getType();
} else if (type != value.getType()) {
throw new ConstraintViolationException(safeGetJCRPath(propState.getPropertyId()) + ": inconsistent value types");
}
if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != type) {
throw new ConstraintViolationException(safeGetJCRPath(propState.getPropertyId()) + ": requiredType constraint is not satisfied");
}
}
EffectiveNodeType.checkSetPropertyValueConstraints(def, values);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class LengthOperand method getValues.
/**
* {@inheritDoc}
*/
public Value[] getValues(ScoreNode sn, EvaluationContext context) throws RepositoryException {
PropertyState ps = property.getPropertyState(sn, context);
if (ps == null) {
return EMPTY;
} else {
ValueFactoryImpl vf = (ValueFactoryImpl) context.getSession().getValueFactory();
QValueFactory qvf = vf.getQValueFactory();
InternalValue[] values = ps.getValues();
Value[] lengths = new Value[values.length];
for (int i = 0; i < lengths.length; i++) {
long len;
int type = values[i].getType();
if (type == PropertyType.NAME) {
len = vf.createValue(qvf.create(values[i].getName())).getString().length();
} else if (type == PropertyType.PATH) {
len = vf.createValue(qvf.create(values[i].getPath())).getString().length();
} else {
len = Util.getLength(values[i]);
}
lengths[i] = vf.createValue(len);
}
return lengths;
}
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class NodeTypeInstanceHandler method computeSystemGeneratedPropertyValues.
/**
* Computes the values of well-known system (i.e. protected) properties.
*
* @param parent the parent node state
* @param def the definition of the property to compute
* @return the computed values
*/
public InternalValue[] computeSystemGeneratedPropertyValues(NodeState parent, QPropertyDefinition def) {
InternalValue[] genValues = null;
Name name = def.getName();
Name declaringNT = def.getDeclaringNodeType();
if (NameConstants.JCR_UUID.equals(name)) {
// jcr:uuid property of the mix:referenceable node type
if (NameConstants.MIX_REFERENCEABLE.equals(declaringNT)) {
genValues = new InternalValue[] { InternalValue.create(parent.getNodeId().toString()) };
}
} else if (NameConstants.JCR_PRIMARYTYPE.equals(name)) {
// jcr:primaryType property (of any node type)
genValues = new InternalValue[] { InternalValue.create(parent.getNodeTypeName()) };
} else if (NameConstants.JCR_MIXINTYPES.equals(name)) {
// jcr:mixinTypes property (of any node type)
Set<Name> mixins = parent.getMixinTypeNames();
genValues = new InternalValue[mixins.size()];
int i = 0;
for (Name n : mixins) {
genValues[i++] = InternalValue.create(n);
}
} else if (NameConstants.JCR_CREATED.equals(name)) {
// jcr:created property of a version or a mix:created
if (NameConstants.MIX_CREATED.equals(declaringNT) || NameConstants.NT_VERSION.equals(declaringNT)) {
genValues = new InternalValue[] { InternalValue.create(Calendar.getInstance()) };
}
} else if (NameConstants.JCR_CREATEDBY.equals(name)) {
// jcr:createdBy property of a mix:created
if (NameConstants.MIX_CREATED.equals(declaringNT)) {
genValues = new InternalValue[] { InternalValue.create(userId) };
}
} else if (NameConstants.JCR_LASTMODIFIED.equals(name)) {
// jcr:lastModified property of a mix:lastModified
if (NameConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
genValues = new InternalValue[] { InternalValue.create(Calendar.getInstance()) };
}
} else if (NameConstants.JCR_LASTMODIFIEDBY.equals(name)) {
// jcr:lastModifiedBy property of a mix:lastModified
if (NameConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
genValues = new InternalValue[] { InternalValue.create(userId) };
}
} else if (NameConstants.JCR_ETAG.equals(name)) {
// jcr:etag property of a mix:etag
if (NameConstants.MIX_ETAG.equals(declaringNT)) {
// TODO: provide real implementation
genValues = new InternalValue[] { InternalValue.create("") };
}
}
return genValues;
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class NodeImpl method setMixinTypesProperty.
void setMixinTypesProperty(Set<Name> mixinNames) throws RepositoryException {
NodeState thisState = data.getNodeState();
// get or create jcr:mixinTypes property
PropertyImpl prop;
if (thisState.hasPropertyName(NameConstants.JCR_MIXINTYPES)) {
prop = (PropertyImpl) itemMgr.getItem(new PropertyId(thisState.getNodeId(), NameConstants.JCR_MIXINTYPES));
} else {
// find definition for the jcr:mixinTypes property and create property
PropertyDefinitionImpl def = getApplicablePropertyDefinition(NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true, true);
prop = createChildProperty(NameConstants.JCR_MIXINTYPES, PropertyType.NAME, def);
}
if (mixinNames.isEmpty()) {
// purge empty jcr:mixinTypes property
removeChildProperty(NameConstants.JCR_MIXINTYPES);
return;
}
// call internalSetValue for setting the jcr:mixinTypes property
// to avoid checking of the 'protected' flag
InternalValue[] vals = new InternalValue[mixinNames.size()];
Iterator<Name> iter = mixinNames.iterator();
int cnt = 0;
while (iter.hasNext()) {
vals[cnt++] = InternalValue.create(iter.next());
}
prop.internalSetValue(vals, PropertyType.NAME);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class PropertyImpl method setValue.
/**
* Same as <code>{@link Property#setValue(String[])}</code> except that
* this method takes an array of <code>Name</code> instead of
* <code>String</code> values.
*
* @param names
* @throws ValueFormatException
* @throws VersionException
* @throws LockException
* @throws ConstraintViolationException
* @throws RepositoryException
*/
public void setValue(Name[] names) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
// check state of this instance
sanityCheck();
// check pre-conditions for setting property value
checkSetValue(true);
// check type according to definition of this property
final PropertyDefinition definition = data.getPropertyDefinition();
int reqType = definition.getRequiredType();
if (reqType == UNDEFINED) {
reqType = NAME;
}
InternalValue[] internalValues = null;
// convert to internal values of correct type
if (names != null) {
internalValues = new InternalValue[names.length];
for (int i = 0; i < names.length; i++) {
Name name = names[i];
InternalValue internalValue = null;
if (name != null) {
if (reqType != NAME) {
// type conversion required
Value targetValue = ValueHelper.convert(ValueFormat.getJCRValue(InternalValue.create(name), sessionContext, getSession().getValueFactory()), reqType, getSession().getValueFactory());
internalValue = InternalValue.create(targetValue, sessionContext, sessionContext.getDataStore());
} else {
// no type conversion required
internalValue = InternalValue.create(name);
}
}
internalValues[i] = internalValue;
}
}
internalSetValue(internalValues, reqType);
}
Aggregations