Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » getURI
getURI [message #422393] Wed, 03 September 2008 22:47 Go to next message
Sam Julian is currently offline Sam JulianFriend
Messages: 29
Registered: July 2009
Junior Member
Hi,
To identify each elements in my Generated Editor I use as identifier an
URI identifier like this:
platform:/resource/xrender/My.xrender/@cloth/@clothParams/@c olisionValueDef

I use EcoreUtil.getAllContents and iterate over the content to get via
EcoreUtil.getID(eobject) the respective ID. If the object has no ID
attribute or the ID attribute is not set getID(eobject) will returns null.
that work fine! and here is my Problem with this issue;
---getEIDAttribute() represents the attribute that will be used as the ID
of an instance.----

1- my clothParamsType generated interface has getId() and
SetId(BigInteger) features.

EcoreUtil.getURI(EObject eObject) do this-->
....
String id = EcoreUtil.getID(eObject);

if (id != null)
{
return URI.createURI("#" + id);
}
....
EcoreUtil.getURI(eobjectWithIdInstance) return
platform:/resource/xrender/My.xrender#999 (BAD IDENTIFIER)

while a generated interface with no Named Id Attribute will returns
platform:/resource/xrender/My.xrender/@cloth/@clothParams/@c olisionValueDef

Q1- How to avoid executing "URI.createURI("#" + id)" ?
Q2- How to apend an unique Id for each eobject? or How to create an ID
feature for the Object--> Overide setID(EObject, String)?

thanks,

Sam
Re: getURI [message #422395 is a reply to message #422393] Wed, 03 September 2008 23:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Sam,

Comments below.

Sam Julian wrote:
> Hi,
> To identify each elements in my Generated Editor I use as identifier
> an URI identifier like this:
> platform:/resource/xrender/My.xrender/@cloth/@clothParams/@c olisionValueDef
Is the # missing?
>
>
> I use EcoreUtil.getAllContents and iterate over the content to get via
> EcoreUtil.getID(eobject) the respective ID.
That's for intrinsic IDS, which looks to be not what the above is showing.
> If the object has no ID attribute or the ID attribute is not set
> getID(eobject) will returns null. that work fine! and here is my
> Problem with this issue;
> ---getEIDAttribute() represents the attribute that will be used as the
> ID of an instance.----
>
> 1- my clothParamsType generated interface has getId() and
> SetId(BigInteger) features.
>
> EcoreUtil.getURI(EObject eObject) do this-->
> ...
It gets to here only if the object isn't contained by a resource...
> String id = EcoreUtil.getID(eObject);
> if (id != null)
> {
> return URI.createURI("#" + id);
> }
> ...
> EcoreUtil.getURI(eobjectWithIdInstance) return
> platform:/resource/xrender/My.xrender#999 (BAD IDENTIFIER)
EMF doesn't actually care if your ID conforms to XML Schema's ID simple
type.
>
> while a generated interface with no Named Id Attribute will returns
> platform:/resource/xrender/My.xrender/@cloth/@clothParams/@c olisionValueDef
>
Yes, if there's no ID, a URI fragment path is used.
>
> Q1- How to avoid executing "URI.createURI("#" + id)" ?
I'm not sure I understand. Generally the resource is responsible for
determining what form of reference it will recognized:

Resource resource = eObject.eResource();
if (resource != null)
{
return
resource.getURI().appendFragment(resource.getURIFragment(eOb ject));

> Q2- How to apend an unique Id for each eobject? or How to create an ID
> feature for the Object--> Overide setID(EObject, String)?
If each object (each EClass) has an EAttribute for which isID is true,
and you've set a value for that attribute, that value is what will be
used to identify the object.
>
> thanks,
>
> Sam
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: getURI [message #422396 is a reply to message #422395] Wed, 03 September 2008 23:39 Go to previous messageGo to next message
Sam Julian is currently offline Sam JulianFriend
Messages: 29
Registered: July 2009
Junior Member
Hi, Ed
thanks, for the Response.

Is the # missing?
no, I let the code delete them.

That's for intrinsic IDS, which looks to be not what the above is showing.
--> Yes, that is right. but getURI use the intrinsic IDS if they are defined,
instead of the Real Resource URI, or?

EMF doesn't actually care if your ID conforms to XML Schema's ID simple
type.
--> my named Id do not conform to XML ID simple type, its just has been
arbitrary choosed.

Yes, if there's no ID, a URI fragment path is used.
--> Yes, and I just want to use URI fragment as an Identifier, but i canŽt do
so if my eobject (generated interface) had an ID feature. shall I, in such a
Case, get the URI direct from the Resource?

Q1- How to avoid executing "URI.createURI("#" + id)" ?

I'm not sure I understand. Generally the resource is responsible for
determining what form of reference it will recognized:

Resource resource = eObject.eResource();
if (resource != null)
{
return
resource.getURI().appendFragment(resource.getURIFragment(eOb ject));
--> I do something like this
Resource res = (Resource) this.editingDomain.getResourceSet()
.getResources().get(0);
Iterator<?> Iterator = EcoreUtil.getAllContents(res.getContents(), true);
while (Iterator.hasNext()){
EcoreUtil.getURI(eObject);
}

Thanks,
Re: getURI [message #422397 is a reply to message #422395] Wed, 03 September 2008 23:55 Go to previous messageGo to next message
Sam Julian is currently offline Sam JulianFriend
Messages: 29
Registered: July 2009
Junior Member
Hi, Ed

I try to get the URI direct from the Resource, but this return also the
same results
-->return platform:/resource/xrender/My.xrender#999
again, I need to suppress getId() as an identifier for URI Fragment. to
get this: platform:/resource/xrender/My.xrender/@cloth/ instead of the
above URI fragment

Thanks
Sam
Re: getURI [message #422398 is a reply to message #422396] Thu, 04 September 2008 00:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Sam,

Comments below.

Sam Julian wrote:
> Hi, Ed
> thanks, for the Response.
>
> Is the # missing?
> no, I let the code delete them.
I'm don't think I understand that comment.
>
> That's for intrinsic IDS, which looks to be not what the above is
> showing.
> --> Yes, that is right. but getURI use the intrinsic IDS if they are
> defined, instead of the Real Resource URI, or?
I'm not sure what you mean by "Real Resource URI". If there's an ID, it
gets used. That's the way it's supposed to work. Of course you can
specialized a ResourceImpl's getURIFragment method if you want it to
behave differently, but a resource is responsible for deciding what
> EMF doesn't actually care if your ID conforms to XML Schema's ID
> simple type.
> --> my named Id do not conform to XML ID simple type, its just has
> been arbitrary choosed.
So it's not a problem?
>
> Yes, if there's no ID, a URI fragment path is used.
> --> Yes, and I just want to use URI fragment as an Identifier, but i
> canŽt do so if my eobject (generated interface) had an ID feature.
> shall I, in such a Case, get the URI direct from the Resource?
You can look ResourceImpl's getURIFragment if you want to compute a
fragment path even though the object has an ID.
>
> Q1- How to avoid executing "URI.createURI("#" + id)" ?
>
> I'm not sure I understand. Generally the resource is responsible for
> determining what form of reference it will recognized:
>
> Resource resource = eObject.eResource();
> if (resource != null)
> {
> return
> resource.getURI().appendFragment(resource.getURIFragment(eOb ject));
> --> I do something like this
> Resource res = (Resource) this.editingDomain.getResourceSet()
> .getResources().get(0);
> Iterator<?> Iterator = EcoreUtil.getAllContents(res.getContents(), true);
> while (Iterator.hasNext()){
> EcoreUtil.getURI(eObject);
> }
I guess what's not entirely clear is what problem you are trying to
solve. If you want to compute a fragment path in all cases, you can
look at the logic in ResourceImpl.getURIFragment or in EcoreUtil.getURI
to see how that's done:

InternalEObject internalEObject = (InternalEObject)eObject;
List<String> uriFragmentPath = new ArrayList<String>();
for (InternalEObject container =
internalEObject.eInternalContainer(); container != null; container =
internalEObject.eInternalContainer())
{

uriFragmentPath.add(container.eURIFragmentSegment(internalEO bject.eContainingFeature(),
internalEObject));
internalEObject = container;
}

StringBuffer result = new StringBuffer("#//");

for (int i = uriFragmentPath.size() - 1; i >= 0; --i)
{
result.append('/');
result.append(uriFragmentPath.get(i));
}
return URI.createURI(result.toString());

>
> Thanks,
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: getURI [message #422399 is a reply to message #422397] Thu, 04 September 2008 00:42 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Sam,

It's not clear why, but as I mentioned in the other note, the logic for
computing a fragment path there in both ResourceImpl.getURIFragment and
EcoreUtil.getURI...


Sam Julian wrote:
> Hi, Ed
>
> I try to get the URI direct from the Resource, but this return also
> the same results
> -->return platform:/resource/xrender/My.xrender#999 again, I need to
> suppress getId() as an identifier for URI Fragment. to get this:
> platform:/resource/xrender/My.xrender/@cloth/ instead of the above URI
> fragment
>
> Thanks
> Sam
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Teneo] Different machine new error
Next Topic:[Teneo] NullPointerException on store
Goto Forum:
  


Current Time: Sat Apr 27 02:09:42 GMT 2024

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

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

Back to the top