Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Cross-Document Links--Target Document Moved--Recovery
Cross-Document Links--Target Document Moved--Recovery [message #412978] Thu, 13 September 2007 19:19 Go to next message
David Lynch is currently offline David LynchFriend
Messages: 27
Registered: July 2009
Junior Member
Ed,

I have another simple question regarding broken links.

I have resource A with cross-document references to resource B (A->B).
Now, imagine that the user moves document B to some other folder in the
Eclipse workspace, effectively "breaking" all A->B references.

Next, the user edits resource A, and logic that I have coded determines
that document B is "missing." Imagine that my editor pops up a resource
chooser dialog to prompt for the location of missing document B. The user
navigates the workspace and finds B.

Armed with the new URI of previously-missing resource B, what is the "best
practices" approach to update the cross-document references in A to
re-establish the links?

Do I have to do this programmatically (i.e., manually) at an object level
or is there a more elegant way to do this at a lower level?

In my fantasy, I'm hoping there is a magical method in EMF that I can call
to say "here is the new resource URI, fix links." Am I dreaming?

TIA,
Dave
Re: Cross-Document Links--Target Document Moved--Recovery [message #412979 is a reply to message #412978] Thu, 13 September 2007 20:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050709070707020505060109
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Dave,

There's almost always a magical method! In this case, the resource
set's, URI converter's URI map will be your best friend:

/**
* Returns the map used for remapping a logical URI to a physical
URI when {@link #normalize normalizing}.
* <p>
* An implementation will typically also delegate to the {@link
URIConverter#URI_MAP global} map,
* so registrations made in this map are <em>local</em> to this
URI converter,
* i.e., they augment or override those of the global map.
* </p>
* <p>
* The map generally specifies instance to instance mapping,
* except for the case that both the key URI and the value URI end
with "/",
* which specifies a folder to folder mapping.
* A folder mapping will remap any URI that has the key as its
{@link URI#replacePrefix prefix},
* e.g., if the map contains:
*<pre>
* http://www.example.com/ -> platform:/resource/example/
*</pre>
* then the URI
*<pre>
* http://www.example.com/a/b/c.d
*</pre>
* will map to
*<pre>
* platform:/resource/example/a/b/c.d
*</pre>
* A matching instance mapping is considered first.
* If there isn't one, the folder mappings are considered starting
with the {@link URI#segmentCount() longest} prefix.
* </p>
* @see #normalize(URI)
* @see #URI_MAP
* @return the map used for remapping a logical URI to a physical URI.
*/
Map<URI, URI> getURIMap();

You can give it a mapping from oldURI to newURI and then all your
proxies pointing at the old location will resolve to the new location.
EcoreUtil.resolveAll can be used to force all the proxies to resolve.
It's like a dream come true.


David Lynch wrote:
> Ed,
>
> I have another simple question regarding broken links.
>
> I have resource A with cross-document references to resource B
> (A->B). Now, imagine that the user moves document B to some other
> folder in the Eclipse workspace, effectively "breaking" all A->B
> references.
>
> Next, the user edits resource A, and logic that I have coded
> determines that document B is "missing." Imagine that my editor pops
> up a resource chooser dialog to prompt for the location of missing
> document B. The user navigates the workspace and finds B.
> Armed with the new URI of previously-missing resource B, what is the
> "best practices" approach to update the cross-document references in A
> to re-establish the links?
>
> Do I have to do this programmatically (i.e., manually) at an object
> level or is there a more elegant way to do this at a lower level?
>
> In my fantasy, I'm hoping there is a magical method in EMF that I can
> call to say "here is the new resource URI, fix links." Am I dreaming?
>
> TIA,
> Dave
>
>


--------------050709070707020505060109
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Dave,<br>
<br>
There's almost always a magical method!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Cross-Document Links--Target Document Moved--Recovery [message #412980 is a reply to message #412979] Thu, 13 September 2007 20:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Ed,

Will the mapping be reversed when the referencing resource (A) is saved
subsequently and needs to compute HREFs? i.e., will this mapping have to
be applied again in subsequent editing sessions of A? Or, will save update
all of the formerly broken URIs to reference the new location of B so that
the serial form is "fixed"?

Cheers,

Christian

Ed Merks wrote:

> Dave,
>
> There's almost always a magical method! In this case, the resource
> set's, URI converter's URI map will be your best friend:
>
> /**
> * Returns the map used for remapping a logical URI to a physical
> URI when {@link #normalize normalizing}.
> * <p>
> * An implementation will typically also delegate to the {@link
> URIConverter#URI_MAP global} map,
> * so registrations made in this map are <em>local</em> to this
> URI converter,
> * i.e., they augment or override those of the global map.
> * </p>
> * <p>
> * The map generally specifies instance to instance mapping,
> * except for the case that both the key URI and the value URI end
> with "/",
> * which specifies a folder to folder mapping.
> * A folder mapping will remap any URI that has the key as its
> {@link URI#replacePrefix prefix},
> * e.g., if the map contains:
> *<pre>
> * http://www.example.com/ -> platform:/resource/example/
> *</pre>
> * then the URI
> *<pre>
> * http://www.example.com/a/b/c.d
> *</pre>
> * will map to
> *<pre>
> * platform:/resource/example/a/b/c.d
> *</pre>
> * A matching instance mapping is considered first.
> * If there isn't one, the folder mappings are considered starting
> with the {@link URI#segmentCount() longest} prefix.
> * </p>
> * @see #normalize(URI)
> * @see #URI_MAP
> * @return the map used for remapping a logical URI to a physical
> URI. */
> Map<URI, URI> getURIMap();
>
> You can give it a mapping from oldURI to newURI and then all your
> proxies pointing at the old location will resolve to the new location.
> EcoreUtil.resolveAll can be used to force all the proxies to resolve.
> It's like a dream come true.
>
>
> David Lynch wrote:
>> Ed,
>>
>> I have another simple question regarding broken links.
>>
>> I have resource A with cross-document references to resource B
>> (A->B). Now, imagine that the user moves document B to some other
>> folder in the Eclipse workspace, effectively "breaking" all A->B
>> references.
>>
>> Next, the user edits resource A, and logic that I have coded
>> determines that document B is "missing." Imagine that my editor pops
>> up a resource chooser dialog to prompt for the location of missing
>> document B. The user navigates the workspace and finds B.
>> Armed with the new URI of previously-missing resource B, what is the
>> "best practices" approach to update the cross-document references in A
>> to re-establish the links?
>>
>> Do I have to do this programmatically (i.e., manually) at an object
>> level or is there a more elegant way to do this at a lower level?
>>
>> In my fantasy, I'm hoping there is a magical method in EMF that I can
>> call to say "here is the new resource URI, fix links." Am I dreaming?
>>
>> TIA,
>> Dave
>>
>>
Re: Cross-Document Links--Target Document Moved--Recovery [message #412981 is a reply to message #412980] Thu, 13 September 2007 21:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000000020108080907040401
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Christian,

The HREF will use whatever is the actual URI of the resource containing
the referenced object at the time you save the reference. I think
you're driving at the fact that you probably have to unload and rename
the resource that failed to load.


Christian W. Damus wrote:
> Hi, Ed,
>
> Will the mapping be reversed when the referencing resource (A) is saved
> subsequently and needs to compute HREFs? i.e., will this mapping have to
> be applied again in subsequent editing sessions of A? Or, will save update
> all of the formerly broken URIs to reference the new location of B so that
> the serial form is "fixed"?
>
> Cheers,
>
> Christian
>
> Ed Merks wrote:
>
>
>> Dave,
>>
>> There's almost always a magical method! In this case, the resource
>> set's, URI converter's URI map will be your best friend:
>>
>> /**
>> * Returns the map used for remapping a logical URI to a physical
>> URI when {@link #normalize normalizing}.
>> * <p>
>> * An implementation will typically also delegate to the {@link
>> URIConverter#URI_MAP global} map,
>> * so registrations made in this map are <em>local</em> to this
>> URI converter,
>> * i.e., they augment or override those of the global map.
>> * </p>
>> * <p>
>> * The map generally specifies instance to instance mapping,
>> * except for the case that both the key URI and the value URI end
>> with "/",
>> * which specifies a folder to folder mapping.
>> * A folder mapping will remap any URI that has the key as its
>> {@link URI#replacePrefix prefix},
>> * e.g., if the map contains:
>> *<pre>
>> * http://www.example.com/ -> platform:/resource/example/
>> *</pre>
>> * then the URI
>> *<pre>
>> * http://www.example.com/a/b/c.d
>> *</pre>
>> * will map to
>> *<pre>
>> * platform:/resource/example/a/b/c.d
>> *</pre>
>> * A matching instance mapping is considered first.
>> * If there isn't one, the folder mappings are considered starting
>> with the {@link URI#segmentCount() longest} prefix.
>> * </p>
>> * @see #normalize(URI)
>> * @see #URI_MAP
>> * @return the map used for remapping a logical URI to a physical
>> URI. */
>> Map<URI, URI> getURIMap();
>>
>> You can give it a mapping from oldURI to newURI and then all your
>> proxies pointing at the old location will resolve to the new location.
>> EcoreUtil.resolveAll can be used to force all the proxies to resolve.
>> It's like a dream come true.
>>
>>
>> David Lynch wrote:
>>
>>> Ed,
>>>
>>> I have another simple question regarding broken links.
>>>
>>> I have resource A with cross-document references to resource B
>>> (A->B). Now, imagine that the user moves document B to some other
>>> folder in the Eclipse workspace, effectively "breaking" all A->B
>>> references.
>>>
>>> Next, the user edits resource A, and logic that I have coded
>>> determines that document B is "missing." Imagine that my editor pops
>>> up a resource chooser dialog to prompt for the location of missing
>>> document B. The user navigates the workspace and finds B.
>>> Armed with the new URI of previously-missing resource B, what is the
>>> "best practices" approach to update the cross-document references in A
>>> to re-establish the links?
>>>
>>> Do I have to do this programmatically (i.e., manually) at an object
>>> level or is there a more elegant way to do this at a lower level?
>>>
>>> In my fantasy, I'm hoping there is a magical method in EMF that I can
>>> call to say "here is the new resource URI, fix links." Am I dreaming?
>>>
>>> TIA,
>>> Dave
>>>
>>>
>>>
>
>


--------------000000020108080907040401
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">
Christian,<br>
<br>
The HREF will use whatever is the actual URI of the resource containing
the referenced object at the time you save the reference.&nbsp; I think
you're driving at the fact that you probably have to unload and rename
the resource that failed to load.<br>
<br>
<br>
Christian W. Damus wrote:
<blockquote cite="mid:fcc8c6$gmo$1@build.eclipse.org" type="cite">
<pre wrap="">Hi, Ed,

Will the mapping be reversed when the referencing resource (A) is saved
subsequently and needs to compute HREFs? i.e., will this mapping have to
be applied again in subsequent editing sessions of A? Or, will save update
all of the formerly broken URIs to reference the new location of B so that
the serial form is "fixed"?

Cheers,

Christian

Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Dave,

There's almost always a magical method! In this case, the resource
set's, URI converter's URI map will be your best friend:

/**
* Returns the map used for remapping a logical URI to a physical
URI when {@link #normalize normalizing}.
* &lt;p&gt;
* An implementation will typically also delegate to the {@link
URIConverter#URI_MAP global} map,
* so registrations made in this map are &lt;em&gt;local&lt;/em&gt; to this
URI converter,
* i.e., they augment or override those of the global map.
* &lt;/p&gt;
* &lt;p&gt;
* The map generally specifies instance to instance mapping,
* except for the case that both the key URI and the value URI end
with "/",
* which specifies a folder to folder mapping.
* A folder mapping will remap any URI that has the key as its
{@link URI#replacePrefix prefix},
* e.g., if the map contains:
*&lt;pre&gt;
* <a class="moz-txt-link-freetext" href="http://www.example.com/">http://www.example.com/</a> -&gt; platform:/resource/example/
*&lt;/pre&gt;
* then the URI
*&lt;pre&gt;
* <a class="moz-txt-link-freetext" href="http://www.example.com/a/b/c.d">http://www.example.com/a/b/c.d</a>
*&lt;/pre&gt;
* will map to
*&lt;pre&gt;
* platform:/resource/example/a/b/c.d
*&lt;/pre&gt;
* A matching instance mapping is considered first.
* If there isn't one, the folder mappings are considered starting
with the {@link URI#segmentCount() longest} prefix.
* &lt;/p&gt;
* @see #normalize(URI)
* @see #URI_MAP
* @return the map used for remapping a logical URI to a physical
URI. */
Map&lt;URI, URI&gt; getURIMap();

You can give it a mapping from oldURI to newURI and then all your
proxies pointing at the old location will resolve to the new location.
EcoreUtil.resolveAll can be used to force all the proxies to resolve.
It's like a dream come true.


David Lynch wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Ed,

I have another simple question regarding broken links.

I have resource A with cross-document references to resource B
(A-&gt;B). Now, imagine that the user moves document B to some other
folder in the Eclipse workspace, effectively "breaking" all A-&gt;B
references.

Next, the user edits resource A, and logic that I have coded
determines that document B is "missing." Imagine that my editor pops
up a resource chooser dialog to prompt for the location of missing
document B. The user navigates the workspace and finds B.
Armed with the new URI of previously-missing resource B, what is the
"best practices" approach to update the cross-document references in A
to re-establish the links?

Do I have to do this programmatically (i.e., manually) at an object
level or is there a more elegant way to do this at a lower level?

In my fantasy, I'm hoping there is a magical method in EMF that I can
call to say "here is the new resource URI, fix links." Am I dreaming?

TIA,
Dave


</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
<br>
</body>
</html>

--------------000000020108080907040401--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Cross-Document Links--Target Document Moved--Recovery [message #414602 is a reply to message #412979] Wed, 14 November 2007 18:58 Go to previous messageGo to next message
parag is currently offline paragFriend
Messages: 83
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_0011_01C826AD.5CF92A50
Content-Type: text/plain;
charset="ISO-8859-15"
Content-Transfer-Encoding: quoted-printable


Ed,

I am following your instructions to make the Rulesheet resource (.ers =
file) with cross-document references to Vocab resource (.ecore file) =
i.e. (Rulesheet -> Vocabulary). But somehow, its failing. The Rulesheet =
(.ers file) was referring objects in Vocabulary (/Test/Vocab/v1.ecore =
file). I moved the Vocabulary to a new location =
(/Test/AnotherVocab/v1.ecore). So now, the Rulesheet won't able to =
access Vocabulary objects. To make it work, the Properties view of =
Rulesheet allows to select new location of Vocabulary and I'm trying to =
reload the resources. But, still the references are not resolved with =
new vocab location.=20

Here is my reference code that sets the new URI for Vocabulary =
resource:


URI lRulesheetURI =3D =
EcoreUtil.getURI(iIRulesheetModelAPI.findRuleset()); // =
lRulesheetURI=3Dplatform:/resource/Test/Rulesheet/rs1_v1.ers #//@ruleset
=20
URI oldVocabURI =3D =
EcoreUtil.getURI(iIRulesheetModelAPI.findRuleset().getVocabu lary()); // =
oldVocabURI=3Dplatform:/resource/Test/Vocab/v1.ecore#/
=20
iIRulesheetModelAPI.findRuleset().eResource()
=
..getResourceSet()
=
..getURIConverter()
.getURIMap()
=
..put(oldVocabURI, aNewResourceURI); // =
aNewResourceURI=3Dplatform:/resource/Test/AnotherVocab/v1.ec ore
=20
=
EcoreUtil.resolveAll(iIRulesheetModelAPI.findRuleset().eReso urce().getRes=
ourceSet()); =20
=20
IVocabularyModelAPI lIVocabularyModelAPI =3D =
iIRulesheetModelAPI.getVocabularyModelAPI();
// unload the old Vocab resource
Resource lOldVocabResource =3D =
lIVocabularyModelAPI.getPrimaryResource();
lIVocabularyModelAPI.unloadResource(lOldVocabResource);
// load the new Vocab resource
Resource lNewVocabResource =3D =
lIVocabularyModelAPI.loadResource(aNewResourceURI);
lIVocabularyModelAPI.setPrimaryResource(lNewVocabResource);
=20
=20
// unload the Rulesheet resource
Resource lOldRulesheetResource =3D =
iIRulesheetModelAPI.getPrimaryResource();
iIRulesheetModelAPI.unloadResource(lOldRulesheetResource);
// reload the same Rulesheet resource
Resource lNewRulesheetResource =3D =
iIRulesheetModelAPI.loadResource(lRulesheetURI);
iIRulesheetModelAPI.setPrimaryResource(lNewRulesheetResource );
=20
=
iIRulesheetModelAPI.setVocabulary(lIVocabularyModelAPI.getDo main());
=20
iIRulesheetModelAPI.validate();


but it is still not resolving proxies (i.e. entities referenced from =
Rulesheet to Vocabulary)

Any idea what is missing here??

Thanks,
Parag


"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:fcc7ls$9tv$1@build.eclipse.org...
Dave,

There's almost always a magical method! In this case, the resource =
set's, URI converter's URI map will be your best friend:

/**
* Returns the map used for remapping a logical URI to a physical =
URI when {@link #normalize normalizing}.
* <p>
* An implementation will typically also delegate to the {@link =
URIConverter#URI_MAP global} map,
* so registrations made in this map are <em>local</em> to this =
URI converter,
* i.e., they augment or override those of the global map.
* </p>
* <p>
* The map generally specifies instance to instance mapping,
* except for the case that both the key URI and the value URI end =
with "/",=20
* which specifies a folder to folder mapping.
* A folder mapping will remap any URI that has the key as its =
{@link URI#replacePrefix prefix},=20
* e.g., if the map contains:
*<pre>
* http://www.example.com/ -> platform:/resource/example/
*</pre>
* then the URI
*<pre>
* http://www.example.com/a/b/c.d
*</pre>
* will map to=20
*<pre>
* platform:/resource/example/a/b/c.d
*</pre>
* A matching instance mapping is considered first.
* If there isn't one, the folder mappings are considered starting =
with the {@link URI#segmentCount() longest} prefix.=20
* </p>
* @see #normalize(URI)
* @see #URI_MAP
* @return the map used for remapping a logical URI to a physical =
URI.
*/
Map<URI, URI> getURIMap();

You can give it a mapping from oldURI to newURI and then all your =
proxies pointing at the old location will resolve to the new location. =
EcoreUtil.resolveAll can be used to force all the proxies to resolve. =
It's like a dream come true.


David Lynch wrote:=20
Ed,=20

I have another simple question regarding broken links.=20

I have resource A with cross-document references to resource B =
(A->B). Now, imagine that the user moves document B to some other =
folder in the Eclipse workspace, effectively "breaking" all A->B =
references.=20

Next, the user edits resource A, and logic that I have coded =
determines that document B is "missing." Imagine that my editor pops up =
a resource chooser dialog to prompt for the location of missing document =
B. The user navigates the workspace and finds B. =20
Armed with the new URI of previously-missing resource B, what is the =
"best practices" approach to update the cross-document references in A =
to re-establish the links?=20

Do I have to do this programmatically (i.e., manually) at an object =
level or is there a more elegant way to do this at a lower level?=20

In my fantasy, I'm hoping there is a magical method in EMF that I =
can call to say "here is the new resource URI, fix links." Am I =
dreaming?=20

TIA,=20
Dave=20





------=_NextPart_000_0011_01C826AD.5CF92A50
Content-Type: text/html;
charset="ISO-8859-15"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type =
content=3Dtext/html;charset=3DISO-8859-15>
<META content=3D"MSHTML 6.00.2900.3199" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><BR>Ed,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;I am following your instructions to make the Rulesheet =
resource (.ers=20
file) with cross-document references to Vocab resource (.ecore file) =
i.e.=20
(Rulesheet -&gt; Vocabulary). But somehow,&nbsp;its failing. The =
Rulesheet (.ers=20
file) was referring objects in Vocabulary (/Test/Vocab/v1.ecore file). I =
moved=20
the Vocabulary to a new location (/Test/AnotherVocab/v1.ecore).&nbsp;So =
now, the=20
Rulesheet won't able to access Vocabulary&nbsp;objects. To make it work, =
the=20
Properties view of Rulesheet allows to select&nbsp;new location=20
of&nbsp;Vocabulary and I'm trying to reload the resources. But, still =
the=20
references are not resolved with new vocab location.&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;Here is my reference code that sets the new URI for =
Vocabulary=20
resource:</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; URI =
lRulesheetURI =3D=20
EcoreUtil.getURI(iIRulesheetModelAPI.findRuleset());&nbs p; //=20
lRulesheetURI=3Dplatform:/resource/Test/Rulesheet/rs1_v1.ers #//@ruleset <B=
R> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; URI oldVocabURI =3D =

EcoreUtil.getURI(iIRulesheetModelAPI.findRuleset().getVocabu lary());&nbsp=
; //=20
oldVocabURI=3Dplatform:/resource/Test/Vocab/v1.ecore#/<BR>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
iIRulesheetModelAPI.findRuleset().eResource()<BR>&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n b=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
..getResourceSet()<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& n=
bsp;=20
..getURIConverter()<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb s=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;=
&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
..getURIMap()<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n b=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
..put(oldVocabURI, aNewResourceURI);&nbsp; //=20
aNewResourceURI=3Dplatform:/resource/Test/AnotherVocab/v1.ec ore <BR>&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
EcoreUtil.resolveAll(iIRulesheetModelAPI.findRuleset().eReso urce().getRes=
ourceSet());&nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; IVocabularyModelAPI =

lIVocabularyModelAPI =3D=20
iIRulesheetModelAPI.getVocabularyModelAPI();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
// unload the old Vocab=20
resource<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Resource=20
lOldVocabResource =3D=20
lIVocabularyModelAPI.getPrimaryResource();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
lIVocabularyModelAPI.unloadResource(lOldVocabResource);<BR>&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
// load the new Vocab=20
resource<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Resource=20
lNewVocabResource =3D=20
lIVocabularyModelAPI.loadResource(aNewResourceURI);<BR>&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
lIVocabularyModelAPI.setPrimaryResource(lNewVocabResource);<BR >&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; // unload the =
Rulesheet=20
resource<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Resource=20
lOldRulesheetResource =3D=20
iIRulesheetModelAPI.getPrimaryResource();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;=20
iIRulesheetModelAPI.unloadResource(lOldRulesheetResource);<BR >&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;=20
// reload the same Rulesheet=20
resource<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Resource=20
lNewRulesheetResource =3D=20
iIRulesheetModelAPI.loadResource(lRulesheetURI);<BR>&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
iIRulesheetModelAPI.setPrimaryResource(lNewRulesheetResource ); <BR>&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
iIRulesheetModelAPI.setVocabulary(lIVocabularyModelAPI.getDo main()); <BR>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
iIRulesheetModelAPI.validate();<BR></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;but it is still not resolving proxies (i.e. entities =
referenced from=20
Rulesheet to Vocabulary)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;Any idea what is missing here??</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks,</DIV>
<DIV>Parag</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" &lt;<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>&gt;=20
wrote in message <A=20
=
href=3D"news:fcc7ls$9tv$1@build.eclipse.org">news:fcc7ls$9tv$1@build.ecli=
pse.org</A>...</DIV>Dave,<BR><BR>There's=20
almost always a magical method!&nbsp; In this case, the resource =
set's, URI=20
converter's URI map will be your best friend:<BR>
<BLOCKQUOTE><SMALL>&nbsp; /**</SMALL><BR><SMALL>&nbsp;&nbsp; * Returns =
the=20
map used for remapping a logical URI to a physical URI when {@link=20
#normalize normalizing}.</SMALL><BR><SMALL>&nbsp;&nbsp; *=20
&lt;p&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; * An implementation will =
typically=20
also delegate to the {@link URIConverter#URI_MAP global}=20
map,</SMALL><BR><SMALL>&nbsp;&nbsp; * so registrations made in this =
map are=20
&lt;em&gt;local&lt;/em&gt; to this URI=20
converter,</SMALL><BR><SMALL>&nbsp;&nbsp; * i.e., they augment or =
override=20
those of the global map.</SMALL><BR><SMALL>&nbsp;&nbsp; *=20
&lt;/p&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; *=20
&lt;p&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; * The map generally =
specifies=20
instance to instance mapping,</SMALL><BR><SMALL>&nbsp;&nbsp; * =
except for=20
the case that both the key URI and the value URI end with "/",=20
</SMALL><BR><SMALL>&nbsp;&nbsp; * which specifies a folder to folder =

mapping.</SMALL><BR><SMALL>&nbsp;&nbsp; * A folder mapping will =
remap any=20
URI that has the key as its {@link URI#replacePrefix prefix},=20
</SMALL><BR><SMALL>&nbsp;&nbsp; * e.g., if the map=20
contains:</SMALL><BR><SMALL>&nbsp;&nbsp;=20
*&lt;pre&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; *&nbsp; <A=20
class=3Dmoz-txt-link-freetext=20
href=3D"http://www.example.com/">http://www.example.com/</A> -&gt;=20
platform:/resource/example/</SMALL><BR><SMALL>&nbsp;&nbsp;=20
*&lt;/pre&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; * then the=20
URI</SMALL><BR><SMALL>&nbsp;&nbsp;=20
*&lt;pre&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; *&nbsp; <A=20
class=3Dmoz-txt-link-freetext=20
=
href=3D"http://www.example.com/a/b/c.d">http://www.example.com/a/b/c.d</A=
></SMALL><BR><SMALL>&nbsp;&nbsp;=20
*&lt;/pre&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; * will map to=20
</SMALL><BR><SMALL>&nbsp;&nbsp; =
*&lt;pre&gt;</SMALL><BR><SMALL>&nbsp;&nbsp;=20
*&nbsp; =
platform:/resource/example/a/b/c.d</SMALL><BR><SMALL>&nbsp;&nbsp;=20
*&lt;/pre&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; * A matching instance =
mapping=20
is considered first.</SMALL><BR><SMALL>&nbsp;&nbsp; * If there isn't =
one,=20
the folder mappings are considered starting with the {@link=20
URI#segmentCount() longest} prefix. </SMALL><BR><SMALL>&nbsp;&nbsp; =
*=20
&lt;/p&gt;</SMALL><BR><SMALL>&nbsp;&nbsp; * @see=20
#normalize(URI)</SMALL><BR><SMALL>&nbsp;&nbsp; * @see=20
#URI_MAP</SMALL><BR><SMALL>&nbsp;&nbsp; * @return the map used for =
remapping=20
a logical URI to a physical URI.</SMALL><BR><SMALL>&nbsp;&nbsp;=20
*/</SMALL><BR><SMALL>&nbsp; Map&lt;URI, URI&gt;=20
getURIMap();</SMALL><BR></BLOCKQUOTE>You can give it a mapping from =
oldURI to=20
newURI and then all your proxies pointing at the old location will =
resolve to=20
the new location.&nbsp; EcoreUtil.resolveAll can be used to force all =
the=20
proxies to resolve.&nbsp; It's like a dream come =
true.<BR><BR><BR>David Lynch=20
wrote:=20
<BLOCKQUOTE =
cite=3Dmid:6893407756798bc9708dbf4c5c9f30ad$1@www.eclipse.org=20
type=3D"cite">Ed, <BR><BR>I have another simple question regarding =
broken=20
links. <BR><BR>I have resource A with cross-document references to =
resource=20
B (A-&gt;B).&nbsp; Now, imagine that the user moves document B to =
some other=20
folder in the Eclipse workspace, effectively "breaking" all A-&gt;B=20
references. <BR><BR>Next, the user edits resource A, and logic that =
I have=20
coded determines that document B is "missing."&nbsp; Imagine that my =
editor=20
pops up a resource chooser dialog to prompt for the location of =
missing=20
document B.&nbsp; The user navigates the workspace and finds =
B.&nbsp;=20
<BR>Armed with the new URI of previously-missing resource B, what is =
the=20
"best practices" approach to update the cross-document references in =
A to=20
re-establish the links? <BR><BR>Do I have to do this =
programmatically (i.e.,=20
manually) at an object level or is there a more elegant way to do =
this at a=20
lower level? <BR><BR>In my fantasy, I'm hoping there is a magical =
method in=20
EMF that I can call to say "here is the new resource URI, fix =
links."&nbsp;=20
Am I dreaming? <BR><BR>TIA, <BR>Dave=20
<BR><BR><BR></BLOCKQUOTE><BR></BLOCKQUOTE></BODY></HTML >

------=_NextPart_000_0011_01C826AD.5CF92A50--
Re: Cross-Document Links--Target Document Moved--Recovery [message #414606 is a reply to message #414602] Wed, 14 November 2007 21:10 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050601030006050806010003
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Parag,

The map should containing mappings for URIs without a fragment. I.e.,
iIRulesheetModelAPI.findRuleset().getVocabulary().eResource. getURI() to
iIRulesheetModelAPI.findRuleset().eResource().getURI().


parag wrote:
>
> Ed,
>
> I am following your instructions to make the Rulesheet resource (.ers
> file) with cross-document references to Vocab resource (.ecore file)
> i.e. (Rulesheet -> Vocabulary). But somehow, its failing. The
> Rulesheet (.ers file) was referring objects in Vocabulary
> (/Test/Vocab/v1.ecore file). I moved the Vocabulary to a new location
> (/Test/AnotherVocab/v1.ecore). So now, the Rulesheet won't able to
> access Vocabulary objects. To make it work, the Properties view of
> Rulesheet allows to select new location of Vocabulary and I'm trying
> to reload the resources. But, still the references are not resolved
> with new vocab location.
>
> Here is my reference code that sets the new URI for Vocabulary resource:
>
>
> URI lRulesheetURI =
> EcoreUtil.getURI(iIRulesheetModelAPI.findRuleset()); //
> lRulesheetURI=platform:/resource/Test/Rulesheet/rs1_v1.ers#/ /@ruleset
>
> URI oldVocabURI =
> EcoreUtil.getURI(iIRulesheetModelAPI.findRuleset().getVocabu lary());
> // oldVocabURI=platform:/resource/Test/Vocab/v1.ecore#/
>
> iIRulesheetModelAPI.findRuleset().eResource()
>
> ..getResourceSet()
>
> ..getURIConverter()
> ..getURIMap()
>
> ..put(oldVocabURI, aNewResourceURI); //
> aNewResourceURI=platform:/resource/Test/AnotherVocab/v1.ecor e
>
>
> EcoreUtil.resolveAll(iIRulesheetModelAPI.findRuleset().eReso urce().getResourceSet());
>
>
> IVocabularyModelAPI lIVocabularyModelAPI =
> iIRulesheetModelAPI.getVocabularyModelAPI();
> // unload the old Vocab resource
> Resource lOldVocabResource =
> lIVocabularyModelAPI.getPrimaryResource();
> lIVocabularyModelAPI.unloadResource(lOldVocabResource);
> // load the new Vocab resource
> Resource lNewVocabResource =
> lIVocabularyModelAPI.loadResource(aNewResourceURI);
> lIVocabularyModelAPI.setPrimaryResource(lNewVocabResource);
>
>
> // unload the Rulesheet resource
> Resource lOldRulesheetResource =
> iIRulesheetModelAPI.getPrimaryResource();
> iIRulesheetModelAPI.unloadResource(lOldRulesheetResource);
> // reload the same Rulesheet resource
> Resource lNewRulesheetResource =
> iIRulesheetModelAPI.loadResource(lRulesheetURI);
> iIRulesheetModelAPI.setPrimaryResource(lNewRulesheetResource );
>
>
> iIRulesheetModelAPI.setVocabulary(lIVocabularyModelAPI.getDo main());
>
> iIRulesheetModelAPI.validate();
>
> but it is still not resolving proxies (i.e. entities referenced from
> Rulesheet to Vocabulary)
>
> Any idea what is missing here??
>
> Thanks,
> Parag
>
>
>
> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
> message news:fcc7ls$9tv$1@build.eclipse.org...
> Dave,
>
> There's almost always a magical method! In this case, the
> resource set's, URI converter's URI map will be your best friend:
>
> /**
> * Returns the map used for remapping a logical URI to a
> physical URI when {@link #normalize normalizing}.
> * <p>
> * An implementation will typically also delegate to the
> {@link URIConverter#URI_MAP global} map,
> * so registrations made in this map are <em>local</em> to
> this URI converter,
> * i.e., they augment or override those of the global map.
> * </p>
> * <p>
> * The map generally specifies instance to instance mapping,
> * except for the case that both the key URI and the value
> URI end with "/",
> * which specifies a folder to folder mapping.
> * A folder mapping will remap any URI that has the key as
> its {@link URI#replacePrefix prefix},
> * e.g., if the map contains:
> *<pre>
> * http://www.example.com/ -> platform:/resource/example/
> *</pre>
> * then the URI
> *<pre>
> * http://www.example.com/a/b/c.d
> *</pre>
> * will map to
> *<pre>
> * platform:/resource/example/a/b/c.d
> *</pre>
> * A matching instance mapping is considered first.
> * If there isn't one, the folder mappings are considered
> starting with the {@link URI#segmentCount() longest} prefix.
> * </p>
> * @see #normalize(URI)
> * @see #URI_MAP
> * @return the map used for remapping a logical URI to a
> physical URI.
> */
> Map<URI, URI> getURIMap();
>
> You can give it a mapping from oldURI to newURI and then all your
> proxies pointing at the old location will resolve to the new
> location. EcoreUtil.resolveAll can be used to force all the
> proxies to resolve. It's like a dream come true.
>
>
> David Lynch wrote:
>> Ed,
>>
>> I have another simple question regarding broken links.
>>
>> I have resource A with cross-document references to resource B
>> (A->B). Now, imagine that the user moves document B to some
>> other folder in the Eclipse workspace, effectively "breaking" all
>> A->B references.
>>
>> Next, the user edits resource A, and logic that I have coded
>> determines that document B is "missing." Imagine that my editor
>> pops up a resource chooser dialog to prompt for the location of
>> missing document B. The user navigates the workspace and finds B.
>> Armed with the new URI of previously-missing resource B, what is
>> the "best practices" approach to update the cross-document
>> references in A to re-establish the links?
>>
>> Do I have to do this programmatically (i.e., manually) at an
>> object level or is there a more elegant way to do this at a lower
>> level?
>>
>> In my fantasy, I'm hoping there is a magical method in EMF that I
>> can call to say "here is the new resource URI, fix links." Am I
>> dreaming?
>>
>> TIA,
>> Dave
>>
>>
>


--------------050601030006050806010003
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Parag,<br>
<br>
The map should containing mappings for URIs without a fragment.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Announce] The EclipseCon 2008 Submission Deadline is Rapidly Approaching.
Next Topic:Abstract classes and attributes
Goto Forum:
  


Current Time: Thu Apr 25 09:27:38 GMT 2024

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

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

Back to the top