use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class CanSetPropertyBooleanTest method testConversions.
/**
* Tests if NodeType.canSetProperty(String propertyName, Value value)
* returns true if value and its type are convertible to BooleanValue.
*/
public void testConversions() throws NotExecutableException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BOOLEAN, false, false, false, false);
if (propDef == null) {
throw new NotExecutableException("No boolean property def that meets the " + "requirements of the test has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value stringValue = NodeTypeUtil.getValueOfType(session, PropertyType.STRING);
assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Boolean and value is a StringValue", nodeType.canSetProperty(propDef.getName(), stringValue));
Value binaryValue = NodeTypeUtil.getValueOfType(session, PropertyType.BINARY);
assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Boolean and value is a BinaryValue" + "in UTF-8", nodeType.canSetProperty(propDef.getName(), binaryValue));
Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a DateValue", nodeType.canSetProperty(propDef.getName(), dateValue));
Value doubleValue = NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE);
assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValue));
Value longValue = NodeTypeUtil.getValueOfType(session, PropertyType.LONG);
assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a LongValue", nodeType.canSetProperty(propDef.getName(), longValue));
Value booleanValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Boolean and value is a BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValue));
Value nameValue = NodeTypeUtil.getValueOfType(session, PropertyType.NAME);
assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a NameValue", nodeType.canSetProperty(propDef.getName(), nameValue));
Value pathValue = NodeTypeUtil.getValueOfType(session, PropertyType.PATH);
assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a PathValue", nodeType.canSetProperty(propDef.getName(), pathValue));
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method getPropertyDefinition.
/**
* Retrieve the <code>PropertyDefinition</code> for the given
* <code>QPropertyDefinition</code>.
*
* @param def
* @return
*/
@Override
public PropertyDefinition getPropertyDefinition(QPropertyDefinition def) {
synchronized (pdCache) {
PropertyDefinition pdi = pdCache.get(def);
if (pdi == null) {
pdi = new PropertyDefinitionImpl(def, this, getNamePathResolver(), valueFactory);
pdCache.put(def, pdi);
}
return pdi;
}
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method toString.
//-------------------------------------------------------------< Object >---
/**
* Returns the the state of this instance in a human readable format.
*/
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("NodeTypeManager (" + super.toString() + ")\n");
builder.append("All NodeTypes:\n");
try {
NodeTypeIterator iter = this.getAllNodeTypes();
while (iter.hasNext()) {
NodeType nt = iter.nextNodeType();
builder.append(nt.getName());
builder.append("\n\tSupertypes");
for (NodeType supertype : nt.getSupertypes()) {
builder.append("\n\t\t" + supertype.getName());
}
builder.append("\n\tMixin\t" + nt.isMixin());
builder.append("\n\tOrderableChildNodes\t" + nt.hasOrderableChildNodes());
builder.append("\n\tPrimaryItemName\t" + (nt.getPrimaryItemName() == null ? "<null>" : nt.getPrimaryItemName()));
for (PropertyDefinition aPd : nt.getPropertyDefinitions()) {
builder.append("\n\tPropertyDefinition");
builder.append(" (declared in " + aPd.getDeclaringNodeType().getName() + ") ");
builder.append("\n\t\tName\t\t" + (aPd.getName()));
String type = aPd.getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(aPd.getRequiredType());
builder.append("\n\t\tRequiredType\t" + type);
String[] vca = aPd.getValueConstraints();
StringBuffer constraints = new StringBuffer();
if (vca == null) {
constraints.append("<null>");
} else {
for (String aVca : vca) {
if (constraints.length() > 0) {
constraints.append(", ");
}
constraints.append(aVca);
}
}
builder.append("\n\t\tValueConstraints\t" + constraints.toString());
Value[] defVals = aPd.getDefaultValues();
StringBuffer defaultValues = new StringBuffer();
if (defVals == null) {
defaultValues.append("<null>");
} else {
for (Value defVal : defVals) {
if (defaultValues.length() > 0) {
defaultValues.append(", ");
}
defaultValues.append(defVal.getString());
}
}
builder.append("\n\t\tDefaultValue\t" + defaultValues.toString());
builder.append("\n\t\tAutoCreated\t" + aPd.isAutoCreated());
builder.append("\n\t\tMandatory\t" + aPd.isMandatory());
builder.append("\n\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aPd.getOnParentVersion()));
builder.append("\n\t\tProtected\t" + aPd.isProtected());
builder.append("\n\t\tMultiple\t" + aPd.isMultiple());
}
for (NodeDefinition aNd : nt.getChildNodeDefinitions()) {
builder.append("\n\tNodeDefinition");
builder.append(" (declared in " + aNd.getDeclaringNodeType() + ") ");
builder.append("\n\t\tName\t\t" + aNd.getName());
NodeType[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
for (NodeType reqPrimaryType : reqPrimaryTypes) {
builder.append("\n\t\tRequiredPrimaryType\t" + reqPrimaryType.getName());
}
}
NodeType defPrimaryType = aNd.getDefaultPrimaryType();
if (defPrimaryType != null) {
builder.append("\n\t\tDefaultPrimaryType\t" + defPrimaryType.getName());
}
builder.append("\n\t\tAutoCreated\t" + aNd.isAutoCreated());
builder.append("\n\t\tMandatory\t" + aNd.isMandatory());
builder.append("\n\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aNd.getOnParentVersion()));
builder.append("\n\t\tProtected\t" + aNd.isProtected());
builder.append("\n\t\tAllowsSameNameSiblings\t" + aNd.allowsSameNameSiblings());
}
}
} catch (RepositoryException e) {
builder.append(e.getMessage());
}
return builder.toString();
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class NodeTypeImpl method internalGetPropertyDefinitions.
Collection<PropertyDefinition> internalGetPropertyDefinitions() {
// TODO distinguish between additive and overriding property definitions. See 3.7.6.8 Item Definitions in Subtypes
Collection<PropertyDefinition> definitions = new ArrayList<PropertyDefinition>();
definitions.addAll(Arrays.asList(getDeclaredPropertyDefinitions()));
for (NodeType type : getSupertypes()) {
definitions.addAll(Arrays.asList(type.getDeclaredPropertyDefinitions()));
}
return definitions;
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class NodeTypeImpl method canSetProperty.
@Override
public boolean canSetProperty(String propertyName, Value value) {
if (value == null) {
return canRemoveProperty(propertyName);
}
try {
EffectiveNodeType effective = new EffectiveNodeType(this, getManager());
PropertyDefinition def = effective.getPropertyDefinition(propertyName, false, value.getType(), false);
return !def.isProtected() && meetsTypeConstraints(value, def.getRequiredType()) && meetsValueConstraints(value, def.getValueConstraints());
} catch (RepositoryException e) {
// TODO don't use exceptions for flow control. Use internal method in ReadOnlyNodeTypeManager instead.
log.debug(e.getMessage());
return false;
}
}
Aggregations