// PageDirectiveAdapter ... the order of initialization is
// critical here, the doc must have been created, but its contents not
// set yet,
// and all factories must have been set up also.
IDOMModel domModel = (IDOMModel) model;
IStructuredDocument structuredDocument = model.getStructuredDocument();
IDOMDocument document = domModel.getDocument();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getExistingAdapter(PageDirectiveAdapter.class);
// ==> // PropagatingAdapter propagatingAdapter = (PropagatingAdapter)
// ((INodeNotifier)
// document).getExistingAdapter(PropagatingAdapter.class);
// ==> // ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter)
// ((INodeNotifier)
// document).getExistingAdapter(ModelQueryAdapter.class);
oldEmbeddedContentType.uninitializeFactoryRegistry(model.getFactoryRegistry());
oldEmbeddedContentType.uninitializeParser(structuredDocument.getParser());
// since 'document' is not recreated in this
// reinit path, we need to remove all adapters,
// except for the propagated adapters (including page
// directive adapter, and model query adapter).
// to accomplish this, we'll just remove all, then
// add back with a call to pre-load adapt.
// let clients decide to unload adapters from document
// Collection oldAdapters = document.getAdapters();
// Iterator oldAdaptersIterator = oldAdapters.iterator();
// while (oldAdaptersIterator.hasNext()) {
// INodeAdapter oldAdapter = (INodeAdapter)
// oldAdaptersIterator.next();
// if (oldAdapter != pageDirectiveAdapter && oldAdapter !=
// propagatingAdapter && oldAdapter != modelQueryAdapter) {
// // DO NOT remove directly!
// // can change contents while in notifity loop!
// //oldAdaptersIterator.remove();
// document.removeAdapter(oldAdapter);
// }
// }
// DMW: I believe something like the following is needed,
// since releases cached adapters
// if (document instanceof DocumentImpl) {
// ((DocumentImpl) document).releaseDocumentType();
// ((DocumentImpl) document).releaseStyleSheets();
// }
// remember, embedded type factories are automatically cleared when
// embededType changed
pageDirectiveAdapter.setEmbeddedType(newEmbeddedContentType);
// // but still need to clear the page directive watchers, and let
// them be rediscovered (with new, accurate node as target)
// pageDirectiveAdapter.clearPageWatchers();
if (newEmbeddedContentType != null) {
// need to null out or else ModelParserAdapter
// won't get reinitialized
((DOMModelImpl) model).setModelParser(null);
newEmbeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
newEmbeddedContentType.initializeParser(structuredDocument.getParser());
// partitioner setup is the responsibility of this loader
IDocumentPartitioner documentPartitioner = structuredDocument.getDocumentPartitioner();
// ISSUE: this logic is flawed, not sure of original intent, but
// added null/type checks for safety.
if (documentPartitioner != null && documentPartitioner instanceof StructuredTextPartitionerForJSP) {
if (newEmbeddedContentType.getFamilyId().equals(ContentTypeIdForXML.ContentTypeID_XML)) {
((StructuredTextPartitionerForJSP) documentPartitioner).setEmbeddedPartitioner(new StructuredTextPartitionerForXML());