use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class GetReferencesNodeTest method testGetReferencesNeverFromVersions.
/**
* Node.getReferences() never returns a reference that is stored in a
* version. 1. Create some test nodes 2. Create a version 1.0 with reference
* 3. Create a new version 1.1 after changing reference 4. Check if
* reference is found by getReferences()
*/
public void testGetReferencesNeverFromVersions() throws RepositoryException, NotExecutableException {
// create some test nodes
initTestNodes();
// create a version 1.0 and reference test node
testNode.checkout();
ensureCanSetProperty(testNode, propertyName1, PropertyType.REFERENCE, false);
testNode.setProperty(propertyName1, nodeToBeReferenced);
testRootNode.getSession().save();
testNode.checkin();
// create a version 1.1 and remove reference
testNode.checkout();
testNode.getProperty(propertyName1).remove();
testRootNode.getSession().save();
testNode.checkin();
// check if reference is returned
boolean nodeToBeReferencedIsReference = false;
PropertyIterator propIter = nodeToBeReferenced.getReferences();
while (propIter.hasNext()) {
nodeToBeReferencedIsReference = true;
fail("Reference found in version.");
// not successful
}
// references in versions should not be found
assertFalse(nodeToBeReferencedIsReference);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class NodeImpl method removeMixin.
/**
* @see Node#removeMixin(String)
*/
public void removeMixin(String mixinName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
checkIsWritable();
Name ntName = getQName(mixinName);
List<Name> mixinValue = getMixinTypes();
// remove name of target mixin
if (!mixinValue.remove(ntName)) {
throw new NoSuchNodeTypeException("Cannot remove mixin '" + mixinName + "': Nodetype is not present on this node.");
}
// mix:referenceable needs additional assertion: the mixin cannot be
// removed, if any references are left to this node.
NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType(ntName);
if (mixin.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
if (!entRemaining.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
PropertyIterator iter = getReferences();
if (iter.hasNext()) {
throw new ConstraintViolationException("Mixin type " + mixinName + " can not be removed: the node is being referenced through at least one property of type REFERENCE");
}
}
}
/*
* mix:lockable: the mixin cannot be removed if the node is currently
* locked even if the editing session is the lock holder.
*/
if (mixin.isNodeType((NameConstants.MIX_LOCKABLE))) {
EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
if (!entRemaining.includesNodeType(NameConstants.MIX_LOCKABLE) && isLocked()) {
throw new ConstraintViolationException(mixinName + " can not be removed: the node is locked.");
}
}
// delegate to operation
Name[] mixins = mixinValue.toArray(new Name[mixinValue.size()]);
Operation op = SetMixin.create(getNodeState(), mixins);
session.getSessionItemStateManager().execute(op);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class HierarchyNodeTest method dump.
/** Recursively outputs the contents of the given node. */
private void dump(Node node) throws RepositoryException {
// Then output the properties
PropertyIterator properties = node.getProperties();
Set<String> set = new HashSet<String>();
while (properties.hasNext()) {
Property property = properties.nextProperty();
set.add(property.getName());
}
if (node.getPrimaryNodeType().getName().equals(ntFolder)) {
assertTrue(hierarchyNodeProps.size() == set.size() && hierarchyNodeProps.containsAll(set));
} else if (node.getPrimaryNodeType().getName().equals(ntFile)) {
assertTrue(hierarchyNodeProps.size() == set.size() && hierarchyNodeProps.containsAll(set));
} else if (node.getPrimaryNodeType().getName().equals(ntResource)) {
assertTrue(resourceProps.size() == set.size() && resourceProps.containsAll(set));
}
// Finally output all the child nodes recursively
NodeIterator nodes = node.getNodes();
while (nodes.hasNext()) {
dump(nodes.nextNode());
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class GetPropertyTest method testGetDeepProperty.
public void testGetDeepProperty() throws RepositoryException {
Node n2 = testRootNode.getNode(nodeName1).addNode(nodeName2);
testRootNode.save();
// other session directly accesses n2.
// consequently n1 is not yet resolved
Node node2 = (Node) readOnly.getItem(n2.getPath());
// now try to access properties below n1 -> should be existing although
// n1 has not yet been resolved.
assertTrue(readOnly.itemExists(prop1Path));
Property p1 = (Property) readOnly.getItem(prop1Path);
assertTrue(p1.isSame(node2.getProperty("../" + Text.getName(prop1Path))));
PropertyIterator it = node2.getParent().getProperties();
assertTrue(it.getSize() >= 3);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class RepositoryServiceImpl method getReferences.
/**
* {@inheritDoc}
*/
public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId, Name propertyName, boolean weakReferences) throws ItemNotFoundException, RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Node node = getNode(nodeId, sInfo);
String jcrName = (propertyName == null) ? null : sInfo.getNamePathResolver().getJCRName(propertyName);
List<PropertyId> ids = new ArrayList<PropertyId>();
PropertyIterator it;
if (weakReferences) {
it = node.getWeakReferences(jcrName);
} else {
it = node.getReferences(jcrName);
}
while (it.hasNext()) {
ids.add(idFactory.createPropertyId(it.nextProperty(), sInfo.getNamePathResolver()));
}
return ids.iterator();
}
Aggregations