Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Loading EMF models from a resource within some plugin
Loading EMF models from a resource within some plugin [message #3177] Tue, 11 November 2008 17:29 Go to next message
Eclipse UserFriend
Originally posted by: szchaler.acm.org

Hi,

I'm trying to use the code below to load a model from an ecore file that
resides in another plugin. This gets me an
StringIndexOutOfBoundsException. What could I be doing wrong?

EmfModel core = new EmfModel();
StringProperties properties = new StringProperties();
properties.put(EmfModel.PROPERTY_NAME, "Core");
properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED, "false");
properties.put(EmfModel.PROPERTY_METAMODEL_URI, EcorePackage.eNS_URI);
properties.put(EmfModel.PROPERTY_MODEL_FILE, "bundleentry://678/resources/core.ecore");
properties.put(EmfModel.PROPERTY_READONLOAD, "true");
properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
.getRawLocation().toPortableString());
module.getContext().getModelRepository().addModel(core);

Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the value
it actually has at runtime. In my real code this is being computed using
FileLocator.find. The Exception is thrown in the load() call. The file
does exist and the plugin has set that directory to be part of the
binary build.

What is the correct way of doing this?

Regards,

Steffen

--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email szschaler@acm.org
WWW http://www.steffen-zschaler.de/

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
http://qosa.ipd.uka.de/

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
http://wikiserver.sse.cs.tu-bs.de/mise09
Re: Loading EMF models from a resource within some plugin [message #3210 is a reply to message #3177] Tue, 11 November 2008 17:37 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
At a first glance it seems that this line is causing the problem:

core.load(properties,
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());

by giving load(...) the second argument
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
it assumes that the path of the model is relative.

Could you please try

core.load(properties,null);

instead and let me know if it works. If not I'll investigate more.

Cheers,
Dimitrios

Steffen Zschaler wrote:
> Hi,
>
> I'm trying to use the code below to load a model from an ecore file that
> resides in another plugin. This gets me an
> StringIndexOutOfBoundsException. What could I be doing wrong?
>
> EmfModel core = new EmfModel();
> StringProperties properties = new StringProperties();
> properties.put(EmfModel.PROPERTY_NAME, "Core");
> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED, "false");
> properties.put(EmfModel.PROPERTY_METAMODEL_URI, EcorePackage.eNS_URI);
> properties.put(EmfModel.PROPERTY_MODEL_FILE,
> "bundleentry://678/resources/core.ecore");
> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
> .getRawLocation().toPortableString());
> module.getContext().getModelRepository().addModel(core);
>
> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the value
> it actually has at runtime. In my real code this is being computed using
> FileLocator.find. The Exception is thrown in the load() call. The file
> does exist and the plugin has set that directory to be part of the
> binary build.
>
> What is the correct way of doing this?
>
> Regards,
>
> Steffen
>
Re: Loading EMF models from a resource within some plugin [message #3243 is a reply to message #3210] Wed, 12 November 2008 10:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: szchaler.acm.org

Thanks, this has helped. For some reason, I am not getting a
FileNotFoundException. Not quite sure why this is, I am assuming OSGI is
hiding this file from me. Well, I guess its time for another workaround :-(

Steffen

Dimitrios Kolovos wrote:
> At a first glance it seems that this line is causing the problem:
>
> core.load(properties,
> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>
>
> by giving load(...) the second argument
> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
> it assumes that the path of the model is relative.
>
> Could you please try
>
> core.load(properties,null);
>
> instead and let me know if it works. If not I'll investigate more.
>
> Cheers,
> Dimitrios
>
> Steffen Zschaler wrote:
>> Hi,
>>
>> I'm trying to use the code below to load a model from an ecore file
>> that resides in another plugin. This gets me an
>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>
>> EmfModel core = new EmfModel();
>> StringProperties properties = new StringProperties();
>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED, "false");
>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>> EcorePackage.eNS_URI);
>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>> "bundleentry://678/resources/core.ecore");
>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>> .getRawLocation().toPortableString());
>> module.getContext().getModelRepository().addModel(core);
>>
>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>> value it actually has at runtime. In my real code this is being
>> computed using FileLocator.find. The Exception is thrown in the
>> load() call. The file does exist and the plugin has set that
>> directory to be part of the binary build.
>>
>> What is the correct way of doing this?
>>
>> Regards,
>>
>> Steffen

--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email szschaler@acm.org
WWW http://www.steffen-zschaler.de/

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
http://qosa.ipd.uka.de/

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
http://wikiserver.sse.cs.tu-bs.de/mise09
Re: Loading EMF models from a resource within some plugin [message #3275 is a reply to message #3243] Wed, 12 November 2008 11:32 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Steffen,

Currently EmfModel is configured to work only with models/metamodels
that reside in the filesystem. I've added support for plugin based
models/metamodels too and committed to the SVN. Are you using Epsilon
from source? If not and it's too much trouble switching to SVN I can
send you a patched plugin to replace in your Eclipse installation. In
the new version you'll be able to load your plugin-based model like this:

properties.put(EmfModel.PROPERTY_MODEL_FILE,
"platform:/plugin/your.plugin.name/core.ecore");

Cheers,
Dimitrios

Steffen Zschaler wrote:
> Thanks, this has helped. For some reason, I am not getting a
> FileNotFoundException. Not quite sure why this is, I am assuming OSGI is
> hiding this file from me. Well, I guess its time for another workaround :-(
>
> Steffen
>
> Dimitrios Kolovos wrote:
>> At a first glance it seems that this line is causing the problem:
>>
>> core.load(properties,
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>
>>
>> by giving load(...) the second argument
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>> it assumes that the path of the model is relative.
>>
>> Could you please try
>>
>> core.load(properties,null);
>>
>> instead and let me know if it works. If not I'll investigate more.
>>
>> Cheers,
>> Dimitrios
>>
>> Steffen Zschaler wrote:
>>> Hi,
>>>
>>> I'm trying to use the code below to load a model from an ecore file
>>> that resides in another plugin. This gets me an
>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>
>>> EmfModel core = new EmfModel();
>>> StringProperties properties = new StringProperties();
>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED, "false");
>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>> EcorePackage.eNS_URI);
>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>> "bundleentry://678/resources/core.ecore");
>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>> .getRawLocation().toPortableString());
>>> module.getContext().getModelRepository().addModel(core);
>>>
>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>> value it actually has at runtime. In my real code this is being
>>> computed using FileLocator.find. The Exception is thrown in the
>>> load() call. The file does exist and the plugin has set that
>>> directory to be part of the binary build.
>>>
>>> What is the correct way of doing this?
>>>
>>> Regards,
>>>
>>> Steffen
>
Re: Loading EMF models from a resource within some plugin [message #3309 is a reply to message #3243] Wed, 12 November 2008 11:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: szchaler.acm.org

This is a multi-part message in MIME format.
--------------070706000409030306070703
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

OK, I have this bit working now. Just to document the stupid mistakes I
made, in case somebody else is making them as well :-) :

* Never try to put something into a StringProperty that is not
actually a String. I tried putting in a URL :-( The thing is:
StringProperty will not tell you about your mistake, but will
rather silently throw your input away, so that load() later on
will not be able to figure out what file you are referring to...
* When you convert the URL to a String, make sure of two things:
o Use FileLocator.toFileURL to make sure the file is put into
some accessible location
o Do NOT use URL.toString() to produce the String. This will
produce a String of the form "file://..." EmfModel.load
cannot actually deal with this and will throw
incomprehensible exceptions at you (Telling you that this is
not a valid relative pathname, which is ... true). Instead,
use URL.getPath() and all will be happy.

Cheers,

Steffen

Steffen Zschaler wrote:
> Thanks, this has helped. For some reason, I am not getting a
> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
> is hiding this file from me. Well, I guess its time for another
> workaround :-(
>
> Steffen
>
> Dimitrios Kolovos wrote:
>> At a first glance it seems that this line is causing the problem:
>>
>> core.load(properties,
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>
>>
>> by giving load(...) the second argument
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>> it assumes that the path of the model is relative.
>>
>> Could you please try
>>
>> core.load(properties,null);
>>
>> instead and let me know if it works. If not I'll investigate more.
>>
>> Cheers,
>> Dimitrios
>>
>> Steffen Zschaler wrote:
>>> Hi,
>>>
>>> I'm trying to use the code below to load a model from an ecore file
>>> that resides in another plugin. This gets me an
>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>
>>> EmfModel core = new EmfModel();
>>> StringProperties properties = new StringProperties();
>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>> "false");
>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>> EcorePackage.eNS_URI);
>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>> "bundleentry://678/resources/core.ecore");
>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>> .getRawLocation().toPortableString());
>>> module.getContext().getModelRepository().addModel(core);
>>>
>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>> value it actually has at runtime. In my real code this is being
>>> computed using FileLocator.find. The Exception is thrown in the
>>> load() call. The file does exist and the plugin has set that
>>> directory to be part of the binary build.
>>>
>>> What is the correct way of doing this?
>>>
>>> Regards,
>>>
>>> Steffen
>

--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email szschaler@acm.org
WWW http://www.steffen-zschaler.de/

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
http://qosa.ipd.uka.de/

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
http://wikiserver.sse.cs.tu-bs.de/mise09


--------------070706000409030306070703
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
OK, I have this bit working now. Just to document the stupid mistakes I
made, in case somebody else is making them as well :-) :<br>
<ul>
<li>Never try to put something into a StringProperty that is not
actually a String. I tried putting in a URL :-( The thing is:
StringProperty will not tell you about your mistake, but will rather
silently throw your input away, so that load() later on will not be
able to figure out what file you are referring to...</li>
<li>When you convert the URL to a String, make sure of two things:</li>
<ul>
<li>Use FileLocator.toFileURL to make sure the file is put into
some accessible location</li>
<li>Do NOT use URL.toString() to produce the String. This will
produce a String of the form <a class="moz-txt-link-rfc2396E" href="file://...">"file://..."</a> EmfModel.load cannot actually
deal with this and will throw incomprehensible exceptions at you
(Telling you that this is not a valid relative pathname, which is ...
true). Instead, use URL.getPath() and all will be happy.</li>
</ul>
</ul>
Cheers,<br>
<br>
Steffen<br>
<br>
Steffen Zschaler wrote:
<blockquote cite="mid:gfea3g$3oc$1@build.eclipse.org" type="cite">Thanks,
this has helped. For some reason, I am not getting a
FileNotFoundException. Not quite sure why this is, I am assuming OSGI
is hiding this file from me. Well, I guess its time for another
workaround :-(
<br>
<br>
Steffen
<br>
<br>
Dimitrios Kolovos wrote:
<br>
<blockquote type="cite">At a first glance it seems that this line is
causing the problem:
<br>
<br>
core.load(properties,
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
<br>
<br>
by giving load(...) the second argument
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
&nbsp;it assumes that the path of the model is relative.
<br>
<br>
Could you please try
<br>
<br>
core.load(properties,null);
<br>
<br>
instead and let me know if it works. If not I'll investigate more.
<br>
<br>
Cheers,
<br>
Dimitrios
<br>
<br>
Steffen Zschaler wrote:
<br>
<blockquote type="cite">Hi,
<br>
<br>
I'm trying to use the code below to load a model from an ecore file
that resides in another plugin. This gets me an
StringIndexOutOfBoundsException. What could I be doing wrong?
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; EmfModel core = new EmfModel();
<br>
&nbsp;&nbsp;&nbsp;&nbsp; StringProperties properties = new StringProperties();
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_NAME, "Core");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
"false");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_METAMODEL_URI,
EcorePackage.eNS_URI);
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_MODEL_FILE,
"bundleentry://678/resources/core.ecore");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_READONLOAD, "true");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; .getRawLocation().toPortableString());
<br>
&nbsp;&nbsp;&nbsp;&nbsp; module.getContext().getModelRepository().addModel(core);
<br>
<br>
Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
value it actually has at runtime. In my real code this is being
computed using FileLocator.find. The Exception is thrown in the load()
call. The file does exist and the plugin has set that directory to be
part of the binary build.
<br>
<br>
What is the correct way of doing this?
<br>
<br>
Regards,
<br>
<br>
Steffen
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email <a class="moz-txt-link-abbreviated" href="mailto:szschaler@acm.org">szschaler@acm.org</a>
WWW <a class="moz-txt-link-freetext" href="http://www.steffen-zschaler.de/">http://www.steffen-zschaler.de/</a>

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
<a class="moz-txt-link-freetext" href="http://qosa.ipd.uka.de/">http://qosa.ipd.uka.de/</a>

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
<a class="moz-txt-link-freetext" href="http://wikiserver.sse.cs.tu-bs.de/mise09">http://wikiserver.sse.cs.tu-bs.de/mise09</a></pre>
</body>
</html>

--------------070706000409030306070703--
Re: Loading EMF models from a resource within some plugin [message #3341 is a reply to message #3309] Wed, 12 November 2008 11:47 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Steffen,

Glad you found a workaround for this and thanks for sharing your
experiences! I'll look into the issues you mentioned and address them in
the next release of Epsilon.

Thanks again!
Dimitrios

Steffen Zschaler wrote:
> OK, I have this bit working now. Just to document the stupid mistakes I
> made, in case somebody else is making them as well :-) :
>
> * Never try to put something into a StringProperty that is not
> actually a String. I tried putting in a URL :-( The thing is:
> StringProperty will not tell you about your mistake, but will
> rather silently throw your input away, so that load() later on
> will not be able to figure out what file you are referring to...
> * When you convert the URL to a String, make sure of two things:
> o Use FileLocator.toFileURL to make sure the file is put into
> some accessible location
> o Do NOT use URL.toString() to produce the String. This will
> produce a String of the form "file://..." EmfModel.load
> cannot actually deal with this and will throw
> incomprehensible exceptions at you (Telling you that this is
> not a valid relative pathname, which is ... true). Instead,
> use URL.getPath() and all will be happy.
>
> Cheers,
>
> Steffen
>
> Steffen Zschaler wrote:
>> Thanks, this has helped. For some reason, I am not getting a
>> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
>> is hiding this file from me. Well, I guess its time for another
>> workaround :-(
>>
>> Steffen
>>
>> Dimitrios Kolovos wrote:
>>> At a first glance it seems that this line is causing the problem:
>>>
>>> core.load(properties,
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>>
>>>
>>> by giving load(...) the second argument
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>>> it assumes that the path of the model is relative.
>>>
>>> Could you please try
>>>
>>> core.load(properties,null);
>>>
>>> instead and let me know if it works. If not I'll investigate more.
>>>
>>> Cheers,
>>> Dimitrios
>>>
>>> Steffen Zschaler wrote:
>>>> Hi,
>>>>
>>>> I'm trying to use the code below to load a model from an ecore file
>>>> that resides in another plugin. This gets me an
>>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>>
>>>> EmfModel core = new EmfModel();
>>>> StringProperties properties = new StringProperties();
>>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>>> "false");
>>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>>> EcorePackage.eNS_URI);
>>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>>> "bundleentry://678/resources/core.ecore");
>>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>>> .getRawLocation().toPortableString());
>>>> module.getContext().getModelRepository().addModel(core);
>>>>
>>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>>> value it actually has at runtime. In my real code this is being
>>>> computed using FileLocator.find. The Exception is thrown in the
>>>> load() call. The file does exist and the plugin has set that
>>>> directory to be part of the binary build.
>>>>
>>>> What is the correct way of doing this?
>>>>
>>>> Regards,
>>>>
>>>> Steffen
>>
>
> --
> Dr. rer. nat. Steffen Zschaler
> Senior Research Associate
>
> Lancaster University
> Lancaster, United Kingdom
>
> Email szschaler@acm.org
> WWW http://www.steffen-zschaler.de/
>
> --
>
> Consider submitting to QoSA 2009, the 5th International Conference on
> the Quality of Software-Architectures.
> http://qosa.ipd.uka.de/
>
> Consider submitting to MiSE 2009, the 3rd International Workshop on
> Models in Software Engineering
> http://wikiserver.sse.cs.tu-bs.de/mise09
>
Re: Loading EMF models from a resource within some plugin [message #3411 is a reply to message #3275] Wed, 12 November 2008 11:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: szchaler.acm.org

Hi,

This sounds really helpful :-) Anyway, I have it working now, so I'll
probably just stick to my solution (which probably does what you are
doing under the covers anyway :-) ).

Steffen

Dimitrios Kolovos wrote:
> Hi Steffen,
>
> Currently EmfModel is configured to work only with models/metamodels
> that reside in the filesystem. I've added support for plugin based
> models/metamodels too and committed to the SVN. Are you using Epsilon
> from source? If not and it's too much trouble switching to SVN I can
> send you a patched plugin to replace in your Eclipse installation. In
> the new version you'll be able to load your plugin-based model like this:
>
> properties.put(EmfModel.PROPERTY_MODEL_FILE,
> "platform:/plugin/your.plugin.name/core.ecore");
>
> Cheers,
> Dimitrios
>
> Steffen Zschaler wrote:
>> Thanks, this has helped. For some reason, I am not getting a
>> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
>> is hiding this file from me. Well, I guess its time for another
>> workaround :-(
>>
>> Steffen
>>
>> Dimitrios Kolovos wrote:
>>> At a first glance it seems that this line is causing the problem:
>>>
>>> core.load(properties,
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>>
>>>
>>> by giving load(...) the second argument
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>>> it assumes that the path of the model is relative.
>>>
>>> Could you please try
>>>
>>> core.load(properties,null);
>>>
>>> instead and let me know if it works. If not I'll investigate more.
>>>
>>> Cheers,
>>> Dimitrios
>>>
>>> Steffen Zschaler wrote:
>>>> Hi,
>>>>
>>>> I'm trying to use the code below to load a model from an ecore file
>>>> that resides in another plugin. This gets me an
>>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>>
>>>> EmfModel core = new EmfModel();
>>>> StringProperties properties = new StringProperties();
>>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>>> "false");
>>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>>> EcorePackage.eNS_URI);
>>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>>> "bundleentry://678/resources/core.ecore");
>>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>>> .getRawLocation().toPortableString());
>>>> module.getContext().getModelRepository().addModel(core);
>>>>
>>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>>> value it actually has at runtime. In my real code this is being
>>>> computed using FileLocator.find. The Exception is thrown in the
>>>> load() call. The file does exist and the plugin has set that
>>>> directory to be part of the binary build.
>>>>
>>>> What is the correct way of doing this?
>>>>
>>>> Regards,
>>>>
>>>> Steffen
>>

--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email szschaler@acm.org
WWW http://www.steffen-zschaler.de/

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
http://qosa.ipd.uka.de/

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
http://wikiserver.sse.cs.tu-bs.de/mise09
Re: Loading EMF models from a resource within some plugin [message #3545 is a reply to message #3341] Wed, 12 November 2008 13:23 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Created https://bugs.eclipse.org/bugs/show_bug.cgi?id=255030 to track this.

Dimitrios Kolovos wrote:
> Hi Steffen,
>
> Glad you found a workaround for this and thanks for sharing your
> experiences! I'll look into the issues you mentioned and address them in
> the next release of Epsilon.
>
> Thanks again!
> Dimitrios
>
> Steffen Zschaler wrote:
>> OK, I have this bit working now. Just to document the stupid mistakes
>> I made, in case somebody else is making them as well :-) :
>>
>> * Never try to put something into a StringProperty that is not
>> actually a String. I tried putting in a URL :-( The thing is:
>> StringProperty will not tell you about your mistake, but will
>> rather silently throw your input away, so that load() later on
>> will not be able to figure out what file you are referring to...
>> * When you convert the URL to a String, make sure of two things:
>> o Use FileLocator.toFileURL to make sure the file is put into
>> some accessible location
>> o Do NOT use URL.toString() to produce the String. This will
>> produce a String of the form "file://..." EmfModel.load
>> cannot actually deal with this and will throw
>> incomprehensible exceptions at you (Telling you that this is
>> not a valid relative pathname, which is ... true). Instead,
>> use URL.getPath() and all will be happy.
>>
>> Cheers,
>>
>> Steffen
>>
>> Steffen Zschaler wrote:
>>> Thanks, this has helped. For some reason, I am not getting a
>>> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
>>> is hiding this file from me. Well, I guess its time for another
>>> workaround :-(
>>>
>>> Steffen
>>>
>>> Dimitrios Kolovos wrote:
>>>> At a first glance it seems that this line is causing the problem:
>>>>
>>>> core.load(properties,
>>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>>>
>>>>
>>>> by giving load(...) the second argument
>>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>>>> it assumes that the path of the model is relative.
>>>>
>>>> Could you please try
>>>>
>>>> core.load(properties,null);
>>>>
>>>> instead and let me know if it works. If not I'll investigate more.
>>>>
>>>> Cheers,
>>>> Dimitrios
>>>>
>>>> Steffen Zschaler wrote:
>>>>> Hi,
>>>>>
>>>>> I'm trying to use the code below to load a model from an ecore file
>>>>> that resides in another plugin. This gets me an
>>>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>>>
>>>>> EmfModel core = new EmfModel();
>>>>> StringProperties properties = new StringProperties();
>>>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>>>> "false");
>>>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>>>> EcorePackage.eNS_URI);
>>>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>>>> "bundleentry://678/resources/core.ecore");
>>>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>>>> .getRawLocation().toPortableString());
>>>>> module.getContext().getModelRepository().addModel(core);
>>>>>
>>>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>>>> value it actually has at runtime. In my real code this is being
>>>>> computed using FileLocator.find. The Exception is thrown in the
>>>>> load() call. The file does exist and the plugin has set that
>>>>> directory to be part of the binary build.
>>>>>
>>>>> What is the correct way of doing this?
>>>>>
>>>>> Regards,
>>>>>
>>>>> Steffen
>>>
>>
>> --
>> Dr. rer. nat. Steffen Zschaler
>> Senior Research Associate
>>
>> Lancaster University
>> Lancaster, United Kingdom
>>
>> Email szschaler@acm.org
>> WWW http://www.steffen-zschaler.de/
>>
>> --
>>
>> Consider submitting to QoSA 2009, the 5th International Conference on
>> the Quality of Software-Architectures.
>> http://qosa.ipd.uka.de/
>>
>> Consider submitting to MiSE 2009, the 3rd International Workshop on
>> Models in Software Engineering
>> http://wikiserver.sse.cs.tu-bs.de/mise09
>>
Re: Loading EMF models from a resource within some plugin [message #561691 is a reply to message #3177] Tue, 11 November 2008 17:37 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
At a first glance it seems that this line is causing the problem:

core.load(properties,
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());

by giving load(...) the second argument
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
it assumes that the path of the model is relative.

Could you please try

core.load(properties,null);

instead and let me know if it works. If not I'll investigate more.

Cheers,
Dimitrios

Steffen Zschaler wrote:
> Hi,
>
> I'm trying to use the code below to load a model from an ecore file that
> resides in another plugin. This gets me an
> StringIndexOutOfBoundsException. What could I be doing wrong?
>
> EmfModel core = new EmfModel();
> StringProperties properties = new StringProperties();
> properties.put(EmfModel.PROPERTY_NAME, "Core");
> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED, "false");
> properties.put(EmfModel.PROPERTY_METAMODEL_URI, EcorePackage.eNS_URI);
> properties.put(EmfModel.PROPERTY_MODEL_FILE,
> "bundleentry://678/resources/core.ecore");
> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
> .getRawLocation().toPortableString());
> module.getContext().getModelRepository().addModel(core);
>
> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the value
> it actually has at runtime. In my real code this is being computed using
> FileLocator.find. The Exception is thrown in the load() call. The file
> does exist and the plugin has set that directory to be part of the
> binary build.
>
> What is the correct way of doing this?
>
> Regards,
>
> Steffen
>
Re: Loading EMF models from a resource within some plugin [message #561710 is a reply to message #3210] Wed, 12 November 2008 10:10 Go to previous message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
Thanks, this has helped. For some reason, I am not getting a
FileNotFoundException. Not quite sure why this is, I am assuming OSGI is
hiding this file from me. Well, I guess its time for another workaround :-(

Steffen

Dimitrios Kolovos wrote:
> At a first glance it seems that this line is causing the problem:
>
> core.load(properties,
> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>
>
> by giving load(...) the second argument
> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
> it assumes that the path of the model is relative.
>
> Could you please try
>
> core.load(properties,null);
>
> instead and let me know if it works. If not I'll investigate more.
>
> Cheers,
> Dimitrios
>
> Steffen Zschaler wrote:
>> Hi,
>>
>> I'm trying to use the code below to load a model from an ecore file
>> that resides in another plugin. This gets me an
>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>
>> EmfModel core = new EmfModel();
>> StringProperties properties = new StringProperties();
>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED, "false");
>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>> EcorePackage.eNS_URI);
>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>> "bundleentry://678/resources/core.ecore");
>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>> .getRawLocation().toPortableString());
>> module.getContext().getModelRepository().addModel(core);
>>
>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>> value it actually has at runtime. In my real code this is being
>> computed using FileLocator.find. The Exception is thrown in the
>> load() call. The file does exist and the plugin has set that
>> directory to be part of the binary build.
>>
>> What is the correct way of doing this?
>>
>> Regards,
>>
>> Steffen

--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email szschaler@acm.org
WWW http://www.steffen-zschaler.de/

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
http://qosa.ipd.uka.de/

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
http://wikiserver.sse.cs.tu-bs.de/mise09
Re: Loading EMF models from a resource within some plugin [message #561726 is a reply to message #3243] Wed, 12 November 2008 11:32 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Steffen,

Currently EmfModel is configured to work only with models/metamodels
that reside in the filesystem. I've added support for plugin based
models/metamodels too and committed to the SVN. Are you using Epsilon
from source? If not and it's too much trouble switching to SVN I can
send you a patched plugin to replace in your Eclipse installation. In
the new version you'll be able to load your plugin-based model like this:

properties.put(EmfModel.PROPERTY_MODEL_FILE,
"platform:/plugin/your.plugin.name/core.ecore");

Cheers,
Dimitrios

Steffen Zschaler wrote:
> Thanks, this has helped. For some reason, I am not getting a
> FileNotFoundException. Not quite sure why this is, I am assuming OSGI is
> hiding this file from me. Well, I guess its time for another workaround :-(
>
> Steffen
>
> Dimitrios Kolovos wrote:
>> At a first glance it seems that this line is causing the problem:
>>
>> core.load(properties,
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>
>>
>> by giving load(...) the second argument
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>> it assumes that the path of the model is relative.
>>
>> Could you please try
>>
>> core.load(properties,null);
>>
>> instead and let me know if it works. If not I'll investigate more.
>>
>> Cheers,
>> Dimitrios
>>
>> Steffen Zschaler wrote:
>>> Hi,
>>>
>>> I'm trying to use the code below to load a model from an ecore file
>>> that resides in another plugin. This gets me an
>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>
>>> EmfModel core = new EmfModel();
>>> StringProperties properties = new StringProperties();
>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED, "false");
>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>> EcorePackage.eNS_URI);
>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>> "bundleentry://678/resources/core.ecore");
>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>> .getRawLocation().toPortableString());
>>> module.getContext().getModelRepository().addModel(core);
>>>
>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>> value it actually has at runtime. In my real code this is being
>>> computed using FileLocator.find. The Exception is thrown in the
>>> load() call. The file does exist and the plugin has set that
>>> directory to be part of the binary build.
>>>
>>> What is the correct way of doing this?
>>>
>>> Regards,
>>>
>>> Steffen
>
Re: Loading EMF models from a resource within some plugin [message #561747 is a reply to message #3243] Wed, 12 November 2008 11:36 Go to previous message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070706000409030306070703
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

OK, I have this bit working now. Just to document the stupid mistakes I
made, in case somebody else is making them as well :-) :

* Never try to put something into a StringProperty that is not
actually a String. I tried putting in a URL :-( The thing is:
StringProperty will not tell you about your mistake, but will
rather silently throw your input away, so that load() later on
will not be able to figure out what file you are referring to...
* When you convert the URL to a String, make sure of two things:
o Use FileLocator.toFileURL to make sure the file is put into
some accessible location
o Do NOT use URL.toString() to produce the String. This will
produce a String of the form "file://.." EmfModel.load
cannot actually deal with this and will throw
incomprehensible exceptions at you (Telling you that this is
not a valid relative pathname, which is ... true). Instead,
use URL.getPath() and all will be happy.

Cheers,

Steffen

Steffen Zschaler wrote:
> Thanks, this has helped. For some reason, I am not getting a
> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
> is hiding this file from me. Well, I guess its time for another
> workaround :-(
>
> Steffen
>
> Dimitrios Kolovos wrote:
>> At a first glance it seems that this line is causing the problem:
>>
>> core.load(properties,
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>
>>
>> by giving load(...) the second argument
>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>> it assumes that the path of the model is relative.
>>
>> Could you please try
>>
>> core.load(properties,null);
>>
>> instead and let me know if it works. If not I'll investigate more.
>>
>> Cheers,
>> Dimitrios
>>
>> Steffen Zschaler wrote:
>>> Hi,
>>>
>>> I'm trying to use the code below to load a model from an ecore file
>>> that resides in another plugin. This gets me an
>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>
>>> EmfModel core = new EmfModel();
>>> StringProperties properties = new StringProperties();
>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>> "false");
>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>> EcorePackage.eNS_URI);
>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>> "bundleentry://678/resources/core.ecore");
>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>> .getRawLocation().toPortableString());
>>> module.getContext().getModelRepository().addModel(core);
>>>
>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>> value it actually has at runtime. In my real code this is being
>>> computed using FileLocator.find. The Exception is thrown in the
>>> load() call. The file does exist and the plugin has set that
>>> directory to be part of the binary build.
>>>
>>> What is the correct way of doing this?
>>>
>>> Regards,
>>>
>>> Steffen
>

--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email szschaler@acm.org
WWW http://www.steffen-zschaler.de/

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
http://qosa.ipd.uka.de/

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
http://wikiserver.sse.cs.tu-bs.de/mise09


--------------070706000409030306070703
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
OK, I have this bit working now. Just to document the stupid mistakes I
made, in case somebody else is making them as well :-) :<br>
<ul>
<li>Never try to put something into a StringProperty that is not
actually a String. I tried putting in a URL :-( The thing is:
StringProperty will not tell you about your mistake, but will rather
silently throw your input away, so that load() later on will not be
able to figure out what file you are referring to...</li>
<li>When you convert the URL to a String, make sure of two things:</li>
<ul>
<li>Use FileLocator.toFileURL to make sure the file is put into
some accessible location</li>
<li>Do NOT use URL.toString() to produce the String. This will
produce a String of the form <a class="moz-txt-link-rfc2396E" href="file://..">"file://.."</a> EmfModel.load cannot actually
deal with this and will throw incomprehensible exceptions at you
(Telling you that this is not a valid relative pathname, which is ...
true). Instead, use URL.getPath() and all will be happy.</li>
</ul>
</ul>
Cheers,<br>
<br>
Steffen<br>
<br>
Steffen Zschaler wrote:
<blockquote cite="mid:gfea3g$3oc$1@build.eclipse.org" type="cite">Thanks,
this has helped. For some reason, I am not getting a
FileNotFoundException. Not quite sure why this is, I am assuming OSGI
is hiding this file from me. Well, I guess its time for another
workaround :-(
<br>
<br>
Steffen
<br>
<br>
Dimitrios Kolovos wrote:
<br>
<blockquote type="cite">At a first glance it seems that this line is
causing the problem:
<br>
<br>
core.load(properties,
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
<br>
<br>
by giving load(...) the second argument
ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
&nbsp;it assumes that the path of the model is relative.
<br>
<br>
Could you please try
<br>
<br>
core.load(properties,null);
<br>
<br>
instead and let me know if it works. If not I'll investigate more.
<br>
<br>
Cheers,
<br>
Dimitrios
<br>
<br>
Steffen Zschaler wrote:
<br>
<blockquote type="cite">Hi,
<br>
<br>
I'm trying to use the code below to load a model from an ecore file
that resides in another plugin. This gets me an
StringIndexOutOfBoundsException. What could I be doing wrong?
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; EmfModel core = new EmfModel();
<br>
&nbsp;&nbsp;&nbsp;&nbsp; StringProperties properties = new StringProperties();
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_NAME, "Core");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
"false");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_METAMODEL_URI,
EcorePackage.eNS_URI);
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_MODEL_FILE,
"bundleentry://678/resources/core.ecore");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_READONLOAD, "true");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
<br>
&nbsp;&nbsp;&nbsp;&nbsp; core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; .getRawLocation().toPortableString());
<br>
&nbsp;&nbsp;&nbsp;&nbsp; module.getContext().getModelRepository().addModel(core);
<br>
<br>
Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
value it actually has at runtime. In my real code this is being
computed using FileLocator.find. The Exception is thrown in the load()
call. The file does exist and the plugin has set that directory to be
part of the binary build.
<br>
<br>
What is the correct way of doing this?
<br>
<br>
Regards,
<br>
<br>
Steffen
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email <a class="moz-txt-link-abbreviated" href="mailto:szschaler@acm.org">szschaler@acm.org</a>
WWW <a class="moz-txt-link-freetext" href="http://www.steffen-zschaler.de/">http://www.steffen-zschaler.de/</a>

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
<a class="moz-txt-link-freetext" href="http://qosa.ipd.uka.de/">http://qosa.ipd.uka.de/</a>

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
<a class="moz-txt-link-freetext" href="http://wikiserver.sse.cs.tu-bs.de/mise09">http://wikiserver.sse.cs.tu-bs.de/mise09</a></pre>
</body>
</html>

--------------070706000409030306070703--
Re: Loading EMF models from a resource within some plugin [message #561766 is a reply to message #3309] Wed, 12 November 2008 11:47 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Steffen,

Glad you found a workaround for this and thanks for sharing your
experiences! I'll look into the issues you mentioned and address them in
the next release of Epsilon.

Thanks again!
Dimitrios

Steffen Zschaler wrote:
> OK, I have this bit working now. Just to document the stupid mistakes I
> made, in case somebody else is making them as well :-) :
>
> * Never try to put something into a StringProperty that is not
> actually a String. I tried putting in a URL :-( The thing is:
> StringProperty will not tell you about your mistake, but will
> rather silently throw your input away, so that load() later on
> will not be able to figure out what file you are referring to...
> * When you convert the URL to a String, make sure of two things:
> o Use FileLocator.toFileURL to make sure the file is put into
> some accessible location
> o Do NOT use URL.toString() to produce the String. This will
> produce a String of the form "file://.." EmfModel.load
> cannot actually deal with this and will throw
> incomprehensible exceptions at you (Telling you that this is
> not a valid relative pathname, which is ... true). Instead,
> use URL.getPath() and all will be happy.
>
> Cheers,
>
> Steffen
>
> Steffen Zschaler wrote:
>> Thanks, this has helped. For some reason, I am not getting a
>> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
>> is hiding this file from me. Well, I guess its time for another
>> workaround :-(
>>
>> Steffen
>>
>> Dimitrios Kolovos wrote:
>>> At a first glance it seems that this line is causing the problem:
>>>
>>> core.load(properties,
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>>
>>>
>>> by giving load(...) the second argument
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>>> it assumes that the path of the model is relative.
>>>
>>> Could you please try
>>>
>>> core.load(properties,null);
>>>
>>> instead and let me know if it works. If not I'll investigate more.
>>>
>>> Cheers,
>>> Dimitrios
>>>
>>> Steffen Zschaler wrote:
>>>> Hi,
>>>>
>>>> I'm trying to use the code below to load a model from an ecore file
>>>> that resides in another plugin. This gets me an
>>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>>
>>>> EmfModel core = new EmfModel();
>>>> StringProperties properties = new StringProperties();
>>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>>> "false");
>>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>>> EcorePackage.eNS_URI);
>>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>>> "bundleentry://678/resources/core.ecore");
>>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>>> .getRawLocation().toPortableString());
>>>> module.getContext().getModelRepository().addModel(core);
>>>>
>>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>>> value it actually has at runtime. In my real code this is being
>>>> computed using FileLocator.find. The Exception is thrown in the
>>>> load() call. The file does exist and the plugin has set that
>>>> directory to be part of the binary build.
>>>>
>>>> What is the correct way of doing this?
>>>>
>>>> Regards,
>>>>
>>>> Steffen
>>
>
> --
> Dr. rer. nat. Steffen Zschaler
> Senior Research Associate
>
> Lancaster University
> Lancaster, United Kingdom
>
> Email szschaler@acm.org
> WWW http://www.steffen-zschaler.de/
>
> --
>
> Consider submitting to QoSA 2009, the 5th International Conference on
> the Quality of Software-Architectures.
> http://qosa.ipd.uka.de/
>
> Consider submitting to MiSE 2009, the 3rd International Workshop on
> Models in Software Engineering
> http://wikiserver.sse.cs.tu-bs.de/mise09
>
Re: Loading EMF models from a resource within some plugin [message #561806 is a reply to message #3275] Wed, 12 November 2008 11:57 Go to previous message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
Hi,

This sounds really helpful :-) Anyway, I have it working now, so I'll
probably just stick to my solution (which probably does what you are
doing under the covers anyway :-) ).

Steffen

Dimitrios Kolovos wrote:
> Hi Steffen,
>
> Currently EmfModel is configured to work only with models/metamodels
> that reside in the filesystem. I've added support for plugin based
> models/metamodels too and committed to the SVN. Are you using Epsilon
> from source? If not and it's too much trouble switching to SVN I can
> send you a patched plugin to replace in your Eclipse installation. In
> the new version you'll be able to load your plugin-based model like this:
>
> properties.put(EmfModel.PROPERTY_MODEL_FILE,
> "platform:/plugin/your.plugin.name/core.ecore");
>
> Cheers,
> Dimitrios
>
> Steffen Zschaler wrote:
>> Thanks, this has helped. For some reason, I am not getting a
>> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
>> is hiding this file from me. Well, I guess its time for another
>> workaround :-(
>>
>> Steffen
>>
>> Dimitrios Kolovos wrote:
>>> At a first glance it seems that this line is causing the problem:
>>>
>>> core.load(properties,
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>>
>>>
>>> by giving load(...) the second argument
>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>>> it assumes that the path of the model is relative.
>>>
>>> Could you please try
>>>
>>> core.load(properties,null);
>>>
>>> instead and let me know if it works. If not I'll investigate more.
>>>
>>> Cheers,
>>> Dimitrios
>>>
>>> Steffen Zschaler wrote:
>>>> Hi,
>>>>
>>>> I'm trying to use the code below to load a model from an ecore file
>>>> that resides in another plugin. This gets me an
>>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>>
>>>> EmfModel core = new EmfModel();
>>>> StringProperties properties = new StringProperties();
>>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>>> "false");
>>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>>> EcorePackage.eNS_URI);
>>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>>> "bundleentry://678/resources/core.ecore");
>>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>>> .getRawLocation().toPortableString());
>>>> module.getContext().getModelRepository().addModel(core);
>>>>
>>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>>> value it actually has at runtime. In my real code this is being
>>>> computed using FileLocator.find. The Exception is thrown in the
>>>> load() call. The file does exist and the plugin has set that
>>>> directory to be part of the binary build.
>>>>
>>>> What is the correct way of doing this?
>>>>
>>>> Regards,
>>>>
>>>> Steffen
>>

--
Dr. rer. nat. Steffen Zschaler
Senior Research Associate

Lancaster University
Lancaster, United Kingdom

Email szschaler@acm.org
WWW http://www.steffen-zschaler.de/

--

Consider submitting to QoSA 2009, the 5th International Conference on
the Quality of Software-Architectures.
http://qosa.ipd.uka.de/

Consider submitting to MiSE 2009, the 3rd International Workshop on
Models in Software Engineering
http://wikiserver.sse.cs.tu-bs.de/mise09
Re: Loading EMF models from a resource within some plugin [message #561884 is a reply to message #3341] Wed, 12 November 2008 13:23 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Created https://bugs.eclipse.org/bugs/show_bug.cgi?id=255030 to track this.

Dimitrios Kolovos wrote:
> Hi Steffen,
>
> Glad you found a workaround for this and thanks for sharing your
> experiences! I'll look into the issues you mentioned and address them in
> the next release of Epsilon.
>
> Thanks again!
> Dimitrios
>
> Steffen Zschaler wrote:
>> OK, I have this bit working now. Just to document the stupid mistakes
>> I made, in case somebody else is making them as well :-) :
>>
>> * Never try to put something into a StringProperty that is not
>> actually a String. I tried putting in a URL :-( The thing is:
>> StringProperty will not tell you about your mistake, but will
>> rather silently throw your input away, so that load() later on
>> will not be able to figure out what file you are referring to...
>> * When you convert the URL to a String, make sure of two things:
>> o Use FileLocator.toFileURL to make sure the file is put into
>> some accessible location
>> o Do NOT use URL.toString() to produce the String. This will
>> produce a String of the form "file://.." EmfModel.load
>> cannot actually deal with this and will throw
>> incomprehensible exceptions at you (Telling you that this is
>> not a valid relative pathname, which is ... true). Instead,
>> use URL.getPath() and all will be happy.
>>
>> Cheers,
>>
>> Steffen
>>
>> Steffen Zschaler wrote:
>>> Thanks, this has helped. For some reason, I am not getting a
>>> FileNotFoundException. Not quite sure why this is, I am assuming OSGI
>>> is hiding this file from me. Well, I guess its time for another
>>> workaround :-(
>>>
>>> Steffen
>>>
>>> Dimitrios Kolovos wrote:
>>>> At a first glance it seems that this line is causing the problem:
>>>>
>>>> core.load(properties,
>>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString());
>>>>
>>>>
>>>> by giving load(...) the second argument
>>>> ResourcesPlugin.getWorkspace().getRoot().getRawLocation().to PortableString(),
>>>> it assumes that the path of the model is relative.
>>>>
>>>> Could you please try
>>>>
>>>> core.load(properties,null);
>>>>
>>>> instead and let me know if it works. If not I'll investigate more.
>>>>
>>>> Cheers,
>>>> Dimitrios
>>>>
>>>> Steffen Zschaler wrote:
>>>>> Hi,
>>>>>
>>>>> I'm trying to use the code below to load a model from an ecore file
>>>>> that resides in another plugin. This gets me an
>>>>> StringIndexOutOfBoundsException. What could I be doing wrong?
>>>>>
>>>>> EmfModel core = new EmfModel();
>>>>> StringProperties properties = new StringProperties();
>>>>> properties.put(EmfModel.PROPERTY_NAME, "Core");
>>>>> properties.put(EmfModel.PROPERTY_IS_METAMODEL_FILE_BASED,
>>>>> "false");
>>>>> properties.put(EmfModel.PROPERTY_METAMODEL_URI,
>>>>> EcorePackage.eNS_URI);
>>>>> properties.put(EmfModel.PROPERTY_MODEL_FILE,
>>>>> "bundleentry://678/resources/core.ecore");
>>>>> properties.put(EmfModel.PROPERTY_READONLOAD, "true");
>>>>> properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, "false");
>>>>> core.load(properties, ResourcesPlugin.getWorkspace().getRoot()
>>>>> .getRawLocation().toPortableString());
>>>>> module.getContext().getModelRepository().addModel(core);
>>>>>
>>>>> Note, I have adjusted the URL passed to PROPERTY_MODEL_FILE to the
>>>>> value it actually has at runtime. In my real code this is being
>>>>> computed using FileLocator.find. The Exception is thrown in the
>>>>> load() call. The file does exist and the plugin has set that
>>>>> directory to be part of the binary build.
>>>>>
>>>>> What is the correct way of doing this?
>>>>>
>>>>> Regards,
>>>>>
>>>>> Steffen
>>>
>>
>> --
>> Dr. rer. nat. Steffen Zschaler
>> Senior Research Associate
>>
>> Lancaster University
>> Lancaster, United Kingdom
>>
>> Email szschaler@acm.org
>> WWW http://www.steffen-zschaler.de/
>>
>> --
>>
>> Consider submitting to QoSA 2009, the 5th International Conference on
>> the Quality of Software-Architectures.
>> http://qosa.ipd.uka.de/
>>
>> Consider submitting to MiSE 2009, the 3rd International Workshop on
>> Models in Software Engineering
>> http://wikiserver.sse.cs.tu-bs.de/mise09
>>
Previous Topic:Debugging ETL transformations
Next Topic:InMemoryEmfModel without resource
Goto Forum:
  


Current Time: Thu Apr 25 12:46:17 GMT 2024

Powered by FUDForum. Page generated in 0.04796 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top