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);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class PropertyImpl method internalSetValue.
/**
* @param values
* @param type
* @throws ConstraintViolationException
* @throws RepositoryException
*/
protected void internalSetValue(InternalValue[] values, int type) throws ConstraintViolationException, RepositoryException {
// check for null value
if (values == null) {
// setting a property to null removes it automatically
((NodeImpl) getParent()).removeChildProperty(((PropertyId) id).getName());
return;
}
ArrayList<InternalValue> list = new ArrayList<InternalValue>();
// compact array (purge null entries)
for (InternalValue v : values) {
if (v != null) {
list.add(v);
}
}
values = list.toArray(new InternalValue[list.size()]);
// modify the state of this property
PropertyState thisState = (PropertyState) getOrCreateTransientItemState();
// free old values as necessary
InternalValue[] oldValues = thisState.getValues();
if (oldValues != null) {
for (InternalValue old : oldValues) {
if (old != null && old.getType() == BINARY) {
// make sure temporarily allocated data is discarded
// before overwriting it
old.discard();
}
}
}
// set new values
thisState.setValues(values);
// set type
if (type == UNDEFINED) {
// fallback to default type
type = STRING;
}
thisState.setType(type);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class PropertyImpl method setValue.
public synchronized void setValue(Value value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
// check state of this instance
sanityCheck();
// check pre-conditions for setting property value
checkSetValue(false);
// check type according to definition of this property
final PropertyDefinition definition = data.getPropertyDefinition();
int reqType = definition.getRequiredType();
if (reqType == UNDEFINED) {
if (value != null) {
reqType = value.getType();
} else {
reqType = STRING;
}
}
if (value == null) {
internalSetValue(null, reqType);
return;
}
InternalValue internalValue;
if (reqType != value.getType()) {
// type conversion required
Value targetVal = ValueHelper.convert(value, reqType, getSession().getValueFactory());
internalValue = InternalValue.create(targetVal, sessionContext, sessionContext.getDataStore());
} else {
// no type conversion required
internalValue = InternalValue.create(value, sessionContext, sessionContext.getDataStore());
}
internalSetValue(new InternalValue[] { internalValue }, reqType);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class PropertyImpl method setValue.
/**
* Sets the values of this property.
*
* @param values property values (possibly <code>null</code>)
* @param valueType default value type if not set in the node type,
* may be {@link PropertyType#UNDEFINED}
* @throws RepositoryException if the property values could not be set
*/
public void setValue(Value[] values, int valueType) throws RepositoryException {
// check state of this instance
sanityCheck();
// check pre-conditions for setting property value
checkSetValue(true);
if (values != null) {
// check type of values
int firstValueType = UNDEFINED;
for (Value value : values) {
if (value != null) {
if (firstValueType == UNDEFINED) {
firstValueType = value.getType();
} else if (firstValueType != value.getType()) {
throw new ValueFormatException("inhomogeneous type of values");
}
}
}
}
final PropertyDefinition definition = data.getPropertyDefinition();
int reqType = definition.getRequiredType();
if (reqType == UNDEFINED) {
// use the given type as property type
reqType = valueType;
}
InternalValue[] internalValues = null;
// convert to internal values of correct type
if (values != null) {
internalValues = new InternalValue[values.length];
// check type of values
for (int i = 0; i < values.length; i++) {
Value value = values[i];
if (value != null) {
if (reqType == UNDEFINED) {
// Use the type of the fist value as the type
reqType = value.getType();
}
if (reqType != value.getType()) {
value = ValueHelper.convert(value, reqType, getSession().getValueFactory());
}
internalValues[i] = InternalValue.create(value, sessionContext, sessionContext.getDataStore());
} else {
internalValues[i] = null;
}
}
}
internalSetValue(internalValues, reqType);
}
Aggregations