Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EcoreUitl.resolveAll
EcoreUitl.resolveAll [message #428083] Mon, 09 March 2009 18:51 Go to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Does EcoreUitl.resolveAll should resolve all proxies for an object all the
time ?

I'm asking the question because of the following:

I have objects that are instance of EPackage!!!
EClass does references objects in others EPackage.

At some point EClass.getSuperTypes returns proxies!
By calling EcoreUitl.resolveAll(ePackage) it will try to resolve them...
it will also initialize the internal structure of
EClassImpl.getAllStructureFeatures.

Now, if I add a ePackage in my registry... and call EcoreUitl.resolveAll
for all my packages.... it will not refresh
EClassImpl.getAllStructureFeatures array ?


Is it a bug ?

Does my observations are correct ?
Re: EcoreUitl.resolveAll [message #428084 is a reply to message #428083] Mon, 09 March 2009 19:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Simon,

Comments below.


Simon Mc Duff wrote:
> Does EcoreUitl.resolveAll should resolve all proxies for an object all
> the time ?
Not sure what you mean by all the time...
>
> I'm asking the question because of the following:
>
> I have objects that are instance of EPackage!!!
> EClass does references objects in others EPackage.
>
> At some point EClass.getSuperTypes returns proxies!
At what point? Generally you should see proxies only if you try hard to
get at them because normally the are resolved on demand.
> By calling EcoreUitl.resolveAll(ePackage) it will try to resolve
> them... it will also initialize the internal structure of
> EClassImpl.getAllStructureFeatures.
Yep.
>
> Now, if I add a ePackage in my registry... and call
> EcoreUitl.resolveAll for all my packages.... it will not refresh
> EClassImpl.getAllStructureFeatures array ?
If the list of super types changes the proxy resolve notification should
cause derived classes to recompute their list of all features.
>
>
> Is it a bug ?
Probably not. :-P
>
> Does my observations are correct ?
I think I missed some details...
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EcoreUitl.resolveAll [message #428085 is a reply to message #428084] Mon, 09 March 2009 20:07 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Maybe with a testcase will be better:
(Cannot posted as a file... I have access only through the web interface
for now).

public void testOneXMIResourceManyViewsOnOneResourceSet() throws Exception
{
byte[] dataPackage1 = null;
byte[] dataPackage2 = null;
{

ResourceSet resourceSet = new ResourceSetImpl();
EPackage[] packages = createDynamicEPackage();
Resource resource = createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL,
resourceSet.getPackageRegistry());
resource.getContents().add(packages[0]);
Resource resource2 =
createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL2,
resourceSet.getPackageRegistry());
resource2.getContents().add(packages[1]);
dataPackage1 = getPackageBytes(packages[0], true,
resourceSet.getPackageRegistry());
dataPackage2 = getPackageBytes(packages[1], true,
resourceSet.getPackageRegistry());
Assert.assertEquals(1,
((EClass)packages[0].getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
}

{
ResourceSet resourceSet = new ResourceSetImpl();
EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
dataPackage1, true, resourceSet.getPackageRegistry());

EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
dataPackage2, true, resourceSet
.getPackageRegistry());

// We wait until we have all packages in the registry before calling
resolveAll
EcoreUtil.resolveAll(package1);
EcoreUtil.resolveAll(package2);
Assert.assertEquals(1,
((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
}

{
ResourceSet resourceSet = new ResourceSetImpl();
EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
dataPackage1, true, resourceSet.getPackageRegistry());
// We Call resolveAll each time. It will initialized the internal
structure of EClassimpl.getEAllStructureFeatures
EcoreUtil.resolveAll(package1);

EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
dataPackage2, true, resourceSet
.getPackageRegistry());
EcoreUtil.resolveAll(package2);

// FAILING!!!!!!
Assert.assertEquals(1,
((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
}
}
Re: EcoreUitl.resolveAll [message #428086 is a reply to message #428085] Mon, 09 March 2009 20:12 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Oops I hit the post button.

Here the complete file for now! Don't look at variable name or method
name... they are not representative.

The problem I want to raise is the following:

Calling EcoreUtil.resolveAll() before having all packages in the
registry.. make it fail!

Simon

public class ExternalReferenceTest extends AbstractCDOTest
{

private static final String HTTP_WWW_ELVER_ORG_SCHOOL2 =
"http:///www.elver.org/School2";

private static final String HTTP_WWW_ELVER_ORG_SCHOOL =
"http:///www.elver.org/School";

public void testOneXMIResourceManyViewsOnOneResourceSet() throws
Exception
{
byte[] dataPackage1 = null;
byte[] dataPackage2 = null;
{

ResourceSet resourceSet = new ResourceSetImpl();
EPackage[] packages = createDynamicEPackage();
Resource resource = createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL,
resourceSet.getPackageRegistry());
resource.getContents().add(packages[0]);
Resource resource2 =
createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL2,
resourceSet.getPackageRegistry());
resource2.getContents().add(packages[1]);
dataPackage1 = getPackageBytes(packages[0], true,
resourceSet.getPackageRegistry());
dataPackage2 = getPackageBytes(packages[1], true,
resourceSet.getPackageRegistry());
Assert.assertEquals(1,
((EClass)packages[0].getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
}

{
ResourceSet resourceSet = new ResourceSetImpl();
EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
dataPackage1, true, resourceSet.getPackageRegistry());

EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
dataPackage2, true, resourceSet
.getPackageRegistry());

// We wait until we have all packages in the registry before calling
resolveAll
EcoreUtil.resolveAll(package1);
EcoreUtil.resolveAll(package2);
Assert.assertEquals(1,
((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
}

{
ResourceSet resourceSet = new ResourceSetImpl();
EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
dataPackage1, true, resourceSet.getPackageRegistry());
// We Call resolveAll each time. It will initialized the internal
structure of EClassimpl.getEAllStructureFeatures
// CALL THAT MAKE INITIALIZE INTERNAL STRUCTURE
EcoreUtil.resolveAll(package1);

EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
dataPackage2, true, resourceSet
.getPackageRegistry());
EcoreUtil.resolveAll(package1);
EcoreUtil.resolveAll(package2);

// FAILING!!!!!!
Assert.assertEquals(1,
((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
}
}

public static byte[] getPackageBytes(EPackage ePackage, boolean zipped,
EPackage.Registry packageRegistry)
{
try
{
Resource resource = ePackage.eResource();
if (resource == null)
{
resource = createPackageResource(ePackage.getNsURI(),
packageRegistry);
resource.getContents().add(ePackage);
}

ByteArrayOutputStream baos = new ByteArrayOutputStream();
resource.save(baos, createResourceOptions(zipped));
return baos.toByteArray();
}
catch (Exception ex)
{
throw WrappedException.wrap(ex);
}
}

public static EPackage createPackage(String uri, byte[] bytes, boolean
zipped, EPackage.Registry packageRegistry)
{
try
{
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Resource resource = createPackageResource(uri, packageRegistry);
resource.load(bais, createResourceOptions(zipped));

EList<EObject> contents = resource.getContents();
EPackage ePackage = (EPackage)contents.get(0);
packageRegistry.put(uri, ePackage);
// EcoreUtil.resolveAll(ePackage);
return ePackage;
}
catch (Exception ex)
{
throw WrappedException.wrap(ex);
}
}

private static Resource createPackageResource(String uri,
EPackage.Registry packageRegistry)
{
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.setPackageRegistry(packageRegistry);

Resource.Factory resourceFactory = new EcoreResourceFactoryImpl();

resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
resourceFactory);

resourceSet.getResourceFactoryRegistry().getProtocolToFactor yMap().put( "*",
resourceFactory);

return resourceSet.createResource(URI.createURI(uri));
}

private static Map<String, Object> createResourceOptions(boolean zipped)
{
Map<String, Object> options = new HashMap<String, Object>();
if (zipped)
{
options.put(Resource.OPTION_ZIP, true);
}

return options;
}

private EPackage[] createDynamicEPackage()
{
final EcoreFactory efactory = EcoreFactory.eINSTANCE;
final EcorePackage epackage = EcorePackage.eINSTANCE;

EClass schoolBookEClass = efactory.createEClass();
schoolBookEClass.setName("SchoolBook");

EClass schoolBook2EClass = efactory.createEClass();
schoolBook2EClass.setName("SchoolBook2");

// create a new attribute for this EClass
EAttribute level = efactory.createEAttribute();
level.setName("level");
level.setEType(epackage.getEInt());
schoolBook2EClass.getEStructuralFeatures().add(level);
schoolBookEClass.getESuperTypes().add(schoolBook2EClass);

// Create a new EPackage and add the new EClasses
EPackage schoolPackage = efactory.createEPackage();
schoolPackage.setName("elv");
schoolPackage.setNsPrefix("elv");
schoolPackage.setNsURI(HTTP_WWW_ELVER_ORG_SCHOOL);
schoolPackage.getEClassifiers().add(schoolBookEClass);

EPackage schoolPackage2 = efactory.createEPackage();
schoolPackage2.setName("elv");
schoolPackage2.setNsPrefix("elv");
schoolPackage2.setNsURI(HTTP_WWW_ELVER_ORG_SCHOOL2);
schoolPackage2.getEClassifiers().add(schoolBook2EClass);

return new EPackage[] { schoolPackage, schoolPackage2 };
}
}
Re: EcoreUitl.resolveAll [message #428095 is a reply to message #428086] Tue, 10 March 2009 13:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000005080004090800020701
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Simon,

Adding this one statement eliminates the problem:

EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
dataPackage2, true, resourceSet
.getPackageRegistry());

* package1.eResource().getResourceSet().getResources().remove( 1);*

EcoreUtil.resolveAll(package1);
EcoreUtil.resolveAll(package2);

Why you ask? Because in order to a proxy to fail to resolve, and
attempt to demand load the resource for the given URI will take place.
This will create in the resource set a resource with that URI. If
course if that resource fails to load, the contents will be empty and
the Resource.getErrors will contain information about what went wrong
during loading. Once the resource set is in this state, repeated
attempts to resolve the proxies will fail very quickly because they'll
find the loaded resource and then fail to find the object in that
resource. In order to resolution to try the whole process from scratch,
you'd need to minimally unload the resource so there will be an attempt
to load it again. But in your case, you're changing the registry so that
the proxy will resolve there, so in that case you need to remove the
bogus "failed" resource.


Simon Mc Duff wrote:
> Oops I hit the post button.
>
> Here the complete file for now! Don't look at variable name or method
> name... they are not representative.
>
> The problem I want to raise is the following:
>
> Calling EcoreUtil.resolveAll() before having all packages in the
> registry.. make it fail!
>
> Simon
>
> public class ExternalReferenceTest extends AbstractCDOTest
> {
>
> private static final String HTTP_WWW_ELVER_ORG_SCHOOL2 =
> "http:///www.elver.org/School2";
>
> private static final String HTTP_WWW_ELVER_ORG_SCHOOL =
> "http:///www.elver.org/School";
>
> public void testOneXMIResourceManyViewsOnOneResourceSet() throws
> Exception
> {
> byte[] dataPackage1 = null;
> byte[] dataPackage2 = null;
> {
>
> ResourceSet resourceSet = new ResourceSetImpl();
> EPackage[] packages = createDynamicEPackage();
> Resource resource =
> createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL,
> resourceSet.getPackageRegistry());
> resource.getContents().add(packages[0]);
> Resource resource2 =
> createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL2,
> resourceSet.getPackageRegistry());
> resource2.getContents().add(packages[1]);
> dataPackage1 = getPackageBytes(packages[0], true,
> resourceSet.getPackageRegistry());
> dataPackage2 = getPackageBytes(packages[1], true,
> resourceSet.getPackageRegistry());
> Assert.assertEquals(1,
> ((EClass)packages[0].getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
>
> }
>
> {
> ResourceSet resourceSet = new ResourceSetImpl();
> EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
> dataPackage1, true, resourceSet.getPackageRegistry());
>
> EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
> dataPackage2, true, resourceSet
> .getPackageRegistry());
>
> // We wait until we have all packages in the registry before
> calling resolveAll
> EcoreUtil.resolveAll(package1);
> EcoreUtil.resolveAll(package2);
> Assert.assertEquals(1,
> ((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
>
> }
>
> {
> ResourceSet resourceSet = new ResourceSetImpl();
> EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
> dataPackage1, true, resourceSet.getPackageRegistry());
> // We Call resolveAll each time. It will initialized the internal
> structure of EClassimpl.getEAllStructureFeatures
> // CALL THAT MAKE INITIALIZE INTERNAL STRUCTURE
> EcoreUtil.resolveAll(package1);
>
> EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
> dataPackage2, true, resourceSet
> .getPackageRegistry());
> EcoreUtil.resolveAll(package1);
> EcoreUtil.resolveAll(package2);
>
> // FAILING!!!!!!
> Assert.assertEquals(1,
> ((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
>
> }
> }
>
> public static byte[] getPackageBytes(EPackage ePackage, boolean
> zipped, EPackage.Registry packageRegistry)
> {
> try
> {
> Resource resource = ePackage.eResource();
> if (resource == null)
> {
> resource = createPackageResource(ePackage.getNsURI(),
> packageRegistry);
> resource.getContents().add(ePackage);
> }
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> resource.save(baos, createResourceOptions(zipped));
> return baos.toByteArray();
> }
> catch (Exception ex)
> {
> throw WrappedException.wrap(ex);
> }
> }
>
> public static EPackage createPackage(String uri, byte[] bytes,
> boolean zipped, EPackage.Registry packageRegistry)
> {
> try
> {
> ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
> Resource resource = createPackageResource(uri, packageRegistry);
> resource.load(bais, createResourceOptions(zipped));
>
> EList<EObject> contents = resource.getContents();
> EPackage ePackage = (EPackage)contents.get(0);
> packageRegistry.put(uri, ePackage);
> // EcoreUtil.resolveAll(ePackage);
> return ePackage;
> }
> catch (Exception ex)
> {
> throw WrappedException.wrap(ex);
> }
> }
>
> private static Resource createPackageResource(String uri,
> EPackage.Registry packageRegistry)
> {
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.setPackageRegistry(packageRegistry);
>
> Resource.Factory resourceFactory = new EcoreResourceFactoryImpl();
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
> resourceFactory);
>
> resourceSet.getResourceFactoryRegistry().getProtocolToFactor yMap().put( "*",
> resourceFactory);
>
> return resourceSet.createResource(URI.createURI(uri));
> }
>
> private static Map<String, Object> createResourceOptions(boolean zipped)
> {
> Map<String, Object> options = new HashMap<String, Object>();
> if (zipped)
> {
> options.put(Resource.OPTION_ZIP, true);
> }
>
> return options;
> }
>
> private EPackage[] createDynamicEPackage()
> {
> final EcoreFactory efactory = EcoreFactory.eINSTANCE;
> final EcorePackage epackage = EcorePackage.eINSTANCE;
>
> EClass schoolBookEClass = efactory.createEClass();
> schoolBookEClass.setName("SchoolBook");
>
> EClass schoolBook2EClass = efactory.createEClass();
> schoolBook2EClass.setName("SchoolBook2");
>
> // create a new attribute for this EClass
> EAttribute level = efactory.createEAttribute();
> level.setName("level");
> level.setEType(epackage.getEInt());
> schoolBook2EClass.getEStructuralFeatures().add(level);
> schoolBookEClass.getESuperTypes().add(schoolBook2EClass);
>
> // Create a new EPackage and add the new EClasses
> EPackage schoolPackage = efactory.createEPackage();
> schoolPackage.setName("elv");
> schoolPackage.setNsPrefix("elv");
> schoolPackage.setNsURI(HTTP_WWW_ELVER_ORG_SCHOOL);
> schoolPackage.getEClassifiers().add(schoolBookEClass);
>
> EPackage schoolPackage2 = efactory.createEPackage();
> schoolPackage2.setName("elv");
> schoolPackage2.setNsPrefix("elv");
> schoolPackage2.setNsURI(HTTP_WWW_ELVER_ORG_SCHOOL2);
> schoolPackage2.getEClassifiers().add(schoolBook2EClass);
>
> return new EPackage[] { schoolPackage, schoolPackage2 };
> }
> }
>
>

--------------000005080004090800020701
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">
Simon,<br>
<br>
Adding this one statement eliminates the problem:<br>
<br>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EcoreUitl.resolveAll [message #428097 is a reply to message #428095] Tue, 10 March 2009 13:45 Go to previous message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
It worked!

I understand!

Thank you Ed for your analyze!!

> Simon,

> Adding this one statement eliminates the problem:

> EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
> dataPackage2, true, resourceSet
> .getPackageRegistry());

> * package1.eResource().getResourceSet().getResources().remove( 1);*

> EcoreUtil.resolveAll(package1);
> EcoreUtil.resolveAll(package2);

> Why you ask? Because in order to a proxy to fail to resolve, and
> attempt to demand load the resource for the given URI will take place.
> This will create in the resource set a resource with that URI. If
> course if that resource fails to load, the contents will be empty and
> the Resource.getErrors will contain information about what went wrong
> during loading. Once the resource set is in this state, repeated
> attempts to resolve the proxies will fail very quickly because they'll
> find the loaded resource and then fail to find the object in that
> resource. In order to resolution to try the whole process from scratch,
> you'd need to minimally unload the resource so there will be an attempt
> to load it again. But in your case, you're changing the registry so that
> the proxy will resolve there, so in that case you need to remove the
> bogus "failed" resource.


> Simon Mc Duff wrote:
>> Oops I hit the post button.
>>
>> Here the complete file for now! Don't look at variable name or method
>> name... they are not representative.
>>
>> The problem I want to raise is the following:
>>
>> Calling EcoreUtil.resolveAll() before having all packages in the
>> registry.. make it fail!
>>
>> Simon
>>
>> public class ExternalReferenceTest extends AbstractCDOTest
>> {
>>
>> private static final String HTTP_WWW_ELVER_ORG_SCHOOL2 =
>> "http:///www.elver.org/School2";
>>
>> private static final String HTTP_WWW_ELVER_ORG_SCHOOL =
>> "http:///www.elver.org/School";
>>
>> public void testOneXMIResourceManyViewsOnOneResourceSet() throws
>> Exception
>> {
>> byte[] dataPackage1 = null;
>> byte[] dataPackage2 = null;
>> {
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>> EPackage[] packages = createDynamicEPackage();
>> Resource resource =
>> createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL,
>> resourceSet.getPackageRegistry());
>> resource.getContents().add(packages[0]);
>> Resource resource2 =
>> createPackageResource(HTTP_WWW_ELVER_ORG_SCHOOL2,
>> resourceSet.getPackageRegistry());
>> resource2.getContents().add(packages[1]);
>> dataPackage1 = getPackageBytes(packages[0], true,
>> resourceSet.getPackageRegistry());
>> dataPackage2 = getPackageBytes(packages[1], true,
>> resourceSet.getPackageRegistry());
>> Assert.assertEquals(1,
>>
((EClass)packages[0].getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
>>
>> }
>>
>> {
>> ResourceSet resourceSet = new ResourceSetImpl();
>> EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
>> dataPackage1, true, resourceSet.getPackageRegistry());
>>
>> EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
>> dataPackage2, true, resourceSet
>> .getPackageRegistry());
>>
>> // We wait until we have all packages in the registry before
>> calling resolveAll
>> EcoreUtil.resolveAll(package1);
>> EcoreUtil.resolveAll(package2);
>> Assert.assertEquals(1,
>>
((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
>>
>> }
>>
>> {
>> ResourceSet resourceSet = new ResourceSetImpl();
>> EPackage package1 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL,
>> dataPackage1, true, resourceSet.getPackageRegistry());
>> // We Call resolveAll each time. It will initialized the internal
>> structure of EClassimpl.getEAllStructureFeatures
>> // CALL THAT MAKE INITIALIZE INTERNAL STRUCTURE
>> EcoreUtil.resolveAll(package1);
>>
>> EPackage package2 = createPackage(HTTP_WWW_ELVER_ORG_SCHOOL2,
>> dataPackage2, true, resourceSet
>> .getPackageRegistry());
>> EcoreUtil.resolveAll(package1);
>> EcoreUtil.resolveAll(package2);
>>
>> // FAILING!!!!!!
>> Assert.assertEquals(1,
>>
((EClass)package1.getEClassifier("SchoolBook")).getEAllStructuralFeatures().size());
>>
>> }
>> }
>>
>> public static byte[] getPackageBytes(EPackage ePackage, boolean
>> zipped, EPackage.Registry packageRegistry)
>> {
>> try
>> {
>> Resource resource = ePackage.eResource();
>> if (resource == null)
>> {
>> resource = createPackageResource(ePackage.getNsURI(),
>> packageRegistry);
>> resource.getContents().add(ePackage);
>> }
>>
>> ByteArrayOutputStream baos = new ByteArrayOutputStream();
>> resource.save(baos, createResourceOptions(zipped));
>> return baos.toByteArray();
>> }
>> catch (Exception ex)
>> {
>> throw WrappedException.wrap(ex);
>> }
>> }
>>
>> public static EPackage createPackage(String uri, byte[] bytes,
>> boolean zipped, EPackage.Registry packageRegistry)
>> {
>> try
>> {
>> ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
>> Resource resource = createPackageResource(uri, packageRegistry);
>> resource.load(bais, createResourceOptions(zipped));
>>
>> EList<EObject> contents = resource.getContents();
>> EPackage ePackage = (EPackage)contents.get(0);
>> packageRegistry.put(uri, ePackage);
>> // EcoreUtil.resolveAll(ePackage);
>> return ePackage;
>> }
>> catch (Exception ex)
>> {
>> throw WrappedException.wrap(ex);
>> }
>> }
>>
>> private static Resource createPackageResource(String uri,
>> EPackage.Registry packageRegistry)
>> {
>> ResourceSet resourceSet = new ResourceSetImpl();
>> resourceSet.setPackageRegistry(packageRegistry);
>>
>> Resource.Factory resourceFactory = new EcoreResourceFactoryImpl();
>>
>>
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
>> resourceFactory);
>>
>> resourceSet.getResourceFactoryRegistry().getProtocolToFactor yMap().put( "*",
>> resourceFactory);
>>
>> return resourceSet.createResource(URI.createURI(uri));
>> }
>>
>> private static Map<String, Object> createResourceOptions(boolean zipped)
>> {
>> Map<String, Object> options = new HashMap<String, Object>();
>> if (zipped)
>> {
>> options.put(Resource.OPTION_ZIP, true);
>> }
>>
>> return options;
>> }
>>
>> private EPackage[] createDynamicEPackage()
>> {
>> final EcoreFactory efactory = EcoreFactory.eINSTANCE;
>> final EcorePackage epackage = EcorePackage.eINSTANCE;
>>
>> EClass schoolBookEClass = efactory.createEClass();
>> schoolBookEClass.setName("SchoolBook");
>>
>> EClass schoolBook2EClass = efactory.createEClass();
>> schoolBook2EClass.setName("SchoolBook2");
>>
>> // create a new attribute for this EClass
>> EAttribute level = efactory.createEAttribute();
>> level.setName("level");
>> level.setEType(epackage.getEInt());
>> schoolBook2EClass.getEStructuralFeatures().add(level);
>> schoolBookEClass.getESuperTypes().add(schoolBook2EClass);
>>
>> // Create a new EPackage and add the new EClasses
>> EPackage schoolPackage = efactory.createEPackage();
>> schoolPackage.setName("elv");
>> schoolPackage.setNsPrefix("elv");
>> schoolPackage.setNsURI(HTTP_WWW_ELVER_ORG_SCHOOL);
>> schoolPackage.getEClassifiers().add(schoolBookEClass);
>>
>> EPackage schoolPackage2 = efactory.createEPackage();
>> schoolPackage2.setName("elv");
>> schoolPackage2.setNsPrefix("elv");
>> schoolPackage2.setNsURI(HTTP_WWW_ELVER_ORG_SCHOOL2);
>> schoolPackage2.getEClassifiers().add(schoolBook2EClass);
>>
>> return new EPackage[] { schoolPackage, schoolPackage2 };
>> }
>> }
>>
>>
Previous Topic:A Question about JET Tutorial 1
Next Topic:code generation guidance, in the interest of (my) time.
Goto Forum:
  


Current Time: Fri Apr 26 22:21:08 GMT 2024

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

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

Back to the top