List<Term> terms = new ArrayList<Term>();
String mixinTypesField = npResolver.getJCRName(NameConstants.JCR_MIXINTYPES);
String primaryTypeField = npResolver.getJCRName(NameConstants.JCR_PRIMARYTYPE);
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
NodeType base = null;
try {
base = ntMgr.getNodeType(session.getJCRName(selector.getNodeTypeQName()));
} catch (RepositoryException e) {
// node type does not exist
}
if (base != null && base.isMixin()) {
// search for nodes where jcr:mixinTypes is set to this mixin
Term t = new Term(FieldNames.PROPERTIES,
FieldNames.createNamedValue(mixinTypesField,
npResolver.getJCRName(selector.getNodeTypeQName())));
terms.add(t);
} else {
// search for nodes where jcr:primaryType is set to this type
Term t = new Term(FieldNames.PROPERTIES,
FieldNames.createNamedValue(primaryTypeField,
npResolver.getJCRName(selector.getNodeTypeQName())));
terms.add(t);
}
// now search for all node types that are derived from base
if (base != null) {
NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
while (allTypes.hasNext()) {
NodeType nt = allTypes.nextNodeType();
NodeType[] superTypes = nt.getSupertypes();
if (Arrays.asList(superTypes).contains(base)) {
Name n = session.getQName(nt.getName());
String ntName = nsMappings.translateName(n);
Term t;
if (nt.isMixin()) {
// search on jcr:mixinTypes
t = new Term(FieldNames.PROPERTIES,
FieldNames.createNamedValue(mixinTypesField, ntName));
} else {
// search on jcr:primaryType