use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class CanSetPropertyBinaryTest method testConversionsMultiple.
/**
* Tests if NodeType.canSetProperty(String propertyName, Value[] values)
* returns true if all values and its types are convertible to BinaryValue.
*/
public void testConversionsMultiple() throws NotExecutableException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BINARY, true, false, false, false);
if (propDef == null) {
throw new NotExecutableException("No multiple string property def that meets the " + "requirements of the test has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value binaryValue = NodeTypeUtil.getValueOfType(session, PropertyType.BINARY);
Value stringValue = NodeTypeUtil.getValueOfType(session, PropertyType.STRING);
Value[] stringValues = new Value[] { stringValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type StringValue", nodeType.canSetProperty(propDef.getName(), stringValues));
Value[] binaryValues = new Value[] { binaryValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type BinaryValue", nodeType.canSetProperty(propDef.getName(), binaryValues));
Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
Value[] dateValues = new Value[] { dateValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type DateValue", nodeType.canSetProperty(propDef.getName(), dateValues));
Value doubleValue = NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE);
Value[] doubleValues = new Value[] { doubleValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValues));
Value longValue = NodeTypeUtil.getValueOfType(session, PropertyType.LONG);
Value[] longValues = new Value[] { longValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type LongValue", nodeType.canSetProperty(propDef.getName(), longValues));
Value booleanValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
Value[] booleanValues = new Value[] { booleanValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValues));
Value nameValue = NodeTypeUtil.getValueOfType(session, PropertyType.NAME);
Value[] nameValues = new Value[] { nameValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type NameValue", nodeType.canSetProperty(propDef.getName(), nameValues));
Value pathValue = NodeTypeUtil.getValueOfType(session, PropertyType.PATH);
Value[] pathValues = new Value[] { pathValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type PathValue", nodeType.canSetProperty(propDef.getName(), pathValues));
}
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 PropertyTest method testMixTitleOnUnstructured.
public void testMixTitleOnUnstructured() throws Exception {
Node n = testRootNode.addNode("unstructured", JcrConstants.NT_UNSTRUCTURED);
n.addMixin("mix:title");
superuser.save();
// create jcr:title property with type LONG => declaring NT is nt:unstructured
Property title = n.setProperty("jcr:title", 12345);
assertEquals(PropertyType.LONG, title.getType());
PropertyDefinition def = title.getDefinition();
assertEquals(JcrConstants.NT_UNSTRUCTURED, def.getDeclaringNodeType().getName());
assertEquals(PropertyType.UNDEFINED, def.getRequiredType());
// changing value to STRING => ValueFormatException expected
try {
title.setValue("str");
fail();
} catch (ValueFormatException e) {
// success
}
// re-setting property to STRING -> change definition => declaring NT is mix:title
n.setProperty("jcr:title", "str");
assertEquals(PropertyType.STRING, title.getType());
assertEquals(PropertyType.STRING, title.getValue().getType());
def = title.getDefinition();
assertEquals("mix:title", def.getDeclaringNodeType().getName());
assertEquals(PropertyType.STRING, def.getRequiredType());
}
Aggregations