diff options
author | dkonstantin | 2015-02-04 17:56:08 +0000 |
---|---|---|
committer | dkonstantin | 2015-02-04 17:56:08 +0000 |
commit | 936875072b028b3e3f2ba0280c67b6fc7ee7d0cf (patch) | |
tree | 2f13636c4442694946cfb296fa2fe1aa41f5cfb9 | |
parent | a9fe6b2c86b43b4e68811c82e8e60ebc216f643b (diff) | |
download | org.eclipse.webtools.incubator.sieditor-master.tar.gz org.eclipse.webtools.incubator.sieditor-master.tar.xz org.eclipse.webtools.incubator.sieditor-master.zip |
retrieveModelObjectURIFragmentNone added to ModelHandler, fix contributed by Kedumpadi, Keerthan ShivaramaHEADmaster
2 files changed, 37 insertions, 0 deletions
diff --git a/plugins/org.eclipse.wst.sse.sieditor.core/api/org/eclipse/wst/sse/sieditor/core/editorfwk/ModelHandler.java b/plugins/org.eclipse.wst.sse.sieditor.core/api/org/eclipse/wst/sse/sieditor/core/editorfwk/ModelHandler.java index f0108d7..952ed52 100644 --- a/plugins/org.eclipse.wst.sse.sieditor.core/api/org/eclipse/wst/sse/sieditor/core/editorfwk/ModelHandler.java +++ b/plugins/org.eclipse.wst.sse.sieditor.core/api/org/eclipse/wst/sse/sieditor/core/editorfwk/ModelHandler.java @@ -100,4 +100,21 @@ public class ModelHandler { // how to get the // correct state? } + + public static IModelObject retrieveModelObjectURIFragmentNone(String s, String uri) { + ResourceSet rs = new ResourceSetImpl(); + Resource resource = rs.createResource(URI.createURI(uri,true,URI.FRAGMENT_NONE)); + + try { + ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes("UTF-8")); //$NON-NLS-1$ + resource.load(is, null); + } catch (IOException e) { + Logger.log(SIEditorCoreActivator.PLUGIN_ID, IStatus.ERROR, "Can not load resource " + resource.getURI(), e); //$NON-NLS-1$ + return null; + } + Object emfObjectList = resource.getContents(); + String extension = uri.substring(uri.lastIndexOf('.') + 1); + ExtensibleObjectFactory factory = ExtensibleObjectFactoryRegistry.get(extension); + return factory.createModelObject(emfObjectList, false); + } } diff --git a/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/core/editorfwk/ModelHandlerTest.java b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/core/editorfwk/ModelHandlerTest.java index 3a38f86..db612d2 100644 --- a/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/core/editorfwk/ModelHandlerTest.java +++ b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/core/editorfwk/ModelHandlerTest.java @@ -37,6 +37,7 @@ import org.eclipse.wst.sse.sieditor.model.xsd.api.ISchema; public class ModelHandlerTest extends SIEditorBaseTest {
+ private static final String FOLDER_NAME_WITH_HASH = "hash#test";
@Test
public void testLoadXSDfromFile() throws IOException, CoreException {
final IFile file = ResourceUtils.copyFileIntoTestProject("pub/xsd/example.xsd", Document_FOLDER_NAME, this.getProject(),
@@ -74,6 +75,25 @@ public class ModelHandlerTest extends SIEditorBaseTest { assertTrue(modelObject instanceof IWsdlModelRoot);
}
+
+ @Test
+ public void testLoadWSDLfromFile_URIwithHASH() throws IOException, CoreException {
+ final IFile file = ResourceUtils.copyFileIntoTestProject("pub/self/mix2/ChangePurchaseOrder_WSD.wsdl",
+ FOLDER_NAME_WITH_HASH, this.getProject(), "ChangePurchaseOrder_WSD.wsdl");
+ refreshProjectNFile(file);
+
+ StringBuffer sb = new StringBuffer();
+ BufferedInputStream bis = new BufferedInputStream(file.getContents());
+ int readedByte;
+ while ((readedByte = bis.read()) > 0) {
+ sb.append((char) readedByte);
+ }
+
+ String fileContent = sb.toString();
+ IModelObject modelObject = ModelHandler.retrieveModelObjectURIFragmentNone(fileContent, "file:/"+file.getLocation().toString());
+
+ assertTrue(modelObject instanceof IWsdlModelRoot);
+ }
@Test
public void testOperationHistoryNotClearedAfterRetrivingModelObject() throws IOException, CoreException, ExecutionException {
|