try {
String mixinTypesField = NameFormat.format(QName.JCR_MIXINTYPES, nsMappings);
String primaryTypeField = NameFormat.format(QName.JCR_PRIMARYTYPE, nsMappings);
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
NodeType base = ntMgr.getNodeType(NameFormat.format(node.getValue(), session.getNamespaceResolver()));
if (base.isMixin()) {
// search for nodes where jcr:mixinTypes is set to this mixin
Term t = new Term(FieldNames.PROPERTIES,
FieldNames.createNamedValue(mixinTypesField,
NameFormat.format(node.getValue(), nsMappings)));
terms.add(t);
} else {
// search for nodes where jcr:primaryType is set to this type
Term t = new Term(FieldNames.PROPERTIES,
FieldNames.createNamedValue(primaryTypeField,
NameFormat.format(node.getValue(), nsMappings)));
terms.add(t);
}
// now search for all node types that are derived from base
NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
while (allTypes.hasNext()) {
NodeType nt = allTypes.nextNodeType();
NodeType[] superTypes = nt.getSupertypes();
if (Arrays.asList(superTypes).contains(base)) {
String ntName = nsMappings.translatePropertyName(nt.getName(),
session.getNamespaceResolver());
Term t;
if (nt.isMixin()) {
// search on jcr:mixinTypes
t = new Term(FieldNames.PROPERTIES,
FieldNames.createNamedValue(mixinTypesField, ntName));
} else {
// search on jcr:primaryType