Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Blackbox library in a standalone QVTo transformation
Blackbox library in a standalone QVTo transformation [message #1220745] Fri, 13 December 2013 11:30 Go to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 59
Registered: August 2013
Member
Hi

I'm trying to follow Michael Heerklotz suggestion:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=326871#c10

Here is my code
        IExtensionRegistry ecliseRegistry = RegistryFactory.createRegistry(null, null, null);
        FileInputStream is = new FileInputStream("plugin.xml");
        RegistryContributor contributor = new RegistryContributor("1", "test", null, null);
        ecliseRegistry.addContribution(is, contributor, false, null, null, null);
        
        for (IExtension ext : ecliseRegistry.getExtensions(contributor)) {
            if (ext.getExtensionPointUniqueIdentifier().equals("org.eclipse.m2m.qvt.oml.javaBlackboxUnits")) {
                for (IConfigurationElement config : ext.getConfigurationElements()) {
                    // JavaBlackboxProvider jbp = new JavaBlackboxProvider();
                    Class<?> providerClass = Class.forName("org.eclipse.m2m.internal.qvt.oml.blackbox.java.JavaBlackboxProvider"); 
                    Object jbp = providerClass.newInstance();
                    
                    // JavaBlackboxProvider.Descriptor descriptor = jbp.createDescriptor(unit);
                    Method createDescriptor = providerClass.getDeclaredMethod("createDescriptor", IConfigurationElement.class);
                    createDescriptor.setAccessible(true);
                    Object descriptor = createDescriptor.invoke(jbp, config);
                    
                    // jbp.fDescriptorMap = new HashMap<?,?>();
                    Field fDescriptorMapField = providerClass.getDeclaredField("fDescriptorMap");
                    fDescriptorMapField.setAccessible(true);
                    fDescriptorMapField.set(jbp, HashMap.class.newInstance());

                    // jbp.fDescriptorMap.put(id, descriptor);
                    Object fDescriptorMap = fDescriptorMapField.get(jbp);
                    Method putMethod = fDescriptorMapField.getType().getDeclaredMethod("put", Object.class, Object.class);
                    putMethod.invoke(fDescriptorMap, "id", descriptor);

                    // BlackboxRegistry.INSTANCE.fProviders = new LinkedList<?>()
                    Class<?> registryClass = Class.forName("org.eclipse.m2m.internal.qvt.oml.blackbox.BlackboxRegistry"); 
                    Field registryInstanceField = registryClass.getDeclaredField("INSTANCE");
                    Object registryInstance = registryInstanceField.get(null);
                    Field fProvidersField = registryClass.getDeclaredField("fProviders");
                    fProvidersField.setAccessible(true);
                    fProvidersField.set(registryInstance, LinkedList.class.newInstance());
                    
                    // BlackboxRegistry.INSTANCE.fProviders.add(jbp);
                    Object fProviders = fProvidersField.get(registryInstance);
                    Method addMethod = fProvidersField.getType().getDeclaredMethod("add", Object.class);
                    addMethod.invoke(fProviders, jbp);
                }
            }
        }

Full version is here:
https://github.com/AresEkb/OclToXPath

But blackbox library still doesn't work. Could someone help me?
Re: Blackbox library in a standalone QVTo transformation [message #1220758 is a reply to message #1220745] Fri, 13 December 2013 12:39 Go to previous message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 59
Registered: August 2013
Member
I works!!

This line
                    putMethod.invoke(fDescriptorMap, "id", descriptor);

should be replaced by
                    putMethod.invoke(fDescriptorMap, "m2m.qvt.oml.ExampleJavaLib", descriptor);

Thanks a lot to Michael. I hope the code will be helpful for somebody else.
Previous Topic:How to create javax.xml.namespace.QName?
Next Topic:OCL Errors in StandAlone QVTo
Goto Forum:
  


Current Time: Sat Oct 25 09:42:17 GMT 2014

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

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