IStructuredModel sModel = null;
try {
sModel = StructuredModelManager.getModelManager()
.getExistingModelForRead(fDocument);
if (sModel != null && (sModel instanceof IDOMModel)) {
final FactoryRegistry factoryRegistry = sModel
.getFactoryRegistry();
// getting the projectionmodelnodeadapter for the first
// time
// so do some initializing
if (!factoryRegistry
.contains(ProjectionModelNodeAdapterHTML.class)
&& createIfNeeded) {
final ProjectionModelNodeAdapterFactoryHTML newFactory = new ProjectionModelNodeAdapterFactoryHTML();
// add factory to factory registry
factoryRegistry.addFactory(newFactory);
// add factory to propogating adapter
final IDOMModel domModel = (IDOMModel) sModel;
final IDOMDocument document = domModel.getDocument();
final PropagatingAdapter propagatingAdapter = (PropagatingAdapter) ((INodeNotifier) document)
.getAdapterFor(PropagatingAdapter.class);
if (propagatingAdapter != null) {
propagatingAdapter
.addAdaptOnCreateFactory(newFactory);
}
}
// try and get the factory
factory = (ProjectionModelNodeAdapterFactoryHTML) factoryRegistry
.getFactoryFor(ProjectionModelNodeAdapterHTML.class);
}
} finally {
if (sModel != null) {
sModel.releaseFromRead();