Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » EcoreUtil.getURI(feature)(EcoreUtil.getURI(feature) returns an unusable uri)
| | | | |
Re: EcoreUtil.getURI(feature) [message #1219633 is a reply to message #1219620] |
Thu, 05 December 2013 06:04 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Geoffry,
When processing wildcards, the deserializer is using things like
org.eclipse.emf.ecore.util.ExtendedMetaData.demandFeature(String,
String, boolean) to create a feature and such demand created metadata
has no enclosing resource. You might consider using
org.eclipse.emf.ecore.util.ExtendedMetaData.getNamespace(EStructuralFeature)
in the case that the URI you get from EcoreUtil.getURI returns the empty
URI, but keep in mind that you "find" that feature again, you have to
demand create it again, and for that you need to know if it's an element
or an attribute to call demandFeature with the right arguments.
On 05/12/2013 1:26 AM, Geoffry Roberts wrote:
> Ed,
>
> Thanks for being so patient. I appreciate it.
> The application stores and EMF document into a document oriented
> database. When it stores data it also stores a uri(s) so the data can
> be retrieved into the proper EMF class(es). When I wrote that
> EcoreUtil.getURI(feature) was returning #///DocumentRoot I called it
> unusable because #///DocumentRoot normalizes into file:///<whatever>,
> which is not a uri for an EMF class. At store time all appears to be
> working, but at retrieval time #///DocumentRoot cannot be interpreted
> successfully and errors ensue. A FileNotFoundException is thrown with
> the message that file:///<whatever> is a directory. I have included
> two examples of usable uris so you see what they look like.
>
> http://www.eclipse.org/emf/2003/XMLType#//XMLTypeDocumentRoot/text
> http://www.openhealthtools.org/mdht/uml/hl7/datatypes#//EN/given
>
> Perhaps my question should be why, when processing this embedded xml,
> am I not getting a usable uri?
>
> Thanks again
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: EcoreUtil.getURI(feature) [message #1220086 is a reply to message #1219575] |
Mon, 09 December 2013 15:35 |
Bryan Hunt Messages: 366 Registered: July 2009 |
Senior Member |
|
|
Hi Ed,
Geoffry is attempting to use MongoEMF to serialize / deserialize his model. The code in question from MongoEMF is:
protected void buildFeatureMap(DBObject dbObject, EAttribute attribute, Object value)
{
FeatureMap.Internal featureMap = (FeatureMap.Internal) value;
Iterator<FeatureMap.Entry> iterator = featureMap.basicIterator();
ArrayList<DBObject> dbFeatureMap = new ArrayList<DBObject>();
while (iterator.hasNext())
{
DBObject dbEntry = new BasicDBObject();
FeatureMap.Entry entry = iterator.next();
EStructuralFeature feature = entry.getEStructuralFeature();
dbEntry.put("key", EcoreUtil.getURI(feature).toString()); <<<-------------------- Get the URI here
if (feature instanceof EAttribute)
{
EDataType eDataType = ((EAttribute) feature).getEAttributeType();
if (!MongoUtils.isNativeType(eDataType))
dbEntry.put("value", convertEMFValueToMongoDBValue(eDataType, entry.getValue()));
else
dbEntry.put("value", entry.getValue());
}
else
dbEntry.put("value", buildReferencedObject((EReference) feature, (EObject) entry.getValue()));
dbFeatureMap.add(dbEntry);
}
dbObject.put(attribute.getName(), dbFeatureMap);
}
Can we improve upon this solution to handle his case generically, or is this something that is model specific?
Bryan
|
|
|
Re: EcoreUtil.getURI(feature) [message #1220139 is a reply to message #1220086] |
Tue, 10 December 2013 05:14 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Bryan,
I assume you're using this URI so that later you can use
ResourceSet.getEObject to load the feature again, but this only works if
the feature isn't a demand created one. If it's demand created, you'll
really need to remember the namespace, the name, and whether it's an
element or an attribute, so you can call
org.eclipse.emf.ecore.util.BasicExtendedMetaData.demandFeature(String,
String, boolean) with the appropriate arguments. Note there are even
cases (an xsi:type within a wildcard's feature map's contents) where you
could end up with an EObject whose eClass() is created using
org.eclipse.emf.ecore.util.BasicExtendedMetaData.demandType(String, String).
On 09/12/2013 4:35 PM, Bryan Hunt wrote:
> Hi Ed,
>
> Geoffry is attempting to use MongoEMF to serialize / deserialize his
> model. The code in question from MongoEMF is:
>
>
> protected void buildFeatureMap(DBObject dbObject, EAttribute
> attribute, Object value)
> {
> FeatureMap.Internal featureMap = (FeatureMap.Internal) value;
> Iterator<FeatureMap.Entry> iterator = featureMap.basicIterator();
> ArrayList<DBObject> dbFeatureMap = new ArrayList<DBObject>();
>
> while (iterator.hasNext())
> {
> DBObject dbEntry = new BasicDBObject();
> FeatureMap.Entry entry = iterator.next();
> EStructuralFeature feature = entry.getEStructuralFeature();
> dbEntry.put("key", EcoreUtil.getURI(feature).toString());
> <<<-------------------- Get the URI here
>
> if (feature instanceof EAttribute)
> {
> EDataType eDataType = ((EAttribute) feature).getEAttributeType();
>
> if (!MongoUtils.isNativeType(eDataType))
> dbEntry.put("value", convertEMFValueToMongoDBValue(eDataType,
> entry.getValue()));
> else
> dbEntry.put("value", entry.getValue());
> }
> else
> dbEntry.put("value", buildReferencedObject((EReference) feature,
> (EObject) entry.getValue()));
>
> dbFeatureMap.add(dbEntry);
> }
>
> dbObject.put(attribute.getName(), dbFeatureMap);
> }
>
>
> Can we improve upon this solution to handle his case generically, or
> is this something that is model specific?
>
> Bryan
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: EcoreUtil.getURI(feature) [message #1220256 is a reply to message #1220237] |
Tue, 10 December 2013 16:50 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Geoffry,
Comments below.
On 10/12/2013 3:32 PM, Geoffry Roberts wrote:
> Ed,
> By "demand created" do you mean created at runtime? If so, this is
> not the case in my situation.
Yes it is.
> What I have are XML tags that are embedded within an element but are
> supposed to be treated as a String.
Treated by what?
> This is what the designers (not me) envisioned. As a result, when
> EMF is used to process these documents (a very attractive thing to do
> from a technical standpoint), EMF creates a feature map treating them
> as elements.
Because they are.
> In the corresponding ecore, these embedded elements are not given a
> datatype.
They're instances of AnyType.
> <thinking out loud>I wonder if this problem would go a way if they
> were given a type.
No.
> We have ST, which, in Java, is implemented as String.</thinking out loud>
If you saved such a thing as XML, the things like < would be encoded as
< so they would not be embedded elements, they'd just be a value that
happens to look like XML when it's decoded.
>
> Thanks
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: EcoreUtil.getURI(feature) [message #1220264 is a reply to message #1220256] |
Tue, 10 December 2013 17:56 |
Bryan Hunt Messages: 366 Registered: July 2009 |
Senior Member |
|
|
Hi Ed,
Here's the other half of the MongoEMF code ...
protected void buildFeatureMap(DBCollection collection, Resource resource, EObject eObject, EAttribute attribute, List<DBObject> values)
{
FeatureMap.Internal featureMap = (FeatureMap.Internal) eObject.eGet(attribute);
for (DBObject entry : values)
{
EStructuralFeature feature = (EStructuralFeature) resource.getResourceSet().getEObject(URI.createURI((String) entry.get("key")), true);
if (feature instanceof EAttribute)
{
EDataType eDataType = ((EAttribute) feature).getEAttributeType();
featureMap.add(feature, convertMongoDBValueToEMFValue(eDataType, entry.get("value")));
}
else
{
EReference reference = (EReference) feature;
DBObject dbReference = (DBObject) entry.get("value");
EObject target = buildReferencedObject(collection, dbReference, resource, reference.isResolveProxies());
featureMap.add(feature, target);
}
}
}
|
|
|
Goto Forum:
Current Time: Thu Sep 26 19:20:12 GMT 2024
Powered by FUDForum. Page generated in 0.04318 seconds
|