protected void recomputeDocumentTypes() { // effective descriptors with override // linked hash map to keep order for reproducibility Map<String, DocumentTypeDescriptor> dtds = new LinkedHashMap<>(); for (DocumentTypeDescriptor dtd : allDocumentTypes) { String name = dtd.name; DocumentTypeDescriptor newDtd = dtd; if (dtd.append && dtds.containsKey(dtd.name)) { newDtd = mergeDocumentTypeDescriptors(dtd, dtds.get(name)); } dtds.put(name, newDtd); } // recompute all types, parents first documentTypes.clear(); documentTypesExtending.clear(); registerDocumentType(new DocumentTypeImpl(TypeConstants.DOCUMENT)); // Document for (String name : dtds.keySet()) { LinkedHashSet<String> stack = new LinkedHashSet<>(); recomputeDocumentType(name, stack, dtds); } // document types having a given facet documentTypesForFacet.clear(); for (DocumentType docType : documentTypes.values()) { for (String facet : docType.getFacets()) { Set<String> set = documentTypesForFacet.get(facet); if (set == null) { documentTypesForFacet.put(facet, set = new HashSet<>()); } set.add(docType.getName()); } } }
protected DocumentType recomputeDocumentType( String name, DocumentTypeDescriptor dtd, DocumentType parent) { // find the facets and schemas names Set<String> facetNames = new HashSet<>(); Set<String> schemaNames = SchemaDescriptor.getSchemaNames(dtd.schemas); facetNames.addAll(Arrays.asList(dtd.facets)); // inherited if (parent != null) { facetNames.addAll(parent.getFacets()); schemaNames.addAll(Arrays.asList(parent.getSchemaNames())); } // add schemas names from facets for (String facetName : facetNames) { CompositeType ct = facets.get(facetName); if (ct == null) { log.warn("Undeclared facet: " + facetName + " used in document type: " + name); // register it with no schemas ct = registerFacet(facetName, Collections.<String>emptySet()); } schemaNames.addAll(Arrays.asList(ct.getSchemaNames())); } // find the schemas List<Schema> docTypeSchemas = new ArrayList<>(); for (String schemaName : schemaNames) { Schema schema = schemas.get(schemaName); if (schema == null) { log.error("Document type: " + name + " uses unknown schema: " + schemaName); continue; } docTypeSchemas.add(schema); } // create doctype PrefetchInfo prefetch = dtd.prefetch == null ? prefetchInfo : new PrefetchInfo(dtd.prefetch); DocumentTypeImpl docType = new DocumentTypeImpl(name, parent, docTypeSchemas, facetNames, prefetch); registerDocumentType(docType); return docType; }