} catch (NoSuchElementException e) {
if (defaultType == null) throw e;
}
final TypeFactory<?> typeFactory = expectedType != null ? context.getTypeSystem().getTypeFactory(expectedType) : defaultType;
if (allowMultiValued) {
return new ExtractFromRow() {
@Override
public Object getValueInRow( RowAccessor row ) {
CachedNode node = row.getNode(indexInRow);
if (node == null) return null;
org.modeshape.jcr.value.Property prop = node.getProperty(propName, cache);
if (prop == null || prop.isEmpty()) return null;
if (prop.isSingle()) {
return typeFactory.create(prop.getFirstValue());
}
assert prop.isMultiple();
Object[] result = new Object[prop.size()];
int i = -1;
for (Object value : prop) {
result[++i] = typeFactory.create(value);
}
return result;
}
@Override
public TypeFactory<?> getType() {
return typeFactory;
}
@Override
public String toString() {
return "(" + selectorName + "." + propertyName + ")";
}
};
}
return new ExtractFromRow() {
@Override
public Object getValueInRow( RowAccessor row ) {
CachedNode node = row.getNode(indexInRow);
if (node == null) return null;
org.modeshape.jcr.value.Property prop = node.getProperty(propName, cache);