use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerXML method getModelForEdit.
/**
* must release model (from edit) after
* @param filename relative to this class (TestStructuredPartitioner)
*/
private IStructuredModel getModelForEdit(String filename) {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new NullStream();
model = modelManager.getModelForEdit(filename, inStream, null);
} catch (IOException ex) {
ex.printStackTrace();
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestXMLContentAssist method loadXMLFile.
protected void loadXMLFile() throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForEdit(file);
document = model.getStructuredDocument();
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestAttributesOrder method ensureDocumentHasGrammar.
/**
* Reusable test to make sure the XML model for the given file has a grammar.
*
* @param file
* the file containing the XML document.
*/
private void ensureDocumentHasGrammar(IFile file) throws IOException, CoreException {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", cmElementDeclaration);
assertNotNull("No content assist available for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", modelQuery.getAvailableContent(documentElement, cmElementDeclaration, ModelQuery.INCLUDE_CHILD_NODES));
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestCyclicGroupReferences method testCyclicGroupReferences.
/**
* Test CMVisitor for cyclic group references.
*/
public void testCyclicGroupReferences() {
// $NON-NLS-1$
IFile file = getFile("Test.xml");
CMVisitor cmVisitor = new CMVisitor();
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
cmElementDeclaration);
cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
} catch (Throwable th) {
fail("Test failed :" + th.getClass().getName());
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestCreateIDs.
private void doTestCreateIDs(String filePath, Class class1, Class class2) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredModel model = modelManager.getNewModelForEdit(file, true);
try {
assertNotNull(model);
if (DEBUG) {
System.out.println("ID: " + model.getId());
System.out.println("BaseLocation" + model.getBaseLocation());
}
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
Aggregations