[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[News.eclipse.modeling.mddi] Using custom resources in ModelBus

Hello Stefan Dellmuth,

In EMF, classes implementing the "Resource" interface are used for managing 
the loading and saving of models (from stream or files).

A ResourceSet is responsible for creating the instances of Resource with the 
method "createResource(URI uri)" or
"getResource(URI uri, boolean loadOnDemand)".
In the default implementation of these methods,
the file extension in the URI is used for determining the concrete Resource 
implementation class to be instantiated.

Therefore, if you have your custom resource implementation class (lets say 
MyResourceImpl),
Then you may tell ModelBus to serialize/deserialize these custom resources 
with the saving/loading mechanism provided by MyResourceImpl.

To so do, you may associate this class with the file extension *.my_xmi. 
(This is similar to how the UML2 plugin associaite the UML2Resource with the 
file extension *.uml2).
1) You provide the class MyResourceImplFactory implementing 
Resource.Factory.
2) At the begining of the programs (both client side and service side), you 
execute this code :

        Map m = 
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();
        m.put("my_xmi", new MyResourceImplFactory() );

3) If you want to send a custom resource via ModelBus, you make sur that the 
URI of this resource has the extension *.my_xmi.

//Use ResourceSet to to create and load resource
ResourceSet rs = new ResourceSetImpl();
Resource r = 
rs.getResource(URI.createFileURI("C:/Programme/Eclipse/workspace/ModelBus%20Test/rsc/xml/TestModel2.my_xmi"), 
true);
// make sure that r is instanceof MyResourceImpl
System.out.println("r intanceof MyResourceImpl? " + (r instanceof 
MyResourceImpl));
// Then, pass the EMF elements in this resource to the service normally.
...

4) At the service side, make sure the MyResourceImplFactory is registered 
before the receiving any invocations (see step2).
The DefaultModelSerializer of ModelBus will use your custom class to 
instantiate a resource and load the transmitted data (see method 
DefaultModelSerializer.deserialize for more detail).

Please do not hesitate to ask any further questions.


Regards,
----------------------------
Prawee SRIPLAKICH
LIP6 - Université Pierre et Marie Curie

104 Avenue du Président Kennedy
75016 Paris

Tel:   +33 (0) 1 44 27 88 61
Fax : +33 (0) 1 44 27 87 71

http://www-src.lip6.fr/homepages/Prawee.Sriplakich/
----------------------------





"Stefan Dellmuth" <sdellmuth@xxxxxxxxxxxxxxxx> a écrit dans le message de 
news: el9bf4$o71$1@xxxxxxxxxxxxxxxxxxxx
> First, I have to thank you! The patch helped a lot!
>
> But, after some more programming, I have a new problem (which is not a 
> bug, I suppose): I want to send an EMF model over the bus, but in order to 
> load the model, a custom resource implementation is necessary.
>
> Of course the DefaultSerializer doesn't know about the custom resource 
> implementation, which leads to errors during deserialization:
>
> 9954 [Thread-4] ERROR 
> org.eclipse.mddi.modelbus.adapter.infrastructure.serialize.emf_xmi.DefaultModelSerializer 
>  - org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Class 
> 'Testmodell' not found. 
> (file:///C:/Programme/Eclipse/workspace/ModelBus%20Test/rsc/xml/TestModel2.xml, 
> 2, 173)
> 9954 [Thread-4] ERROR 
> org.eclipse.mddi.modelbus.adapter.infrastructure.serialize.emf_xmi.DefaultModelSerializer 
>  - Resource with URI rsc/xml/TestModel2.xml is null.
> (This error is repeated for each model element)
> 10135 [Thread-4] ERROR 
> org.eclipse.mddi.modelbus.adapter.infrastructure.transport.ws.DefaultWsInvocationReceiver 
>  - An error occured during invocation process
>
> As a consequence, an empty Vector arrives at the receiver.
>
> Is there a possibility:
> 1) to register my resource somehow? I tried with ModelBusResourceSet and 
> GlobalResourceRegistry, but without success.
> 2) to "configure" the DefaultSerializer so that it can user the custom 
> resource?
>
> Best regards,
> Stefan Dellmuth