selectedFile = (IFile) resource;
int startLine = bean.getElementStartLine() - 1;
int endLine = bean.getElementEndLine();
IModelManager modelManager = StructuredModelManager.getModelManager();
DOMModelImpl modelForRead = null;
try {
modelForRead = (DOMModelImpl) modelManager.getModelForRead(selectedFile);
IStructuredDocument document = modelForRead.getStructuredDocument();
int startOffset = document.getLineOffset(startLine);
int endOffset = document.getLineOffset(endLine);
if (startOffset == endOffset) {
endOffset = document.getLength();
}
for (int i = startOffset; i < endOffset; i++) {
Node node = BeansEditorUtils.getNodeByOffset(document, i);
String localName = node.getLocalName();
if (localName != null && localName.equals(BeansSchemaConstants.ELEM_BEAN)) {
NamedNodeMap attributes = node.getAttributes();
String beanName = bean.getElementName();
boolean matched = matchAndSelect(beanName, BeansSchemaConstants.ATTR_ID,
attributes, node);
if (selectedBean != null) {
return;
}
if (!matched) {
String className = bean.getClassName();
matchAndSelect(className, BeansSchemaConstants.ATTR_CLASS, attributes, node);
if (selectedBean != null) {
return;
}
}
}
}
}
catch (IOException e) {
StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID,
"Failed to get XML node from bean selection.", e));
}
catch (CoreException e) {
StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID,
"Failed to get XML node from bean selection.", e));
}
catch (BadLocationException e) {
StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID,
"Failed to get XML node from bean selection.", e));
}
finally {
if (modelForRead != null) {
modelForRead.releaseFromRead();
modelForRead = null;
}
}
}
}