use of org.apache.jackrabbit.spi.commons.query.qom.NodeNameImpl in project jackrabbit by apache.
the class Ordering method fromQOM.
/**
* Creates an ordering from a JCR QOM ordering.
*
* @param ordering the JCR QOM ordering specification.
* @param scs the sort comparator source from the search index.
* @param nsMappings the index internal namespace mappings.
* @return an ordering.
* @throws RepositoryException if an error occurs while translating the JCR
* QOM ordering.
*/
public static Ordering fromQOM(final OrderingImpl ordering, final SharedFieldComparatorSource scs, final NamespaceMappings nsMappings) throws RepositoryException {
final Name[] selectorName = new Name[1];
QOMTreeVisitor visitor = new DefaultTraversingQOMTreeVisitor() {
public Object visit(LengthImpl node, Object data) throws Exception {
PropertyValueImpl propValue = (PropertyValueImpl) node.getPropertyValue();
selectorName[0] = propValue.getSelectorQName();
return new SortField(propValue.getPropertyQName().toString(), new LengthSortComparator(nsMappings), !ordering.isAscending());
}
public Object visit(LowerCaseImpl node, Object data) throws Exception {
SortField sf = (SortField) ((DynamicOperandImpl) node.getOperand()).accept(this, data);
selectorName[0] = node.getSelectorQName();
return new SortField(sf.getField(), new LowerCaseSortComparator(sf.getComparatorSource()), !ordering.isAscending());
}
public Object visit(UpperCaseImpl node, Object data) throws Exception {
SortField sf = (SortField) ((DynamicOperandImpl) node.getOperand()).accept(this, data);
selectorName[0] = node.getSelectorQName();
return new SortField(sf.getField(), new UpperCaseSortComparator(sf.getComparatorSource()), !ordering.isAscending());
}
public Object visit(FullTextSearchScoreImpl node, Object data) throws Exception {
selectorName[0] = node.getSelectorQName();
return new SortField(null, SortField.SCORE, !ordering.isAscending());
}
public Object visit(NodeLocalNameImpl node, Object data) throws Exception {
selectorName[0] = node.getSelectorQName();
return new SortField(FieldNames.LOCAL_NAME, SortField.STRING, !ordering.isAscending());
}
public Object visit(NodeNameImpl node, Object data) throws Exception {
selectorName[0] = node.getSelectorQName();
return new SortField(FieldNames.LABEL, SortField.STRING, !ordering.isAscending());
}
public Object visit(PropertyValueImpl node, Object data) throws Exception {
selectorName[0] = node.getSelectorQName();
return new SortField(node.getPropertyQName().toString(), scs, !ordering.isAscending());
}
public Object visit(OrderingImpl node, Object data) throws Exception {
return ((DynamicOperandImpl) node.getOperand()).accept(this, data);
}
};
try {
SortField field = (SortField) ordering.accept(visitor, null);
return new Ordering(selectorName[0], field);
} catch (Exception e) {
throw new RepositoryException(e);
}
}
Aggregations