use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class BatchTest method testEmptyValueArray.
public void testEmptyValueArray() throws RepositoryException {
NodeId nid = getNodeId(testPath);
Name propName = resolver.getQName("mvProperty");
Batch b = rs.createBatch(si, nid);
b.addProperty(nid, propName, new QValue[0]);
rs.submit(b);
PropertyId pid = getPropertyId(nid, propName);
PropertyInfo pi = rs.getPropertyInfo(si, pid);
assertTrue(pi.isMultiValued());
assertEquals(Arrays.asList(new QValue[0]), Arrays.asList(pi.getValues()));
assertFalse(pi.getType() == PropertyType.UNDEFINED);
Iterator<? extends ItemInfo> it = rs.getItemInfos(si, nid);
while (it.hasNext()) {
ItemInfo info = it.next();
if (!info.denotesNode()) {
PropertyInfo pInfo = (PropertyInfo) info;
if (propName.equals((pInfo.getId().getName()))) {
assertTrue(pi.isMultiValued());
assertEquals(Arrays.asList(new QValue[0]), Arrays.asList(pi.getValues()));
assertFalse(pi.getType() == PropertyType.UNDEFINED);
break;
}
}
}
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class ItemInfoJsonHandler method endArray.
public void endArray() throws IOException {
try {
if (propertyType == PropertyType.UNDEFINED) {
if (propValues.isEmpty()) {
// make sure that type is set for mv-properties with empty value array.
propertyType = vFactory.retrieveType(getValueURI());
} else {
propertyType = propValues.get(0).getType();
}
}
// create multi-valued property info
NodeInfoImpl parent = getCurrentNodeInfo();
Path p = pFactory.create(parent.getPath(), name, true);
PropertyId id = idFactory.createPropertyId(parent.getId(), name);
PropertyInfoImpl propInfo = new PropertyInfoImpl(id, p, propertyType, propValues.toArray(new QValue[propValues.size()]));
propInfo.checkCompleted();
getCurrentPropInfos().add(propInfo);
} catch (RepositoryException e) {
throw new IOException(e.getMessage(), e);
} finally {
// reset property-related handler state
propertyType = PropertyType.UNDEFINED;
multiValuedProperty = false;
propValues.clear();
name = null;
}
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class NodeInfoImpl method createSerializableNodeInfo.
/**
* Creates a new serializable <code>NodeInfo</code> for the given
* <code>NodeInfo</code>.
*
* @param nodeInfo
*/
public static NodeInfo createSerializableNodeInfo(NodeInfo nodeInfo, final IdFactory idFactory) {
if (nodeInfo instanceof Serializable) {
return nodeInfo;
} else {
List<PropertyId> serRefs = new ArrayList<PropertyId>();
for (PropertyId ref : nodeInfo.getReferences()) {
NodeId parentId = ref.getParentId();
parentId = idFactory.createNodeId(parentId.getUniqueID(), parentId.getPath());
serRefs.add(idFactory.createPropertyId(parentId, ref.getName()));
}
NodeId nodeId = nodeInfo.getId();
nodeId = idFactory.createNodeId(nodeId.getUniqueID(), nodeId.getPath());
final Iterator<PropertyId> propIds = nodeInfo.getPropertyIds();
final Iterator<ChildInfo> childInfos = nodeInfo.getChildInfos();
return new NodeInfoImpl(nodeInfo.getPath(), nodeId, nodeInfo.getIndex(), nodeInfo.getNodetype(), nodeInfo.getMixins(), serRefs.iterator(), new Iterator<PropertyId>() {
public boolean hasNext() {
return propIds.hasNext();
}
public PropertyId next() {
PropertyId propId = propIds.next();
NodeId parentId = propId.getParentId();
idFactory.createNodeId(parentId.getUniqueID(), parentId.getPath());
return idFactory.createPropertyId(parentId, propId.getName());
}
public void remove() {
throw new UnsupportedOperationException();
}
}, ((childInfos == null) ? null : new Iterator<ChildInfo>() {
public boolean hasNext() {
return childInfos.hasNext();
}
public ChildInfo next() {
ChildInfo cInfo = childInfos.next();
if (cInfo instanceof Serializable) {
return cInfo;
} else {
return new ChildInfoImpl(cInfo.getName(), cInfo.getUniqueID(), cInfo.getIndex());
}
}
public void remove() {
throw new UnsupportedOperationException();
}
}));
}
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class NodeImpl method getReferences.
/**
* @param name
* @param weak
* @return
* @throws RepositoryException
*/
private LazyItemIterator getReferences(String name, boolean weak) throws RepositoryException {
checkStatus();
Name propName = (name == null) ? null : getQName(name);
Iterator<PropertyId> itr = getNodeState().getNodeReferences(propName, weak);
return new LazyItemIterator(getItemManager(), session.getHierarchyManager(), itr);
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class RepositoryServiceImpl method getItemInfos.
/**
* {@inheritDoc}
*/
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws ItemNotFoundException, RepositoryException {
if (!itemId.denotesNode()) {
PropertyId propertyId = (PropertyId) itemId;
PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, propertyId);
return Iterators.singleton(propertyInfo);
} else {
NodeId nodeId = (NodeId) itemId;
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Node node = getNode(nodeId, sInfo);
Name ntName = null;
try {
ntName = sInfo.getNamePathResolver().getQName(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString());
} catch (NameException e) {
// ignore. should never occur
}
int depth = batchReadConfig.getDepth(ntName);
if (depth == BatchReadConfig.DEPTH_DEFAULT) {
NodeInfo info;
try {
info = new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
} catch (NameException e) {
throw new RepositoryException(e);
}
return Collections.singletonList(info).iterator();
} else {
final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
ItemVisitor visitor = new TraversingItemVisitor(false, depth) {
@Override
protected void entering(Property property, int i) throws RepositoryException {
try {
itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamePathResolver(), getQValueFactory()));
} catch (NameException e) {
throw new RepositoryException(e);
}
}
@Override
protected void entering(Node node, int i) throws RepositoryException {
try {
itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver()));
} catch (NameException e) {
throw new RepositoryException(e);
}
}
@Override
protected void leaving(Property property, int i) {
// nothing to do
}
@Override
protected void leaving(Node node, int i) {
// nothing to do
}
};
visitor.visit(node);
return itemInfos.iterator();
}
}
}
Aggregations