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 |
Denis Nikiforov Messages: 346 Registered: August 2013 |
Senior 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 #1699267 is a reply to message #1220758] |
Tue, 23 June 2015 07:43 |
Denis Nikiforov Messages: 346 Registered: August 2013 |
Senior Member |
|
|
Hi
The API for blackbox libraries was added:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=326871
Thanks a lot!
But, can you provide an example? How to use it?
The following code reads blackbox unit descriptions from plugin.xml and registers them:
private static void registerBlackboxUnits() throws FileNotFoundException, ClassNotFoundException, InvalidRegistryObjectException
{
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()) {
List<String> packageURIs = new ArrayList<String>();
for (IConfigurationElement chld : config.getChildren()) {
packageURIs.add(chld.getAttribute("nsURI"));
}
BlackboxRegistry.INSTANCE.addStandaloneModule(
Class.forName(config.getAttribute("class")),
"uml2xsd." + config.getAttribute("name"),
config.getAttribute("name"),
packageURIs.toArray(new String[] {}));
}
}
}
}
But I receive the warning:
Discouraged access: The method 'BlackboxRegistry.addStandaloneModule(Class<?>, String, String, String[])' is not API (restriction on required library 'C:\Work\eclipse\plugins\org.eclipse.m2m.qvt.oml_3.5.0.v20150603-1058.jar')
And also the code looks very ugly. Is there a better approach?
[Updated on: Tue, 23 June 2015 07:43] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Tue Sep 24 11:56:58 GMT 2024
Powered by FUDForum. Page generated in 0.03811 seconds
|