Skip to main content



      Home
Home » Modeling » EMF » Loading proxy resources
Loading proxy resources [message #395962] Fri, 30 September 2005 15:16 Go to next message
Eclipse UserFriend
Originally posted by: bdberry.us.ibm.com

ok, I have the objects in my model saving to seperate files. I can load
the parent object from its file fine and I see that the proxy object is
described as...

com.ibm.enav.model.service.impl.ServiceDefinitionImpl@176c74b
(eProxyURI: services.srv#/)

However, making any calls to this object in order to retrieve attributes
that exist in the resource to which it was persisted (xml file) do not
work. How do I force the loading of the proxy? I thought that was
supposed to be built in with the lazy loading scheme.
Re: Loading proxy resources [message #395963 is a reply to message #395962] Fri, 30 September 2005 15:26 Go to previous messageGo to next message
Eclipse UserFriend
Brian Berry wrote:
> ok, I have the objects in my model saving to seperate files. I can load
> the parent object from its file fine and I see that the proxy object is
> described as...
>
> com.ibm.enav.model.service.impl.ServiceDefinitionImpl@176c74b
> (eProxyURI: services.srv#/)
>
> However, making any calls to this object in order to retrieve attributes
> that exist in the resource to which it was persisted (xml file) do not
> work. How do I force the loading of the proxy? I thought that was
> supposed to be built in with the lazy loading scheme.

ECoreUtil.resolve*

Look at those set of methods...

Cheers,

~ Chris
Re: Loading proxy resources [message #395964 is a reply to message #395962] Fri, 30 September 2005 16:06 Go to previous messageGo to next message
Eclipse UserFriend
Brian,

Be sure that you've set resolveProxies to true.

I'm suspicious that your proxy's URI is not an absolute URI. This makes
me think that you didn't create such a good URI when you saved the
file. It's best to use an absolute URI and so when saving to the file
system, a pattern like this works best URI.createFileURI(new
java.io.File(filepath).getAbsolutePath()). If you use just a file name
you are relying on the current directory being correct (and your cross
file references won't be deresolved to be nice relative URIs).

I also didn't see any resource set in your previous examples. Your
resource needs to be in a resource set to be able to resolve proxies,
since resolving a proxy requires that a resource be demand loaded into
the containing resource set. I should have thought to mention that
earlier. It's probably a good idea to look at the generated
XyzExample.java in generated *.tests plugin since it shows the general
pattern you'd normally follow to be able to use a set of interrelated
resources.


Brian Berry wrote:

> ok, I have the objects in my model saving to seperate files. I can
> load the parent object from its file fine and I see that the proxy
> object is described as...
>
> com.ibm.enav.model.service.impl.ServiceDefinitionImpl@176c74b
> (eProxyURI: services.srv#/)
>
> However, making any calls to this object in order to retrieve
> attributes that exist in the resource to which it was persisted (xml
> file) do not work. How do I force the loading of the proxy? I
> thought that was supposed to be built in with the lazy loading scheme.
Re: Loading proxy resources [message #395966 is a reply to message #395963] Fri, 30 September 2005 16:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bdberry.us.ibm.com

Chris Aniszczyk wrote:
> Brian Berry wrote:
>
>> ok, I have the objects in my model saving to seperate files. I can
>> load the parent object from its file fine and I see that the proxy
>> object is described as...
>>
>> com.ibm.enav.model.service.impl.ServiceDefinitionImpl@176c74b
>> (eProxyURI: services.srv#/)
>>
>> However, making any calls to this object in order to retrieve
>> attributes that exist in the resource to which it was persisted (xml
>> file) do not work. How do I force the loading of the proxy? I
>> thought that was supposed to be built in with the lazy loading scheme.
>
>
> ECoreUtil.resolve*
>
> Look at those set of methods...
>
> Cheers,
>
> ~ Chris
Seems to have no effect. Here is my method for loading a file...

public static EObject loadFile(String fileName) throws IOException {
EObject result = null;
Map options = new HashMap();
Map map = new HashMap();
Resource resource = null;

SolutionPackageImpl.init();
ControlPackageImpl.init();
ServicePackageImpl.init();

Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
map = reg.getExtensionToFactoryMap();
map.put("*", new XMIResourceFactoryImpl());
resource = new XMIResourceImpl(URI.createFileURI(fileName));
options.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE);
options.put(XMIResource.OPTION_ENCODING, "UTF-8");
resource.load(options);
result = (EObject) resource.getContents().get(0);

return result;
}


My test code is as follows...

engagementInfo = (EngagementInfo)EmfObjectHandler.load("testme-def.enav");

EcoreUtil.resolveAll(engagementInfo);
printServiceDefinition(engagementInfo.getServiceDefinition() );


the call to getServiceDefinition should get an EMF object that has been
persisted to a seperate file. However, my print method returns null as
if is not loaded properly. The rest of my EngagementInfo object seems
fine - just the proxy references seem useless.
Re: Loading proxy resources [message #395967 is a reply to message #395966] Fri, 30 September 2005 17:46 Go to previous messageGo to next message
Eclipse UserFriend
Brian Berry wrote:
> Chris Aniszczyk wrote:
>
>> Brian Berry wrote:
>>
>>> ok, I have the objects in my model saving to seperate files. I can
>>> load the parent object from its file fine and I see that the proxy
>>> object is described as...
>>>
>>> com.ibm.enav.model.service.impl.ServiceDefinitionImpl@176c74b
>>> (eProxyURI: services.srv#/)
>>>
>>> However, making any calls to this object in order to retrieve
>>> attributes that exist in the resource to which it was persisted (xml
>>> file) do not work. How do I force the loading of the proxy? I
>>> thought that was supposed to be built in with the lazy loading scheme.
>>
>>
>>
>> ECoreUtil.resolve*
>>
>> Look at those set of methods...
>>
>> Cheers,
>>
>> ~ Chris
>
> Seems to have no effect. Here is my method for loading a file...
>
> public static EObject loadFile(String fileName) throws IOException {
> EObject result = null;
> Map options = new HashMap();
> Map map = new HashMap();
> Resource resource = null;
>
> SolutionPackageImpl.init();
> ControlPackageImpl.init();
> ServicePackageImpl.init();
>
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> map = reg.getExtensionToFactoryMap();
> map.put("*", new XMIResourceFactoryImpl());
> resource = new XMIResourceImpl(URI.createFileURI(fileName));
> options.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE);
> options.put(XMIResource.OPTION_ENCODING, "UTF-8");
> resource.load(options);
> result = (EObject) resource.getContents().get(0);
>
> return result;
> }
>
>
> My test code is as follows...
>
> engagementInfo = (EngagementInfo)EmfObjectHandler.load("testme-def.enav");
>
> EcoreUtil.resolveAll(engagementInfo);
> printServiceDefinition(engagementInfo.getServiceDefinition() );
>
>
> the call to getServiceDefinition should get an EMF object that has been
> persisted to a seperate file. However, my print method returns null as
> if is not loaded properly. The rest of my EngagementInfo object seems
> fine - just the proxy references seem useless.

Like Ed said, ResourceSet is your friend if you need to resolve proxies.

Ctrl+Shift+T, ResourceSet, go!

Cheers,

~ Chris
Re: Loading proxy resources [message #395969 is a reply to message #395964] Sat, 01 October 2005 01:19 Go to previous message
Eclipse UserFriend
Originally posted by: bdberry.us.ibm.com

Ed Merks wrote:
> Brian,
>
> Be sure that you've set resolveProxies to true.
> I'm suspicious that your proxy's URI is not an absolute URI. This makes
> me think that you didn't create such a good URI when you saved the
> file. It's best to use an absolute URI and so when saving to the file
> system, a pattern like this works best URI.createFileURI(new
> java.io.File(filepath).getAbsolutePath()). If you use just a file name
> you are relying on the current directory being correct (and your cross
> file references won't be deresolved to be nice relative URIs).
> I also didn't see any resource set in your previous examples. Your
> resource needs to be in a resource set to be able to resolve proxies,
> since resolving a proxy requires that a resource be demand loaded into
> the containing resource set. I should have thought to mention that
> earlier. It's probably a good idea to look at the generated
> XyzExample.java in generated *.tests plugin since it shows the general
> pattern you'd normally follow to be able to use a set of interrelated
> resources.
>
>
> Brian Berry wrote:
>
>> ok, I have the objects in my model saving to seperate files. I can
>> load the parent object from its file fine and I see that the proxy
>> object is described as...
>>
>> com.ibm.enav.model.service.impl.ServiceDefinitionImpl@176c74b
>> (eProxyURI: services.srv#/)
>>
>> However, making any calls to this object in order to retrieve
>> attributes that exist in the resource to which it was persisted (xml
>> file) do not work. How do I force the loading of the proxy? I
>> thought that was supposed to be built in with the lazy loading scheme.
>
>
I changed my load and save code to use the resource set and everything
works great now - thanks. I have been using the same load/save code
since EMF v1.x and I never needed to load from seperate files so I never
discovered a different way to do it. This was very helpful.
Previous Topic:SDO Code generation without eclipse installation
Next Topic:A problem with ecore imported from xsd file
Goto Forum:
  


Current Time: Sun Aug 03 17:54:20 EDT 2025

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

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

Back to the top