use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class NodeTypeImpl method canSetProperty.
/**
* {@inheritDoc}
*/
public boolean canSetProperty(String propertyName, Value value) {
if (value == null) {
// setting a property to null is equivalent of removing it
return canRemoveItem(propertyName);
}
try {
Name name = resolver.getQName(propertyName);
QPropertyDefinition def;
try {
// try to get definition that matches the given value type
def = ent.getApplicablePropertyDef(name, value.getType(), false);
} catch (ConstraintViolationException cve) {
// fallback: ignore type
def = ent.getApplicablePropertyDef(name, PropertyType.UNDEFINED, false);
}
if (def.isProtected()) {
return false;
}
if (def.isMultiple()) {
return false;
}
int targetType;
if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) {
// type conversion required
targetType = def.getRequiredType();
} else {
// no type conversion required
targetType = value.getType();
}
// perform type conversion as necessary and create InternalValue
// from (converted) Value
InternalValue internalValue;
if (targetType != value.getType()) {
// type conversion required
Value targetVal = ValueHelper.convert(value, targetType, valueFactory);
internalValue = InternalValue.create(targetVal, resolver, store);
} else {
// no type conversion required
internalValue = InternalValue.create(value, resolver, store);
}
EffectiveNodeType.checkSetPropertyValueConstraints(def, new InternalValue[] { internalValue });
return true;
} catch (NameException be) {
// implementation specific exception, fall through
} catch (RepositoryException re) {
// fall through
}
return false;
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class NodeTypeWriter method addNodeTypeDef.
/**
* Builds a node type definition element under the current element.
*
* @param def node type definition
* @throws RepositoryException if the default property values
* cannot be serialized
* @throws NamespaceException if the node type definition contains
* invalid namespace references
*/
private void addNodeTypeDef(QNodeTypeDefinition def) throws NamespaceException, RepositoryException {
builder.startElement(Constants.NODETYPE_ELEMENT);
// simple attributes
builder.setAttribute(Constants.NAME_ATTRIBUTE, resolver.getJCRName(def.getName()));
builder.setAttribute(Constants.ISMIXIN_ATTRIBUTE, def.isMixin());
builder.setAttribute(Constants.ISQUERYABLE_ATTRIBUTE, def.isQueryable());
builder.setAttribute(Constants.ISABSTRACT_ATTRIBUTE, def.isAbstract());
builder.setAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE, def.hasOrderableChildNodes());
// primary item name
Name item = def.getPrimaryItemName();
if (item != null) {
builder.setAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE, resolver.getJCRName(item));
} else {
builder.setAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE, "");
}
// supertype declarations
Name[] supertypes = def.getSupertypes();
if (supertypes.length > 0) {
builder.startElement(Constants.SUPERTYPES_ELEMENT);
for (Name supertype : supertypes) {
builder.addContentElement(Constants.SUPERTYPE_ELEMENT, resolver.getJCRName(supertype));
}
builder.endElement();
}
// property definitions
QPropertyDefinition[] properties = def.getPropertyDefs();
for (QPropertyDefinition property : properties) {
addPropDef(property);
}
// child node definitions
QNodeDefinition[] nodes = def.getChildNodeDefs();
for (QNodeDefinition node : nodes) {
addChildNodeDef(node);
}
builder.endElement();
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class PropertyTypeRegistry method nodeTypeRegistered.
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);
}
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class TestAll method testDoubleProperty.
/** Test for the <code>double</code> property definition type. */
public void testDoubleProperty() {
QPropertyDefinition def = getPropDef("propertyNodeType", "doubleProperty");
assertEquals("doubleProperty requiredType", PropertyType.DOUBLE, def.getRequiredType());
assertEquals("doubleProperty valueConstraints", 3, def.getValueConstraints().length);
assertEquals("doubleProperty valueConstraints[0]", "[,0.0)", (def.getValueConstraints())[0].getString());
assertEquals("doubleProperty valueConstraints[1]", "(1.0,2.0)", (def.getValueConstraints())[1].getString());
assertEquals("doubleProperty valueConstraints[2]", "(3.0,]", (def.getValueConstraints())[2].getString());
assertEquals("doubleProperty defaultValues", 1, def.getDefaultValues().length);
assertEquals("doubleProperty defaultValues[0]", "1.5", getDefaultValue(def, 0));
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class TestAll method testMultipleProperty.
/** Test for the <code>multiple</code> property definition attribute. */
public void testMultipleProperty() {
QPropertyDefinition def = getPropDef("propertyNodeType", "multipleProperty");
assertEquals("multipleProperty multiple", true, def.isMultiple());
}
Aggregations